:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6672;
  --line: #d9dde3;
  --line-strong: #b9bfc8;
  --accent: #1a73e8;
  --yes-bg: #b7e1cd;
  --yes-text: #0d5c2c;
  --no-bg: #f4c7c3;
  --no-text: #8c1d18;
  --na-bg: #eceef1;
  --hell: #c5221f;
  --god: #b06000;
  --me-bg: #e8f0fe;
  --toast-bg: #202124;
  --toast-text: #ffffff;
  --error: #c5221f;
  --side-w: 210px;
  --col-w: 112px;
  --row-h: 26px;
  --head-h: 112px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1d2024;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2f343a;
    --line-strong: #444b53;
    --accent: #8ab4f8;
    --yes-bg: #1e4d33;
    --yes-text: #b7f0cc;
    --no-bg: #4d2422;
    --no-text: #f6c4bf;
    --na-bg: #24282d;
    --hell: #f28b82;
    --god: #fdd663;
    --me-bg: #1f2d44;
    --toast-bg: #e6e8eb;
    --toast-text: #15171a;
    --error: #f28b82;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1d2024;
  --text: #e6e8eb;
  --muted: #9aa1ab;
  --line: #2f343a;
  --line-strong: #444b53;
  --accent: #8ab4f8;
  --yes-bg: #1e4d33;
  --yes-text: #b7f0cc;
  --no-bg: #4d2422;
  --no-text: #f6c4bf;
  --na-bg: #24282d;
  --hell: #f28b82;
  --god: #fdd663;
  --me-bg: #1f2d44;
  --toast-bg: #e6e8eb;
  --toast-text: #15171a;
  --error: #f28b82;
  color-scheme: dark;
}

@media (max-width: 640px) {
  :root {
    --side-w: 150px;
    --col-w: 96px;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand h1 { font-size: 17px; margin: 0; white-space: nowrap; }
.badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 7px;
}

.user { display: flex; align-items: center; gap: 10px; font-size: 13px; white-space: nowrap; }
.user .muted { color: var(--muted); }
.button {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  text-decoration: none;
}
.button:hover { border-color: var(--accent); color: var(--accent); }
.button.primary { background: #5865f2; border-color: #5865f2; color: #fff; }
.button.primary:hover { background: #4752c4; color: #fff; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.tabs button {
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 6px 11px;
  cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] {
  color: var(--text);
  background: var(--bg);
  border-color: var(--line);
  font-weight: 600;
}
.tabs button.hell { color: var(--hell); }
.tabs button.god { color: var(--god); }
.tabs .sep { width: 1px; background: var(--line); margin: 6px 4px; flex: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
}
.toolbar input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px 9px;
  width: 210px;
  max-width: 100%;
}
.toolbar input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.info { color: var(--muted); font-size: 12px; margin-left: auto; }

.notice {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
}

main { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 16px 16px; }
.loading, .empty { color: var(--muted); }

/* the sheet grid: a corner, the jump names, the player names and the cells, only the visible ones drawn */
.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  grid-template-rows: var(--head-h) 1fr;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}
.corner {
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--muted);
}
.corner strong { color: var(--text); font-size: 14px; }
.head-wrap, .side-wrap { overflow: hidden; position: relative; }
.head-wrap { border-bottom: 1px solid var(--line-strong); }
.side-wrap { border-right: 1px solid var(--line-strong); }
.head, .side { position: absolute; top: 0; left: 0; will-change: transform; }
.body { overflow: auto; position: relative; }
.cells { position: absolute; top: 0; left: 0; }

.h {
  position: absolute;
  top: 0;
  width: var(--col-w);
  height: var(--head-h);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.h .name {
  flex: 1;
  padding: 5px 6px 0;
  font-size: 12px;
  line-height: 15px;
  font-weight: 600;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.h .count {
  height: 22px;
  padding: 0 6px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
}

.s {
  position: absolute;
  left: 0;
  width: var(--side-w);
  height: var(--row-h);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  font-size: 13px;
}
.s .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s .name small { color: var(--muted); }
.s .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.s.me { background: var(--me-bg); font-weight: 600; }

.c {
  position: absolute;
  width: var(--col-w);
  height: var(--row-h);
  border-right: 1px solid var(--surface);
  border-bottom: 1px solid var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  user-select: none;
}
.c.y { background: var(--yes-bg); color: var(--yes-text); }
.c.n { background: var(--no-bg); color: var(--no-text); }
.c.na { background: var(--na-bg); }
.c.edit { cursor: pointer; }
.c.edit:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.c.saving { opacity: 0.55; }

/* leaderboard */
.board {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
}
.board table { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
.board th, .board td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.board th {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.board th.hell { color: var(--hell); }
.board th.god { color: var(--god); }
.board .rank, .board .player { text-align: left; }
.board td.player { font-weight: 600; }
.board td.zero { color: var(--muted); }
.board td.total { font-weight: 700; }
.board tr.me td { background: var(--me-bg); }
.board .player small { color: var(--muted); font-weight: 400; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.toast.error { background: var(--error); color: #fff; }
