/* groups — design tokens and base layout
   The four difficulty colours are the familiar yellow/green/blue/purple set;
   everything around them is our own. */

:root {
  /* ---- palettes -------------------------------------------------------
     Every colour is defined exactly once here. The blocks underneath only
     *map* a palette onto the tokens the rest of the sheet uses, so changing
     a colour is still a single edit.

     The four difficulty colours get a set per theme: the classic pastels are
     tuned for a white page and glare on a dark one, so the dark set is
     deepened while keeping the same hue relationships. Ink colours are picked
     for contrast against their own fill. */

  --lt-l0: #f0c53f; --lt-l0-ink: #40300a; --lt-l0-glow: rgba(240, 197, 63, .48);
  --lt-l1: #8cc152; --lt-l1-ink: #1e3410; --lt-l1-glow: rgba(140, 193, 82, .46);
  --lt-l2: #6f9bee; --lt-l2-ink: #0f2148; --lt-l2-glow: rgba(111, 155, 238, .46);
  --lt-l3: #b072d4; --lt-l3-ink: #341744; --lt-l3-glow: rgba(176, 114, 212, .46);
  --lt-bg: #f6f7f9;
  --lt-surface: #ffffff;
  --lt-surface-2: #eceef2;
  --lt-tile: #e2e6ec;
  --lt-tile-hover: #d5dae2;
  --lt-tile-edge: rgba(16, 19, 26, .07);
  --lt-ink: #10131a;
  --lt-ink-soft: #5a6270;
  --lt-ink-faint: #8b93a1;
  --lt-line: #d8dce3;
  --lt-accent: #10131a;
  --lt-accent-ink: #ffffff;
  --lt-hint-mark: #6f7787;
  --lt-heart: #e0364f;
  --lt-heart-lost: #c2c7d0;
  --lt-shadow-1: 0 1px 2px rgba(16, 19, 26, .06), 0 2px 8px rgba(16, 19, 26, .04);
  --lt-shadow-2: 0 8px 30px rgba(16, 19, 26, .14);

  --dk-l0: #d9ae35; --dk-l0-ink: #241a02; --dk-l0-glow: rgba(217, 174, 53, .40);
  --dk-l1: #79ab48; --dk-l1-ink: #13230a; --dk-l1-glow: rgba(121, 171, 72, .38);
  --dk-l2: #6188d4; --dk-l2-ink: #0a142e; --dk-l2-glow: rgba(97, 136, 212, .40);
  --dk-l3: #9761b8; --dk-l3-ink: #1e0e29; --dk-l3-glow: rgba(151, 97, 184, .40);
  --dk-bg: #0e1014;
  --dk-surface: #171a21;
  --dk-surface-2: #1f232c;
  --dk-tile: #262b35;
  --dk-tile-hover: #323846;
  --dk-tile-edge: rgba(255, 255, 255, .05);
  --dk-ink: #f2f4f8;
  --dk-ink-soft: #a8b1c0;
  --dk-ink-faint: #6f7889;
  --dk-line: #2c313c;
  --dk-accent: #f2f4f8;
  --dk-accent-ink: #10131a;
  --dk-hint-mark: #98a1b2;
  --dk-heart: #f0576d;
  --dk-heart-lost: #3a4150;
  --dk-shadow-1: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 10px rgba(0, 0, 0, .3);
  --dk-shadow-2: 0 10px 40px rgba(0, 0, 0, .55);

  /* Shared by both themes. */
  --danger: #d1435b;
  --good: #2f9e6a;
  --tile-ratio: 1.22;
  --radius: 10px;
  --radius-lg: 16px;
  --gap: 8px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --font: 'Libre Franklin', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* ---- light is the default ---- */
  color-scheme: light;
  --l0: var(--lt-l0); --l0-ink: var(--lt-l0-ink); --l0-glow: var(--lt-l0-glow);
  --l1: var(--lt-l1); --l1-ink: var(--lt-l1-ink); --l1-glow: var(--lt-l1-glow);
  --l2: var(--lt-l2); --l2-ink: var(--lt-l2-ink); --l2-glow: var(--lt-l2-glow);
  --l3: var(--lt-l3); --l3-ink: var(--lt-l3-ink); --l3-glow: var(--lt-l3-glow);
  --bg: var(--lt-bg);
  --surface: var(--lt-surface);
  --surface-2: var(--lt-surface-2);
  --tile: var(--lt-tile);
  --tile-hover: var(--lt-tile-hover);
  --tile-edge: var(--lt-tile-edge);
  --ink: var(--lt-ink);
  --ink-soft: var(--lt-ink-soft);
  --ink-faint: var(--lt-ink-faint);
  --line: var(--lt-line);
  --accent: var(--lt-accent);
  --accent-ink: var(--lt-accent-ink);
  --hint-mark: var(--lt-hint-mark);
  --heart: var(--lt-heart);
  --heart-lost: var(--lt-heart-lost);
  --shadow-1: var(--lt-shadow-1);
  --shadow-2: var(--lt-shadow-2);
}

