html { box-sizing: border-box; -webkit-text-size-adjust: 100%; }
:root { color-scheme: light; padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); }
body { margin: 0; }
[hidden] { display: none !important; }
img { max-width: 100%; }
/* Layout: one phone-height column. A dark "screen" shows the clue, the title's tiles sit under it, the keyboard docks at the bottom. */
:root {
  --bg: #F2F0F7; --surface: #FBFAFD; --fg: #1B1830; --muted: #625E78; --line: #D4CFE3;
  --accent: #4B3FD1; --accent-fg: #FFFFFF;
  --screen: #1B1830; --screen-fg: #F2F0F7; --screen-muted: #A9A4C4;
  --ok: #1F7A63; --ok-fg: #FFFFFF;
  --near: #B26A00; --near-bg: #FBEBCF; --near-fg: #5C3700;
  --miss: #DDD9EA; --miss-fg: #57536C; --tile-line: #8A84A3; --key: #E2DEEE;
  --scrim: rgba(15, 13, 28, 0.55);
  --display: "Instrument Serif", Georgia, "Times New Roman", serif;
  --ui: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #13111C; --surface: #1D1A2B; --fg: #ECE9F5; --muted: #A39EBD; --line: #36314D;
    --accent: #9A91FF; --accent-fg: #13111C;
    --screen: #0A0911; --screen-fg: #F2F0F7; --screen-muted: #A9A4C4;
    --ok: #3FB594; --ok-fg: #08221B;
    --near: #E3A63F; --near-bg: #3A2C10; --near-fg: #F3CF8A;
    --miss: #2A2740; --miss-fg: #A09BBA; --tile-line: #76719A; --key: #2D2944;
    --scrim: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #13111C; --surface: #1D1A2B; --fg: #ECE9F5; --muted: #A39EBD; --line: #36314D;
  --accent: #9A91FF; --accent-fg: #13111C;
  --screen: #0A0911; --screen-fg: #F2F0F7; --screen-muted: #A9A4C4;
  --ok: #3FB594; --ok-fg: #08221B;
  --near: #E3A63F; --near-bg: #3A2C10; --near-fg: #F3CF8A;
  --miss: #2A2740; --miss-fg: #A09BBA; --tile-line: #76719A; --key: #2D2944;
  --scrim: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}
html, body { height: 100%; }
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--fg); font-family: var(--ui); font-size: 1rem; display: flex; justify-content: center; }
.app { width: 100%; max-width: 35rem; height: 100%; display: flex; flex-direction: column; gap: 0.75rem; padding-block: 0.75rem;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, dialog:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 0.6rem; }
.brand h1 { font-family: var(--display); font-weight: 400; font-size: clamp(1.45rem, 6.6vw, 2rem); line-height: 1; margin: 0; letter-spacing: 0.01em; white-space: nowrap; }
.tag { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); padding: 0.15rem 0.45rem; border-radius: 999px; }
.nav { display: flex; gap: 0.25rem; }
.link { background: none; border: 0; padding: 0.4rem 0.5rem; min-height: 2.75rem; font-size: 0.9rem; font-weight: 500; color: var(--muted); border-radius: 0.4rem; }
.link:hover { color: var(--fg); background: var(--key); }

.stage { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 0.9rem; }
/* The clue, its hints and the take counter stay in view while earlier guesses scroll underneath. */
.pinned { position: sticky; top: 0; z-index: 1; background: var(--bg); display: flex; flex-direction: column; gap: 0.6rem; padding-bottom: 0.6rem; }
.screen { background: var(--screen); color: var(--screen-fg); border-radius: 0.5rem; padding: 0.9rem 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; }
.slate { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--screen-muted); }
.clue { font-family: var(--emoji); font-size: clamp(2rem, 11vw, 3.6rem); line-height: 1.25; text-align: center; overflow-wrap: anywhere; margin: 0; }
.clue.long { font-size: clamp(1.5rem, 7vw, 2.4rem); }

