/*
 * styles.css — all styling for Equation Traffic Light.
 * Set dressing follows C:\Repo\Dev\DevilsHeavy13 (itself after DevilsRoulette,
 * MemoryPoker and The Devil's Plan): a lit concrete cell wall, dark slabs with
 * a gold hairline, purple game furniture, gold for anything you act on,
 * engraved Cinzel caps and Zilla Slab.
 *
 * used_by: index.html
 * related: offline.html (carries its own minimal copy of the palette);
 *          ui.js (builds the board, keypad and result drawer this styles)
 * rules:
 *   - Mobile-first at ~380px. Every tappable control is at least 44px.
 *   - Colour has one meaning each: gold = you / act now, purple = game
 *     furniture, and red / yellow / green are the three traffic-light clues.
 *   - Controls are NOT purple. Every button is the near-black slab with a gold
 *     hairline and a gold light bleeding off its bottom edge, after
 *     C:\Repo\Dev\DevilsRoulette. Purple is left to the furniture that is
 *     only looked at: the masthead ribbon and the archive's current row.
 *     The clue colours are a departure from the purple-and-gold-only rule
 *     because they ARE the game.
 *   - Text straight on the wall is dark ink; text on a slab is cream or gold.
 *   - Every character on a game piece — board cell, keypad key — is set in the
 *     display face, the same engraved caps as the wordmark. Body face is for
 *     prose only.
 *   - Fonts are local files in fonts/. No url() to another origin, ever.
 *   - Anything not needed right now is display:none, not greyed out.
 *   - The page is exactly one screen tall (.shell is 100dvh) and never scrolls:
 *     the board takes whatever height is left, and ui.js sizes --cell to fit.
 *   - .drawer (the result) is fixed to the bottom edge. Slid away
 *     ([data-open="false"]) it shows only its 46px handle, which sits exactly
 *     over the 46px footer, so it never covers the board.
 * message: --cell, --cell-h and --gap are written by ui.js (sizeBoard);
 *   everything on the board is measured from them.
 * wiki: README.md
 */
@font-face { font-family: "Cinzel"; font-weight: 400 700; font-style: normal; font-display: swap; src: url("fonts/cinzel-latin.woff2") format("woff2"); }
@font-face { font-family: "Zilla Slab"; font-weight: 400; font-style: normal; font-display: swap; src: url("fonts/zilla-slab-400.woff2") format("woff2"); }
@font-face { font-family: "Zilla Slab"; font-weight: 600; font-style: normal; font-display: swap; src: url("fonts/zilla-slab-600.woff2") format("woff2"); }
@font-face { font-family: "Zilla Slab"; font-weight: 700; font-style: normal; font-display: swap; src: url("fonts/zilla-slab-700.woff2") format("woff2"); }

