/* Styles: one file for every page.
   Colours are CSS variables ("tokens") so dark mode only has to redefine them. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --good: #0ca30c;
  --bad: #d03b3b;
  --good-wash: rgba(12, 163, 12, 0.1);
  --bad-wash: rgba(208, 59, 59, 0.1);
  /* puzzle symbol colours (by position in the puzzle; shape is the main cue) */
  --sym-0: #2a78d6;
  --sym-1: #eda100;
  --sym-2: #e34948;
  --sym-3: #1baf7a;
  --sym-ring: rgba(11, 11, 11, 0.35);
  --mx-grey: #a9a7a0;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #45453f;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --good-wash: rgba(12, 163, 12, 0.16);
    --bad-wash: rgba(208, 59, 59, 0.18);
    --sym-0: #3987e5;
    --sym-ring: rgba(255, 255, 255, 0.3);
    --mx-grey: #75736c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 0.75rem; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------------ layout */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1040px; margin: 0 auto; padding: 14px 16px;
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.topbar a:not(.brand) { font-size: 0.95rem; text-decoration: none; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px 48px; }
.wrap.narrow { max-width: 640px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card, .card + section, section + section { margin-top: 16px; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--bad); font-weight: 500; }
.eyebrow {
  font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 4px;
}

/* ------------------------------------------------------------------ controls */

.btn, input, select {
  font: inherit; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink);
}
.btn { padding: 10px 16px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 6px 12px; font-size: 0.875rem; }
.btn.danger { color: var(--bad); }
input, select { padding: 10px 12px; min-width: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.row { display: flex; align-items: center; gap: 8px; }
.row input { flex: 1; }

.linklike {
  background: none; border: 0; padding: 0; font: inherit; color: var(--accent);
  cursor: pointer; text-decoration: underline;
}

/* ------------------------------------------------------------------ question page */

.puzzle h2 { margin-bottom: 14px; }

.figure { margin: 4px 0 18px; display: flex; justify-content: center; }
.figure:empty { display: none; }

.lines {
  margin: 0; padding: 14px 18px; border-radius: 10px; background: var(--surface-2);
  font: 600 clamp(1.15rem, 4.6vw, 1.5rem)/1.6 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%;
}

.lines.prose { font: 500 1.05rem/1.7 var(--font); }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.options.wide { grid-template-columns: 1fr; }
.options.wide .option { font-size: 1rem; min-height: 50px; }
.option .picture { flex: 1; display: flex; justify-content: center; }
.option .picture .pz-svg { width: 100%; max-width: 120px; height: auto; }
.option {
  display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px 14px;
  font: 600 1.1rem var(--font); text-align: left;
  font-variant-numeric: tabular-nums;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--ink); cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-wash); }
.option:disabled { cursor: default; }
.option .key {
  flex: none; display: inline-grid; place-items: center; width: 22px; height: 22px;
  border-radius: 6px; background: var(--surface-2); color: var(--muted);
  font-size: 0.75rem; font-weight: 600;
}
.option .mark { margin-left: auto; font-size: 1.1rem; }
.option.is-correct { border-color: var(--good); background: var(--good-wash); }
.option.is-correct .mark { color: var(--good); }
.option.is-wrong { border-color: var(--bad); background: var(--bad-wash); }
.option.is-wrong .mark { color: var(--bad); }
.options.is-done .option:not(.is-correct):not(.is-wrong) { opacity: 0.55; }

.puzzle-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 12px; min-height: 36px;
}
.feedback { margin: 0; font-weight: 600; }
.feedback .icon-good { color: var(--good); }
.feedback .icon-bad { color: var(--bad); }

.status-line { margin-top: 14px; text-align: center; color: var(--muted); font-size: 0.9rem; }
.status-line strong { color: var(--ink); }

.loading { opacity: 0.5; transition: opacity 0.2s; }

