/* styles.css -- sudoStates: self-contained deep-pine theme.
 *
 * Design tokens are vendored from the aswmac site (assets/css/base.css) so the
 * game looks at home when copied onto the site, but the project ships its own
 * copy -- no external stylesheet, no web font (system stack), no fetch.
 *
 * Map rendering contract (with index.html + game.js):
 *   .state       -> stroke equals fill  => no visible borders (seamless body)
 *   .state:hover -> only that state's outline lights up (accent)
 *   .state.missed-> faint orange tint, sticky for the round (tripped here)
 *   .state.wrong -> temporary red outline (cleared when the target is hit)
 *   .state.done  -> persistent accent outline + tinted fill (the map fills in)
 *   .state.done.missed -> done + orange tint (was picked wrong earlier)
 */

:root {
  /* Color system (deep pine / forest, dark is default) */
  --bg:        #0e1512;
  --surface:   #16211c;
  --surface-2: #1d2b24;
  --border:    #2b3a33;
  --text:      #e8efe9;
  --text-dim:  #9fb3a8;
  --accent:    #6ee7a0;
  --accent-2:  #f2b64c;
  --danger:    #e76a5a;

  /* Map colors (dark) */
  --map-fill:      #34453d;
  --done-fill:     #40584a;
  --missed-fill:   #66603f;  /* faint orange tint: tripped here this round */
  --missed-done:   #7d7a4d;  /* done, but was picked wrong earlier */
  --overlay-bg:    rgba(14, 21, 18, 0.78);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-6: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-2: 0 2px 4px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.4);

  /* Typography -- system stack only (no web fonts, no fetch) */
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

/* Light mode (mirrors the site's light tokens) */
@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f0f4f2;
    --surface:   #e8efe9;
    --surface-2: #dce6e3;
    --border:    #bfc9c5;
    --text:      #0e1512;
    --text-dim:  #5c6b65;
    --accent:    #0f5c36;
    --accent-2:  #b8860b;
    --danger:    #a83225;

    --map-fill:      #c6d4cc;
    --done-fill:     #aec7b9;
    --missed-fill:   #c6c193;
    --missed-done:   #b0ad82;
    --overlay-bg:    rgba(240, 244, 242, 0.82);
  }
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h2 { font-size: clamp(1.4rem, 2.5vw, 1.9rem); font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { font: inherit; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.4em;
}

/* Utilities */
.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;
}
.hidden { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--bg);
  padding: 8px 16px; border-radius: 0 0 8px 0; z-index: 100;
}
.skip-link:focus { left: 0; }

/* Header */
.site-header {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 16px 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: 0.01em; }
.brand:hover { text-decoration: none; }
.brand span { color: var(--accent); }
.brand-sep { color: var(--text-dim); }
.brand-sub { color: var(--text-dim); font-weight: 600; font-size: 1rem; }
#btn-about { margin-left: auto; }
#btn-focus { margin-left: auto; }
#btn-about + #btn-focus { margin-left: 0; }

/* Focus mode: minimize the chrome so the map gets all the space. The header
   shrinks to the toggle button itself; the prompt keeps a compact single line. */
#site-header.focus .brand,
#site-header.focus .brand-sep,
#site-header.focus .brand-sub,
#site-header.focus #btn-about { display: none; }
#site-header.focus #btn-focus { margin-left: 0; }
#game.focus .stat,
#game.focus #btn-reset,
#game.focus .legend,
#game.focus .site-footer { display: none; }
#game.focus .prompt-bar { margin: 8px 0 10px; }
#game.focus .prompt { flex: 1 1 auto; min-width: 0; padding: 4px 14px; }
#game.focus .prompt-name { font-size: clamp(1.1rem, 2.6vw, 1.5rem); }
#game.focus .map-frame { padding: 6px; }
/* Fit to screen: lift the 1040px column ceiling, then size the map to the
   smaller of full width and what fits the viewport height (975:610 ratio) --
   a wide display fills horizontally, a tall one fills vertically, and it
   never overflows. The 200px estimate is the remaining chrome (header,
   compact prompt, paddings, the atlas bar when shown). */
#site-header.focus,
#game.focus { max-width: none; }
#game.focus #map {
  width: min(100%, calc((100vh - 200px) * 1.5984));
  margin: 0 auto;
}

/* Layout */
.game {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

/* Prompt bar */
.prompt-bar {
  display: flex;
  align-items: stretch;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0 14px;
}
.stat, .prompt {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 74px;
}
.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}
.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-value.missed { color: var(--danger); }
.prompt { flex: 1 1 220px; min-width: 180px; }
/* A constant-height single line (clipped, not wrapping). The name is the
   longest piece of content, so letting it wrap would grow the prompt row,
   which grows the page, which on mobile trips a transient vertical
   scrollbar -- the "white bar" flash on the right and bottom that appeared
   whenever a new (longer) state name showed up. One clipped line keeps the
   layout height constant; the full name is carried in the title attribute. */
.prompt-name {
  display: block;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: clamp(1.7rem, 4.5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.15;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
  font-size: 1rem;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-1); filter: brightness(1.1); }
.btn:active { transform: translateY(0); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface); }
.btn-small { padding: 0.5rem 0.9rem; font-size: 0.9rem; align-self: center; }