/* Follow the system, unless the player has explicitly chosen light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --l0: var(--dk-l0); --l0-ink: var(--dk-l0-ink); --l0-glow: var(--dk-l0-glow);
    --l1: var(--dk-l1); --l1-ink: var(--dk-l1-ink); --l1-glow: var(--dk-l1-glow);
    --l2: var(--dk-l2); --l2-ink: var(--dk-l2-ink); --l2-glow: var(--dk-l2-glow);
    --l3: var(--dk-l3); --l3-ink: var(--dk-l3-ink); --l3-glow: var(--dk-l3-glow);
    --bg: var(--dk-bg);
    --surface: var(--dk-surface);
    --surface-2: var(--dk-surface-2);
    --tile: var(--dk-tile);
    --tile-hover: var(--dk-tile-hover);
    --tile-edge: var(--dk-tile-edge);
    --ink: var(--dk-ink);
    --ink-soft: var(--dk-ink-soft);
    --ink-faint: var(--dk-ink-faint);
    --line: var(--dk-line);
    --accent: var(--dk-accent);
    --accent-ink: var(--dk-accent-ink);
    --hint-mark: var(--dk-hint-mark);
    --heart: var(--dk-heart);
    --heart-lost: var(--dk-heart-lost);
    --shadow-1: var(--dk-shadow-1);
    --shadow-2: var(--dk-shadow-2);
  }
}

/* An explicit dark choice wins regardless of what the system says. */
:root[data-theme='dark'] {
  color-scheme: dark;
  --l0: var(--dk-l0); --l0-ink: var(--dk-l0-ink); --l0-glow: var(--dk-l0-glow);
  --l1: var(--dk-l1); --l1-ink: var(--dk-l1-ink); --l1-glow: var(--dk-l1-glow);
  --l2: var(--dk-l2); --l2-ink: var(--dk-l2-ink); --l2-glow: var(--dk-l2-glow);
  --l3: var(--dk-l3); --l3-ink: var(--dk-l3-ink); --l3-glow: var(--dk-l3-glow);
  --bg: var(--dk-bg);
  --surface: var(--dk-surface);
  --surface-2: var(--dk-surface-2);
  --tile: var(--dk-tile);
  --tile-hover: var(--dk-tile-hover);
  --tile-edge: var(--dk-tile-edge);
  --ink: var(--dk-ink);
  --ink-soft: var(--dk-ink-soft);
  --ink-faint: var(--dk-ink-faint);
  --line: var(--dk-line);
  --accent: var(--dk-accent);
  --accent-ink: var(--dk-accent-ink);
  --hint-mark: var(--dk-hint-mark);
  --heart: var(--dk-heart);
  --heart-lost: var(--dk-heart-lost);
  --shadow-1: var(--dk-shadow-1);
  --shadow-2: var(--dk-shadow-2);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; }

/* ---------- shell ---------- */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 64px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}

.wordmark {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.03em;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* The mark: four squares in difficulty order. Colours are set once here;
   each context only chooses a size. */
.pips i:nth-child(1) { background: var(--l0); }
.pips i:nth-child(2) { background: var(--l1); }
.pips i:nth-child(3) { background: var(--l2); }
.pips i:nth-child(4) { background: var(--l3); }

.wordmark .pips { display: grid; grid-template-columns: repeat(2, 7px); gap: 2px; }
.wordmark .pips i { width: 7px; height: 7px; border-radius: 2px; display: block; }

.topbar .spacer { flex: 1; }

.nickname-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s var(--ease), transform .15s var(--ease);
}
.nickname-chip:hover { border-color: var(--ink-faint); }
.nickname-chip:active { transform: scale(.97); }