/* puzzle SVGs (drawn by the server; colours come from here so they follow the theme) */
.pz-svg { display: block; max-width: 100%; height: auto; }
.pz-text { fill: var(--ink); font: 600 18px var(--font); }
.pz-rule { stroke: var(--grid); stroke-width: 1; }
.sym { stroke: var(--sym-ring); stroke-width: 1.5; }
.sym-0 { fill: var(--sym-0); }
.sym-1 { fill: var(--sym-1); }
.sym-2 { fill: var(--sym-2); }
.sym-3 { fill: var(--sym-3); }
.lg-gate { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.lg-open { fill: none; }
.lg-wire { fill: none; stroke: var(--ink-2); stroke-width: 1.75; }
.lg-label { fill: var(--ink-2); font: 600 11.5px var(--font); }
.lg-small { font-size: 10px; }
.lg-dot { fill: var(--ink); }
.lg-out { font-weight: 700; }
.mx-cell { fill: var(--surface-2); stroke: var(--grid); }
.mx-missing { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; }
.mx-q { fill: var(--accent); font-size: 28px; }
.mx-shape { stroke: var(--ink); stroke-width: 1.75; stroke-linejoin: round; }
.mx-fill-0 { fill: var(--surface); }
.mx-fill-1 { fill: var(--mx-grey); }
.mx-fill-2 { fill: var(--ink); }

/* ------------------------------------------------------------------ dashboard */

.note {
  border-left: 3px solid var(--accent); background: var(--accent-wash);
  padding: 10px 14px; border-radius: 0 10px 10px 0; font-size: 0.9rem; color: var(--ink-2);
}

.section-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px; margin-bottom: 12px;
}
.section-head h2 { margin: 0; }
.updated { font-size: 0.8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.updated::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good);
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.selected td { background: var(--accent-wash); }
tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.tiles { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { font-size: 0.8rem; color: var(--muted); margin: 0 0 2px; }
.tile .value { font-size: 1.6rem; font-weight: 650; margin: 0; }
.tile.hero .value { font-size: 3rem; line-height: 1.1; }
.tile .sub { font-size: 0.85rem; color: var(--ink-2); margin: 2px 0 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.grid-2 > .card { margin-top: 0; }
/* grid items default to min-width: auto, which lets a wide table push the page sideways */
.grid-2 > *, .tiles > * { min-width: 0; }

/* accuracy meter inside table cells */
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter-track {
  width: 80px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden;
}
.meter-fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }

.result-good { color: var(--good); font-weight: 600; }
.result-bad { color: var(--bad); font-weight: 600; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .ref { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--accent); opacity: 0.12; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font: 600 13px var(--font); }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; }
.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); padding: 8px 10px; font-size: 0.8rem; color: var(--ink-2);
}
.tooltip strong { display: block; font-size: 1.05rem; color: var(--ink); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; margin: 0; }

/* ------------------------------------------------------------------ phones */

@media (max-width: 720px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile.hero { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .card { padding: 16px; }
  .option { min-height: 54px; padding: 8px 10px; font-size: 1rem; gap: 8px; }
  .tile.hero .value { font-size: 2.6rem; }
}

/* ------------------------------------------------------------------ spatial puzzles */

:root {
  --vx-top: #b7d3f6; --vx-x: #6da7ec; --vx-y: #2a78d6; --vx-edge: #0d366b;
  --paper: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root { --vx-top: #6da7ec; --vx-x: #2a78d6; --vx-y: #184f95; --vx-edge: #0b0b0b; --paper: #2c2c2a; }
}
.vx { stroke: var(--vx-edge); stroke-width: 1.2; stroke-linejoin: round; }
.vx-top { fill: var(--vx-top); }
.vx-x { fill: var(--vx-x); }
.vx-y { fill: var(--vx-y); }

.cube-face { stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; }
.cube-top { fill: var(--paper); }
.cube-x { fill: var(--surface-2); }
.cube-y { fill: var(--grid); }
.gl { fill: var(--ink); }
.gl-line { fill: none; stroke: var(--ink); stroke-width: 10; }
.gl-text { fill: var(--ink); font-family: var(--font); font-weight: 700; }
.net-sq { fill: var(--paper); stroke: var(--ink); stroke-width: 1.5; }

.poly { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }

.pf-ghost { fill: none; stroke: var(--grid); stroke-width: 1; }
.pf-paper { fill: var(--paper); stroke: var(--ink-2); stroke-width: 1.5; }
.pf-moving { fill: var(--accent-wash); stroke: var(--accent); stroke-width: 1.5; }
.pf-fold { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; }
.pf-arrow { fill: none; stroke: var(--accent); stroke-width: 2; }
.pf-head { fill: var(--accent); }
.pf-hole { fill: var(--page); stroke: var(--ink); stroke-width: 1.5; }
.pf-grid { stroke: var(--grid); stroke-width: 0.75; }
.pf-step { fill: var(--muted); font: 600 22px var(--font); }

.dice-floor { fill: var(--surface-2); stroke: var(--axis); stroke-width: 1; }
.dice-end { fill: var(--accent-wash); stroke: var(--accent); stroke-width: 1.5; }
.dice-path { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.dice-arrow { fill: var(--accent); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.gallery > .card { margin-top: 0; min-width: 0; }

/* ------------------------------------------------------------------ accounts */

.nav { display: flex; align-items: center; gap: 14px; font-size: 0.95rem; }
.notice { margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--good-wash); }
.actions { display: inline-flex; gap: 6px; }
.stack { display: grid; gap: 12px; margin-top: 12px; }
.stack label { display: grid; gap: 4px; font-weight: 500; font-size: 0.95rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--grid); margin-top: 8px; }
.tab {
  background: none; border: 0; padding: 10px 12px; font: inherit; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }
.puzzle-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.puzzle-head .eyebrow { margin: 0; }
.help-dialog {
  max-width: min(520px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); padding: 20px;
}
.help-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.help-key { margin: 8px 0 14px; overflow-x: auto; }
.help-key .pz-svg { max-width: 100%; height: auto; }
