/* =========================================================================
   Chain — Daily Word Chain
   Zero-dependency stylesheet. System font stack only. Mobile-first.
   ========================================================================= */

/* Visibility is toggled in JS via el.hidden. Author display rules (.streak,
   .modal-overlay, .state-screen, …) otherwise beat the UA [hidden] style, so
   force it: anything with the hidden attribute is truly hidden. */
[hidden] { display: none !important; }

:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --ink: #18181b;
  --muted: #71717a;
  --faint: #d1d5db;
  --line: #e4e4e7;
  --accent-blue: #2563eb;
  --good: #0d5c1f;
  --bad: #dc2626;
  --hint: #8b4513;
  --reveal: #2563eb;
  --clue: #a16207;     /* yellow  — solved using the clue */
  --letters: #c2410c;  /* orange  — solved after revealing letters */
  --fail: #52525b;     /* black   — revealed / skipped the word */
  /* Wordle per-letter feedback fills (distinct from the tier underlines).
     Fills are darkened so white text clears WCAG 4.5:1 and the three states
     differ in luminance (not hue alone) for colorblind viewers; a redundant
     status glyph is added on the tiles/keys below. */
  --wd-correct: #15803d;  /* green  — right letter, right spot (white ~4.9:1) */
  --wd-present: #b45309;  /* amber  — right letter, wrong spot (white ~4.6:1) */
  --wd-absent:  #6b7280;  /* grey   — not in the word (white ~4.0:1) */
  --wd-on:      #ffffff;  /* text on filled tiles/keys */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --slot-base: 32px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0f;
    --panel: #161618;
    --ink: #f5f5f5;
    --muted: #b4bac2;
    --faint: #3f3f46;
    --line: #27272a;
    --accent-blue: #3b82f6;
    --good: #22c55e;
    --bad: #f87171;
    --hint: #f59e0b;
    --reveal: #3b82f6;
    --clue: #eab308;
    --letters: #fdba74;
    --fail: #d4d4d8;
    /* Wordle fills — tuned for contrast on the dark surface. Present is
       darkened so #f5f5f5 text clears 4.5:1; absent is lightened so an
       eliminated key separates from the idle key (~#232325) by >=3:1. */
    --wd-correct: #15803d;
    --wd-present: #8a5a0a;
    --wd-absent:  #666d79;
    --wd-on:      #f5f5f5;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}