/* ---------- generic bits ---------- */
.view { animation: viewIn .28s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

h1, h2, h3 { letter-spacing: -.02em; margin: 0; }

.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s var(--ease), border-color .15s var(--ease), background .15s var(--ease), opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--ink-faint); }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary:disabled {
  background: transparent;
  color: var(--ink-faint);
  border-color: var(--line);
  opacity: 1;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 14px; font-size: 13px; }

.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- home ---------- */
/* Same column width as the board, so the two screens feel like one product. */
.home { max-width: 540px; margin: 0 auto; width: 100%; }

.hero { text-align: center; margin-bottom: 26px; }

.hero .brand {
  display: flex; align-items: center; justify-content: center;
  gap: 15px; margin-bottom: 12px;
}
.hero .brand .pips { display: grid; grid-template-columns: repeat(2, 21px); gap: 4px; }
.hero .brand .pips i { width: 21px; height: 21px; border-radius: 6px; display: block; }
.hero .brand .name {
  font-size: 46px; font-weight: 800; letter-spacing: -.045em; line-height: 1;
}
.hero .tagline { font-size: 17px; font-weight: 700; margin: 0 0 5px; letter-spacing: -.01em; }
.hero .sub { color: var(--ink-soft); margin: 0; font-size: 14px; }

/* The hero is the mark on this page, so the one in the bar would just be a
   smaller copy of it sitting directly above. */
body[data-view='home'] .topbar .wordmark { display: none; }

/* ---------- appearance toggle ---------- */
.appearance {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-top: 18px;
}
.appearance .label {
  font-size: 11px; font-weight: 800; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint);
}
.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
}
.seg button {
  border: 0; background: transparent; border-radius: 999px;
  padding: 6px 14px; font-size: 12.5px; font-weight: 700;
  color: var(--ink-soft); cursor: pointer;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.seg button:hover:not([aria-pressed='true']) { color: var(--ink); }
.seg button[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }
.seg button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.daily-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 18px 18px;
  box-shadow: var(--shadow-1);
  margin-bottom: 18px;
}
.daily-card .eyebrow {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-faint);
}
/* The four difficulty colours as a maker's mark, not as a difficulty cue. */
.daily-card .eyebrow .pips { display: flex; gap: 3px; }
.daily-card .eyebrow .pips i { width: 6px; height: 6px; border-radius: 2px; display: block; }

.daily-card .date { font-size: 23px; font-weight: 800; margin: 8px 0 3px; letter-spacing: -.02em; }
.daily-card .meta { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; }
.daily-card .countdown { font-variant-numeric: tabular-nums; font-weight: 700; }

/* Mode cards sit on the board's tile surface, inside the card's own surface —
   the same figure-on-ground relationship the grid has. */
.mode-grid { display: grid; gap: 8px; }
.mode-card {
  display: flex; align-items: center; gap: 13px; width: 100%;
  text-align: left; padding: 13px 15px;
  border: 1px solid var(--tile-edge); background: var(--tile);
  border-radius: var(--radius); cursor: pointer; color: inherit;
  transition: transform .14s var(--ease), background .16s var(--ease), border-color .16s var(--ease);
}
.mode-card:hover { background: var(--tile-hover); }
.mode-card:active { transform: scale(.985); }
.mode-card:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.mode-card .icon {
  width: 36px; height: 36px; flex: none; border-radius: 9px;
  display: grid; place-items: center; font-size: 17px;
  background: var(--surface); border: 1px solid var(--tile-edge);
}
.mode-card .name { font-weight: 800; font-size: 15px; }
.mode-card .blurb { font-size: 12.5px; color: var(--ink-soft); margin-top: 1px; }
.mode-card .done {
  margin-left: auto; flex: none;
  font-size: 10.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
  color: var(--good); border: 1px solid currentColor; border-radius: 999px;
  padding: 3px 8px; opacity: .9;
}

.home-links { display: flex; gap: 8px; }
.home-links .btn { flex: 1; padding: 11px 8px; }

/* Sections rise in turn, echoing the way a solved row settles. */
.rise { animation: riseIn 420ms var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes riseIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- game ---------- */
.play {
  max-width: 540px;
  margin: 0 auto;
  width: 100%;
  /* Lets a solved row size itself from the board's width, so it can match a
     tile row exactly and the grid never shifts as groups resolve. */
  container-type: inline-size;
}

.game-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.game-head .title { font-size: 18px; font-weight: 800; line-height: 1.2; }
.game-head .sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }

.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 20px; letter-spacing: -.02em;
  padding: 4px 10px; border-radius: 8px; background: var(--surface-2);
}
.clock.urgent { color: var(--danger); }

.prompt {
  text-align: center; font-size: 14px; font-weight: 600; color: var(--ink-soft);
  margin: 0 0 14px;
}

/* ---------- solved rows ---------- */
.solved-stack { display: grid; gap: var(--gap); margin-bottom: var(--gap); }
/* Before the first group is solved the stack must take up nothing at all,
   margin included, or the column loses one gap's height on the first solve. */
.solved-stack:empty { display: none; }

.solved-row {
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
  display: flex; flex-direction: column; justify-content: center;
}

/* On the board, a solved row is exactly as tall as the row of tiles it
   replaces — four tiles and three gaps across the board's width — so solving
   a group swaps one band for another without the grid moving.
   The first declaration is the fallback where container queries are missing. */
.play .solved-row {
  height: 76px;
  height: calc((100cqw - 3 * var(--gap)) / (4 * var(--tile-ratio)));
}
.solved-row .name {
  font-weight: 800; font-size: 14.5px; letter-spacing: .015em;
  text-transform: uppercase; line-height: 1.2;
}
.solved-row .words {
  font-size: 13.5px; margin-top: 4px; opacity: .8; font-weight: 600;
  letter-spacing: .01em;
}

.solved-row.l0 { background: var(--l0); color: var(--l0-ink); box-shadow: 0 6px 26px -2px var(--l0-glow); }
.solved-row.l1 { background: var(--l1); color: var(--l1-ink); box-shadow: 0 6px 26px -2px var(--l1-glow); }
.solved-row.l2 { background: var(--l2); color: var(--l2-ink); box-shadow: 0 6px 26px -2px var(--l2-glow); }
.solved-row.l3 { background: var(--l3); color: var(--l3-ink); box-shadow: 0 6px 26px -2px var(--l3-glow); }

/* A group you never found: present but visibly not earned. */
.solved-row.revealed { box-shadow: none; opacity: .72; }
.solved-row.revealed .name::after {
  content: ' · missed'; font-weight: 700; opacity: .6; text-transform: none;
}

/* The fourth group in Timed, handed over once the other three are down. */
.solved-row.given { box-shadow: none; opacity: .8; }
.solved-row.given .name::after {
  content: ' · given'; font-weight: 700; opacity: .6; text-transform: none;
}

/* Only a newly-solved row animates. Re-rendering the board must not replay
   the entrance on rows that were already there. */
.solved-row.is-new { animation: rowIn 420ms var(--ease) both; }
@keyframes rowIn {
  0%   { opacity: 0; transform: scaleY(.55); }
  55%  { opacity: 1; }
  100% { opacity: 1; transform: none; }
}
/* On a loss the remaining groups cascade rather than appearing all at once. */
.solved-row.is-new.cascade { animation-delay: calc(var(--i, 0) * 110ms); }

/* ---------- board ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.tile {
  position: relative;
  aspect-ratio: var(--tile-ratio) / 1;
  border: 1px solid var(--tile-edge);
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(10px, 3.1vw, 15px);
  letter-spacing: -.005em;
  text-transform: uppercase;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 5px;
  overflow: hidden;
  word-break: break-word;
  line-height: 1.15;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform .14s var(--ease),
    background .16s var(--ease),
    color .16s var(--ease),
    border-color .16s var(--ease);
}
.tile:hover:not(.selected):not(:disabled) { background: var(--tile-hover); }
.tile:active:not(:disabled) { transform: scale(.94); }
.tile:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.tile.selected {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  transform: scale(.965);
}

/* Hint marker. Every word marked by a hint belongs to the same group, so two
   markers on the board means those two words go together. */
.tile.hinted::after {
  content: '';
  position: absolute; top: 7px; right: 7px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--hint-mark);
  box-shadow: 0 0 0 2px var(--tile);
}
.tile.selected.hinted::after {
  background: var(--accent-ink);
  box-shadow: 0 0 0 2px var(--accent);
  opacity: .75;
}