/* Map */
.map-frame {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: clamp(8px, 2vw, 18px);
}
#map {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

/* The states: no visible borders by default (stroke == fill). */
.state {
  fill: var(--map-fill);
  fill-rule: evenodd; /* robust if a future source adds hole rings (lakes) */
  stroke: var(--map-fill);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill 0.15s ease, stroke 0.15s ease;
}
/* Hover reveals exactly one outline; everything else stays seamless. */
.state:hover {
  stroke: var(--accent);
  stroke-width: 1.5;
}
/* Sticky "tripped here this round" mark: faint tint, stroke follows the fill
   so it stays seamless in the borderless body. */
.state.missed {
  fill: var(--missed-fill);
  stroke: var(--missed-fill);
}
/* Temporary wrong flash (class removed ~0.9 s later, or on hit). */
.state.wrong {
  stroke: var(--danger);
  stroke-width: 2;
}
.state.wrong:hover { stroke: var(--danger); }
/* Permanent done: tinted fill + accent outline. */
.state.done {
  fill: var(--done-fill);
  stroke: var(--accent);
  stroke-width: 1.5;
}
.state.done:hover { stroke: var(--accent); }
/* Done, but picked wrong earlier: good outline, tinted fill. */
.state.done.missed {
  fill: var(--missed-done);
}

@media (prefers-reduced-motion: no-preference) {
  .state.wrong { animation: wrong-pulse 0.9s ease-out; }
  @keyframes wrong-pulse {
    0% { stroke-width: 4; }
    100% { stroke-width: 2; }
  }
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: inherit;
  padding: 16px;
}
.overlay-card {
  max-width: 460px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
@media (prefers-reduced-motion: no-preference) {
  .overlay-card { animation: fade-in 0.35s ease-out; }
  @keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }
}
/* The round-end card carries the most content (results, best line, a history
   table, buttons). The base .overlay backdrop is 0.78 alpha + a 6 px blur,
   which lets the finished map's colored states bleed through and clutter the
   card. So this one fully covers the map (opaque, no blur). It also scrolls
   if the card is taller than the frame, and the backdrop reads as a dismiss
   target (click outside the card -> view the map; see game.js). */
#end-overlay {
  background: var(--bg);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  overflow-y: auto;
  align-items: flex-start;
  cursor: pointer;
}
#end-overlay .overlay-card {
  margin: auto;
  cursor: default;
}

.overlay-lede {
  color: var(--text-dim);
  margin: 0 0 4px;
}
.overlay-rules {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  text-align: left;
}
.overlay-rules li { margin: 0 0 6px; color: var(--text); }
.overlay-rules li::before { content: "▸ "; color: var(--accent); }
.kbd-hint { color: var(--text-dim); font-size: 0.85rem; margin: 8px 0 0; }
.version-line { color: var(--text-dim); font-size: 0.85rem; margin: 4px 0 0; }

.results {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
  margin: 4px 0 0;
}
.result {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
}
.result dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}
.result dd {
  margin: 2px 0 0;
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.best-badge {
  background: var(--accent-2);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 2px 12px;
  border-radius: 999px;
}
.best-line { color: var(--text-dim); font-size: 0.9rem; margin: 0; }
.btn-row { display: flex; gap: 10px; justify-content: center; }

/* Round history (results overlay) */
.history { width: 100%; max-width: 520px; margin-top: 6px; }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
  margin: 0;
}
.history-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 6px; }
.history-table th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.history-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.history-table tbody tr:last-child td { border-bottom: none; }
.history-empty { color: var(--text-dim); font-size: 0.85rem; margin: 8px 0 0; text-align: center; }

/* View-map (atlas) bar: where the results card parks itself so the finished
   map stays fully observable. Slides along the bottom edge of the map frame. */
.atlas-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.atlas-summary {
  font-weight: 600;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

/* Legend + footer */
.legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 14px 0 0;
}
.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-left: 12px;
  vertical-align: middle;
}
.swatch:first-child { margin-left: 0; }
.swatch-base   { background: var(--map-fill); border: 1px solid var(--border); }
.swatch-done   { background: var(--done-fill); border: 1.5px solid var(--accent); }
.swatch-wrong  { background: var(--map-fill); border: 1.5px solid var(--danger); }
.swatch-missed { background: var(--missed-fill); border: 1px solid var(--border); }

.site-footer { margin-top: 20px; text-align: center; }
.footline { color: var(--text-dim); font-size: 0.85rem; margin: 0; }
.back-link { color: var(--text-dim); }
.back-link:hover { color: var(--accent); }

/* Prompt text: plain refresh on change (no pop animation). The old
   scale-pop forced a synchronous reflow on every pick; with the name now a
   constant-height line there is nothing to animate and nothing to reflow. */

/* Mobile: stats row wraps, prompt takes full width */
@media (max-width: 620px) {
  .prompt-bar { gap: 8px; }
  .stat { min-width: 0; flex: 1 1 auto; padding: 5px 10px; }
  .stat-value { font-size: 1rem; }
  .prompt { flex-basis: 100%; order: -1; }
  .results { grid-template-columns: repeat(2, 1fr); }
  .atlas-summary { display: none; }  /* keep the two buttons usable on narrow screens */
}