@media (max-width: 520px) {
  :root { --slot-base: 28px; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Lock to the dynamic viewport. We ship our own on-screen keyboard and never
     open the native one, so the height is stable — plain 100dvh is correct and
     consistent across browsers (a JS VisualViewport override misbehaved on
     Firefox Android and collapsed the board). overflow:hidden keeps the page
     pinned; only .chain scrolls. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}
.app {
  width: 100%;
  max-width: 480px;
  /* App-shell: header + dock stay fixed, only .chain scrolls. Fills the body,
     which tracks the visible viewport above the keyboard. */
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ---------- HEADER ---------- */
header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.wordmark {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 4px;
  text-transform: uppercase;
  line-height: 1;
}
.submeta {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hgroup { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.counter { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.dots { display: flex; gap: 3px; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--faint);
  transition: background 0.25s ease;
}
.dot.filled { background: var(--good); }

.streak {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  background: color-mix(in srgb, var(--hint) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--hint) 32%, transparent);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.streak .flame { font-size: 12px; }

.ctrls { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.btn {
  font-family: inherit;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 6px 8px;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease, box-shadow 0.1s ease;
}
.btn:hover { border-color: var(--muted); background: color-mix(in srgb, var(--ink) 5%, var(--panel)); }
.btn:active { transform: scale(0.96); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.18); }
.btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
/* 44x44 hit area; glyph stays its visual size, centered. */
.btn.icon {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
}
.btn.primary {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
  font-weight: 700;
  font-size: 14px;
  padding: 0 16px;
  min-height: 44px;
}
.btn.primary:hover {
  background: color-mix(in srgb, #fff 12%, var(--accent-blue));
  border-color: color-mix(in srgb, #fff 12%, var(--accent-blue));
}
.btn.primary:active { box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.28); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 700; }
.btn.danger:hover {
  background: color-mix(in srgb, #fff 12%, var(--bad));
  border-color: color-mix(in srgb, #fff 12%, var(--bad));
}
.btn.danger:active { box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.28); }

/* ---------- BANNER ---------- */
.banner {
  margin: var(--space-2) var(--space-4) 0;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-blue) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-blue) 28%, transparent);
  border-radius: 8px;
}

/* ---------- LEGEND ---------- */
.legend-wrap { padding: 0 var(--space-4); }
details.legend { margin: var(--space-2) 0 0; }
details.legend summary {
  cursor: pointer;
  font-size: 11px;
  color: var(--muted);
  list-style: none;
  user-select: none;
}
details.legend summary::-webkit-details-marker { display: none; }
details.legend summary::before { content: "▸ "; }
details.legend[open] summary::before { content: "▾ "; }
.legend-body {
  display: flex; flex-wrap: wrap; gap: var(--space-3);
  font-size: 11px; color: var(--muted);
  padding: var(--space-2) 0;
}
.legend-body span { display: inline-flex; align-items: center; gap: 4px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: 0 0 auto; }
.sw-green { background: var(--good); }
.sw-yellow { background: var(--clue); }
.sw-orange { background: var(--letters); }
.sw-black { background: var(--fail); }

/* ---------- CHAIN ---------- */
.chain {
  flex: 1;
  min-height: 0; /* allow the scroll area to shrink inside the flex column */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  /* Center the board when it fits the column (looks composed on tall iPad /
     desktop screens); `safe` falls back to top-aligned + scroll when the
     board grows past the viewport, so nothing is ever clipped. */
  justify-content: safe center;
  padding: var(--space-3) var(--space-4) var(--space-3);
}
.connector {
  height: 0;
  opacity: 0;
  overflow: hidden;
  transition: height 0.3s ease, opacity 0.3s ease;
  padding-left: 28px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}
.connector.open {
  height: auto;
  min-height: 22px;
  opacity: 1;
  padding-top: 2px;
  padding-bottom: 2px;
}
.connector .cicon { font-size: 12px; opacity: 0.85; }
.connector .clabel { line-height: 1.3; }

.row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0 var(--space-1) var(--space-2);
  border-left: 4px solid transparent;
  border-radius: 4px;
  position: relative;
  min-height: 40px;
  transition: opacity 0.25s ease, background 0.2s ease;
}
.row .idx {
  width: 18px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.row .glyph {
  width: 16px;
  flex: 0 0 auto;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}
.slots {
  display: flex;
  align-items: flex-end;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
}
.wordgroup { display: flex; gap: 4px; }
.wordgap { width: 14px; flex: 0 0 auto; }
.slot {
  width: var(--slotSize, var(--slot-base));
  height: var(--slotSize, var(--slot-base));
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 2px solid var(--faint);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: calc(var(--slotSize, var(--slot-base)) * 0.52);
  color: var(--ink);
  position: relative;
  transition: transform 0.18s ease, border-color 0.2s ease, color 0.2s ease;
}
.row .gutter {
  width: 28px;
  flex: 0 0 auto;
  text-align: center;
  color: var(--accent-blue);
  font-size: 14px;
}

/* caret */
.slot.caret::after {
  content: "";
  position: absolute;
  bottom: 4px;
  width: 60%;
  height: 2px;
  background: var(--accent-blue);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* tile tints
   NOTE: "green" carries two distinct meanings, intentionally differentiated by
   TREATMENT, not just hue, so they don't conflate:
     - SOLVED-earned (here): thin underline + the row-level ✓ glyph, no fill.
     - Frozen Wordle "correct" (.g-correct below): solid fill + corner ✓ glyph.
   Keep this split if these greens are ever retuned. */
.slot.t-earned { border-bottom-color: var(--good); color: var(--ink); }
.slot.t-hinted { border-bottom-color: var(--hint); color: var(--hint); }     /* active-play letter reveal */
.slot.t-given { border-bottom-color: var(--muted); color: var(--ink); }      /* the given starter word */
.slot.t-clue { border-bottom-color: var(--clue); color: var(--ink); }        /* solved via clue */
.slot.t-letters { border-bottom-color: var(--letters); color: var(--letters); } /* solved after revealing letters */
.slot.t-revealed { border-bottom-color: var(--fail); color: var(--fail); }   /* revealed / skipped */

/* Wordle per-letter feedback: FILLED tiles (frozen after a wrong full guess).
   These intentionally fill the whole tile to read as Wordle squares, distinct
   from the thin tier underlines above. */
.slot.g-correct,
.slot.g-present,
.slot.g-absent {
  color: var(--wd-on);
  border-bottom-color: transparent;
  border-radius: 4px;
}
.slot.g-correct { background: var(--wd-correct); }
.slot.g-present { background: var(--wd-present); }
.slot.g-absent  { background: var(--wd-absent); }
/* The active row tints its slots blue; override that for frozen feedback. */
.row.active .slot.g-correct,
.row.active .slot.g-present,
.row.active .slot.g-absent { border-bottom-color: transparent; }

/* Redundant NON-HUE channel (colorblind safety): a tiny status glyph in the
   bottom-right corner so the three states differ by shape, not color alone.
   check = correct, ring = present/elsewhere, dash = absent. Distinct from the solved
   tier states, which use a row-level ✓/👁/• glyph + an underline (no fill). */
.slot.g-correct, .slot.g-present, .slot.g-absent { overflow: hidden; }
.slot.g-correct::after,
.slot.g-present::after,
.slot.g-absent::after {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
  color: var(--wd-on);
  opacity: 0.95;
}
.slot.g-correct::after { content: "\2713"; }   /* ✓ check */
.slot.g-present::after { content: "\2218"; }   /* ∘ ring  */
.slot.g-absent::after  { content: "\2013"; }   /* – dash  */

/* row states */
.row.locked { opacity: 0.55; }
.row.locked .slot { border-bottom-color: var(--faint); }
.row.given .idx { opacity: 0.45; font-weight: 600; }

.row.active {
  border-left-color: var(--accent-blue);
  background: color-mix(in srgb, var(--accent-blue) 11%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-blue) 22%, transparent);
}
.row.active:focus-within {
  outline: 2px solid var(--accent-blue);
  outline-offset: 1px;
}
.row.active .slot {
  --slotSize: var(--slotActive, var(--slot-base));
  border-bottom-color: var(--accent-blue);
}
.row.active .idx { color: var(--accent-blue); }

.row.solved .slot { font-weight: 800; }

.row.wrong { animation: shake 0.38s ease; }
/* Don't paint the red "wrong" underline beneath frozen Wordle feedback tiles,
   which would read as a contradictory red line under a green/amber fill. */
.row.wrong .slot:not(.g-correct):not(.g-present):not(.g-absent) { border-bottom-color: var(--bad) !important; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  15% { transform: translateX(-7px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-5px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

.slot.pop { animation: pop 0.12s ease; }
@keyframes pop { 50% { transform: scale(1.12); } }

.slot.flip { animation: flip 0.2s ease; }
@keyframes flip { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* Cascade: ~400ms each, staggered ~70ms left-to-right across the row's slots.
   JS may also set `animation-delay` inline; these nth-of-type defaults give a
   sensible stagger out of the box. */
.slot.cascade {
  animation: cascade 0.4s ease both;
  animation-delay: calc(var(--cascade-i, 0) * 70ms);
}
.slot.cascade:nth-of-type(1) { --cascade-i: 0; }
.slot.cascade:nth-of-type(2) { --cascade-i: 1; }
.slot.cascade:nth-of-type(3) { --cascade-i: 2; }
.slot.cascade:nth-of-type(4) { --cascade-i: 3; }
.slot.cascade:nth-of-type(5) { --cascade-i: 4; }
.slot.cascade:nth-of-type(6) { --cascade-i: 5; }
.slot.cascade:nth-of-type(7) { --cascade-i: 6; }
.slot.cascade:nth-of-type(8) { --cascade-i: 7; }
.slot.cascade:nth-of-type(9) { --cascade-i: 8; }
.slot.cascade:nth-of-type(n+10) { --cascade-i: 9; }
@keyframes cascade {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); background: color-mix(in srgb, var(--good) 25%, transparent); }
  100% { transform: scale(1); }
}

/* category chip above active row */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  background: color-mix(in srgb, var(--hint) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--hint) 35%, transparent);
  border-radius: 8px;
  padding: 2px 8px;
  margin: 2px 0 4px 28px;
}

/* Crossword-style clue card shown for the active word after the first hint. */
.cluecard {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13.5px;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-blue) 17%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-blue) 35%, transparent);
  border-left: 4px solid var(--accent-blue);
  border-radius: 10px;
  padding: 7px 11px;
  margin: 2px 0 6px 28px;
}
.cluecard .clue-tag {
  flex-shrink: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--ink) 35%, var(--accent-blue));
  transform: translateY(-1px);
}
.cluecard .clue-tag::before {
  content: "💡";
  font-size: 11px;
  -webkit-text-fill-color: initial;
}
.cluecard .clue-text { line-height: 1.35; font-weight: 500; }