/* Longer words step down in size rather than jumping straight to tiny, so a
   board of mixed lengths still reads as one grid. */
.tile.len-m { font-size: clamp(9px, 2.6vw, 13px); }
.tile.len-s { font-size: clamp(8px, 2.2vw, 11px); letter-spacing: -.02em; }
.tile.len-xs { font-size: clamp(7px, 1.9vw, 9.5px); letter-spacing: -.03em; line-height: 1.1; }

/* ---------- solve sequence ----------
   1. the four tiles bounce in turn
   2. they take the group's difficulty colour   <- the reveal
   3. they collapse, and the coloured row expands in their place            */
.tile.solve-l0 { --solve-bg: var(--l0); --solve-ink: var(--l0-ink); }
.tile.solve-l1 { --solve-bg: var(--l1); --solve-ink: var(--l1-ink); }
.tile.solve-l2 { --solve-bg: var(--l2); --solve-ink: var(--l2-ink); }
.tile.solve-l3 { --solve-bg: var(--l3); --solve-ink: var(--l3-ink); }

.tile.solving {
  animation: tileSolve 560ms var(--ease) both;
  animation-delay: calc(var(--i, 0) * 82ms);
  z-index: 1;
}
@keyframes tileSolve {
  0%   { transform: scale(.965); background: var(--accent); color: var(--accent-ink); }
  26%  { transform: scale(1.09); background: var(--accent); color: var(--accent-ink); }
  46%  { background: var(--solve-bg); color: var(--solve-ink); }
  62%  { transform: scale(.985); }
  100% { transform: scale(1); background: var(--solve-bg); color: var(--solve-ink); }
}

/* Listed after .solving so it takes over the animation slot. */
.tile.collapsing {
  background: var(--solve-bg);
  color: var(--solve-ink);
  animation: tileCollapse 240ms var(--ease) both;
}
@keyframes tileCollapse {
  to { transform: scale(.86); opacity: 0; }
}

/* ---------- mistake feedback ---------- */
.board.shaking .tile.selected { animation: shake 480ms var(--ease); }
@keyframes shake {
  0%, 100% { transform: translateX(0) scale(.965); }
  15% { transform: translateX(-7px) scale(.965); }
  30% { transform: translateX(6px) scale(.965); }
  45% { transform: translateX(-5px) scale(.965); }
  60% { transform: translateX(4px) scale(.965); }
  80% { transform: translateX(-2px) scale(.965); }
}

/* ---------- lives ---------- */
.lives {
  display: flex; align-items: center; gap: 9px; justify-content: center;
  margin: 20px 0 14px;
}
.lives .label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.lives .hearts { display: flex; gap: 7px; align-items: center; }
.lives .heart {
  width: 17px; height: 17px; display: block; color: var(--heart);
  transition: color .32s var(--ease), transform .32s var(--ease), opacity .32s var(--ease);
}
.lives .heart svg { width: 100%; height: 100%; display: block; fill: currentColor; }
.lives .heart.lost { color: var(--heart-lost); transform: scale(.82); opacity: .6; }
/* The heart you just spent gets one beat of attention before it fades. */
.lives .heart.just-lost { animation: heartBreak 520ms var(--ease); }
@keyframes heartBreak {
  0%   { transform: scale(1); color: var(--heart); opacity: 1; }
  30%  { transform: scale(1.42); color: var(--heart); opacity: 1; }
  58%  { transform: scale(.9); }
  100% { transform: scale(.82); color: var(--heart-lost); opacity: .6; }
}

/* ---------- controls ---------- */
.toast-slot { min-height: 36px; display: grid; place-items: center; margin-bottom: 6px; }
.toast {
  background: var(--accent); color: var(--accent-ink);
  padding: 8px 17px; border-radius: 999px;
  font-size: 13px; font-weight: 700;
  animation: toastIn .24s var(--ease) both;
  text-align: center;
}
.toast.warn { background: var(--danger); color: #fff; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(9px) scale(.95); }
  to { opacity: 1; transform: none; }
}

.controls { display: flex; gap: 9px; justify-content: center; align-items: center; flex-wrap: wrap; }
.controls .btn { min-width: 104px; }
.controls .btn.primary { min-width: 132px; }

/* ---------- results ---------- */
/* Shown above a daily result you're revisiting, so it's obvious why there is
   no board here. */