:root {
  /* Concrete */
  --wall-lit: #a5a39e;
  --wall-mid: #7e7c78;
  --wall-dark: #5a5855;
  --wall-deep: #3e3d3b;

  /* Ink on the wall */
  --ink: #221e1b;
  --ink-soft: #3d3732;
  --ink-faint: #524c46;

  /* Slabs laid on the wall */
  --slab: #25211e;
  --slab-deep: #1a1816;
  --slab-bg: linear-gradient(180deg, rgba(48, 44, 41, 0.94), rgba(26, 24, 22, 0.96));
  --line: rgba(240, 220, 164, 0.2);
  --line-soft: rgba(240, 220, 164, 0.1);
  --cream: #d6cec2;
  --mute: #9c948a;
  --stock: #fbf9f4;

  /* Purple: the game furniture */
  --purple-900: #2d1245;
  --purple-700: #4a1d73;
  --purple-600: #5f2a94;
  --purple-500: #7634b4;
  --purple-400: #8a46c9;
  --purple-300: #ad7ae0;
  --purple-100: #e4d4f5;

  /* Gold: you, and anything you act on */
  --gold-600: #9c7628;
  --gold-500: #c6992f;
  --gold-400: #d9b254;
  --gold-200: #f0dca4;

  /* The traffic light: the game's one fact */
  --red: #e5594a;
  --red-deep: #9c2a21;
  --red-dim: #4a1a16;
  --amber: #e6c24d;
  --amber-deep: #a8761a;
  --amber-dim: #3c2a08;
  --green: #5cc487;
  --green-deep: #1f6a43;
  --green-dim: #173a28;

  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --body: "Zilla Slab", Rockwell, Georgia, serif;
  --turn: 0.75s;
  --ease: cubic-bezier(0.22, 0.61, 0.24, 1);
  --ease-snap: cubic-bezier(0.34, 1.46, 0.5, 1);
  --shadow-slab: 0 10px 24px -14px rgba(0, 0, 0, 0.9);

  /* Written by ui.js once the board is measured. --cell is the width, which
     nine across decides; --cell-h takes up whatever height is left. */
  --cell: 34px;
  --cell-h: 38px;
  --gap: 4px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: dark; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.4;
  color: var(--cream);
  background-color: var(--wall-dark);
  /* One overhead light on a concrete wall. */
  background-image: radial-gradient(120% 88% at 50% 12%, var(--wall-lit) 0%, var(--wall-mid) 42%, var(--wall-dark) 74%, var(--wall-deep) 100%);
  background-attachment: fixed;
  touch-action: manipulation;
  overflow-x: hidden;
  /* House rule: the sites are played, not read. Dragging across the board or
     the keypad must never paint a text selection. The exception below matches
     PWATemplate: form fields, and anything marked .selectable, stay selectable. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* The exception: anything the user types into, or any value they would
   reasonably want to copy out, stays selectable. */
input,
textarea,
select,
[contenteditable],
.selectable {
  -webkit-user-select: text;
  user-select: text;
}

/* Concrete grain */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 8s steps(6) infinite;
}
@keyframes grain {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-2%, 1%); }
  50% { transform: translate(1%, -2%); }
  75% { transform: translate(2%, 1%); }
}

button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

/* One screen, no scrolling. Below 540px tall (a phone on its side) it gives up
   and scrolls rather than crush the board. */
.shell {
  position: relative;
  z-index: 1;
  width: min(100%, 460px);
  height: 100vh;
  height: 100dvh;
  min-height: 540px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.shell > * { flex: none; }

/* ---------------- masthead ---------------- */

.masthead { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }

/* The purple ribbon with notched ends that every title hangs from. */
.eyebrow {
  display: inline-block;
  padding: 3px 16px;
  font-family: var(--display);
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--gold-200);
  background: linear-gradient(180deg, var(--purple-700), var(--purple-900));
  box-shadow: inset 0 0 0 1px var(--gold-600), inset 0 1px 0 rgba(240, 220, 164, 0.3);
  clip-path: polygon(0 0, 100% 0, calc(100% - 9px) 50%, 100% 100%, 0 100%, 9px 50%);
}
.masthead .eyebrow { padding: 3px 12px; font-size: 0.44rem; letter-spacing: 0.1em; }

