/* Meridian – dark theme. Design tokens live in :root. */
:root {
  --bg: #1b1c1e; --surface: #232527; --surface-2: #2b2d30; --border: #383b3f; --border-soft: #2f3235;
  --ink: #e4e4e1; --muted: #8b9095;
  --accent: rgb(50, 100, 150); --accent-text: #86aedb; --accent-ink: #ffffff; --accent-dim: rgba(50, 100, 150, .28);
  --ok: #8dbf86; --ok-dim: rgba(141, 191, 134, .14); --bad: #dc6f64; --bad-dim: rgba(220, 111, 100, .14);
  --sea: #161718; --land: #3c3f44; --land-hover: #3f5875; --land-stroke: #1b1c1e; --out: #25272a;
  --radius: 6px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  /* Type scale – use these tokens instead of ad-hoc sizes. Weights: 400 body, 500 buttons, 600 labels/headings. */
  /* --fs-sm is the one shared small/body text size (14px); hierarchy comes from weight */
  --fs-sm: .875rem; --fs-md: 1rem; --fs-lg: 1.25rem; --fs-xl: 1.6rem; --fs-2xl: 2.5rem; --fs-display: 3.2rem;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  /* Soft glows in the UI accent blue (--accent) on the dark base; panels are semi-transparent so they shine through. */
  background:
    radial-gradient(900px 640px at 6% -6%, rgba(50, 100, 150, .60), transparent 62%),
    radial-gradient(800px 580px at 98% 4%, rgba(63, 125, 185, .42), transparent 62%),
    radial-gradient(940px 720px at 74% 108%, rgba(50, 100, 150, .52), transparent 62%),
    radial-gradient(720px 540px at 0% 106%, rgba(63, 125, 185, .36), transparent 62%),
    var(--bg);
  background-attachment: fixed; color: var(--ink);
  font: 14px/1.5 var(--sans); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
button { font: inherit; color: inherit; }
kbd { font: 11px var(--mono); color: inherit; opacity: .65; margin-left: 8px; border: 1px solid currentColor; border-radius: 3px; padding: 0 5px; }
[hidden] { display: none !important; }

.screen { display: none; max-width: 1000px; margin: 0 auto; padding: 24px 20px 40px; }
.screen.active { display: block; }
#game.active { display: flex; flex-direction: column; height: calc(100dvh - var(--pt, 0px)); padding: 0 0 16px; max-width: none; gap: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  padding: 9px 16px; border-radius: var(--radius); cursor: pointer; font-weight: 500;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--border); }
.btn.icon { width: 36px; height: 36px; padding: 0; font-size: 18px; line-height: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Home ---------- */
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 24px; border-bottom: 1px solid var(--border-soft); }
.appbar-brand { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-md); font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.appbar-logo { width: 28px; height: 28px; flex: none; }
.appbar-user { display: flex; align-items: center; gap: 4px; color: var(--muted); font: var(--fs-sm) var(--sans); }
.account { position: relative; margin-left: 8px; }
.avatar { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-radius: 50%; cursor: pointer;
  background: var(--accent-dim); border: 1px solid var(--accent); color: var(--accent-text); transition: filter .12s; }
.avatar:hover, .avatar[aria-expanded="true"] { filter: brightness(1.3); }
.avatar svg { width: 19px; height: 19px; }
.account-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 300px; padding: 6px; display: grid;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.account-menu:focus { outline: none; }
.account-menu > button { appearance: none; background: none; border: 0; border-radius: 4px; padding: 8px 10px; text-align: left; cursor: pointer;
  font: var(--fs-sm) var(--sans); color: var(--ink); }
.account-menu > button:hover, .account-menu > button:focus-visible { background: var(--accent-dim); outline: none; }
.account-menu .danger { color: var(--bad); }
.account-menu .danger:hover, .account-menu .danger:focus-visible { background: var(--bad-dim); }
.menu-sep { height: 1px; margin: 6px 0; border: 0; background: var(--border-soft); }
/* Code card: one field for the own code (masked, eye to reveal) and for entering another code */
.code-card { display: grid; gap: 8px; padding: 6px 4px 2px; justify-items: start; }
.code-title { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); font-weight: 600; }
.code-title img { flex: none; }
.code-field { position: relative; width: 100%; }
.code-input { width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 9px 40px 9px 12px; color: var(--ink);
  font: 600 1.05rem var(--mono); letter-spacing: .1em; transition: border-color .12s, box-shadow .12s; }
