:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #d6d4cd;
  --line-strong: #8f8d86;
  --key: #dcdad3;
  --correct: #5f9c55;
  --present: #c4a83c;
  --absent: #7b7d80;
  --on-color: #ffffff;
  --danger: #d0453a;
  --focus: #2f6fdd;
  /* Tiles grow to fill the screen: whatever height is left after the keyboard,
     status line and best guess (--chrome), split across 6 rows, but never wider
     than 5 tiles fit across the screen.
     Heights use --app-h, the screen height read once on load (see index.html),
     so nothing resizes when a phone browser hides its bars on scroll. */
  --app-h: 100vh;
  --app-h: 100svh;
  --key-h: clamp(50px, calc(var(--app-h) * 0.07), 58px);
  --gutter: 16px;
  --chrome: calc(140px + 3 * var(--key-h));
  --tile: clamp(34px, min(calc((100vw - 2 * var(--gutter) - 24px) / 5), calc((var(--app-h) - var(--chrome)) / 6)), 100px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --panel: #1b1b1d;
    --text: #ececee;
    --muted: #9a9aa0;
    --line: #3a3a3c;
    --line-strong: #6b6b70;
    --key: #59595d;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --danger: #ff6b5e;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button { font: inherit; color: inherit; }
kbd {
  font: 600 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 5px;
}


.ghost {
  background: transparent; border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
.ghost:hover { background: var(--key); }
.ghost.small { padding: 4px 10px; font-size: 13px; margin-top: 8px; }

.layout {
  max-width: 1040px; margin: 0 auto; padding: 0 var(--gutter) 40px;
  display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 32px; align-items: start;
}
@media (max-width: 760px) {
  :root { --gutter: 10px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 8px; }
}

/* ---- Board ---- */
/* The board, keyboard and best guess fill exactly one screen, so the best guess
   is the last thing above the fold. */
.play {
  display: flex; flex-direction: column; align-items: center;
  min-height: var(--app-h);
  padding-top: 16px;
}
@media (min-width: 761px) {
  .play { position: sticky; top: 0; }
  .words { padding-top: 16px; }
}
.board { display: grid; gap: 6px; flex: 1; align-content: center; }
/* Leftover height (when the screen's width caps the tiles) goes mostly above the
   board, keeping the board close to the keyboard. */
.play::before { content: ""; flex: 1; }
.row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: 6px; }

.tile {
  position: relative;
  width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  font-size: calc(var(--tile) * 0.52); font-weight: 800; text-transform: uppercase;
  border: 2px solid var(--line); background: transparent; color: var(--text);
  border-radius: 3px; padding: 0;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
.tile.filled { border-color: var(--line-strong); }
.tile.pop { animation: pop 0.1s; }
@keyframes pop { 50% { transform: scale(1.08); } }
.tile.markable { cursor: pointer; }
.tile.markable:hover { filter: brightness(1.08); }
.tile:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.tile.absent, .tile.present, .tile.correct, .tile.in { border-color: transparent; color: var(--on-color); }
.tile.absent { background: var(--absent); }
.tile.present { background: var(--present); }
.tile.correct { background: var(--correct); }
.tile.in { background: linear-gradient(135deg, var(--present) 50%, var(--correct) 50%); }

.tile.conflict { outline: 3px solid var(--danger); outline-offset: 1px; }

.status { margin: 8px 0 0; color: var(--muted); text-align: center; font-size: 14px; }
/* Takes no room unless there is something to say, so the tiles get that space. */
.status:empty { display: none; }
.status.error { color: var(--danger); font-weight: 600; }

/* ---- Keyboard ---- */
/* Every row sits on the same 20 half-key columns, so keys line up like a real
   keyboard: letters are 2 columns wide, the middle row starts half a key in,
   and the bottom row has 1.5-key slots at each end. */
.keyboard { display: grid; row-gap: 6px; width: 100%; max-width: max(480px, calc(5 * var(--tile) + 24px)); margin-top: 12px; }
.kb-row { display: grid; grid-template-columns: repeat(20, minmax(0, 1fr)); column-gap: 5px; }
.key {
  grid-column: span 2; height: var(--key-h); padding: 0; min-width: 0;
  border: 0; border-radius: 5px; background: var(--key); color: var(--text);
  font-weight: 700; font-size: 14px; text-transform: uppercase; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.kb-row:nth-child(2) .key:first-child { grid-column: 2 / span 2; }
.key.wide { grid-column: span 3; font-size: 16px; }
.key.spacer { visibility: hidden; }
.key.absent { background: var(--absent); color: var(--on-color); }
.key.present { background: var(--present); color: var(--on-color); }
.key.correct { background: var(--correct); color: var(--on-color); }
.key:active { filter: brightness(0.9); }

/* ---- Word panel ---- */
.words { min-width: 0; }
.suggest { width: 100%; max-width: 480px; min-height: calc(2.9em + 26px); margin: 0; padding: 12px 0 14px; font-size: 14px; color: var(--muted); text-align: center; }
.suggest b { color: var(--text); }
.suggest .pick {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: 800 15px ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase;
  color: var(--text); text-decoration: underline; text-decoration-color: var(--correct); text-underline-offset: 3px;
}

.list-head, .other summary { display: flex; align-items: baseline; gap: 8px; font-size: 16px; margin: 18px 0 10px; font-weight: 700; }
.words > .list-head:first-child { margin-top: 0; }
.count { color: var(--muted); font-weight: 500; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 5px;
  padding: 4px 8px; cursor: pointer;
  font: 600 14px ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; letter-spacing: 0.05em;
}
.chip:hover { border-color: var(--line-strong); }
.chip.best { border-color: var(--correct); box-shadow: inset 0 0 0 1px var(--correct); }
.chips.dim .chip { color: var(--muted); font-weight: 500; }
.empty { color: var(--muted); margin: 0; }
.other summary { cursor: pointer; list-style: none; }
.other summary::-webkit-details-marker { display: none; }
.other summary::before { content: "▸"; color: var(--muted); }
.other[open] summary::before { content: "▾"; }
.note { color: var(--muted); font-size: 13px; margin: -4px 0 10px; }

/* ---- About (for people and search engines) ---- */
.about {
  max-width: 1040px; margin: 0 auto; padding: 24px 16px 48px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 14px;
}
.about h1 { font-size: 16px; color: var(--text); margin: 0 0 8px; }
.about p { margin: 0 0 8px; max-width: 68ch; }
