:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #1d1b19;
  --muted: #77716a;
  --line: #e2ddd5;
  --accent: #2f6fde;
  --fail: #d6336c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 6px 18px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131211;
    --surface: #1e1c1a;
    --surface-2: #252320;
    --ink: #f1ece4;
    --muted: #9b948a;
    --line: #36322e;
    --accent: #6a9bff;
    --fail: #ff6b98;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131211;
  --surface: #1e1c1a;
  --surface-2: #252320;
  --ink: #f1ece4;
  --muted: #9b948a;
  --line: #36322e;
  --accent: #6a9bff;
  --fail: #ff6b98;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }

/* ---------- theme toggle ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0; flex: none;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme]) .theme-toggle .icon-moon { display: block; }
}

/* ---------- dashboard ---------- */
.home {
  max-width: 1160px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.home-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.home-head h1 { margin: 0; font-size: clamp(28px, 5vw, 40px); font-weight: 800; letter-spacing: -0.02em; }
.home-head p { margin: 4px 0 0; color: var(--muted); }

.genre { margin-top: 28px; }
.genre-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.genre-head h2 { margin: 0; font-size: 20px; font-weight: 750; }
.genre-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.arrows { display: flex; gap: 6px; flex: none; }
.arrows button {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 16px; cursor: pointer;
}
.arrows button:disabled { opacity: 0.35; cursor: default; }
.arrows button:not(:disabled):hover { border-color: var(--muted); }

.track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(220px, 260px);
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 4px;
  padding: 4px 4px 14px;
  margin: 0 -4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.card {
  scroll-snap-align: start;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgb(0 0 0 / 0.12); }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card .art {
  position: relative;
  aspect-ratio: 16 / 9;
  display: grid; place-items: center;
  font-size: 56px;
  background:
    radial-gradient(circle at 25% 20%, rgb(255 255 255 / 0.35), transparent 55%),
    linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 55%, #000));
}
.card .art span { filter: drop-shadow(0 4px 8px rgb(0 0 0 / 0.25)); }
/* The screenshot covers the emoji; if it fails to load, the emoji shows instead. */
.card .art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card .ext {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 999px; color: #fff; background: rgb(0 0 0 / 0.3);
}
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card h3 { margin: 0; font-size: 17px; font-weight: 750; }
.card .blurb { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.35; flex: 1; }
.card .scores { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.card .scores strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- game page ---------- */
.play {
  max-width: 720px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.play.wide { max-width: 900px; }
.play-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.play-head h1 { margin: 0; font-size: 18px; font-weight: 750; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back {
  display: inline-flex; align-items: center; height: 36px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; font-weight: 600; font-size: 14px; flex: none;
}
.back:hover { border-color: var(--muted); }
.stats { display: flex; gap: 18px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.value { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
@media (max-width: 480px) {
  .back span { display: none; }
  .play-head h1 { font-size: 16px; }
  .stats { gap: 12px; }
  .value { font-size: 1.25rem; }
}

.stage {
  position: relative;
  width: 100%;
  min-width: 260px;
  margin: 0 auto;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}
.stage canvas { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 16px; text-align: center;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.o-title { margin: 0; font-size: clamp(1.6rem, 6vw, 2.4rem); font-weight: 800; }
.o-title.fail { color: var(--fail); }
.o-msg { margin: 0 0 8px; color: var(--muted); max-width: 34ch; }
.o-btn {
  font: inherit; font-size: 1.05rem; font-weight: 700;
  padding: 12px 32px; border: 0; border-radius: 999px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.o-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.o-hint { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }
.o-level { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.o-level select {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; cursor: pointer;
}
.lvl-tag {
  display: inline-block; vertical-align: 2px; margin-left: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #fff; background: #e08a2c;
}
.lvl-tag[data-lv="hardest"] { background: var(--fail); }
.lvl-tag[hidden] { display: none; }

.board { margin-top: 28px; }
.board h2 { font-size: 1rem; font-weight: 700; margin: 0 0 12px; }
.board-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.board-head h2 { margin: 0; }
.tabs { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.tabs button {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
  border: 0; border-radius: 8px; padding: 5px 12px; background: none; cursor: pointer;
}
.tabs button[aria-selected="true"] { color: #fff; background: var(--accent); }
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; white-space: nowrap; }
th {
  text-align: left; font-weight: 600; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, td.rank { font-variant-numeric: tabular-nums; }
td.rank { color: var(--muted); }
td strong { color: var(--accent); }
td .sub, td.sub { color: var(--muted); font-size: 0.8rem; }
td.empty { text-align: center; color: var(--muted); padding: 24px; }
tr.mine td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.note { margin: 12px 0 0; font-size: 0.82rem; color: var(--muted); text-align: center; }

.site-foot { margin-top: 40px; text-align: center; font-size: 13px; color: var(--muted); }
.site-foot a { text-decoration: none; }
.site-foot a:hover { text-decoration: underline; }
