:root {
  --bg: #f3efe6;
  --bg-elev: #fffcf6;
  --ink: #1b1814;
  --ink-muted: #5c574e;
  --line: #d9d0c1;
  --accent: #b5471d;
  --seen-bg: #1f6b4a;
  --seen-ink: #f6f3ea;
  --bar: #1f6b4a;
  --bar-track: #e4ddd0;
  --danger: #9b2c2c;
  --shadow: 0 1px 2px rgba(27, 24, 20, 0.06), 0 8px 24px rgba(27, 24, 20, 0.06);
  --font-ui: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-plate: "Oswald", "Arial Narrow", "Franklin Gothic Medium", sans-serif;
  --btn-fg: #fff;
  --status-bg: #efe3c4;
  --status-fg: #4a3a14;
  --current-ring: #b5471d;
  --radius: 12px;
  --pad: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #13110e;
  --bg-elev: #1c1915;
  --ink: #f3eee4;
  --ink-muted: #b3ab9e;
  --line: #3a342c;
  --accent: #e08a4f;
  --seen-bg: #d4922d;
  --seen-ink: #1a140a;
  --bar: #e08a4f;
  --bar-track: #2a261f;
  --danger: #e07070;
  --btn-fg: #1a140a;
  --status-bg: #3a3118;
  --status-fg: #f0e0b8;
  --current-ring: #e08a4f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #13110e;
    --bg-elev: #1c1915;
    --ink: #f3eee4;
    --ink-muted: #b3ab9e;
    --line: #3a342c;
    --accent: #e08a4f;
    --seen-bg: #d4922d;
    --seen-ink: #1a140a;
    --bar: #e08a4f;
    --bar-track: #2a261f;
    --danger: #e07070;
    --btn-fg: #1a140a;
    --status-bg: #3a3118;
    --status-fg: #f0e0b8;
    --current-ring: #e08a4f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: calc(12px + var(--safe-t)) calc(var(--pad) + var(--safe-r)) calc(40px + var(--safe-b)) calc(var(--pad) + var(--safe-l));
  max-width: 920px;
  margin: 0 auto;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--bg-elev);
  color: var(--ink);
  padding: 8px 12px;
  z-index: 20;
}
.skip:focus { left: 8px; }

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

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.brand h1 {
  font-family: var(--font-plate);
  font-weight: 600;
  font-size: 1.85rem;
  letter-spacing: 0.04em;
  margin: 0;
  line-height: 1.1;
  text-transform: uppercase;
}

.tagline {
  margin: 2px 0 0;
  color: var(--ink-muted);
  font-size: 0.92rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn, .icon-btn, .tile {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn {
  background: var(--accent);
  color: var(--btn-fg, #fff);
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.9rem;
  min-height: 40px;
}

.btn-ghost {
  background: transparent;
  color: var(--ink) !important;
  border: 1.5px solid var(--line);
}

.btn-danger {
  background: var(--danger);
  color: #fff !important;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--bg-elev);
  display: grid;
  place-items: center;
  padding: 0;
}

.theme-icon::before {
  content: "◐";
  font-size: 1.1rem;
  line-height: 1;
}

.progress-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.progress-label, .game-code {
  margin: 0;
}

.progress-label { font-size: 1.05rem; }
.progress-label strong { font-size: 1.35rem; }
.denom { color: var(--ink-muted); font-weight: 700; }
.game-code { color: var(--ink-muted); font-size: 0.88rem; letter-spacing: 0.02em; }
.game-code strong { color: var(--ink); letter-spacing: 0.08em; font-family: var(--font-plate); font-size: 1rem; }

.bar {
  margin-top: 8px;
  height: 10px;
  border-radius: 999px;
  background: var(--bar-track);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--bar);
  border-radius: inherit;
  transition: width 0.25s ease;
}

.complete-banner {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--seen-bg);
  color: var(--seen-ink);
  font-weight: 700;
  text-align: center;
}

.status-banner {
  margin: -4px 0 14px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--status-bg, #efe3c4);
  color: var(--status-fg, #4a3a14);
  font-size: 0.9rem;
}

.current-card,
.finish-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  text-align: center;
}

.current-kicker {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.current-letter {
  font-family: var(--font-plate);
  font-weight: 600;
  font-size: clamp(4.2rem, 22vw, 6.2rem);
  letter-spacing: 0.04em;
  line-height: 1;
  margin: 2px 0 0;
}

.current-prompt {
  margin: 6px 0 14px;
  color: var(--ink-muted);
}

.word-form {
  display: flex;
  gap: 8px;
  max-width: 440px;
  margin: 0 auto;
}

.word-form input,
.name-row input,
.dialog input[type="text"] {
  font: inherit;
  font-size: 16px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}

.word-form input {
  flex: 1;
  min-width: 0;
}

.word-form .btn {
  flex-shrink: 0;
  padding-left: 16px;
  padding-right: 16px;
}

.word-error {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 700;
}

.name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 0;
  font-size: 0.88rem;
  color: var(--ink-muted);
  font-weight: 700;
}

.name-row input {
  width: 11.5rem;
  min-height: 36px;
  padding: 6px 10px;
  font-weight: 400;
  color: var(--ink);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.word-form input:focus,
.name-row input:focus,
.dialog input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.finish-title {
  font-family: var(--font-plate);
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0 0 8px;
}

.finish-copy {
  margin: 0 auto 16px;
  max-width: 28rem;
  color: var(--ink-muted);
}

.board { margin-bottom: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 5.8rem;
  padding: 10px 7px 9px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--bg-elev);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), var(--shadow);
  text-align: center;
  cursor: default;
}

.tile .abbr {
  font-family: var(--font-plate);
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
}

.tile .word,
.tile .when {
  font-size: 0.72rem;
  line-height: 1.2;
  color: var(--ink-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile .when { font-size: 0.68rem; }

.tile.upcoming {
  opacity: 0.55;
}

.tile.current {
  opacity: 1;
  border-color: var(--current-ring);
  box-shadow: 0 0 0 2px var(--current-ring), var(--shadow);
}

.tile.current .word {
  font-weight: 700;
  color: var(--accent);
  white-space: normal;
}

.tile.done {
  background: var(--seen-bg);
  border-color: var(--seen-bg);
  color: var(--seen-ink);
  box-shadow: none;
  opacity: 1;
}

.tile.done .word,
.tile.done .when {
  color: var(--seen-ink);
  opacity: 0.88;
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  z-index: 30;
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: calc(100% - 32px);
}

.dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-elev);
  color: var(--ink);
  padding: 0;
  width: min(400px, calc(100% - 32px));
  box-shadow: var(--shadow);
}

.dialog::backdrop { background: rgba(20, 16, 12, 0.45); }

.dialog form { padding: 18px 18px 16px; }
.dialog h2 { margin: 0 0 8px; font-size: 1.2rem; }
.dialog p { margin: 0 0 16px; color: var(--ink-muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .tile { min-height: 6.2rem; }
  .tile .abbr { font-size: 1.9rem; }
}
