/* Layout: a chart-table app. Light chart paper for study surfaces, with a deliberately
   dark night-water stage wherever lights, flashes or radar-style scenes need darkness. */
:root {
  --paper: #F4F7F7;
  --panel: #FFFFFF;
  --ink: #12273A;
  --muted: #566977;
  --line: #D6E0E3;
  --shoal: #D5E9F1;
  --land: #EEDFB2;
  --magenta: #9E1F68;          /* NOAA chart magenta, the accent */
  --on-accent: #FFFFFF;
  --ok: #1D7445;
  --ok-bg: #E3F3EA;
  --bad: #B3261E;
  --bad-bg: #FBE7E5;
  --warn: #8A5A00;
  /* Night stage: always dark, by design */
  --night: #050C16;
  --night-2: #0B1828;
  --night-line: #1C2E44;
  --night-ink: #C9D6E2;
  --l-red: #FF3B30;
  --l-green: #27E36A;
  --l-white: #FFF6DD;
  --l-yellow: #FFC23A;
  --f-display: 'Big Shoulders Display', 'Arial Narrow', 'Helvetica Neue', sans-serif;
  --f-body: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0C141D; --panel: #131F2B; --ink: #E4ECF1; --muted: #93A5B3; --line: #243546;
    --shoal: #14314A; --land: #3B3424; --magenta: #E066A4; --on-accent: #1A0712;
    --ok: #5BCB8A; --ok-bg: #12301F; --bad: #FF7A6E; --bad-bg: #3A1512; --warn: #E8B54A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0C141D; --panel: #131F2B; --ink: #E4ECF1; --muted: #93A5B3; --line: #243546;
  --shoal: #14314A; --land: #3B3424; --magenta: #E066A4; --on-accent: #1A0712;
  --ok: #5BCB8A; --ok-bg: #12301F; --bad: #FF7A6E; --bad-bg: #3A1512; --warn: #E8B54A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { background: var(--paper); color: var(--ink); }
body { margin: 0; font-family: var(--f-body); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--magenta); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.mono { font-family: var(--f-mono); }

.wrap { max-width: 1120px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* ---------- Header / HUD ---------- */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--panel); }
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 9; background: var(--panel); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--f-display); font-weight: 800; font-size: 1.6rem; letter-spacing: 0.02em; text-transform: uppercase; }
.brand-mark { width: 26px; height: 26px; color: var(--magenta); display: inline-flex; }
.brand-mark svg { width: 100%; height: 100%; overflow: visible; }
.hud { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.hud .lbl, .lbl { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.hud strong { display: block; font-size: 0.95rem; }
.hud-meter { min-width: 180px; }
.hud-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; background: var(--magenta); transition: width 0.6s ease; }
@media (max-width: 640px) { .hud-streak, .hud-rank { display: none; } .hud-meter { min-width: 150px; } }

/* ---------- Buttons & controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 999px; background: var(--magenta); color: var(--on-accent); padding: 11px 20px; font-weight: 700; text-decoration: none; cursor: pointer; font-size: 0.95rem; transition: transform 0.12s ease, filter 0.12s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.small { padding: 8px 14px; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.linkish { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; font-size: 0.85rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 7px; cursor: pointer; font-weight: 600; font-size: 0.85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.12), inset 0 0 0 1px var(--line); }
.seg .sw { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
.tog { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 13px; cursor: pointer; font-weight: 600; font-size: 0.85rem; color: var(--muted); }
.tog[aria-pressed="true"] { border-color: var(--magenta); color: var(--magenta); background: color-mix(in srgb, var(--magenta) 8%, var(--panel)); }

/* ---------- Home ---------- */
.home { padding-block: 32px 64px; display: grid; gap: 48px; }
.hero { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 28px; align-items: stretch; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } }
.eyebrow { font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--magenta); font-weight: 700; margin-bottom: 10px; }
.hero h1 { font-family: var(--f-display); font-weight: 800; font-size: clamp(2.6rem, 6vw, 4.6rem); line-height: 0.95; text-transform: uppercase; letter-spacing: 0.005em; }
.lede { font-size: 1.08rem; color: var(--muted); max-width: 62ch; margin-top: 14px; }
.hero-cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.logbook { align-self: start; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.log-rank { font-family: var(--f-display); font-weight: 800; font-size: 2.1rem; line-height: 1; text-transform: uppercase; }
.ladder { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.ladder span { height: 8px; border-radius: 2px; background: var(--line); }
.ladder span.on { background: var(--magenta); }
.log-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0; }
.log-stats dt { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.log-stats dd { margin: 0; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.sec { display: grid; gap: 16px; }
.sec-head { display: grid; gap: 4px; border-top: 2px solid var(--ink); padding-top: 14px; }
.sec-code { font-family: var(--f-mono); font-size: 0.75rem; color: var(--magenta); letter-spacing: 0.08em; }
.sec-head h2 { font-family: var(--f-display); font-weight: 800; font-size: 2rem; text-transform: uppercase; line-height: 1; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; text-decoration: none; color: var(--ink); display: grid; gap: 6px; align-content: start; transition: border-color 0.15s, transform 0.15s; }
.tile:hover { border-color: var(--magenta); transform: translateY(-2px); }
.tile h3 { font-size: 1.08rem; }
.tile p { color: var(--muted); font-size: 0.9rem; }
.tile-top { display: flex; justify-content: space-between; align-items: center; }
.tile-kind { font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.kind-game .tile-kind, .kind-hands .tile-kind, .kind-audio .tile-kind { color: var(--magenta); }
.stars { display: inline-flex; gap: 3px; }
.stars i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--line); }
.stars i.on { background: var(--magenta); border-color: var(--magenta); }
.foot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); padding-top: 18px; }
.foot p { max-width: 70ch; }

