/* ================= THEME TOKENS ================= */
:root,
:root[data-theme="paper"],
[data-preview="paper"] {
  --bg: #f3efe4;
  --surface: #fffdf6;
  --surface-2: #f1ece0;
  --text: #1c2333;
  --muted: #5e6677;
  --border: #d9d2c1;
  --accent: #2456c9;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .08);

  --board-bg: #fffdf6;
  --grid-minor: rgba(64, 128, 191, .14);
  --grid-major: rgba(64, 128, 191, .34);
  --axis: #2b3a55;
  --label: #5e6677;
  --point: #2456c9;
  --point-ring: #fffdf6;
  --user-line: #e2552c;
  --best-line: #15965a;
  --residual: rgba(226, 85, 44, .6);
  --glow: 0;
  --chalk: 0;
  --label-family: "Space Grotesk", system-ui, sans-serif;

  --ui-font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display-font: "Space Grotesk", system-ui, sans-serif;
  --display-weight: 700;
  --base-size: 16px;
  --display-scale: 1;
  --radius: 14px;
  color-scheme: light;
}

:root[data-theme="paper-dark"],
[data-preview="paper-dark"] {
  --bg: #12151c;
  --surface: #1a1f29;
  --surface-2: #222835;
  --text: #e7eaf0;
  --muted: #9aa3b5;
  --border: #2e3544;
  --accent: #7aa7ff;
  --accent-text: #0d1220;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);

  --board-bg: #171b24;
  --grid-minor: rgba(122, 167, 255, .08);
  --grid-major: rgba(122, 167, 255, .2);
  --axis: #c9d3e6;
  --label: #9aa3b5;
  --point: #7aa7ff;
  --point-ring: #171b24;
  --user-line: #ff7a4f;
  --best-line: #3ddc84;
  --residual: rgba(255, 122, 79, .6);
  color-scheme: dark;
}

:root[data-theme="neon"],
[data-preview="neon"] {
  --bg: #07040f;
  --surface: #110a22;
  --surface-2: #1a1033;
  --text: #f3ecff;
  --muted: #a99bc9;
  --border: #3a2470;
  --accent: #ff2bd6;
  --accent-text: #0a0614;
  --shadow: 0 0 0 1px rgba(255, 43, 214, .25), 0 0 24px rgba(255, 43, 214, .18);

  --board-bg: #0a0617;
  --grid-minor: rgba(0, 240, 255, .07);
  --grid-major: rgba(0, 240, 255, .2);
  --axis: #00f0ff;
  --label: #7fe9ff;
  --point: #fff36b;
  --point-ring: none;
  --user-line: #ff2bd6;
  --best-line: #39ff14;
  --residual: rgba(255, 43, 214, .65);
  --glow: 14;
  --label-family: "VT323", monospace;

  --ui-font: "VT323", ui-monospace, monospace;
  --display-font: "Press Start 2P", ui-monospace, monospace;
  --display-weight: 400;
  --base-size: 20px;
  --display-scale: .62;
  --radius: 4px;
  color-scheme: dark;
}

:root[data-theme="chalk"],
[data-preview="chalk"] {
  --bg: #1f2b25;
  --surface: #2c3d34;
  --surface-2: #34483d;
  --text: #f4f1e6;
  --muted: #bfc8bd;
  --border: #4d6457;
  --accent: #fff27a;
  --accent-text: #1f2b25;
  --shadow: inset 0 0 0 1px rgba(255, 255, 255, .04), 0 10px 30px rgba(0, 0, 0, .35);

  --board-bg: #2f4a3c;
  --grid-minor: rgba(255, 255, 255, .07);
  --grid-major: rgba(255, 255, 255, .18);
  --axis: #f4f1e6;
  --label: #dfe5d8;
  --point: #fbf8ec;
  --point-ring: none;
  --user-line: #ffb0a0;
  --best-line: #fff27a;
  --residual: rgba(255, 176, 160, .65);
  --chalk: 1;
  --label-family: "Patrick Hand", cursive;

  --ui-font: "Patrick Hand", "Comic Sans MS", cursive;
  --display-font: "Patrick Hand", cursive;
  --display-weight: 400;
  --base-size: 19px;
  --display-scale: 1.1;
  --radius: 10px;
  color-scheme: dark;
}