.code-input::placeholder { color: var(--muted); font-weight: 400; letter-spacing: normal; opacity: .8; }
.code-input:hover { border-color: var(--muted); }
.code-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-dim); }
.code-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; padding: 0; display: grid; place-items: center;
  background: none; border: 0; border-radius: 4px; color: var(--muted); cursor: pointer; transition: color .12s, background .12s; }
.code-eye:hover { color: var(--ink); background: var(--accent-dim); }
.code-eye svg { width: 18px; height: 18px; }
.code-copy { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 4px; cursor: pointer; font: 500 var(--fs-sm) var(--sans);
  background: var(--accent-dim); border: 1px solid var(--accent); color: var(--accent-text); transition: filter .12s; }
.code-copy:hover { filter: brightness(1.25); }
.code-copy svg { width: 15px; height: 15px; }
.code-note { color: var(--muted); font-size: var(--fs-sm); }
.code-help { margin: 0; color: var(--muted); font-size: var(--fs-sm); line-height: 1.4; }
.code-note:empty { display: none; }
.code-card .form-error { margin: 0; }
.appbar-user .btn { padding: 3px 10px; font-size: var(--fs-sm); }
@media (max-width: 860px) { .appbar { padding: 6px 14px; } }
@media (max-width: 440px) {
  .appbar-brand { font-size: var(--fs-sm); } .appbar-user { gap: 0; } .appbar-user .btn { padding: 3px 6px; }
  .appbar { position: relative; } .account { position: static; }
  .account-menu { left: 10px; right: 10px; width: auto; top: calc(100% + 4px); }   /* full width minus margin */
}