.done-notice {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px;
  text-align: center;
}
.done-notice .headline { font-size: 13.5px; font-weight: 700; }
.done-notice .sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.done-notice .countdown { font-variant-numeric: tabular-nums; font-weight: 700; }

.results { text-align: center; max-width: 540px; margin: 0 auto; width: 100%; }
.results h2 { font-size: 30px; font-weight: 800; margin-bottom: 5px; letter-spacing: -.025em; }
.results .verdict-sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 20px; }

/* Stat tiles borrow the board's tile surface so the summary reads as the same
   material as the grid it came from. */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px; }
.stat {
  background: var(--tile); border: 1px solid var(--tile-edge);
  border-radius: var(--radius); padding: 14px 8px;
}
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .k {
  font-size: 10.5px; color: var(--ink-faint); text-transform: uppercase;
  letter-spacing: .09em; font-weight: 800; margin-top: 3px;
}

/* Guess history: one row per guess, coloured by where each word belonged. */
.share-grid { display: inline-grid; grid-template-columns: repeat(4, 24px); gap: 4px; margin-bottom: 20px; }
.share-grid span { width: 24px; height: 24px; border-radius: 6px; display: block; }
.share-grid .s0 { background: var(--l0); }
.share-grid .s1 { background: var(--l1); }
.share-grid .s2 { background: var(--l2); }
.share-grid .s3 { background: var(--l3); }

.mistake-log { text-align: left; margin-bottom: 20px; }
.mistake-log ol { margin: 0; padding-left: 20px; }
.mistake-log li { font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
.mistake-log .oneaway { color: var(--danger); font-weight: 700; }

/* Off the board, rows size to their content — four full-height bands would
   push the buttons off the screen. */
.results .solved-row { min-height: 62px; }

/* ---------- leaderboard ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: background .15s var(--ease), border-color .15s var(--ease);
}
.tab[aria-selected='true'] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.lb-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint); font-weight: 700; padding: 0 8px 8px;
}
.lb-table td { padding: 11px 8px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.lb-table tr.me td { background: var(--surface-2); font-weight: 700; }
.lb-table .rank { width: 38px; color: var(--ink-faint); font-weight: 700; }
.lb-table tr.me .rank { color: var(--ink); }
.lb-table .who { font-variant-numeric: normal; font-weight: 600; }
.lb-table .tag {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; margin-left: 6px;
}

.empty {
  text-align: center; color: var(--ink-soft); font-size: 14px;
  padding: 34px 16px; border: 1px dashed var(--line); border-radius: var(--radius);
}

/* ---------- archive ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input, .filters select {
  font: inherit; font-size: 14px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.filters input { flex: 1 1 100%; min-width: 140px; }
.filters select { flex: 1 1 0; min-width: 0; }

.archive-list { display: grid; gap: 8px; }
.archive-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; width: 100%; text-align: left;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s var(--ease), transform .12s var(--ease);
}
.archive-item:hover { border-color: var(--ink-faint); }
.archive-item:active { transform: scale(.995); }
.archive-item .swatches { display: grid; grid-template-columns: repeat(2, 9px); gap: 2px; flex: none; }
.archive-item .swatches i { width: 9px; height: 9px; border-radius: 2px; display: block; }
.archive-item .idx { font-weight: 800; font-size: 14px; }
.archive-item .when { font-size: 12px; color: var(--ink-faint); }
.archive-item .played { margin-left: auto; font-size: 13px; font-weight: 800; color: var(--good); }
.archive-item .played.attempted { color: var(--ink-faint); }
.archive-item .src {
  margin-left: auto; font-size: 10px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-faint);
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px;
}
.archive-item .played + .src { margin-left: 8px; }

.pager { display: flex; justify-content: center; gap: 10px; margin-top: 16px; align-items: center; }
.pager .count { font-size: 13px; color: var(--ink-soft); }

/* ---------- speed round ---------- */
.speed-head { text-align: center; margin-bottom: 18px; }
.speed-head .big { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.speed-head .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-faint); font-weight: 700; }

.speed-bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.speed-bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .12s linear; }
.speed-bar.low i { background: var(--danger); }