/* Engraved into the wall. Two lines, because the title is a mouthful. */
.wordmark {
  font-family: var(--display);
  font-size: clamp(1rem, 5.4vw, 1.3rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #171412;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.16), 0 -1px 1px rgba(0, 0, 0, 0.5);
}

/* Hamburger menu. Built from the same parts as the status bar: a dark slab, a
   gold hairline, gold display labels. Opaque, so nothing bleeds through. */
.menu { position: relative; flex: none; }
.menu-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 0; background: var(--slab-bg); box-shadow: var(--shadow-slab); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 0.2s ease; }
.menu-btn:hover, .menu-btn[aria-expanded="true"] { background: linear-gradient(180deg, #3a3228, #1c1916); border-color: var(--gold-400); }
.menu-btn:focus-visible, .menu-item:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.menu-bars { position: relative; width: 16px; height: 12px; }
.menu-bars i { position: absolute; left: 0; width: 16px; height: 2px; background: var(--gold-200); border-radius: 1px; transition: transform 0.22s var(--ease), opacity 0.15s ease, top 0.22s var(--ease); }
.menu-bars i:nth-child(1) { top: 0; }
.menu-bars i:nth-child(2) { top: 5px; }
.menu-bars i:nth-child(3) { top: 10px; }
.menu-btn[aria-expanded="true"] .menu-bars i:nth-child(1) { top: 5px; transform: rotate(45deg); }
.menu-btn[aria-expanded="true"] .menu-bars i:nth-child(2) { opacity: 0; }
.menu-btn[aria-expanded="true"] .menu-bars i:nth-child(3) { top: 5px; transform: rotate(-45deg); }
.menu-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; width: 200px; display: flex; flex-direction: column; border: 1px solid var(--line); border-top: 2px solid var(--gold-400); background: var(--slab); box-shadow: 0 18px 34px -10px rgba(0, 0, 0, 0.9); animation: sheet-in 0.2s var(--ease) both; }
.menu-panel[hidden] { display: none; }
.menu-item { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 36px; padding: 0 12px 0 26px; border: 0; background: none; font-family: var(--display); font-size: 0.58rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; text-decoration: none; color: var(--gold-200); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 0.18s ease, color 0.18s ease; }
.menu-item::before { content: ''; position: absolute; left: 11px; top: 50%; width: 5px; height: 5px; margin-top: -3px; background: var(--gold-400); transform: rotate(45deg); opacity: 0.55; transition: opacity 0.18s ease; }
.menu-item + .menu-item { border-top: 1px solid var(--line-soft); }
.menu-item:hover, .menu-item:active { background: rgba(240, 220, 164, 0.07); color: var(--stock); }
.menu-item:hover::before, .menu-item:active::before { opacity: 1; }
.menu-more { border-top: 1px solid var(--line); background: rgba(240, 220, 164, 0.04); }
.menu-more::after { content: '\2197'; font-size: 0.8rem; letter-spacing: 0; }

/* The two-state pill pair in the menu (Guesses: Any / Valid). */
.opt-pills { display: flex; gap: 4px; font-family: var(--body); font-size: 0.72rem; letter-spacing: 0; line-height: 1; text-transform: none; }
.opt-pills i { padding: 2px 6px; border: 1px solid var(--line); font-style: normal; font-weight: 600; color: var(--mute); }
.opt-pills i.on { color: var(--slab-deep); background: var(--gold-200); border-color: var(--gold-200); }

/* ---------------- buttons ---------------- */

.btn {
  appearance: none;
  min-height: 46px;
  min-width: 46px;
  padding: 8px 12px;
  border: 1px solid rgba(240, 220, 164, 0.26);
  border-radius: 2px;
  background: linear-gradient(180deg, #332e2a, #191715);
  /* Near-black, with a gold light bleeding up off the bottom edge. */
  box-shadow: inset 0 1px 0 rgba(240, 220, 164, 0.1), inset 0 -14px 20px -16px var(--gold-400), 0 8px 18px -10px rgba(0, 0, 0, 0.95);
  font-family: var(--display);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-200);
  cursor: pointer;
  transition: transform 0.16s var(--ease-snap), filter 0.2s ease, box-shadow 0.25s ease, border-color 0.2s;
}
.btn:hover:not(:disabled) { filter: brightness(1.18); transform: translateY(-2px); border-color: rgba(240, 220, 164, 0.5); }
.btn:active:not(:disabled) { transform: translateY(0); filter: brightness(0.95); }
.btn:focus-visible { outline: 2px solid var(--gold-200); outline-offset: 2px; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; box-shadow: none; }

.btn-ghost { background: rgba(24, 20, 18, 0.62); border-color: rgba(240, 220, 164, 0.28); box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: rgba(58, 50, 40, 0.75); border-color: rgba(240, 220, 164, 0.45); filter: none; }
.btn-danger { border-color: var(--red) !important; color: var(--red) !important; }
/* Gold: the one button that moves the game on. */
.btn-primary { background: linear-gradient(180deg, var(--gold-200), var(--gold-500)); border-color: var(--gold-600); color: #1d1608; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 8px 18px -10px rgba(0, 0, 0, 0.95); }
.btn-wide { width: 100%; min-height: 54px; font-size: 0.8rem; letter-spacing: 0.22em; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }

/* ---------------- status strip ---------------- */

.status { display: grid; grid-template-columns: auto auto 1fr; border: 1px solid var(--line); background: var(--slab-bg); box-shadow: var(--shadow-slab); }
.stat { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 5px 12px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line-soft); }
.stat-wide { align-items: flex-start; }
.stat-label { display: block; font-family: var(--display); font-size: 0.46rem; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-200); white-space: nowrap; }
.stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.05; color: var(--stock); font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); }
#puzzle-no { color: var(--gold-400); }
#try-no small { font-size: 0.6rem; font-weight: 600; color: var(--mute); }
.stat-day { max-width: 100%; font-size: 0.92rem; font-weight: 600; line-height: 1.55; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Not today's equation. Quiet rather than loud: the day itself is the news. */
.stat-day.is-archive { color: var(--mute); }

/* ---------------- the board ---------------- */

/* The middle of the screen, and the point of it. Eight rows of nine cells.
   ui.js measures what is left over and writes --cell, so the grid always fits
   on one screen without the page scrolling. */
.board-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board { display: grid; grid-template-columns: repeat(9, var(--cell)); gap: var(--gap); }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--cell);
  height: var(--cell-h);
  border: 1px solid var(--line-soft);
  background: rgba(24, 20, 18, 0.42);
  font-family: var(--display);
  font-size: calc(var(--cell) * 0.52);
  font-weight: 700;
  line-height: 1;
  color: var(--stock);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  transition: border-color 0.15s ease, background 0.15s ease;
}
/* A cell you have typed into but not submitted: brighter frame, and a control.
   Tapping it takes that one character back and leaves a hole for the next key,
   so a single wrong cell never costs you the rest of the row. */