.panel { display: grid; gap: 0; margin-bottom: 36px; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(35, 37, 39, .58); backdrop-filter: blur(16px); }
.setting { padding: 16px 18px; }
.setting + .setting { border-top: 1px solid var(--border); }
.setting h2, .section-title {
  font-size: var(--fs-sm); color: var(--muted); font-weight: 600; margin-bottom: 12px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: transparent; border-radius: 4px; padding: 5px 12px;
  cursor: pointer; font-size: var(--fs-sm); color: var(--muted); transition: all .12s;
}
.chip:hover { color: var(--ink); border-color: var(--muted); }
.chip[aria-checked="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent-text); font-weight: 500; }

/* Region picker as a world map */
.regionmap { position: relative; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; background: var(--sea); }
#rmap { display: block; width: 100%; height: auto; aspect-ratio: 1000 / 470; user-select: none; }
.rm-sea { fill: var(--sea); cursor: pointer; }
.rm-neutral { fill: var(--out); pointer-events: none; }
.rm-region { fill: var(--land); cursor: pointer; outline: none; transition: fill .15s; }
.rm-region.hover { fill: var(--land-hover); }
.rm-region.sel { fill: var(--accent); }
.rm-region.sel.hover { fill: #3f7cb9; }
.rm-region:focus-visible { stroke: var(--accent-text); stroke-width: 2; vector-effect: non-scaling-stroke; }
.rm-borders { fill: none; stroke: var(--land-stroke); stroke-width: .5; stroke-opacity: .55; vector-effect: non-scaling-stroke; pointer-events: none; }
.rm-edges { fill: none; stroke: var(--bg); stroke-width: 1.6; vector-effect: non-scaling-stroke; pointer-events: none; }
.rm-label { font-size: 13px; font-weight: 600; fill: var(--muted); text-anchor: middle; dominant-baseline: middle; pointer-events: none;
  paint-order: stroke; stroke: rgba(0, 0, 0, .55); stroke-width: 4px; stroke-linejoin: round; transition: fill .15s; }
.rm-label.sel { fill: #fff; }
.rm-world { position: absolute; right: 8px; bottom: 8px; background: var(--surface); }
.rm-caption { position: absolute; left: 10px; bottom: 6px; font: var(--fs-sm) var(--sans); color: var(--muted); pointer-events: none; }
.rm-caption b { color: var(--ink); font-family: var(--sans); font-weight: 600; }
.rm-caption span { opacity: .8; }
@media (max-width: 560px) {
  .rm-label { display: none; }
  .rm-caption { position: static; padding: 6px 2px 0; }
}

.start-box { display: grid; gap: 8px; margin-top: 12px; }
.start-count { font-weight: 400; }
/* Practice / repeat: each sits in its own blue frame (repeat also carries its explanation) */
.practice-panel { background: var(--accent-dim); display: grid; gap: 10px; }
/* Higher specificity than ".setting + .setting", which would otherwise draw a grey top border between stacked frames. */
.panel.practice-panel.setting { border: 1px solid var(--accent); }
.btn.practice { width: 100%; padding: 14px 16px; font-size: var(--fs-md); font-weight: 600; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.practice:hover:not(:disabled), .btn.practice:focus-visible { filter: brightness(1.2); }
.btn.practice:disabled { opacity: .5; cursor: default; }
.practice-hint { margin: 0; color: var(--accent-text); font-size: var(--fs-sm); line-height: 1.4; }
/* Primary call to action: green like the "learned" status, same size as a game-mode card. */
.btn.start { width: 100%; padding: 14px 16px; font-size: var(--fs-md); font-weight: 600; background: var(--ok); border-color: var(--ok); color: #14210f; }
.btn.start:hover:not(:disabled), .btn.start:focus-visible { filter: brightness(1.1); }
.btn.start:disabled { opacity: .5; cursor: default; }
.btn.start kbd { opacity: .7; }
.btn.stop { color: var(--bad); border-color: var(--border); }
.btn.stop:hover { border-color: var(--bad); background: var(--bad-dim); }
/* Game modes: three toggleable cards side by side (one column on wide screens, see below) */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mode { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; text-align: left; padding: 18px; cursor: pointer; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); transition: background .12s, border-color .12s; }
.mode:hover { background: var(--surface-2); border-color: var(--muted); }
.mode[aria-checked="true"] { background: var(--accent-dim); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mode .ico { width: 46px; height: 46px; flex: none; display: grid; place-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--muted); transition: color .12s, border-color .12s; }
.mode .ico svg { width: 27px; height: 27px; }
.mode:hover .ico { color: var(--ink); }
.mode[aria-checked="true"] .ico { color: var(--accent-text); border-color: var(--accent); }
.mode .txt { display: grid; gap: 3px; }
.mode b { font-weight: 600; font-size: var(--fs-md); }
.mode small { color: var(--muted); font-size: var(--fs-sm); line-height: 1.35; }
/* Checkbox in the card corner, same look as the filter toggles */
.mode { position: relative; }
.mode .box { position: absolute; top: 10px; right: 10px; width: 15px; height: 15px; border: 1.5px solid var(--muted); border-radius: 3px; display: grid; place-items: center; transition: all .12s; }
.mode[aria-checked="true"] .box { background: var(--accent); border-color: var(--accent); }
.mode[aria-checked="true"] .box::after { content: ""; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
@media (max-width: 560px) {
  .modes { gap: 8px; }
  .mode { padding: 12px; gap: 10px; }
  .mode .ico { width: 38px; height: 38px; } .mode .ico svg { width: 22px; height: 22px; }
  .mode b { font-size: var(--fs-sm); } .mode small { font-size: var(--fs-sm); }
}

/* Wide screens: region picker + filters on the left (takes all remaining width), game modes + practice/repeat on the right (260–360px). */
@media (min-width: 900px) {
  #home.active { display: grid; grid-template-columns: minmax(0, 1fr) clamp(260px, 26vw, 360px); gap: 20px; align-items: stretch; max-width: 1680px;
    /* Fit the home screen into the viewport below the sticky header, so it never needs scrolling (falls back to scrolling on very short windows). */
    height: calc(100dvh - var(--pt, 0px)); min-height: 560px; box-sizing: border-box; padding: 16px 20px; grid-template-rows: minmax(0, 1fr); }
  #home .panel { margin-bottom: 0; }

  /* Left frame fills the row height; the map area absorbs any extra space. */
  #home > .panel:first-child { display: flex; flex-direction: column; min-height: 0; }
  #home > .panel:first-child > .setting:first-child { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #home .regionmap { flex: 1; min-height: 0; }
  #home #rmap { height: 100%; aspect-ratio: auto !important; }   /* the SVG letterboxes inside the available area (JS sets an inline aspect-ratio) */

  /* Right column: modes frame (with start button) grows, practice frame keeps its natural height. */
  #home .side { display: flex; flex-direction: column; gap: 20px; min-height: 0; }
  #home .modes-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #home .modes { flex: 1; min-height: 0; grid-template-columns: 1fr; grid-auto-rows: minmax(0, 1fr); gap: 8px; }   /* all mode buttons share the same height */
  #home .mode { flex-direction: row; align-items: center; gap: 12px; padding: 6px 30px 6px 14px; min-height: 0; }
  #home .mode .box { top: 8px; right: 8px; }
  #home .mode .ico { width: 36px; height: 36px; }
  #home .mode .ico svg { width: 22px; height: 22px; }
}

/* ---------- Game ---------- */
.topbar { display: flex; align-items: center; gap: 18px; flex: none; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface); position: relative; }
.counter { margin-left: auto; font: 500 var(--fs-sm) var(--sans); color: var(--muted); }
.score { font: 600 var(--fs-sm) var(--sans); color: var(--ok); min-width: 44px; text-align: right; }

.stage { flex: 1; min-height: 0; display: grid; gap: 0; grid-template-columns: 340px 1fr; margin: 16px 16px 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.stage > .card { border: 0; border-radius: 0; }
.question { padding: 22px 20px; display: flex; flex-direction: column; gap: 14px; overflow: auto; }
.stage > .question { border-right: 1px solid var(--border); }
.q-label { color: var(--muted); font-size: var(--fs-sm); font-weight: 400; }
.q-main { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; line-height: 1.15; word-break: break-word; }
.q-flag img { width: 100%; max-width: 260px; border: 1px solid var(--border); display: block; aspect-ratio: 4/3; object-fit: cover; background: var(--surface-2); border-radius: 3px; }
.q-main:empty { display: none; }

.options { display: grid; gap: 6px; }
.feedback { padding: 10px 12px; border-radius: 4px; font-weight: 500; border-left: 3px solid; font-size: var(--fs-sm); }
.feedback.ok { background: var(--ok-dim); color: var(--ok); border-color: var(--ok); }
.feedback.bad { background: var(--bad-dim); color: var(--bad); border-color: var(--bad); }
.feedback small { display: block; font-weight: 400; color: var(--ink); opacity: .8; margin-top: 2px; font-size: var(--fs-sm); }
.next { margin-top: auto; }

.mapwrap { position: relative; overflow: hidden; background: var(--sea); min-height: 260px; }
#map { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; }
#map.dragging { cursor: grabbing; }
#map g.view.animate { transition: transform .6s cubic-bezier(.3,.7,.2,1); }
.c { fill: var(--land); stroke: var(--land-stroke); stroke-width: .6; vector-effect: non-scaling-stroke; stroke-linejoin: round; transition: fill .12s; }
.c.q { cursor: pointer; }
.c.q:hover { fill: var(--land-hover); }
.c.out, .c.neutral { fill: var(--out); }
.c.focus { fill: var(--accent); }
.c.q.ok { fill: var(--ok); }
.c.q.bad { fill: var(--bad); }
.dot { fill: var(--sea); stroke: var(--accent-text); stroke-width: 1.4; vector-effect: non-scaling-stroke; cursor: pointer; }
.dot:hover { fill: var(--accent-text); }
.dot.focus { fill: var(--accent); }
.dot.ok { fill: var(--ok); stroke: var(--ok); }
.dot.bad { fill: var(--bad); stroke: var(--bad); }
.dot.out { display: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.c.pulse, .dot.pulse { animation: pulse .7s ease-in-out 3; }

.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
/* Toast: a fixed overlay (outside the map), so it shows on every screen; sits below the sticky progress header */
.toast { position: fixed; left: 50%; top: calc(var(--pt, 0px) + 12px); transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 28px);
  background: var(--ink); color: var(--bg); padding: 6px 14px; border-radius: 4px; font-weight: 500; font-size: var(--fs-sm); pointer-events: none; }

@media (max-width: 860px) {
  .screen { padding: 20px 14px 32px; }
  #game.active { padding-bottom: 10px; }
  .stage { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); margin: 10px 10px 0; }
  .question { padding: 14px; gap: 10px; }
  .stage > .question { border-right: 0; border-bottom: 1px solid var(--border); }
  .q-main { font-size: var(--fs-lg); }
  .q-flag img { max-width: 150px; }
  .question.mapq { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .question.mapq .q-label { width: 100%; }
  .question.mapq .next { margin: 0 0 0 auto; }
  .mapwrap { min-height: 0; }
}

/* ---------- Result ---------- */
#result.active { display: grid; place-items: start center; }
.result-card { width: 100%; max-width: 720px; padding: 32px; margin-top: 4vh; }
.big { font: 600 var(--fs-2xl)/1 var(--mono); margin-bottom: 14px; }
.ring { --p: 0; height: 4px; margin-bottom: 20px; background: linear-gradient(90deg, var(--accent) calc(var(--p) * 1%), var(--border) 0); }
.result-card h2 { font-size: var(--fs-md); font-weight: 600; }
.result-card p { color: var(--muted); margin: 2px 0 22px; font-size: var(--fs-sm); }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.mistakes { margin-top: 28px; display: grid; gap: 0; border-top: 1px solid var(--border); }
.mistakes h3 { padding: 14px 0 8px; font-size: var(--fs-sm); color: var(--muted); font-weight: 600; }
.mrow { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border-soft); }
.mrow img { width: 34px; height: 25px; object-fit: cover; border-radius: 2px; border: 1px solid var(--border); }
.mrow b { flex: 1; font-weight: 500; }
.mrow span { color: var(--muted); font-size: var(--fs-sm); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Global progress bar ---------- */
.progress-top { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--border); }
.pg-inner { padding: 12px 24px 12px; max-width: none; }
.pg-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.pg-title { font-size: var(--fs-sm); color: var(--muted); font-weight: 600; }
.pg-summary { font: var(--fs-sm) var(--sans); color: var(--ink); }
.pg-summary b { color: var(--ok); font-size: var(--fs-md); }
.pg-summary span { color: var(--muted); margin-left: 8px; }
.pg-bar { display: flex; gap: 2px; height: 16px; border-radius: 3px; overflow: hidden; background: var(--border); }
.pg-bar i { display: block; min-width: 3px; transition: flex .5s ease; }
.pg-legend { display: flex; flex-wrap: wrap; gap: 4px 20px; list-style: none; margin: 8px 0 0; padding: 0; font-size: var(--fs-sm); color: var(--muted); }
.pg-legend li { display: flex; align-items: center; gap: 7px; }
.pg-legend b { font: 400 var(--fs-sm) var(--sans); color: var(--ink); }
.pg-legend i { width: 10px; height: 10px; border-radius: 2px; display: block; }
.pg-bar .learned, .pg-legend .learned { background: var(--ok); }
.pg-bar .twice, .pg-legend .twice { background: var(--accent-text); }
.pg-bar .once, .pg-legend .once { background: var(--accent); }
.pg-bar .wrong, .pg-legend .wrong { background: var(--bad); }
.pg-bar .new, .pg-legend .new { background: #50545a; }
@media (max-width: 860px) { .pg-inner { padding: 10px 14px; } .pg-bar { height: 12px; } .pg-legend { gap: 2px 14px; font-size: var(--fs-sm); } }

.pg-line { display: flex; align-items: center; gap: 10px; }
.pg-line .pg-bar { flex: 1; }
.pg-toggle { flex: none; width: 32px; height: 24px; display: grid; place-items: center; background: var(--accent); border: 1px solid var(--accent); border-radius: 4px; color: var(--accent-ink); cursor: pointer; transition: filter .12s; }
.pg-toggle:hover, .pg-toggle:focus-visible { filter: brightness(1.2); }
.pg-toggle svg { transition: transform .2s; }
.pg-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
/* Acrylic header: the glass effect lives on a pseudo-element, because a backdrop-filter on .progress-top itself
   would stop the floating detail panel from blurring the page behind it. */
.progress-top::before { content: ""; position: absolute; inset: 0; z-index: -1; background: rgba(35, 37, 39, .7); backdrop-filter: blur(14px); }
/* Expandable details float over the page content (no layout shift, no scrollbar); the height animates 0fr → 1fr. */
.pg-detail { position: absolute; top: 100%; left: 0; right: 0; display: grid; grid-template-rows: 0fr; transition: grid-template-rows .28s ease;
  background: rgba(35, 37, 39, .7); backdrop-filter: blur(14px); }
.pg-detail.open { grid-template-rows: 1fr; border-bottom: 1px solid var(--border); box-shadow: 0 12px 24px rgba(0, 0, 0, .35); }
.pg-detail-clip { overflow: hidden; min-height: 0; }
.pg-detail-rows { padding: 12px 24px 14px; border-top: 1px solid var(--border-soft); display: grid; gap: 7px; }
.pg-row { display: grid; grid-template-columns: 72px 1fr 78px; align-items: center; gap: 12px; }
.pg-name { font-size: var(--fs-sm); color: var(--muted); font-weight: 600; }
.pg-bar.sm { height: 10px; }
.pg-count { font: var(--fs-sm) var(--sans); color: var(--muted); text-align: right; }
.pg-count b { color: var(--ok); }

/* ---------- Result statistics ---------- */
.res-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.res-head .big { margin: 0; }
.res-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; }
.tile { padding: 12px 14px; border-right: 1px solid var(--border); display: grid; gap: 2px; }
.tile:last-child { border-right: 0; }
.tile b { font: 600 var(--fs-lg) var(--mono); }
.tile span { color: var(--muted); font-size: var(--fs-sm); }
.tile.ok b { color: var(--ok); } .tile.bad b { color: var(--bad); }
.res-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; font-size: var(--fs-sm); }
.res-table th { text-align: left; font-size: var(--fs-sm); color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.res-table td { padding: 8px; border-bottom: 1px solid var(--border-soft); font-family: var(--mono); }
.res-table td:first-child { font-family: inherit; }
.res-table td.ok { color: var(--ok); } .res-table td.bad { color: var(--bad); }
.res-table th:not(:first-child), .res-table td:not(:first-child) { text-align: right; }

/* ---------- Score & effects ---------- */
.pg-right { display: flex; align-items: baseline; gap: 22px; }
.pg-score { font: var(--fs-sm) var(--sans); color: var(--muted); }
.pg-score b { font-size: var(--fs-md); color: var(--ink); transition: color .3s; }
.pg-score.up b { animation: scoreUp .7s; } .pg-score.down b { animation: scoreDown .7s; }
@keyframes scoreUp { 0% { color: var(--ok); transform: scale(1.25); } 100% { color: var(--ink); transform: none; } }
@keyframes scoreDown { 0% { color: var(--bad); transform: scale(1.25); } 100% { color: var(--ink); transform: none; } }
.pg-score b { display: inline-block; }

.fx-confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
.fx-flash { position: fixed; inset: 0; pointer-events: none; z-index: 55; opacity: 0;
  box-shadow: inset 0 0 140px 40px rgba(220, 111, 100, .6); background: rgba(220, 111, 100, .12); }
.fx-flash.show { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.fx-delta { position: fixed; z-index: 65; pointer-events: none; opacity: 0; transform: translate(-50%, -50%); text-align: center; text-shadow: 0 2px 12px rgba(0,0,0,.55); }
.fx-delta b { display: block; font: 600 var(--fs-display)/1 var(--mono); }
.fx-delta small { display: block; font-weight: 500; font-size: var(--fs-sm); margin-top: 4px; }
.fx-delta.pos { color: var(--ok); } .fx-delta.neg { color: var(--bad); }
.fx-delta.show { animation: deltaPop 1.1s ease-out forwards; }
@keyframes deltaPop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  35% { transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}
body.shake main.screen.active { animation: shakeScreen .45s; }
@keyframes shakeScreen {
  10%, 90% { transform: translateX(-3px); } 20%, 80% { transform: translateX(6px); }
  30%, 50%, 70% { transform: translateX(-10px); } 40%, 60% { transform: translateX(10px); }
}
@media (max-width: 860px) { :root { --fs-display: 3rem; } .pg-right { gap: 12px; } }

/* ---------- Keyboard ---------- */
.btn kbd { margin: 0 3px 0 8px; }
/* Key combination such as Shift + Enter: separate keys joined by a plus sign */
.kbd-combo { display: inline-flex; align-items: baseline; gap: 4px; margin-left: 8px; opacity: .65; font-weight: 400; line-height: 1; }
.btn .kbd-combo kbd { margin: 0; opacity: 1; }
@media (hover: none) { .btn kbd, .kbd-combo { display: none; } }

/* ---------- Filter toggles ---------- */
.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.toggle { display: inline-flex; align-items: center; gap: 9px; padding: 9px 14px; color: var(--muted); }
.btn.toggle .box { width: 15px; height: 15px; border: 1.5px solid var(--muted); border-radius: 3px; display: grid; place-items: center; flex: none; transition: all .12s; }
.btn.toggle[aria-checked="true"] { color: var(--ink); border-color: var(--accent); background: var(--accent-dim); }
.btn.toggle[aria-checked="true"] .box { background: var(--accent); border-color: var(--accent); }
.btn.toggle[aria-checked="true"] .box::after { content: ""; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.topbar .toggles { gap: 6px; }
.topbar .btn { padding: 7px 12px; font-size: var(--fs-sm); }
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .topbar .toggles { order: 5; width: 100%; }
}

.toggles-label { align-self: center; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; margin-right: 4px; }

/* ---------- Capital input ---------- */
.capbox { position: relative; }
.capbox input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 11px 12px; color: var(--ink); font: inherit; font-size: var(--fs-sm); }
.capbox input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-dim); }
.capbox input:disabled { opacity: .6; }
.caplist { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; margin: 0; padding: 4px; list-style: none; max-height: 260px; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.caplist li { padding: 8px 10px; border-radius: 3px; cursor: pointer; }
.caplist li:hover, .caplist li.active { background: var(--accent-dim); color: var(--ink); }
.cap-actions { display: flex; gap: 8px; margin-top: 4px; }
@media (max-width: 860px) { .caplist { position: static; margin-top: 6px; max-height: 180px; } }
.topbar .btn { white-space: nowrap; }

/* ---------- Dialogs & session note ---------- */
.modal { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: min(480px, calc(100vw - 28px)); width: 100%; }
.modal::backdrop { background: rgba(0, 0, 0, .65); }
.modal h2 { font-size: var(--fs-md); margin-bottom: 10px; }
.modal p { color: var(--ink); opacity: .88; font-size: var(--fs-sm); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.modal-actions #switchCopy { margin-right: auto; }
.modal p + p { margin-top: 8px; }
.mono-code { font: 600 var(--fs-sm) var(--mono); letter-spacing: .08em; white-space: nowrap; }
/* Loading layer; under prefers-reduced-motion the global rule stops the spin, leaving a static ring */
.modal.busy[open] { display: grid; width: auto; padding: 22px 28px; }
.busy [role=status] { display: flex; align-items: center; gap: 14px; font-size: var(--fs-sm); }
.spinner { width: 28px; height: 28px; flex: none; border: 3px solid var(--border); border-top-color: var(--accent-text); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.form-error { color: var(--bad); font-size: var(--fs-sm); margin-top: 8px; }
.form-error:empty { display: none; }
.session-note { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 28px);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; font-size: var(--fs-sm); box-shadow: 0 10px 30px rgba(0,0,0,.45); }
@media (max-width: 560px) { .pg-title { display: none; } .pg-head { justify-content: flex-end; } }