/* ---------- speed: intro ---------- */
.speed-intro {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 22px 20px; text-align: center;
}
.speed-intro h3 { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.speed-intro .lede { font-size: 14.5px; color: var(--ink-soft); margin: 0 0 18px; line-height: 1.5; }
.speed-intro .lede b { color: var(--ink); font-weight: 800; }

.speed-rules { display: grid; gap: 8px; text-align: left; margin-bottom: 20px; }
.speed-rule {
  display: flex; align-items: center; gap: 11px;
  background: var(--tile); border: 1px solid var(--tile-edge);
  border-radius: var(--radius); padding: 11px 13px; font-size: 13.5px;
}
.speed-rule .ico {
  width: 28px; height: 28px; flex: none; border-radius: 8px;
  display: grid; place-items: center; font-size: 14px;
  background: var(--surface); border: 1px solid var(--tile-edge);
}

/* ---------- timed session ---------- */
.timed-puzzle { animation: riseIn 320ms var(--ease) both; }
.timed-meta {
  text-align: center; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 10px;
}

/* ---------- speed: play ---------- */
/* Stays put for the whole run. The feedback line below changes; this does
   not, because the rules should never scroll away mid-game. */
.speed-instruction {
  text-align: center; font-size: 13.5px; font-weight: 600;
  color: var(--ink-soft); margin: 0 0 12px;
}

.speed-words { display: grid; gap: 10px; margin-bottom: 14px; }
.speed-word {
  padding: 17px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); font-weight: 800; font-size: 16px; text-transform: uppercase;
  cursor: pointer; transition: transform .12s var(--ease), background .18s var(--ease), border-color .18s var(--ease), color .18s;
}
/* Hover is a background shift, never a border: a highlighted outline on one
   of five words reads as "this is the answer". It is also suppressed on the
   freshly-rendered round until the pointer actually moves, because rounds
   advance on their own and would otherwise mark whichever word happened to
   land under a resting cursor. Touch devices get no hover state at all. */
@media (hover: hover) and (pointer: fine) {
  .speed-words:not(.await-move) .speed-word:not(:disabled):hover { background: var(--surface-2); }
}
.speed-word:active:not(:disabled) { transform: scale(.98); }
.speed-word.right { background: var(--good); border-color: var(--good); color: #fff; animation: tilePop .34s var(--ease); }
.speed-word.wrong { background: var(--danger); border-color: var(--danger); color: #fff; animation: shake .5s var(--ease); }
.speed-word.reveal { border-color: var(--good); color: var(--good); }
.speed-word:disabled { cursor: default; }

.speed-feedback {
  text-align: center; min-height: 44px;
  display: flex; flex-direction: column; justify-content: flex-start; gap: 3px;
}
.speed-feedback .result { font-size: 14px; font-weight: 700; }
.speed-feedback .result.good { color: var(--good); }
.speed-feedback .result.bad { color: var(--danger); }
.speed-feedback .because { font-size: 12.5px; color: var(--ink-faint); }
.streak b { color: var(--ink); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 16, .55);
  display: grid; place-items: center; padding: 20px; z-index: 50;
  animation: fadeIn .18s var(--ease);
  backdrop-filter: blur(3px);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 24px; width: 100%; max-width: 380px; box-shadow: var(--shadow-2);
  animation: modalIn .24s var(--ease) both;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
.modal h3 { font-size: 19px; margin-bottom: 6px; }
.modal p { font-size: 14px; color: var(--ink-soft); margin: 0 0 16px; }
.modal input {
  font: inherit; font-size: 16px; width: 100%; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--ink); margin-bottom: 8px;
}
.modal .err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0 0 8px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- misc ---------- */
.loading { text-align: center; padding: 60px 0; color: var(--ink-soft); }
.spinner {
  width: 26px; height: 26px; margin: 0 auto 12px;
  border: 3px solid var(--line); border-top-color: var(--ink);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footnote { text-align: center; font-size: 12px; color: var(--ink-faint); margin-top: 26px; }

@media (max-width: 460px) {
  .app { padding: 0 12px 48px; }
  :root { --gap: 6px; }
  .stat .v { font-size: 19px; }

  /* The three secondary actions share a row; Submit gets its own full-width
     row rather than wrapping onto one by accident. */
  .controls .btn { flex: 1; min-width: 0; padding: 10px 8px; }
  .controls .btn.primary { flex-basis: 100%; min-width: 100%; order: 1; }

  .game-head .title { font-size: 16px; }
  .solved-row { padding: 10px; }
  .solved-row .name { font-size: 13px; }
  .solved-row .words { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