.cell-draft, .cell-pending { border-color: var(--gold-400); background: linear-gradient(180deg, rgba(58, 52, 46, 0.9), rgba(26, 23, 21, 0.95)); box-shadow: inset 0 -10px 16px -14px var(--gold-400); }
.cell-draft { cursor: pointer; animation: cell-pop 0.14s var(--ease-snap); }
.cell-draft:hover { border-color: var(--gold-200); background: linear-gradient(180deg, rgba(78, 70, 60, 0.95), rgba(36, 32, 28, 0.96)); }
/* The slot it would leave behind, sketched in on hover. */
.cell-draft:hover::after { content: ""; position: absolute; inset: 3px; border: 1px dashed rgba(240, 220, 164, 0.45); }
.cell-draft:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.cell-draft:active { transform: scale(0.94); }
/* Sent, not yet turned over. Looks like a draft cell but is not a control. */
.cell-pending { cursor: default; }
/* Where the next character lands. */
.cell-here { border-color: var(--gold-200); box-shadow: inset 0 0 0 1px rgba(240, 220, 164, 0.35); animation: cell-blink 1.4s ease-in-out infinite; }
@keyframes cell-pop { from { transform: scale(0.86); } }
@keyframes cell-blink { 50% { border-color: var(--gold-600); } }