/* ---------- DOCK ---------- */
.dock {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
/* playArea stacks the input row and the hint row; give them real separation
   (the dock's gap only applies between #playArea and #status). */
#playArea { display: flex; flex-direction: column; gap: var(--space-3); }
.inputrow { display: flex; gap: var(--space-2); align-items: stretch; }
#guess {
  flex: 1 1 auto;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  min-height: 44px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
#guess:focus { outline: 2px solid var(--accent-blue); outline-offset: -1px; }
.hint-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.btn.hint { font-size: 12px; min-height: 44px; padding: 0 12px; }
.hint-count { font-size: 11px; color: var(--muted); }
.confirm { font-size: 12px; color: var(--bad); display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.confirm .btn { min-height: 44px; padding: 4px 10px; }
.status {
  font-size: 12.5px;
  color: var(--muted);
  min-height: 18px;
  text-align: center;
}
.status.bad { color: var(--bad); }
.status.good { color: var(--good); }

/* ---------- ON-SCREEN KEYBOARD ----------
   Wordle-style. Replaces the native text input so the mobile keyboard never
   opens; footprint is fixed (~3 compact rows) leaving room for the board. */
.keyboard { display: flex; flex-direction: column; gap: 6px; touch-action: manipulation; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0;
  min-width: 0;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--ink) 6%, var(--panel));
  color: var(--ink);
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s ease, transform 0.04s ease;
}
.key:hover { background: color-mix(in srgb, var(--ink) 12%, var(--panel)); }
.key:active { transform: translateY(1px); background: color-mix(in srgb, var(--accent-blue) 24%, var(--panel)); }
.key:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.key-wide { flex: 1.5 1 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }

/* Accumulated Wordle key colors for the current word (filled keys). */
.key.key-correct,
.key.key-present,
.key.key-absent {
  color: var(--wd-on);
  border-color: transparent;
}
.key.key-correct { background: var(--wd-correct); }
.key.key-present { background: var(--wd-present); }
.key.key-absent  { background: var(--wd-absent); }
/* Keep the colored state legible on hover/active rather than washing it out. */
.key.key-correct:hover { background: color-mix(in srgb, #fff 10%, var(--wd-correct)); }
.key.key-present:hover { background: color-mix(in srgb, #fff 10%, var(--wd-present)); }
.key.key-absent:hover  { background: color-mix(in srgb, #fff 10%, var(--wd-absent)); }
/* Redundant NON-HUE channel on the colored keys, matching the tiles, so an
   eliminated/known key is distinguishable without relying on color. */
.key.key-correct, .key.key-present, .key.key-absent { position: relative; }
.key.key-correct::after,
.key.key-present::after,
.key.key-absent::after {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
  color: var(--wd-on);
  opacity: 0.9;
}
.key.key-correct::after { content: "\2713"; }  /* ✓ check */
.key.key-present::after { content: "\2218"; }  /* ∘ ring  */
.key.key-absent::after  { content: "\2013"; }  /* – dash  */
@media (max-width: 380px) {
  .key { height: 46px; font-size: 16px; }
  .kb-row { gap: 4px; }
  .keyboard { gap: 5px; }
}

.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;
}

/* ---------- WIN PANEL ---------- */
.win {
  text-align: center;
  padding: var(--space-2) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.win h2 { margin: 0; font-size: 22px; }
.win .stat { font-size: 13px; color: var(--muted); }
.win .squares {
  font-size: 18px;
  letter-spacing: 2px;
  line-height: 1.2;
  word-break: break-all;
}
.win .btns { display: flex; gap: var(--space-2); justify-content: center; margin-top: var(--space-1); flex-wrap: wrap; }
.win .btns .btn { min-height: 44px; padding: 0 18px; font-size: 14px; }

/* ---------- SCREENS (archive / state) ---------- */
.screen {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}
.screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.screen-head h2 { margin: 0; font-size: 20px; }
.screen-sub { font-size: 12.5px; color: var(--muted); margin: var(--space-2) 0 var(--space-4); }

.archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.archive-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}
.archive-item:hover { border-color: var(--muted); }
.archive-item:active { transform: scale(0.99); }
.archive-item:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.archive-item.today {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-blue) 30%, transparent);
}
.archive-item .a-num {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 34px;
}
.archive-item .a-date { color: var(--muted); font-size: 13px; flex: 1 1 auto; }
.archive-item .a-today-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-blue);
}
.archive-item .a-glyph { font-size: 16px; flex: 0 0 auto; width: 22px; text-align: center; }
.a-glyph.clean { color: var(--good); }
.a-glyph.help { color: var(--hint); }
.a-glyph.unplayed { color: var(--faint); }

/* ---------- STATE SCREEN (loading / error / empty) ---------- */
.state-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-3);
  color: var(--muted);
}
.state-screen h2 { margin: 0; font-size: 18px; color: var(--ink); }
.state-screen p { margin: 0; font-size: 13px; max-width: 320px; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- MODALS ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 420px;
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: modalIn 0.18s ease;
}
.modal.small { max-width: 340px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-2);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 0 var(--space-4) var(--space-4); }
.modal-body p { font-size: 13.5px; line-height: 1.5; color: var(--ink); }
.modal-body .how-list { font-size: 13.5px; line-height: 1.5; padding-left: 18px; color: var(--ink); }
.modal-body .how-list li { margin-bottom: 6px; }
.modal-body kbd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}
.how-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}
.how-legend span { display: inline-flex; align-items: center; gap: 6px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.modal-actions .btn { min-height: 44px; padding: 0 16px; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- VIEW TOGGLING ---------- */
/* When the archive or a state screen is shown, hide the game chrome. */
body.view-archive .legend-wrap,
body.view-archive .chain,
body.view-archive .dock,
body.view-archive .banner,
body.view-state .legend-wrap,
body.view-state .chain,
body.view-state .dock,
body.view-state .banner,
body.view-state header .hgroup,
body.view-state header .ctrls { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  .slot.caret::after { animation: none; }
  /* No spinning for reduced-motion users; show a steady, slightly dimmed ring. */
  .spinner {
    animation: none !important;
    opacity: 0.6;
  }
}

/* =========================================================================
   RESPONSIVE — small screens
   ========================================================================= */

/* Stack win actions and modal/confirm actions full-width on narrow phones. */
@media (max-width: 480px) {
  .win .btns {
    flex-direction: column;
    align-items: stretch;
  }
  .win .btns .btn { width: 100%; }

  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .modal-actions .btn { width: 100%; }

  .confirm {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .confirm .btn { width: 100%; }

  /* Keep the share grid on one line on small screens. */
  .win .squares {
    font-size: 14px;
    letter-spacing: 0;
  }
}

/* Squeeze the legend so its four items fit on a single line. */
@media (max-width: 400px) {
  .legend-body {
    gap: var(--space-2);
    font-size: 10px;
    flex-wrap: nowrap;
  }
  .legend-body span { gap: 3px; }
  .swatch { width: 10px; height: 10px; }
}

/* On touch-sized screens, thicken the active row's left accent so the
   currently-playing row reads clearly at a glance. */
@media (max-width: 520px) {
  .row { border-left-width: 5px; }
  .row.active {
    border-left-width: 6px;
    padding-left: var(--space-1);
  }
}

/* Tighten the wordmark on the smallest phones. */
@media (max-width: 375px) {
  .wordmark {
    font-size: 18px;
    letter-spacing: 2px;
  }
}

/* ====================== NATIVE-ONLY UI ======================
   Rendered only inside the iOS/Android app (injected by native.js when
   window.Capacitor is present). Harmless/unused on the web build. */
.native-settings {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}
.native-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}
.native-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-blue);
  cursor: pointer;
}