:root[data-theme="gold"],
[data-preview="gold"] {
  --bg: #0a0907;
  --surface: #14110c;
  --surface-2: #1c1810;
  --text: #f5ecd6;
  --muted: #b9a783;
  --border: #3e321f;
  --accent: #d9b44a;
  --accent-text: #1a1305;
  --shadow: 0 0 0 1px rgba(217, 180, 74, .14), 0 12px 32px rgba(0, 0, 0, .55);

  --board-bg: #0d0b08;
  --grid-minor: rgba(217, 180, 74, .07);
  --grid-major: rgba(217, 180, 74, .2);
  --axis: #e8c96a;
  --label: #c4ad78;
  --point: #f4e4b8;
  --point-ring: #0d0b08;
  --user-line: #e9b949;
  --best-line: #fbf6e9;
  --residual: rgba(233, 185, 73, .5);
  --glow: 7;
  --chalk: 0;
  --gold: 1;
  --label-family: "Playfair Display", Georgia, serif;

  --ui-font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display-font: "Playfair Display", Georgia, "Times New Roman", serif;
  --display-weight: 700;
  --base-size: 16px;
  --display-scale: 1.04;
  --radius: 6px;
  color-scheme: dark;
}

/* ================= BASE ================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: var(--base-size);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s, color .25s;
}
:root[data-theme="chalk"] body {
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255,255,255,.05), transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(255,255,255,.04), transparent 60%),
    var(--bg);
}
:root[data-theme="gold"] body {
  background:
    radial-gradient(ellipse at 50% -10%, rgba(217, 180, 74, .14), transparent 55%),
    radial-gradient(ellipse at 50% 120%, rgba(120, 84, 20, .18), transparent 60%),
    var(--bg);
}
:root[data-theme="neon"] body {
  background:
    radial-gradient(ellipse at 50% -20%, rgba(255, 43, 214, .16), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 240, 255, .12), transparent 60%),
    var(--bg);
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display-font); font-weight: var(--display-weight); margin: 0; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; }

/* ================= MENU ================= */
#menu { align-items: flex-start; justify-content: center; padding: 32px 16px 48px; }
.menu-inner { width: 100%; max-width: 860px; }
.menu-head { text-align: center; margin: 12px 0 32px; }
.menu-head h1 { font-size: calc(clamp(2.2rem, 7vw, 3.8rem) * var(--display-scale)); letter-spacing: -.02em; line-height: 1.1; }
.accent { color: var(--accent); }
:root[data-theme="neon"] .accent { text-shadow: 0 0 12px var(--accent); }
:root[data-theme="gold"] .accent, :root[data-theme="gold"] .gold-text {
  background: linear-gradient(100deg, #a77c22 0%, #f7e08f 35%, #d9b44a 55%, #fff3c4 70%, #b8892a 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: gold-sheen 6s ease-in-out infinite;
}
:root[data-theme="gold"] .menu-head h1 { font-style: italic; letter-spacing: 0; }
@keyframes gold-sheen { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
:root[data-theme="neon"] .menu-head h1 { text-shadow: 0 0 18px rgba(0, 240, 255, .5); letter-spacing: 0; }
.tagline { color: var(--muted); margin: 10px 0 0; }

.section-label {
  font-family: var(--ui-font);
  font-size: .78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 10px;
}
:root[data-theme="neon"] .section-label, :root[data-theme="chalk"] .section-label { font-size: .95rem; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 28px; }
.mode-card {
  text-align: left;
  display: flex; flex-direction: column; gap: 8px;
  padding: 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.mode-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.mode-name { font-family: var(--display-font); font-weight: var(--display-weight); font-size: calc(1.2rem * var(--display-scale)); }
.mode-desc { color: var(--muted); font-size: .92em; }
:root[data-theme="neon"] .mode-card:hover { box-shadow: 0 0 0 1px var(--accent), 0 0 28px rgba(255, 43, 214, .35); }

.menu-options { display: grid; grid-template-columns: auto 1fr auto; gap: 24px; align-items: start; margin-bottom: 24px; }

.segmented {
  display: inline-flex; flex-wrap: wrap; padding: 4px; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px);
}
.segmented button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: calc(var(--radius) - 6px);
  color: var(--muted);
}
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-text); }