/* Marked cells. Each colour is solid, as the lights are. */
.cell-red { border-color: var(--red-deep); background: linear-gradient(180deg, #b8463a, var(--red-deep)); color: #ffeeeb; }
.cell-yellow { border-color: var(--amber-deep); background: linear-gradient(180deg, var(--amber), var(--amber-deep)); color: #241a05; text-shadow: none; }
.cell-green { border-color: var(--green-deep); background: linear-gradient(180deg, var(--green), var(--green-deep)); color: #06200f; text-shadow: none; }

/* The reveal: each cell in a submitted row turns over in turn. ui.js sets the
   delay per cell, so the row reads left to right like a scoreboard. */
.cell-turn { animation: cell-turn 0.42s var(--ease) both; }
@keyframes cell-turn {
  0% { transform: rotateX(0deg); }
  45% { transform: rotateX(92deg); }
  100% { transform: rotateX(0deg); }
}
/* The winning row takes a bow once the reveal is through. */
.cell-win { animation: cell-win 0.5s var(--ease-snap) both; }
@keyframes cell-win {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-11px) scale(1.04); }
}
.row-bad { animation: row-shake 0.34s ease both; }
@keyframes row-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* The one-line complaint, over the board. */
.toast {
  position: absolute;
  top: 2px;
  left: 50%;
  z-index: 15;
  max-width: 92%;
  padding: 8px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold-400);
  background: linear-gradient(180deg, #302c29, #1a1816);
  box-shadow: 0 14px 28px -12px rgba(0, 0, 0, 0.95);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--stock);
  text-align: center;
  animation: toast-in 0.2s var(--ease) both;
}
.toast-good { border-left-color: var(--green); }
.toast-bad { border-left-color: var(--red); }
@keyframes toast-in { from { transform: translate(-50%, -10px); opacity: 0; } }

/* ---------------- the keypad ---------------- */

.keypad { display: flex; flex-direction: column; gap: 5px; }
.keypad-row { display: flex; gap: 4px; justify-content: center; }
.key {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 2px;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(60, 55, 51, 0.95), rgba(32, 29, 26, 0.96));
  box-shadow: inset 0 1px 0 rgba(240, 220, 164, 0.14), 0 4px 10px -8px rgba(0, 0, 0, 0.9);
  font-family: var(--display);
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1;
  color: var(--stock);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s var(--ease-snap), filter 0.18s ease, background 0.2s ease, border-color 0.2s ease;
}
.key:hover:not(:disabled) { filter: brightness(1.2); }
.key:active:not(:disabled) { transform: translateY(1px); filter: brightness(0.9); }
.key:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.key-wide { flex: 1.9 1 0; font-size: 0.6rem; letter-spacing: 0.16em; }
/* Enter is the one key that moves the game on, so it is gold. */
.key-go { background: linear-gradient(180deg, var(--gold-200), var(--gold-500)); border-color: var(--gold-600); color: #1d1608; }
.key-back { background: linear-gradient(180deg, #332e2a, #191715); border-color: rgba(240, 220, 164, 0.26); box-shadow: inset 0 1px 0 rgba(240, 220, 164, 0.1), inset 0 -12px 18px -14px var(--gold-400); color: var(--gold-200); }
/* Keys carry the best mark their character has earned. */
.key-red { background: linear-gradient(180deg, #6e2b23, var(--red-dim)); border-color: var(--red-dim); color: #b89a95; }
.key-yellow { background: linear-gradient(180deg, var(--amber), var(--amber-deep)); border-color: var(--amber-deep); color: #241a05; }
.key-green { background: linear-gradient(180deg, var(--green), var(--green-deep)); border-color: var(--green-deep); color: #06200f; }
.key:disabled { opacity: 0.5; cursor: default; }

/* ---------------- drawer (the result) ---------------- */

.drawer {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  width: min(100%, 460px);
  max-height: 94dvh;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(240, 220, 164, 0.4);
  border-width: 0 1px;
  background: linear-gradient(180deg, #302c29, #1a1816);
  box-shadow: 0 -20px 44px -14px rgba(0, 0, 0, 0.9);
  transition: transform 0.34s var(--ease), box-shadow 0.34s ease;
  animation: drawer-in 0.36s var(--ease) backwards;
}
/* Slid away: only the handle is left, over the footer. */
.drawer[data-open="false"] { transform: translateY(calc(100% - 46px - env(safe-area-inset-bottom))); box-shadow: 0 -6px 16px -8px rgba(0, 0, 0, 0.8); }
@keyframes drawer-in { from { transform: translateY(100%); } }

.drawer-handle {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  height: 46px;
  padding: 7px 14px 0;
  border: 0;
  border-top: 2px solid var(--gold-400);
  background: linear-gradient(180deg, #332e2a, #191715);
  box-shadow: inset 0 -16px 22px -18px var(--gold-400);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* Grab bar */
.drawer-handle::before { content: ""; position: absolute; top: 5px; left: 50%; width: 38px; height: 3px; margin-left: -19px; border-radius: 2px; background: rgba(240, 220, 164, 0.5); }
.drawer-handle:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.drawer-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--display); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-200); }
.drawer-title.is-safe { color: var(--green); }
.drawer-title.is-dead { color: var(--red); }
.drawer-chev { flex: none; display: inline-flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 0.52rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--cream); }
.drawer-chev::after { content: ""; width: 7px; height: 7px; border: solid var(--gold-400); border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); transition: transform 0.3s var(--ease); }
.drawer[data-open="false"] .drawer-chev::after { transform: translateY(2px) rotate(-135deg); }
.drawer-body { flex: 1; display: flex; flex-direction: column; gap: 9px; padding: 11px 12px 12px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* ---------------- the verdict ---------------- */

.verdict { padding: 9px 10px 8px; text-align: center; border: 1px solid; background: var(--slab-deep); animation: slam 0.45s var(--ease) both; }
.verdict-word { font-family: var(--display); font-size: clamp(1.05rem, 7.2vw, 1.9rem); font-weight: 700; letter-spacing: 0.1em; line-height: 1.05; }
.verdict-sub { margin-top: 5px; font-size: 0.86rem; color: var(--cream); }
.verdict-safe { border-color: var(--green); }
.verdict-safe .verdict-word { color: var(--green); text-shadow: 0 0 24px rgba(92, 196, 135, 0.35); }
.verdict-dead { border-color: var(--red); }
.verdict-dead .verdict-word { color: var(--red); text-shadow: 0 0 24px rgba(229, 89, 74, 0.35); }
@keyframes slam { from { transform: scale(1.25); opacity: 0; } }

/* The answer, spelled out on a loss — the same cells, at rest. */
.answer-row { display: flex; gap: 4px; justify-content: center; }
.answer-cell { display: grid; place-items: center; width: 32px; height: 36px; border: 1px solid var(--green-deep); background: linear-gradient(180deg, var(--green), var(--green-deep)); font-family: var(--display); font-size: 1rem; font-weight: 700; color: #06200f; }

/* The countdown to the next equation. */
.next-up { display: flex; align-items: baseline; justify-content: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); background: var(--slab-deep); }
.next-up span { font-family: var(--display); font-size: 0.48rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-200); }
.next-up b { font-size: 1.1rem; font-weight: 700; color: var(--stock); font-variant-numeric: tabular-nums; }

/* ---------------- stats ---------------- */

.sheet-overlay { place-items: center; padding: 10px; }
.sheet { display: flex; flex-direction: column; width: min(100%, 440px); max-height: min(92svh, 760px); padding: 0; animation: sheet-in 0.28s var(--ease) both; }
@keyframes sheet-in { from { transform: translateY(14px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); }
.sheet-head .modal-title { margin: 0; }
.stats-body { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; overflow-y: auto; overscroll-behavior: contain; }
.stats-body .section-title { margin: 8px 0 0; color: var(--gold-200); text-shadow: none; }
.stats-empty { padding: 28px 8px; text-align: center; color: var(--cream); }
.stats-note { font-size: 0.74rem; color: var(--mute); }

/* Section titles sit straight on the wall, engraved like the wordmark. */
.section-title { margin-bottom: 5px; font-family: var(--display); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.26em; text-transform: uppercase; color: var(--ink); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.14); }

.stats-hero { padding: 12px; border: 1px solid var(--line); border-left: 5px solid var(--gold-400); background: var(--slab-deep); }
.stats-hero-rate { font-size: 2.5rem; font-weight: 700; line-height: 1; color: var(--stock); font-variant-numeric: tabular-nums; }
.stats-hero-sub { margin-top: 4px; font-size: 0.92rem; }

.facts { display: grid; grid-template-columns: 1fr 1fr; margin: 0; border: 1px solid var(--line); background: var(--slab-deep); }
.fact { padding: 7px 10px; min-width: 0; border-bottom: 1px solid var(--line-soft); }
.fact:nth-child(odd) { border-right: 1px solid var(--line-soft); }
.fact dt { font-family: var(--display); font-size: 0.46rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-200); }
.fact dd { margin: 2px 0 0; font-size: 0.94rem; font-weight: 600; color: var(--stock); }

/* The guess distribution: one bar per try, the row you just finished picked out. */
.dist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.dist li { display: grid; grid-template-columns: 14px 1fr; gap: 8px; align-items: center; font-size: 0.86rem; }
.dist-n { font-family: var(--display); font-weight: 700; color: var(--gold-200); text-align: right; }
.dist-bar { position: relative; height: 20px; background: rgba(240, 220, 164, 0.1); }
.dist-bar i { display: block; height: 100%; min-width: 20px; background: linear-gradient(90deg, var(--green-deep), var(--green)); }
.dist-bar b { position: absolute; top: 0; left: 6px; height: 20px; display: flex; align-items: center; font-size: 0.78rem; font-weight: 700; color: var(--stock); }
.dist-now .dist-bar i { background: linear-gradient(90deg, var(--gold-600), var(--gold-200)); }
.dist-now .dist-bar b { color: #1d1608; }

/* ---------------- the archive ---------------- */

.archive { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); background: var(--slab-deep); }
.archive li + li { border-top: 1px solid var(--line-soft); }
.archive-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; width: 100%; min-height: 46px; padding: 6px 10px; border: 0; background: none; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 0.18s ease; }
.archive-row:hover { background: rgba(240, 220, 164, 0.07); }
.archive-row:focus-visible { outline: 2px solid var(--gold-200); outline-offset: -3px; }
.archive-row[aria-current="true"] { background: linear-gradient(168deg, #3a332b, #1f1c19); box-shadow: inset 3px 0 0 var(--gold-400); }
.archive-no { font-family: var(--display); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.1em; color: var(--gold-200); font-variant-numeric: tabular-nums; }
.archive-day { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; font-weight: 600; color: var(--stock); }
.archive-day small { display: block; font-size: 0.68rem; font-weight: 400; color: var(--mute); }
.archive-mark { flex: none; font-family: var(--display); font-size: 0.52rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.archive-won { color: var(--green); }
.archive-lost { color: var(--red); }
.archive-open { color: var(--amber); }
.archive-new { color: var(--mute); }

/* ---------------- rules, footer ---------------- */

/* The rules sheet: short blocks under engraved headings, scannable rather than
   read end to end. Tables carry the lookups, prose only the ideas. */
.rules-body { display: flex; flex-direction: column; gap: 10px; font-size: 0.88rem; line-height: 1.45; color: var(--cream); }
.rules-body p { margin: 0; }
.rules-body b, .rules-body strong { color: var(--gold-200); }
.rules-body em { color: var(--stock); font-style: italic; }

.rules-head { margin: 4px 0 -2px; font-family: var(--display); font-size: 0.54rem; font-weight: 700; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold-200); }
.rules-note { font-size: 0.78rem; color: var(--mute); }

.rules-legend { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); background: var(--slab-deep); }
.rules-legend li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; }
.rules-legend li + li { border-top: 1px solid var(--line-soft); }
.swatch { flex: none; width: 22px; height: 22px; border: 1px solid rgba(0, 0, 0, 0.5); }
.swatch-red { background: linear-gradient(180deg, #b8463a, var(--red-deep)); }
.swatch-yellow { background: linear-gradient(180deg, var(--amber), var(--amber-deep)); }
.swatch-green { background: linear-gradient(180deg, var(--green), var(--green-deep)); }

.rules-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; border: 1px solid var(--line); background: var(--slab-deep); }
.rules-table th, .rules-table td { padding: 6px 9px; text-align: left; vertical-align: top; }
.rules-table tr + tr th, .rules-table tr + tr td { border-top: 1px solid var(--line-soft); }
.rules-table th { width: 72px; font-family: var(--display); font-size: 0.5rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-200); white-space: nowrap; }
.rules-table td:first-child { width: 24px; font-family: var(--display); font-weight: 700; color: var(--gold-400); }

/* The keypad, laid out as it sits under the board. */
.rules-deal { display: flex; flex-direction: column; gap: 8px; padding: 9px 10px; border: 1px solid var(--line); background: var(--slab-deep); }
.rules-deal-row { display: flex; align-items: center; gap: 10px; }
.rules-deal-label { flex: none; width: 54px; font-family: var(--display); font-size: 0.48rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-200); }
.rules-cards { display: flex; flex-wrap: wrap; gap: 4px; }
.rules-cards i { display: grid; place-items: center; width: 24px; height: 30px; border: 1px solid var(--purple-700); border-radius: 3px; background: linear-gradient(170deg, #efe9dd, #cfc5b4); font-family: var(--display); font-size: 0.8rem; font-weight: 700; font-style: normal; color: #2d1245; }

/* Exactly as tall as a drawer handle, which sits over it when a drawer is slid away. */
.site-footer { display: flex; align-items: center; justify-content: space-between; height: 46px; font-size: 0.78rem; color: var(--ink-soft); }
.site-footer a { color: inherit; text-underline-offset: 3px; }
.site-footer a:hover { color: var(--purple-900); }

/* ---------------- modals (install prompt, sheets) ---------------- */

.modal-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: end center; padding: 16px; background: rgba(12, 10, 9, 0.72); }
.modal { width: min(100%, 420px); padding: 18px; border: 1px solid rgba(240, 220, 164, 0.4); background: linear-gradient(180deg, #302c29, #1a1816); box-shadow: 0 36px 70px -20px #000; outline: none; }
.modal-title { margin: 0 0 8px; font-family: var(--display); font-size: 0.86rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-200); }
.modal-body { margin: 0 0 16px; font-size: 0.92rem; color: var(--cream); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------- reduced motion ---------------- */

@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; }
  .cell-turn, .cell-win, .cell-draft, .row-bad, .verdict, .drawer, .sheet, .menu-panel, .toast { animation: none; }
  .cell-here { animation: none; }
  .drawer { transition: none; }
}
