/* Colour roles come from the validated palette. Both modes are selected --
   the dark steps were chosen for the dark surface, not flipped from the light
   ones. Light is the base; dark arrives either from the OS preference or from
   the in-page toggle, and the toggle wins both ways. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f4f4f1;
  --raised: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --target: #eb6834;
  --ramp-lo: #86b6ef;
  --ramp-mid: #2a78d6;
  --ramp-hi: #0d366b;
  --good: #006300;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #101014;
    --page: #0a0a0c;
    --raised: #17171d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --target: #d95926;
    --ramp-lo: #184f95;
    --ramp-mid: #3987e5;
    --ramp-hi: #cde2fb;
    --good: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #101014;
  --page: #0a0a0c;
  --raised: #17171d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --target: #d95926;
  --ramp-lo: #184f95;
  --ramp-mid: #3987e5;
  --ramp-hi: #cde2fb;
  --good: #0ca30c;
}

* { box-sizing: border-box; }

/* A class-level `display` outranks the user-agent rule for [hidden], which
   would otherwise leave the loading overlay and the empty-state note on top of
   the app forever. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 -apple-system, system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.nowrap { white-space: nowrap; }

/* ---------- loading ---------- */

.loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--page); z-index: 10;
}
.loading-inner { width: min(360px, 82vw); text-align: center; }
.loading-note { color: var(--text-secondary); font-size: 13px; margin: 10px 0 18px; }
.loading-pct { color: var(--text-muted); font-size: 12px; margin: 10px 0 0;
               font-variant-numeric: tabular-nums; }
.bar { height: 3px; background: var(--gridline); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: var(--ramp-mid); transition: width 0.15s linear; }

/* ---------- chrome ---------- */

.app { max-width: 1400px; margin: 0 auto; padding: 22px 22px 60px; }

.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.wordmark {
  margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.015em;
}
.wordmark span { color: var(--target); }
.topbar-meta { display: flex; align-items: center; gap: 10px; }
.game-label { color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.benchmarks {
  margin: 10px 0 20px; color: var(--text-secondary); font-size: 13px;
  max-width: 78ch; line-height: 1.55;
}
.benchmarks b { color: var(--text-primary); font-weight: 600;
                font-variant-numeric: tabular-nums; }

button {
  font: inherit; cursor: pointer; border-radius: 7px;
  border: 1px solid var(--border); background: var(--raised);
  color: var(--text-primary); padding: 7px 13px;
  transition: border-color 0.12s, background 0.12s;
}
button:hover { border-color: var(--axis); }
button:focus-visible { outline: 2px solid var(--ramp-mid); outline-offset: 2px; }
.ghost { background: transparent; color: var(--text-secondary); }
.ghost:hover { color: var(--text-primary); }
.small { padding: 5px 10px; font-size: 13px; }
.primary {
  background: var(--ramp-mid); border-color: transparent; color: #fff; font-weight: 600;
  padding: 9px 20px;
}
.primary:hover { filter: brightness(1.08); }

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

.layout {
  display: grid; gap: 18px;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr);
  align-items: start;
}
@media (max-width: 980px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
}
.canvas-wrap { position: relative; aspect-ratio: 4 / 3; min-height: 320px; }
@media (max-width: 980px) { .canvas-wrap { aspect-ratio: 1 / 1; } }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%;
                      touch-action: none; }
.map-empty {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0;
  color: var(--text-muted); font-size: 13px; text-align: center; padding: 0 30px;
}

/* ---------- legend ---------- */

.legend { margin-top: 12px; border-top: 1px solid var(--gridline); padding-top: 12px; }
.legend-row { display: flex; gap: 18px; flex-wrap: wrap; }

.projections {
  display: inline-flex; margin-bottom: 12px; padding: 2px; gap: 2px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--page);
}
.projections button {
  border: 0; background: transparent; color: var(--text-secondary);
  padding: 5px 12px; font-size: 13px; border-radius: 6px;
}
.projections button:hover { color: var(--text-primary); }
.projections button[aria-pressed="true"] {
  background: var(--raised); color: var(--text-primary); font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}
.legend-item { display: inline-flex; align-items: center; gap: 7px;
               font-size: 13px; color: var(--text-secondary); }
.swatch { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.swatch-target { background: var(--target); }
.swatch-guess { background: linear-gradient(90deg, var(--ramp-lo), var(--ramp-hi)); }

.legend-scale { display: flex; align-items: center; gap: 9px; margin-top: 10px; }
.scale-bar {
  flex: 1; height: 7px; border-radius: 4px; min-width: 90px;
  background: linear-gradient(90deg, var(--ramp-lo), var(--ramp-mid), var(--ramp-hi));
}
.scale-cap { font-size: 11px; color: var(--text-muted); white-space: nowrap;
             font-variant-numeric: tabular-nums; }
.legend-note { margin: 10px 0 0; font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ---------- play panel ---------- */

.guess-form { display: flex; gap: 8px; }
.guess-input {
  flex: 1; min-width: 0; font: inherit; padding: 9px 12px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-primary);
}
.guess-input:focus { outline: 2px solid var(--ramp-mid); outline-offset: -1px; border-color: transparent; }

.message { margin: 10px 0 0; font-size: 13px; min-height: 20px; color: var(--text-secondary); }
.message.error { color: var(--target); }
.message.win { color: var(--good); font-weight: 600; }

.actions { display: flex; align-items: center; gap: 6px; margin: 14px 0 10px; }
.spacer { flex: 1; }

.table-wrap { max-height: 540px; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.guesses { width: 100%; border-collapse: collapse; font-size: 14px; }
.guesses thead th {
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 7px 8px; border-bottom: 1px solid var(--gridline);
}
.guesses th.num, .guesses td.num { text-align: right; }
.guesses th.col-n, .guesses td.col-n { width: 36px; color: var(--text-muted); }
.guesses th.prox { width: 34%; }
.guesses td { padding: 7px 8px; border-bottom: 1px solid var(--gridline);
              font-variant-numeric: tabular-nums; }
.guesses td.word { font-variant-numeric: normal; }
.guesses tr.latest td { background: color-mix(in srgb, var(--ramp-mid) 12%, transparent); }
.guesses tr.correct td { background: color-mix(in srgb, var(--good) 18%, transparent);
                         font-weight: 600; }

.dotcell { display: inline-flex; align-items: center; gap: 8px; }
.rowdot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.prox-bar { display: flex; align-items: center; gap: 8px; }
.prox-track { flex: 1; height: 5px; border-radius: 3px; background: var(--gridline);
              overflow: hidden; min-width: 40px; }
/* display:block matters: an inline span ignores width and height, which left
   every proximity bar looking empty. */
.prox-fill { display: block; height: 100%; background: var(--ramp-mid); border-radius: 3px; }
.prox-val { font-size: 12px; color: var(--text-secondary); min-width: 34px; text-align: right; }
.cold { color: var(--text-muted); font-size: 13px; }

.empty-note { color: var(--text-muted); font-size: 13px; padding: 14px 8px; margin: 0; }

/* ---------- about ---------- */

.about { margin-top: 20px; border-top: 1px solid var(--gridline); padding-top: 14px; }
.about summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.about summary:hover { color: var(--text-primary); }
.about-body { max-width: 74ch; }
.about-body p { color: var(--text-secondary); font-size: 14px; }
.about-body strong { color: var(--text-primary); }