.themes { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-opt { grid-column: 1 / -1; order: 3; }
.theme-swatch {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 8px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px;
  font-size: .9em;
}
.theme-swatch[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.theme-swatch span { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); }
.sw-paper span { background: linear-gradient(135deg, #fffdf6 50%, #2456c9 50%); }
.sw-paper-dark span { background: linear-gradient(135deg, #171b24 50%, #7aa7ff 50%); }
.sw-neon span { background: linear-gradient(135deg, #0a0617 50%, #ff2bd6 50%); }
.sw-chalk span { background: linear-gradient(135deg, #2f4a3c 50%, #fff27a 50%); }
.sw-gold span { background: linear-gradient(135deg, #0d0b08 50%, #e9c25a 50%); box-shadow: 0 0 0 1px #b98f2e; }
.theme-swatch.locked { color: var(--muted); border-style: dashed; }
.theme-swatch.locked span { filter: saturate(.55) brightness(.9); }
.theme-swatch .lock { font-size: .85em; opacity: .8; margin-left: -2px; }
.theme-swatch .price {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: .82em; font-variant-numeric: tabular-nums; font-weight: 600;
  padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.theme-swatch .price.afford { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); }
.theme-swatch:not([aria-checked="true"]):hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.theme-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.theme-bal { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--accent); white-space: nowrap; }
.theme-bal:empty { display: none; }
.cr { color: var(--accent); }
.credit-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 11px; border-radius: 999px; font-size: .92em;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
}
.credit-pill b { font-variant-numeric: tabular-nums; }
.credit-pill.bump { animation: bump .5s ease-out; }
@keyframes bump { 40% { transform: scale(1.15); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.toggle {
  padding: 8px 14px; border-radius: calc(var(--radius) - 2px);
  background: var(--surface); border: 1.5px solid var(--border);
}
.toggle[aria-pressed="true"] { color: var(--muted); }

.how {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; color: var(--muted);
}
.how summary { cursor: pointer; color: var(--text); font-weight: 600; }
.how p { margin: 10px 0; }
.how strong { color: var(--text); }
.about { margin-top: 28px; color: var(--muted); font-size: .95em; line-height: 1.6; }
.about h2 { color: var(--text); font-size: 1.05rem; margin: 22px 0 6px; }
.about h2:first-child { margin-top: 0; }
.about p, .about ol, .about ul { margin: 6px 0; }
.about ol, .about ul { padding-left: 1.3em; }
.about li { margin: 3px 0; }
.about strong, .tagline strong { color: var(--text); font-weight: 600; }
.formula {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .88em;
  background: var(--surface-2); padding: 8px 12px; border-radius: 8px; color: var(--text);
  overflow-x: auto;
}
.tier-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 14px; padding: 0; margin: 12px 0 4px; }
.tier-legend li { display: flex; align-items: center; gap: 6px; }

/* ================= TIER BADGES ================= */
.tier-badge {
  --tc: #888;
  display: inline-grid; place-items: center;
  width: 56px; height: 56px; border-radius: 14px;
  font-family: var(--display-font); font-weight: 700; font-style: normal;
  font-size: calc(1.9rem * var(--display-scale));
  color: #fff; background: var(--tc);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--tc) 45%, transparent);
}
.tier-badge.sm { width: 26px; height: 26px; border-radius: 7px; font-size: calc(.85rem * var(--display-scale)); box-shadow: none; }
.tier-badge.lg { width: 92px; height: 92px; border-radius: 22px; font-size: calc(3.2rem * var(--display-scale)); }
.tier-badge.pending { background: transparent; box-shadow: inset 0 0 0 2px var(--border); }
.tier-S { --tc: #f5a10b; color: #3b2500; background: linear-gradient(135deg, #ffd34d, #f5a10b); }
.tier-A { --tc: #22a861; }
.tier-B { --tc: #3474e0; }
.tier-C { --tc: #0f9e93; }
.tier-D { --tc: #e8731c; }
.tier-F { --tc: #dc3b3b; }
:root[data-theme="neon"] .tier-badge:not(.pending) { box-shadow: 0 0 18px var(--tc), 0 0 2px #fff inset; }
:root[data-theme="neon"] .tier-S { box-shadow: 0 0 22px #ffc93c; }
:root[data-theme="chalk"] .tier-badge:not(.pending) { border: 2px dashed rgba(255,255,255,.55); }
.pop { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(.2) rotate(-12deg); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* ================= GAME ================= */
#game { flex-direction: column; }
.hud {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.hud-title { font-family: var(--display-font); font-weight: var(--display-weight); font-size: calc(1.05rem * var(--display-scale)); white-space: nowrap; }
.hud-stats { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.hud-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; flex: none;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-size: 1.1rem;
}
.icon-btn[hidden] { display: none; }
.icon-btn.off { opacity: .45; text-decoration: line-through; }

.stat {
  display: inline-flex; flex-direction: column; align-items: center;
  min-width: 58px; padding: 3px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  line-height: 1.15;
}
.stat small { font-size: .68em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat b { font-variant-numeric: tabular-nums; font-size: 1.05em; }

.timebar { height: 6px; background: var(--surface-2); }
.timebar[hidden] { display: none; }
#timebar-fill { height: 100%; background: var(--accent); transform-origin: left; transition: background-color .3s; }
.timebar.low #timebar-fill { background: #dc3b3b; }
:root[data-theme="neon"] #timebar-fill { box-shadow: 0 0 12px var(--accent); }

.play {
  flex: 1;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px;
  padding: 20px; max-width: 1180px; width: 100%; margin: 0 auto; align-items: start;
}
.board-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.board {
  position: relative;
  width: min(100%, calc(100dvh - 150px));
  min-width: 260px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  background: var(--board-bg);
}
:root[data-theme="chalk"] .board { border: 10px solid #6b4a2f; box-shadow: inset 0 0 30px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.4); }
:root[data-theme="gold"] .board {
  border: 1px solid #8a6a26;
  box-shadow: 0 0 0 4px #14110c, 0 0 0 5px rgba(217, 180, 74, .55), 0 18px 40px rgba(0, 0, 0, .6);
}
:root[data-theme="gold"] .btn.primary { background: linear-gradient(135deg, #f3d77e, #c89b2e); border-color: #c89b2e; }
:root[data-theme="gold"] .mode-card:hover, :root[data-theme="gold"] .daily-card:hover { box-shadow: 0 0 0 1px var(--accent), 0 10px 32px rgba(217, 180, 74, .18); }
:root[data-theme="gold"] .tier-badge:not(.pending) { box-shadow: 0 0 0 1px rgba(255, 236, 170, .5) inset, 0 4px 18px color-mix(in srgb, var(--tc) 40%, transparent); }
:root[data-theme="neon"] .board { border-color: rgba(0, 240, 255, .4); box-shadow: 0 0 30px rgba(0, 240, 255, .15); }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--board-bg) 70%, transparent);
  pointer-events: none;
}
.overlay[hidden] { display: none; }
#overlay-text { font-family: var(--display-font); font-weight: var(--display-weight); font-size: calc(5rem * var(--display-scale)); color: var(--accent); }
:root[data-theme="neon"] #overlay-text { text-shadow: 0 0 24px var(--accent); }
.pulse { animation: pulse .6s ease-out; }
@keyframes pulse { 0% { transform: scale(1.8); opacity: 0; } 40% { opacity: 1; } 100% { transform: scale(1); } }

.flash { position: absolute; inset: 0; pointer-events: none; }
.flash[hidden] { display: none; }
.flash.go { animation: flash .9s ease-out forwards; background: radial-gradient(circle, rgba(255, 211, 77, .45), transparent 70%); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.hint { margin: 12px 0 0; color: var(--muted); text-align: center; min-height: 1.5em; font-size: .95em; }
.hint.warn { color: #dc3b3b; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.panel [hidden] { display: none !important; }
.round-info { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.ri-main { font-family: var(--display-font); font-weight: var(--display-weight); font-size: calc(1.3rem * var(--display-scale)); width: 100%; }
.chip { font-size: .8em; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.chip.diff-easy { color: #22a861; border-color: color-mix(in srgb, #22a861 50%, transparent); }
.chip.diff-medium { color: #d48a00; border-color: color-mix(in srgb, #d48a00 50%, transparent); }
.chip.diff-hard { color: #dc3b3b; border-color: color-mix(in srgb, #dc3b3b 50%, transparent); }
.chip.diff-superhard { color: #b0379a; border-color: color-mix(in srgb, #b0379a 50%, transparent); }
.chip.diff-nightmare { color: var(--surface); background: #7b2cbf; border-color: #7b2cbf; }
:root[data-theme="gold"] .chip.diff-superhard,
:root[data-theme="paper-dark"] .chip.diff-superhard,
:root[data-theme="neon"] .chip.diff-superhard,
:root[data-theme="chalk"] .chip.diff-superhard { color: #f07ad8; border-color: color-mix(in srgb, #f07ad8 50%, transparent); }
:root[data-theme="gold"] .chip.diff-nightmare,
:root[data-theme="paper-dark"] .chip.diff-nightmare,
:root[data-theme="neon"] .chip.diff-nightmare,
:root[data-theme="chalk"] .chip.diff-nightmare { color: #fff; background: #8f3fe0; border-color: #8f3fe0; }
.panel-tip { color: var(--muted); font-size: .92em; margin: 0 0 16px; }

.score-row { display: flex; align-items: center; gap: 6px; }
.score-num {
  font-family: var(--display-font); font-weight: var(--display-weight);
  font-size: calc(3.4rem * var(--display-scale)); line-height: 1; font-variant-numeric: tabular-nums;
}
.score-max { color: var(--muted); align-self: flex-end; margin-bottom: 6px; }
.score-row .tier-badge { margin-left: auto; }
.tier-label { margin: 6px 0 14px; font-weight: 600; }
.eqs { margin: 0 0 10px; display: grid; gap: 8px; }
.eqs > div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.eqs dt { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9em; white-space: nowrap; }
.eqs dd { margin: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .88em; white-space: nowrap; }
:root[data-theme="neon"] .eqs dd { font-family: var(--ui-font); font-size: 1.05em; }
:root[data-theme="chalk"] .eqs dd { font-family: var(--ui-font); font-size: 1em; }
.sw { display: inline-block; width: 16px; height: 4px; border-radius: 2px; }
.sw-user { background: var(--user-line); }
.sw-best { background: var(--best-line); }
.err { color: var(--muted); font-size: .8em; margin: 0 0 16px; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  padding: 11px 18px; border-radius: calc(var(--radius) - 4px);
  border: 1.5px solid var(--border); background: var(--surface-2); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); flex: 1; }
.btn.ghost { background: transparent; }
.btn:not(:disabled):hover { filter: brightness(1.06); }
:root[data-theme="neon"] .btn.primary { box-shadow: 0 0 16px rgba(255, 43, 214, .5); }

/* ================= SUMMARY ================= */
#summary { align-items: flex-start; justify-content: center; padding: 40px 16px; }
.summary-inner {
  width: 100%; max-width: 640px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px;
}
#sum-title { font-size: calc(1.5rem * var(--display-scale)); margin-bottom: 20px; }
.sum-hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.sum-big { font-family: var(--display-font); font-weight: var(--display-weight); font-size: calc(4.2rem * var(--display-scale)); line-height: 1; font-variant-numeric: tabular-nums; }
.sum-caption { color: var(--muted); margin-top: 6px; }
.sum-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.sum-stats .stat { padding: 6px 14px; }
.sum-stats .tiers b { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.sum-table-wrap { max-height: 320px; overflow: auto; margin-bottom: 20px; border: 1px solid var(--border); border-radius: 10px; }
.sum-table { width: 100%; border-collapse: collapse; font-size: .92em; }
.sum-table th, .sum-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.sum-table th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .85em; }
.sum-table tr:last-child td { border-bottom: 0; }
.sum-table td { font-variant-numeric: tabular-nums; }

/* ================= ACCOUNT BAR ================= */
.account-bar { display: flex; justify-content: flex-end; min-height: 38px; }
.account-bar > span { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.account-bar [hidden] { display: none; }
.acct-name { color: var(--muted); font-size: .92em; }
.acct-name b { color: var(--text); }
.link-btn {
  background: none; border: 0; padding: 4px 2px; color: var(--accent);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.btn.small { padding: 6px 14px; }

/* ================= DAILY CARD ================= */
.daily { display: grid; grid-template-columns: 1fr auto; gap: 14px; margin-bottom: 28px; align-items: stretch; }
.daily-card {
  text-align: left; display: flex; flex-direction: column; gap: 8px; padding: 20px 22px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, var(--surface)), var(--surface) 70%);
  border: 1.5px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.daily-card:hover { transform: translateY(-3px); border-color: var(--accent); }
:root[data-theme="neon"] .daily-card:hover { box-shadow: 0 0 0 1px var(--accent), 0 0 28px rgba(255, 43, 214, .35); }
.daily-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.daily-top .mode-name { font-size: calc(1.45rem * var(--display-scale)); }
.daily-status { font-weight: 600; font-size: .92em; }
.daily-status.live { color: var(--accent); }
.daily-status.done { color: var(--best-line); }
.daily-status.error { color: #dc3b3b; }
.daily-side {
  display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  text-align: center; min-width: 190px;
}
.daily-next { color: var(--muted); font-size: .88em; }
.daily-next b, .lb-sub b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ================= CARD SCREENS (auth / leaderboard / profile) ================= */
#auth, #leaderboard, #profile { align-items: flex-start; justify-content: center; padding: 40px 16px; }
.card-inner {
  position: relative; width: 100%; max-width: 640px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px;
}
.auth-inner { max-width: 440px; }
.card-inner > h2 { font-size: calc(1.5rem * var(--display-scale)); margin: 0 48px 16px 0; overflow-wrap: anywhere; }
.card-inner .back { position: absolute; top: 20px; right: 20px; }
.card-inner .section-label { margin-top: 22px; }
.auth-tabs { display: flex; margin-bottom: 14px; }
.auth-tabs[hidden] { display: none; }
.auth-tabs button { flex: 1; }
.auth-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form[hidden] { display: none; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92em; }
.auth-form small { font-weight: 400; color: var(--muted); font-size: .88em; }
.auth-form input {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: calc(var(--radius) - 6px);
  padding: 10px 12px; width: 100%; min-width: 0;
}
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.auth-form .btn.primary { flex: none; }
.auth-form > .link-btn { align-self: center; }
.code-input { font-size: 1.5em !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.form-note { margin: 0; color: var(--muted); font-size: .92em; overflow-wrap: anywhere; }
.form-note b { color: var(--text); }
.form-links { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.inline-form { flex-direction: row; }
.inline-form .btn { flex: none; }
.form-msg { margin: 0 0 12px; min-height: 0; font-size: .92em; }
.form-msg:empty { display: none; }
.form-msg.error { color: #dc3b3b; }
.form-msg.ok { color: var(--best-line); }
.form-msg.info { color: var(--accent); }
#pf-msg, #lb-msg { margin-top: 10px; }

.lb-sub { color: var(--muted); margin: -6px 0 18px; font-size: .92em; overflow-wrap: anywhere; }
.lb-wrap { max-height: none; }
.lb-table td.rank { width: 64px; font-weight: 600; white-space: nowrap; }
.lb-table td.name { overflow-wrap: anywhere; }
.lb-table tr.me td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.lb-table tr.gap td { text-align: center; color: var(--muted); padding: 2px; }
.you {
  margin-left: 8px; font-size: .75em; padding: 1px 8px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); vertical-align: middle;
}
.sum-daily {
  margin: -6px 0 18px; padding: 12px 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.sum-daily[hidden] { display: none; }
.sum-daily p { margin: 0; flex: 1 1 240px; }

/* ================= CREDITS EARNED ================= */
.sum-credits {
  margin: -6px 0 18px; padding: 14px 16px; border-radius: 10px;
  border: 1.5px solid color-mix(in srgb, var(--accent) 50%, var(--border));
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, var(--surface)), var(--surface) 75%);
}
.sum-credits[hidden] { display: none; }
.earn-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.earn-amt {
  font-family: var(--display-font); font-weight: var(--display-weight);
  font-size: calc(1.6rem * var(--display-scale)); font-variant-numeric: tabular-nums;
}
.earn-amt.done { animation: bump .5s ease-out; }
.earn-sub { color: var(--muted); font-size: .88em; }
.earn-bal { margin: 6px 0 0; color: var(--muted); }
.earn-bal b { color: var(--text); }
.earn-bal .ok { color: var(--best-line); font-weight: 600; }

/* ================= THEME DIALOG ================= */
.modal {
  width: min(400px, calc(100vw - 32px)); padding: 22px; margin: auto;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0, 0, 0, .55); }
.modal h2 { font-size: calc(1.4rem * var(--display-scale)); margin: 14px 0 4px; }
.modal .result-actions { margin-top: 16px; }
.td-price { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.td-msg { margin: 8px 0 0; color: var(--muted); font-size: .94em; }
.td-msg b { color: var(--text); }
.modal .form-msg { margin: 10px 0 0; }
.td-preview {
  position: relative; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); background: var(--bg);
}
.pv-board { display: block; width: 100%; height: auto; }
.pv-bg { fill: var(--board-bg); }
.pv-minor { stroke: var(--grid-major); stroke-width: .6; fill: none; }
.pv-axis { stroke: var(--axis); stroke-width: 1.2; fill: none; }
.pv-best { stroke: var(--best-line); stroke-width: 1.6; fill: none; }
.pv-user { stroke: var(--user-line); stroke-width: 1.6; fill: none; }
.pv-pts circle { fill: var(--point); }
[data-preview="neon"] .pv-board path, [data-preview="neon"] .pv-pts { filter: drop-shadow(0 0 2px currentColor); color: #ff2bd6; }
[data-preview="gold"] .pv-pts { filter: drop-shadow(0 0 1.5px rgba(255, 230, 160, .8)); }
.pv-name {
  position: absolute; left: 10px; bottom: 8px; padding: 2px 10px; border-radius: 999px;
  font-family: var(--display-font); font-weight: var(--display-weight); font-size: calc(.9rem * var(--display-scale));
  background: var(--surface); color: var(--accent); border: 1px solid var(--border);
}

/* ================= RESPONSIVE ================= */
@media (max-width: 820px) {
  .modes { grid-template-columns: 1fr; }
  .daily { grid-template-columns: 1fr; }
  .daily-side { flex-direction: row; justify-content: space-between; align-items: center; text-align: left; }
  .menu-options { grid-template-columns: 1fr; gap: 18px; }
  .play { grid-template-columns: 1fr; padding: 12px 16px 20px; gap: 12px; }
  .board { width: min(100%, calc(100dvh - 290px)); }
  .hint { margin-top: 8px; }
  .panel { padding: 14px 16px; }
  .panel-tip { display: none; }
  .round-info { margin-bottom: 8px; }
  .ri-main { width: auto; margin-right: 4px; }
  .score-num { font-size: calc(2.6rem * var(--display-scale)); }
  .tier-badge:not(.sm):not(.lg) { width: 46px; height: 46px; font-size: calc(1.5rem * var(--display-scale)); }
  .tier-label { margin: 4px 0 10px; }
}
@media (max-width: 520px) {
  .card-inner { padding: 20px 16px; }
  .card-inner .back { top: 14px; right: 14px; }
  #auth, #leaderboard, #profile, #summary { padding: 20px 16px; }
  .sum-table th, .sum-table td { padding: 8px; }
  .hud { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .hud-title { flex: 1; }
  .hud-stats { order: 3; width: 100%; justify-content: center; margin-left: 0; }
  .stat { min-width: 0; flex: 1; }
  .summary-inner { padding: 20px 16px; }
  .sum-big { font-size: calc(3.2rem * var(--display-scale)); }
  .tier-badge.lg { width: 72px; height: 72px; font-size: calc(2.4rem * var(--display-scale)); }
  .eqs > div { flex-direction: column; gap: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
