/* Layout: on wide screens the grid and controls stay pinned on the left while the word list fills the rest of the width.
   On narrow screens everything stacks in one column. */
:root {
  --bg: #eef1f4;
  --fg: #1b2430;
  --muted: #5d6877;
  --tray: #1f3a5f;
  --die: #fbfaf7;
  --die-fg: #1b2430;
  --accent: #e8a33d;
  --accent-fg: #2a1a03;
  --line: #d3d9e0;
  --chip: #ffffff;
  --error: #b4382c;
  --display: "Bricolage Grotesque", "Arial Black", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10161e; --fg: #e6ebf1; --muted: #9aa6b4; --tray: #0a2340;
    --die: #e9e6dd; --die-fg: #141a22; --accent: #f0b04f; --accent-fg: #2a1a03;
    --line: #263241; --chip: #18212c; --error: #ef7a6c; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10161e; --fg: #e6ebf1; --muted: #9aa6b4; --tray: #0a2340;
  --die: #e9e6dd; --die-fg: #141a22; --accent: #f0b04f; --accent-fg: #2a1a03;
  --line: #263241; --chip: #18212c; --error: #ef7a6c; color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 1rem;
  line-height: 1.5; padding-inline: 16px; padding-block: 24px 48px;
}
main { display: flex; flex-direction: column; gap: 24px; }
.panel { display: flex; flex-direction: column; gap: 24px; }
@media (min-width: 900px) {
  body { padding-inline: 32px; }
  main { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; gap: 40px; align-items: start; }
  .panel { position: sticky; top: 24px; }
}

header { display: flex; flex-direction: column; gap: 4px; }
h1 { font-family: var(--display); font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.2rem); line-height: 1.1; margin: 0; text-wrap: balance; }
.hint { color: var(--muted); margin: 0; }
kbd { font-family: var(--body); font-size: 0.85em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--chip); }

.tray {
  background: var(--tray); border-radius: 18px; padding: clamp(10px, 3vw, 18px);
  width: min(100%, 400px); align-self: center; cursor: text;
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 0.08), 0 10px 24px rgb(10 20 35 / 0.25);
}
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(8px, 2.5vw, 12px); }
.cell {
  /* min-height keeps empty cells visible in browsers without aspect-ratio support */
  aspect-ratio: 1; min-height: clamp(52px, 17vw, 82px); max-width: 100%; border: 0; border-radius: 14%; background: var(--die); color: var(--die-fg);
  font-family: var(--display); font-weight: 800; font-size: clamp(1.6rem, 8vw, 2.6rem); text-transform: uppercase;
  display: grid; place-items: center; position: relative; cursor: pointer; padding: 0;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / 0.12);
  transition: transform 120ms ease, background-color 120ms ease;
}
.cell.empty { background: rgb(255 255 255 / 0.12); box-shadow: none; }
.cell.cursor { outline: 3px solid var(--accent); outline-offset: 2px; }
.cell.on-path { background: var(--accent); color: var(--accent-fg); }
.cell .step {
  position: absolute; top: 6%; left: 9%; font-family: var(--body); font-size: 0.75rem; font-weight: 700; opacity: 0.75;
}
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
button.btn {
  font: inherit; font-weight: 700; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--chip); color: var(--fg);
}
button.btn.primary { background: var(--tray); border-color: var(--tray); color: #fff; }
button.btn:disabled { opacity: 0.5; cursor: progress; }
button.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.status { text-align: center; color: var(--muted); margin: 0; min-height: 1.5em; font-variant-numeric: tabular-nums; }
.status.error { color: var(--error); }

.summary { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.summary strong { font-family: var(--display); font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.summary span { color: var(--muted); }
.words { display: flex; flex-wrap: wrap; gap: 8px; }
.word {
  font: inherit; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer;
  border: 1px solid var(--line); background: var(--chip); color: var(--fg); border-radius: 8px; padding: 4px 10px;
}
.word.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.word:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#results { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* Captures typing, including on phone keyboards, without being visible */
#kbd { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .cell { transition: none; } }