.takes { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.6rem; white-space: nowrap; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.pips { display: flex; gap: 0.3rem; }
.pip { width: 1.4rem; height: 0.4rem; border-radius: 999px; background: var(--line); }
.pip.used { background: var(--muted); }
.pip.now { background: var(--accent); }
.pip.won { background: var(--ok); }

.board { container-type: inline-size; display: flex; flex-direction: column; gap: 1rem; padding-bottom: 0.25rem; }
.row { --gap: 4px; --tile: min(2.6rem, calc((100cqw - (var(--n) - 1) * var(--gap)) / var(--n)));
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem calc(var(--tile) * 0.45); }
.row + .row { border-top: 1px dashed var(--line); padding-top: 1rem; }
.word { display: flex; gap: var(--gap); }
.tile { width: var(--tile); height: calc(var(--tile) * 1.15); font-size: calc(var(--tile) * 0.56); font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center; border-radius: 0.25rem; border: 2px solid var(--tile-line); background: var(--surface); color: var(--fg); }
.tile.filled { border-color: var(--muted); }
.tile.cursor { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.tile.ok { background: var(--ok); border-color: var(--ok); color: var(--ok-fg); }
.tile.near { background: var(--near-bg); border-color: var(--near); color: var(--near-fg); border-style: dashed; }
.tile.miss { background: var(--miss); border-color: var(--miss); color: var(--miss-fg); }
.fixed { width: calc(var(--tile) * 0.5); height: calc(var(--tile) * 1.15); font-size: calc(var(--tile) * 0.6); font-weight: 700; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.row.reveal .tile { animation: flip 0.32s ease both; animation-delay: calc(var(--d) * 28ms); }
@keyframes flip { from { transform: scaleY(0.1); opacity: 0.3; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .row.reveal .tile { animation: none; } }

.dock { display: flex; flex-direction: column; gap: 0.35rem; }
.krow { display: flex; gap: 0.3rem; justify-content: center; }
.key { flex: 1; min-width: 0; height: 3rem; border: 0; border-radius: 0.35rem; background: var(--key); color: var(--fg); font-weight: 600; font-size: 1rem; padding: 0; touch-action: manipulation; }
.key.num { height: 2.4rem; }
.key.wide { flex: 1.7; font-size: 0.85rem; }
.key.go { background: var(--accent); color: var(--accent-fg); }
.key.go:disabled { background: var(--key); color: var(--muted); cursor: default; }
.key.ok { background: var(--ok); color: var(--ok-fg); }
.key.near { background: var(--near-bg); color: var(--near-fg); box-shadow: inset 0 0 0 2px var(--near); }
.key.miss { background: transparent; color: var(--miss-fg); box-shadow: inset 0 0 0 1px var(--line); }
.half { flex: 0.5; }

.end { background: var(--surface); border: 1px solid var(--line); border-radius: 0.5rem; padding: 1rem; display: flex; flex-direction: column; gap: 0.7rem; }
.end h2 { font-family: var(--display); font-weight: 400; font-size: 1.9rem; line-height: 1.1; margin: 0; text-wrap: balance; }
.end p { margin: 0; color: var(--muted); line-height: 1.45; }
.end .answer { font-family: var(--display); font-style: italic; font-size: 1.35rem; color: var(--fg); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 0.4rem; padding: 0.6rem 0.9rem; font-weight: 600; font-size: 0.95rem; }
a.btn { text-decoration: none; color: var(--fg); display: inline-flex; align-items: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.count { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--fg); }
.sharebox { width: 100%; min-height: 6.5rem; font: inherit; font-size: 0.9rem; padding: 0.6rem; border-radius: 0.4rem; border: 1px solid var(--line); background: var(--bg); color: var(--fg); resize: none; }

dialog { border: 1px solid var(--line); border-radius: 0.6rem; background: var(--surface); color: var(--fg); padding: 1.25rem; width: min(30rem, calc(100% - 2rem)); }
dialog::backdrop { background: var(--scrim); }
dialog h2 { font-family: var(--display); font-weight: 400; font-size: 1.8rem; margin: 0 0 0.75rem; }
dialog p, dialog li { line-height: 1.5; color: var(--fg); }
dialog ul { padding-left: 1.1rem; margin: 0.5rem 0; display: flex; flex-direction: column; gap: 0.5rem; }
.legend { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.9rem 0; }
.legend div { display: flex; align-items: center; gap: 0.7rem; }
.legend .tile { --tile: 2.1rem; flex: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0.5rem 0 1rem; text-align: center; }
.stats b { display: block; font-family: var(--display); font-weight: 400; font-size: 2.2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.stats span { font-size: 0.75rem; color: var(--muted); }
.dlg-foot { display: flex; justify-content: flex-end; margin-top: 0.75rem; }

/* Hints */
.hints { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 0.5rem; }
.hint { font-size: 0.85rem; font-weight: 600; color: var(--screen-fg); border: 1px solid var(--screen-muted); border-radius: 999px; padding: 0.25rem 0.75rem; }
.hintbtn { border: 1px solid var(--accent); background: none; color: var(--accent); border-radius: 999px; padding: 0.3rem 0.8rem; min-height: 2.25rem; font-weight: 600; font-size: 0.85rem; }
.hintbtn:disabled { border-color: var(--line); color: var(--muted); cursor: default; }
.end .meta { font-size: 0.9rem; }

/* Text for screen readers only */
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.end h2:focus { outline: none; }
.end h2:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

dialog h3 { margin: 1rem 0 0.25rem; font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
dialog a { color: var(--accent); }

.brand h1 .the { font-size: 0.6em; font-style: italic; color: var(--muted); }
.slate { flex-wrap: wrap; row-gap: 0.2rem; }
.slate span { white-space: nowrap; }
