:root {
  --bg: #f5f2ea;
  --surface: #fffdf8;
  --surface-2: #ece7da;
  --ink: #1f1d19;
  --ink-soft: #5c574d;
  --ink-faint: #8d8778;
  --line: #d9d2c1;
  --accent: #1e6b47;
  --accent-ink: #ffffff;
  --wrong: #b8402a;
  --wrong-bg: #f7dfd8;
  --close: #9a6a08;
  --close-bg: #f8ebc8;
  --correct: #1e6b47;
  --correct-bg: #d6ecdf;
  --redact-bg: #1f1d19;
  --redact-ink: #f5f2ea;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

/* Dark tokens apply for a dark OS setting unless the viewer picked light, and always when they picked dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412;
    --surface: #1f1d1a;
    --surface-2: #2a2824;
    --ink: #f1ede4;
    --ink-soft: #bdb6a7;
    --ink-faint: #8a8476;
    --line: #3a3732;
    --accent: #4cb581;
    --accent-ink: #0e1a13;
    --wrong: #f08a73;
    --wrong-bg: #3d221c;
    --close: #f0c35a;
    --close-bg: #3a3018;
    --correct: #6fd39e;
    --correct-bg: #1d3528;
    --redact-bg: #f1ede4;
    --redact-ink: #151412;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #151412;
  --surface: #1f1d1a;
  --surface-2: #2a2824;
  --ink: #f1ede4;
  --ink-soft: #bdb6a7;
  --ink-faint: #8a8476;
  --line: #3a3732;
  --accent: #4cb581;
  --accent-ink: #0e1a13;
  --wrong: #f08a73;
  --wrong-bg: #3d221c;
  --close: #f0c35a;
  --close-bg: #3a3018;
  --correct: #6fd39e;
  --correct-bg: #1d3528;
  --redact-bg: #f1ede4;
  --redact-ink: #151412;
  --shadow: none;
  color-scheme: dark;
}

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

body {
  margin: 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 528px; margin: 0 auto; padding-block: 14px 10px;
  border-bottom: 1px solid var(--line);
}
.brand { text-align: center; }
.brand h1 {
  margin: 0; font: 700 1.6rem/1.1 Georgia, "Times New Roman", serif; letter-spacing: 0.01em;
}
.subtitle { margin: 2px 0 0; font-size: 0.8rem; color: var(--ink-faint); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  display: grid; place-items: center; font-weight: 700;
}
.icon-btn:hover { background: var(--surface-2); }

.game { max-width: 528px; margin: 0 auto; padding-block: 16px 48px; }
.loading { color: var(--ink-faint); text-align: center; }

.pips { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; }
.pip {
  width: 26px; height: 8px; border-radius: 4px; background: var(--surface-2);
}
.pip.wrong { background: var(--wrong); }
.pip.close { background: var(--close); }
.pip.correct { background: var(--correct); }
.pip.current { outline: 2px solid var(--ink-soft); outline-offset: 2px; }

.clues { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.clue {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.clue.latest { border: 2px solid var(--ink); padding: 14px 16px; }
.clue.latest .clue-text { font-size: 1.12rem; }
.clue.older { opacity: 0.78; box-shadow: none; }
.clue-label {
  display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 4px;
}
.clue-text { margin: 0; font-family: Georgia, "Times New Roman", serif; line-height: 1.45; }
.clue.enter { animation: rise 260ms ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(-6px); } }

.redact {
  background: var(--redact-bg); color: var(--redact-ink);
  border-radius: 4px; padding: 0 5px; font-family: system-ui, sans-serif; font-size: 0.85em;
}

.guesses { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
}
.tag.wrong { background: var(--wrong-bg); color: var(--wrong); }
.tag.close { background: var(--close-bg); color: var(--close); }
.tag.correct { background: var(--correct-bg); color: var(--correct); }

.guess-form {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 18px;
  position: sticky; bottom: 0; padding-block: 10px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--bg);
}
.combo { position: relative; }
#guess-input {
  width: 100%; height: 48px; padding: 0 14px; font-size: 1rem;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
#guess-input:focus { outline: none; border-color: var(--ink); }
.suggestions {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 5;
  list-style: none; margin: 0; padding: 4px; max-height: 280px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
}
.suggestions.down { bottom: auto; top: calc(100% + 6px); }
.suggestions li { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--surface-2); }
.suggestions li.used { color: var(--ink-faint); text-decoration: line-through; }
.suggestions .alias { color: var(--ink-faint); font-size: 0.82rem; margin-left: 6px; }

.primary, .secondary {
  height: 48px; padding: 0 20px; border-radius: var(--radius); font-weight: 700;
}
.primary { background: var(--accent); color: var(--accent-ink); border: none; }
.primary:hover { filter: brightness(1.08); }
.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.secondary:hover { background: var(--surface-2); }

.form-message { grid-column: 1 / -1; margin: 0; min-height: 1.3em; font-size: 0.88rem; color: var(--wrong); }
.form-message[data-tone="close"] { color: var(--close); }

.result {
  margin-top: 22px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.result-head { text-align: center; }
.result-status { margin: 0; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.result-status.won { color: var(--correct); }
.result-status.lost { color: var(--wrong); }
.result-sport { margin: 4px 0; font: 700 2rem/1.15 Georgia, serif; }
.result-blurb { margin: 0 auto; max-width: 40ch; color: var(--ink-soft); }
.result h3 { margin: 18px 0 8px; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); }
.rule-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rule-list li { border-top: 1px solid var(--line); padding-top: 8px; }
.rule-list p { margin: 0; }
.rule-ref { font-size: 0.8rem; color: var(--ink-faint); }
.reveal-btn {
  border: 1px dashed var(--line); background: none; color: var(--ink-soft);
  border-radius: 8px; padding: 6px 10px; width: 100%; text-align: left;
}
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.next-up { margin: 12px 0 0; text-align: center; font-size: 0.85rem; color: var(--ink-faint); }

dialog {
  width: min(440px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--ink); padding: 22px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin: 0 0 12px; font: 700 1.4rem Georgia, serif; }
dialog h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
dialog [data-close] { width: 100%; margin-top: 16px; }
.help-steps { padding-left: 1.2em; margin: 0; display: grid; gap: 8px; }
.help-note { color: var(--ink-soft); font-size: 0.92rem; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stat-grid strong { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat-grid span { font-size: 0.75rem; color: var(--ink-faint); }
.dist { display: grid; gap: 4px; }
.dist-row { display: grid; grid-template-columns: 16px 1fr; gap: 8px; align-items: center; font-size: 0.85rem; }
.dist-bar {
  background: var(--surface-2); color: var(--ink); border-radius: 4px;
  padding: 1px 6px; text-align: right; min-width: 24px; font-weight: 600;
}
.dist-bar.today { background: var(--accent); color: var(--accent-ink); }

.toast {
  position: fixed; left: 50%; top: calc(18px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  font-weight: 600; font-size: 0.9rem; z-index: 20;
}

@media (prefers-reduced-motion: reduce) {
  .clue.enter { animation: none; }
}

.share-fallback {
  width: 100%; margin-top: 10px; padding: 8px 10px; resize: none;
  font: 0.9rem/1.4 ui-monospace, Consolas, monospace;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.clue-ref {
  display: block; margin-top: 6px; font-size: 0.78rem; color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.clue-ref .redact { font-size: 0.9em; }

.credits {
  max-width: 528px; margin: 0 auto; padding-block: 8px calc(28px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line); color: var(--ink-faint); font-size: 0.78rem; line-height: 1.5;
}
.credits p { margin: 8px 0 0; max-width: 65ch; }
.credits a { color: var(--ink-soft); }

.modes {
  display: flex; gap: 4px; max-width: 528px; margin: 12px auto 0; padding: 4px;
  background: var(--surface-2); border-radius: 999px;
}
.modes button {
  flex: 1; height: 36px; border: none; border-radius: 999px;
  background: transparent; color: var(--ink-soft); font-weight: 600;
}
.modes button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.practice-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  margin-bottom: 14px; font-size: 0.88rem; color: var(--ink-soft);
}
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { color: var(--ink-faint); }
.link-btn {
  border: none; background: none; padding: 4px 0; color: var(--accent);
  font-weight: 700; text-decoration: underline; text-underline-offset: 3px;
}

.rule-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
.flag { font-size: 0.8rem; color: var(--ink-faint); }
.flag:hover { color: var(--wrong); }