/* ---------- Module page ---------- */
.mod { padding-block: 20px 64px; display: grid; gap: 18px; }
.crumbs { display: flex; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.mod-head h1 { font-family: var(--f-display); font-weight: 800; font-size: clamp(2.2rem, 5vw, 3.4rem); text-transform: uppercase; line-height: 0.95; }
.mod-head .lede { margin-top: 8px; }
.mod-body { display: grid; gap: 16px; }

.game { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .game { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; gap: 14px; min-width: 0; }
.card h2 { font-size: 1.15rem; }
.card h3 { font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.prompt { font-size: 1.2rem; font-weight: 700; line-height: 1.35; }
.prompt small { display: block; font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-top: 4px; }
.ctrl-group { display: grid; gap: 6px; }
.ctrl-grid { display: grid; gap: 12px; }

.stage { background: radial-gradient(120% 90% at 50% 0%, var(--night-2), var(--night)); border-radius: 14px; overflow: hidden; position: relative; color: var(--night-ink); }
.stage svg { display: block; width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage .stage-label { position: absolute; left: 14px; top: 12px; font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: #7F93A8; }
.stage.day { background: linear-gradient(#BFD9E8, #E6F1F6 55%, #9DC3D6 55.2%, #7FAEC6); }
.paper-stage { background: var(--shoal); border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.paper-stage svg { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }

.scorebar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.scorebar > div { background: var(--paper); border-radius: 8px; padding: 8px 10px; }
.scorebar strong { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.fb { border-radius: 10px; padding: 12px 14px; display: grid; gap: 6px; font-size: 0.95rem; }
.fb.ok { background: var(--ok-bg); color: var(--ink); box-shadow: inset 3px 0 0 var(--ok); }
.fb.bad { background: var(--bad-bg); color: var(--ink); box-shadow: inset 3px 0 0 var(--bad); }
.fb.ok strong { color: var(--ok); }
.fb.bad strong { color: var(--bad); }
.fb ul { margin: 0; padding-left: 18px; }
.memory { font-family: var(--f-mono); font-size: 0.85rem; background: var(--paper); border-radius: 8px; padding: 8px 10px; }

.jur { display: inline-block; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; padding: 3px 8px; border-radius: 4px; border: 1px solid currentColor; }
.jur-BOTH { color: var(--muted); }
.jur-INT { color: #2860B8; }
.jur-INL { color: var(--warn); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .jur-INT { color: #7EAEF5; } }
:root[data-theme="dark"] .jur-INT { color: #7EAEF5; }

.opts { display: grid; gap: 8px; }
.opt { text-align: left; border: 1.5px solid var(--line); background: var(--panel); border-radius: 10px; padding: 12px 14px; cursor: pointer; font-size: 0.98rem; display: flex; gap: 12px; align-items: flex-start; }
.opt:hover:not([disabled]) { border-color: var(--magenta); }
.opt .key { font-family: var(--f-mono); font-size: 0.78rem; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; flex: none; margin-top: 2px; }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt[disabled] { cursor: default; }

/* Ordering list (drag) */
.order { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.order li { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: grab; touch-action: none; user-select: none; }
.order li.dragging { opacity: 0.9; border-color: var(--magenta); box-shadow: 0 8px 24px rgba(0,0,0,0.18); cursor: grabbing; position: relative; z-index: 2; }
.order li .pos { font-family: var(--f-mono); font-size: 0.8rem; color: var(--muted); width: 1.5em; }
.order li .grip { margin-left: auto; color: var(--muted); display: flex; gap: 4px; }
.order li .grip button { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; width: 30px; height: 28px; cursor: pointer; }
.order li.right { border-color: var(--ok); background: var(--ok-bg); }
.order li.wrong { border-color: var(--bad); background: var(--bad-bg); }
.order .lights { display: inline-flex; flex-direction: column; gap: 2px; padding: 4px; background: var(--night); border-radius: 5px; }
.order .lights i, .mini-lights i { width: 9px; height: 9px; border-radius: 50%; display: block; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

input.num { font: inherit; font-variant-numeric: tabular-nums; width: 6.5em; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--panel); color: var(--ink); font-size: 1.05rem; }
input.num:focus { border-color: var(--magenta); outline: none; }

/* Toasts */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 999px; font-weight: 700; z-index: 50; transition: opacity 0.4s, transform 0.4s; }
.toast.rank { background: var(--magenta); color: var(--on-accent); }
.toast.out { opacity: 0; transform: translate(-50%, 10px); }
.xp-float { position: fixed; right: calc(24px + env(safe-area-inset-right, 0px)); top: calc(80px + env(safe-area-inset-top, 0px)); font-family: var(--f-display); font-weight: 800; font-size: 1.6rem; color: var(--magenta); z-index: 50; animation: rise 1.3s ease-out forwards; pointer-events: none; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } 20% { opacity: 1; } to { opacity: 0; transform: translateY(-36px); } }
@media (prefers-reduced-motion: reduce) { .xp-float { animation: none; } .tile, .btn { transition: none; } }

/* Horn */
.horn { width: 100%; padding: 26px; border-radius: 14px; border: 0; background: var(--ink); color: var(--paper); font-family: var(--f-display); font-weight: 800; font-size: 1.6rem; text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.horn.on { background: var(--magenta); color: var(--on-accent); }
.blasts { display: flex; gap: 6px; align-items: center; min-height: 26px; flex-wrap: wrap; }
.blasts i { height: 12px; border-radius: 6px; background: var(--ink); display: block; }
.blasts i.S { width: 14px; }
.blasts i.P { width: 56px; }
.blasts i.B { width: 56px; height: 12px; background: repeating-linear-gradient(90deg, var(--warn) 0 4px, transparent 4px 7px); }
.blasts i.k { width: 10px; height: 10px; background: var(--warn); border-radius: 50%; }
.blasts i.G { width: 22px; height: 22px; border-radius: 50%; background: none; border: 3px solid var(--warn); }
.blasts i.live { background: var(--magenta); }

/* Drag tokens (fire) */
.tokens { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.token { border: 1.5px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px; cursor: grab; touch-action: none; user-select: none; display: grid; gap: 4px; justify-items: center; text-align: center; font-weight: 700; font-size: 0.85rem; }
.token.sel { border-color: var(--magenta); box-shadow: 0 0 0 3px color-mix(in srgb, var(--magenta) 25%, transparent); }
.token small { font-weight: 500; color: var(--muted); font-size: 0.72rem; }
.token svg { width: 34px; height: 54px; }
.ghost-token { position: fixed; pointer-events: none; z-index: 60; opacity: 0.92; transform: translate(-50%, -50%); }
.drop-hot { outline: 3px dashed var(--magenta); outline-offset: 4px; }

table.ref { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
table.ref th, table.ref td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.ref th { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.scroll-x { overflow-x: auto; }

.result-big { font-family: var(--f-display); font-weight: 800; font-size: 3.4rem; line-height: 1; }
.pass { color: var(--ok); }
.fail { color: var(--bad); }
.ladder-tvmdc { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 560px) { .ladder-tvmdc { grid-template-columns: 1fr; } }
.rung { background: var(--paper); border-radius: 10px; padding: 10px; display: grid; gap: 6px; justify-items: start; min-width: 0; }
.rung .big { font-family: var(--f-display); font-weight: 800; font-size: 2.2rem; line-height: 1; }
.rung.given .val { font-family: var(--f-mono); font-size: 1.15rem; font-weight: 600; }
.rung .lbl { font-size: 0.68rem; }
