:root {
  color-scheme: light;
  --page: #f3f0e9;
  --surface: #fffdf8;
  --ink: #22201c;
  --ink-2: #5a564d;
  --muted: #8f8a7f;
  --line: #e2ddd1;
  --accent: #2f6f8f;
  --accent-ink: #fffdf8;
  --tile: #2f4a5c;
  --tile-edge: #1e3240;
  --tile-face: #fffdf8;
  --cons: #2f6f8f;
  --vowel: #d9a441;
  --double: #8a5d9b;
  --gift: #4f9a72;
  --blank: #e6e0d3;
  --meaning: #c8553d;
  --hit: #4f9a72;
  --miss: #d8d2c4;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #151519;
    --surface: #1f1f25;
    --ink: #efece4;
    --ink-2: #c2bdb2;
    --muted: #8c877d;
    --line: #34343d;
    --accent: #5a9bbd;
    --accent-ink: #151519;
    --tile: #3d6178;
    --tile-edge: #2a4556;
    --tile-face: #f3efe6;
    --blank: #4a4852;
    --miss: #3a3942;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 "Petrov Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
h1 { display: flex; align-items: center; gap: 8px; font-size: 30px; line-height: 1; margin: 0; letter-spacing: -0.035em; font-weight: 800; }
.logo { width: 28px; height: 28px; flex: none; }
.logo-rim { fill: var(--surface); stroke: var(--ink); stroke-width: 2.5; }
.logo-a { fill: var(--cons); }
.logo-b { fill: var(--vowel); }
.logo-hub { fill: var(--ink); }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.header-buttons { display: flex; gap: 8px; }
.icon {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 15px; padding: 0;
}
.icon[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 14px 16px; margin-bottom: 12px;
}
.label {
  margin: 0 0 10px; color: var(--accent);
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
}

/* The board: one tile per letter, words kept whole. */
.board { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 14px; padding: 4px 0 2px; }
.word { display: flex; gap: 4px; }
.tile {
  display: grid; place-items: center;
  width: 28px; height: 36px; border-radius: 5px;
  background: var(--tile); box-shadow: inset 0 -3px 0 var(--tile-edge);
  font-weight: 800; font-size: 20px; color: var(--ink); line-height: 1;
}
.tile.shown, .tile.missed, .tile.typed { background: var(--tile-face); box-shadow: inset 0 0 0 2px var(--tile); color: #22201c; }
.tile.missed { color: var(--meaning); }
.tile.typed { color: var(--accent); }
.tile.punct { background: none; box-shadow: none; width: 10px; color: var(--ink); }
.board.solving .tile:not(.shown):not(.punct) { background: var(--tile-face); box-shadow: inset 0 0 0 2px var(--muted); }
.board.solving .tile.cursor { box-shadow: inset 0 0 0 3px var(--accent); }
.tile.flip { animation: flip 0.5s ease-out both; }
@keyframes flip {
  0% { transform: rotateX(90deg); background: var(--vowel); }
  55% { transform: rotateX(-14deg); background: var(--vowel); }
  100% { transform: none; }
}
.board.solved .tile.shown { animation: bounce 0.5s ease-out both; }
@keyframes bounce {
  40% { transform: translateY(-6px); }
}
@media (max-width: 400px) {
  .tile { width: 24px; height: 32px; font-size: 18px; }
  .word { gap: 3px; }
  .board { gap: 8px 11px; }
}

.meaning { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.meaning .label { color: var(--meaning); margin-bottom: 6px; }
.meaning .cost { color: var(--muted); letter-spacing: 0.06em; }
.scratch {
  position: relative; min-height: 52px; border-radius: 8px; overflow: hidden;
  background: color-mix(in srgb, var(--meaning) 10%, var(--surface));
  display: grid; place-items: center;
}
.scratch-text { margin: 0; padding: 12px 14px; font-size: 16px; text-align: center; }
.foil {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: grab; transition: opacity 0.5s ease;
}
.foil.gone { opacity: 0; pointer-events: none; }

/* The wheel and what to do next. */
.wheel-row { display: flex; align-items: center; gap: 14px; }
.wheel { display: block; flex: none; width: min(180px, 46vw); overflow: visible; }
.rim { fill: none; stroke: var(--ink); stroke-width: 4; }
.seg { stroke: var(--surface); stroke-width: 1.2; }
.seg.c1 { fill: var(--cons); }
.seg.c2 { fill: var(--vowel); }
.seg.c3 { fill: var(--double); }
.seg.free { fill: var(--gift); }
.seg.blank { fill: var(--blank); }
.seg.bankrupt { fill: #16150f; }
.seg.lit { filter: brightness(1.18) saturate(1.1); stroke: var(--ink); stroke-width: 2.5; }
.seg-label { font: 800 9px "Petrov Sans", system-ui, sans-serif; letter-spacing: 0.06em; fill: #fffdf8; pointer-events: none; }
.seg-label.c2, .seg-label.blank { fill: #22201c; }
.seg-label.cash { font-size: 10px; letter-spacing: 0.02em; }
.seg-label.bankrupt, .seg-label.free, .seg-label.blank { font-size: 7.5px; }
.peg { fill: var(--surface); stroke: var(--ink); stroke-width: 1; }
.hub { fill: var(--surface); stroke: var(--ink); stroke-width: 3; }
.hub-dot { fill: var(--ink); }
.pointer { fill: var(--ink); transform-origin: 0 -112px; transition: transform 0.12s ease-out; }
.pointer.flick { transform: rotate(-22deg); transition: none; }

.status { flex: 1; min-width: 0; }
.status .label { margin-bottom: 6px; }
.pips { display: flex; flex-wrap: wrap; gap: 4px; }
.pip { width: 12px; height: 12px; border-radius: 3px; border: 1.5px solid var(--line); }
.pip.next { border-color: var(--ink); }
.pip.hit { background: var(--hit); border-color: var(--hit); }
.pip.nil { background: var(--miss); border-color: var(--miss); }
.pip.clue { background: var(--meaning); border-color: var(--meaning); }
.pip.wrong { background: var(--ink); border-color: var(--ink); }
.pip.broke { background: var(--meaning); border-color: var(--meaning); }
.bonus { margin: 0 0 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
.breakdown { margin: 4px 0 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.cash { margin: 0 0 2px; font-weight: 800; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; }
.prompt { margin: 10px 0 0; font-weight: 600; min-height: 3em; line-height: 1.35; }

.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
#buy { order: 3; flex-basis: 100%; }
#buy.on { border-color: var(--vowel); background: color-mix(in srgb, var(--vowel) 18%, var(--surface)); }
.buttons .primary { flex: 2; }
.buttons .secondary { flex: 1; }
.primary, .secondary {
  border-radius: 999px; padding: 12px 18px; font-weight: 700; font-size: 16px;
}
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.secondary { border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
.primary:disabled, .secondary:disabled { opacity: 0.4; }
.primary:not(:disabled):active, .secondary:not(:disabled):active { transform: translateY(1px); }

/* The letters. */
.keys { margin: 4px 0 12px; display: grid; gap: 6px; }
.keys .row { display: flex; justify-content: center; gap: 5px; }
.keys button {
  flex: 1 1 0; max-width: 44px; height: 46px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 16px; padding: 0;
}
.keys button.wide { flex: 1.5 1 0; max-width: 64px; }
.keys button:disabled { opacity: 0.35; }
.keys button.hit { background: var(--hit); border-color: var(--hit); color: #fffdf8; opacity: 1; }
.keys button.miss { background: var(--miss); border-color: var(--miss); color: var(--ink-2); opacity: 0.55; text-decoration: line-through; }
.keys button:not(:disabled):not(.hit):not(.miss):hover { border-color: var(--accent); }
.keys.picking button:not(:disabled):not(.hit):not(.miss) { border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }

/* The result. */
.result { text-align: center; }
.result .label { margin-bottom: 4px; }
.score { font-size: 52px; font-weight: 800; margin: 0; line-height: 1.05; letter-spacing: -0.04em; }
.score small { font-size: 22px; color: var(--muted); font-weight: 600; }
.squares { font-size: 20px; letter-spacing: 2px; margin: 8px 0 0; }
.verdict { margin: 4px 0 14px; color: var(--ink-2); }
.result .primary { width: 100%; }
.toast { min-height: 1.5em; margin: 8px 0 4px; color: var(--ink-2); font-size: 14px; white-space: pre-wrap; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); margin: 4px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.stats dd { margin: 0; font-size: 22px; font-weight: 800; }
.next { color: var(--muted); font-size: 13px; margin: 0; }

dialog {
  max-width: min(460px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(20, 18, 14, 0.4); }
dialog h2 { margin: 0 0 8px; letter-spacing: -0.02em; }
dialog ol { padding-left: 20px; margin: 0 0 16px; }
dialog li { margin: 6px 0; }
dialog ul { padding-left: 18px; margin: 4px 0; }
dialog form { text-align: right; }

/* Wide screens: like puddle and cabble, use the room. The board runs the
   full width with bigger tiles; the wheel and the letters sit side by side
   under it; the result, once the game's over, sits under the board. */
@media (min-width: 900px) {
  main {
    max-width: 1240px; padding-left: 24px; padding-right: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "head head" "board board" "play keys" "result result";
    column-gap: 20px;
    align-items: start;
  }
  header { grid-area: head; margin-bottom: 20px; }
  h1 { font-size: 36px; }
  .logo { width: 34px; height: 34px; }
  .board-card { grid-area: board; margin-bottom: 20px; }
  #play { grid-area: play; margin-bottom: 0; }
  #keys { grid-area: keys; margin: 0; align-self: center; gap: 8px; }
  #result { grid-area: result; justify-self: center; width: min(100%, 560px); }
  .card { padding: 20px 24px 22px; }
  .label { font-size: 12px; }

  .board { gap: 18px 30px; padding: 16px 0 10px; }
  .word { gap: 6px; }
  .tile { width: 46px; height: 60px; border-radius: 7px; font-size: 34px; box-shadow: inset 0 -4px 0 var(--tile-edge); }
  .tile.punct { width: 16px; }
  .meaning { margin-top: 20px; padding-top: 16px; }
  .scratch { min-height: 66px; }
  .scratch-text { font-size: 19px; padding: 16px 20px; }

  .wheel-row { gap: 24px; }
  .wheel { width: 280px; }
  .pip { width: 14px; height: 14px; border-radius: 3px; }
  .pips { gap: 5px; flex-wrap: nowrap; }
  .prompt { font-size: 20px; margin-top: 14px; }
  .buttons { margin-top: 20px; }
  .primary, .secondary { padding: 14px 20px; font-size: 17px; }

  .keys .row { gap: 8px; }
  .keys button { max-width: 60px; height: 62px; border-radius: 8px; font-size: 20px; }
  .keys button.wide { max-width: 90px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile.flip, .board.solved .tile.shown { animation: none; }
}
