:root {
  --paper: #f4efe4;
  --ink: #241c15;
  --card: #fffdf8;
  --coral: #e25b45;
  --coral-dark: #c44733;
  --teal: #1f7a6b;
  --gold: #e7b143;
  --line: #e6d9c6;
  --muted: #6d6258;
  --shadow: 0 16px 40px rgba(36, 28, 21, 0.08);
  --radius: 18px;
  color-scheme: light;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at top left, rgba(226, 91, 69, 0.08), transparent 32%),
    radial-gradient(circle at bottom right, rgba(31, 122, 107, 0.08), transparent 28%),
    var(--paper);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--teal); }
h1, h2 { font-family: Palatino, "Iowan Old Style", Georgia, serif; font-weight: 700; letter-spacing: -0.03em; }
h1 { margin: 0; font-size: 2.4rem; }
h2 { margin: 0 0 0.4rem; font-size: 1.35rem; }

.home-body { min-height: 100vh; }
.home-frame {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 20px 20px;
}
.home-top { margin-bottom: 16px; }
.home-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(240px, 0.8fr);
  gap: 28px;
  align-items: start;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.narrow { max-width: 440px; margin: 10vh auto; }
.stack > * + * { margin-top: 14px; }
.brand { display: flex; gap: 14px; align-items: center; }
a.brand { color: inherit; text-decoration: none; }
a.brand:hover strong { text-decoration: underline; }
.brand.compact h1 { font-size: 1.6rem; }
.brand-name { font-family: Palatino, "Iowan Old Style", Georgia, serif; font-weight: 700; letter-spacing: -0.03em; font-size: 2.4rem; }
.legal h1 { font-size: 2rem; }
.legal h2 { margin-top: 1.35rem; font-size: 1.2rem; }
.legal p, .legal li { line-height: 1.55; }
.legal .updated { color: var(--muted); font-size: 0.9rem; }
.site-footer { margin-top: 22px; padding-bottom: 28px; font-size: 0.9rem; }
.site-footer.center { text-align: center; }
.site-footer a { color: var(--muted); }
.gate-links { display: flex; gap: 14px; align-items: center; }
.topbar-privacy { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-decoration: none; }
.topbar-privacy:hover { text-decoration: underline; }
.logo { width: 56px; height: 56px; flex: none; }
.logo.small { width: 36px; height: 36px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.75rem; color: var(--coral); }
.lede, .aside p, .hint-note, .scoring-note { color: var(--muted); line-height: 1.5; }
.aside { padding: 12px 8px; }
.aside ol { padding-left: 1.2rem; line-height: 1.5; }
label { display: grid; gap: 6px; font-size: 0.92rem; font-weight: 600; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 500;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(31, 122, 107, 0.45);
  outline-offset: 2px;
}
button, .button-link {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-decoration: none;
}
.primary { background: var(--coral); color: white; }
.primary:hover { background: var(--coral-dark); }
.secondary { background: var(--teal); color: white; }
.ghost { background: transparent; border: 1px solid var(--line); }
.primary:disabled, .secondary:disabled, button:disabled { opacity: 0.55; cursor: not-allowed; }
.or { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.or::before, .or::after { content: ""; height: 1px; background: var(--line); }
.form-error { min-height: 1.2em; color: var(--coral-dark); font-weight: 700; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-status { font-size: 1.2rem; }

.app { min-height: 100vh; display: flex; flex-direction: column; }
#screen-lobby, #screen-game, #screen-results { flex: 1 1 auto; }
#screen-game { min-height: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.topbar .status-pill { margin-right: auto; }
.status-pill, .badge {
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.82rem;
}
.status-pill.warn { background: #fff4d6; }
.toast {
  margin: 0 16px 8px;
  background: #241c15;
  color: white;
  border-radius: 12px;
  padding: 10px 14px;
}
.lobby, .results {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto 16px;
  display: grid;
  gap: 14px;
}
.results {
  width: min(460px, calc(100% - 24px));
  margin-top: 8px;
  align-self: start;
  justify-self: center;
}
.lobby { grid-template-columns: 1.1fr 0.9fr 0.9fr; align-items: start; }
.lobby .card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.lobby .card > * { margin: 0; }
.lobby .card > button { align-self: flex-start; margin-top: 2px; }
.word-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.word-note.ok { color: var(--teal); }
.word-note.bad { color: var(--coral-dark); font-weight: 700; }
.lobby .section-head h2 { margin: 0; }
.section-head, .stage-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lock-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-weight: 700;
  cursor: pointer;
}
.lock-row input {
  width: auto;
  flex: none;
  margin-top: 3px;
  accent-color: var(--teal);
}
.lock-copy { display: grid; gap: 3px; }
.lock-help { color: var(--muted); font-size: 0.84rem; font-weight: 500; line-height: 1.4; }
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.player-list .name { font-weight: 700; margin-right: auto; }
.player-list .score { font-variant-numeric: tabular-nums; }
.badge.host { background: #fff1d2; }
.badge.you { background: #e7f6f2; }
.badge.off { background: #f6e4df; }

.play {
  width: min(1280px, calc(100% - 16px));
  margin: 0 auto 12px;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 280px;
  gap: 12px;
  min-height: 0;
}
.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.timer {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 800;
}
.hint { display: flex; flex-wrap: wrap; gap: 6px; min-height: 42px; align-items: center; }
.hint-letter, .hint-gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hint-letter {
  min-width: 28px;
  height: 36px;
  padding: 0 4px;
  border-bottom: 3px solid var(--ink);
  font-family: Palatino, Georgia, serif;
  font-size: 1.3rem;
  text-transform: uppercase;
}
.hint-gap { width: 18px; }
.canvas-wrap { position: relative; min-height: 420px; flex: 1; }
canvas {
  width: 100%;
  height: 100%;
  min-height: 420px;
  background: white;
  border-radius: 14px;
  border: 1px solid var(--line);
  touch-action: none;
  cursor: crosshair;
  display: block;
}
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 253, 248, 0.92);
  border-radius: 14px;
  text-align: center;
}
.overlay .choices { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.overlay h3 { margin: 0 0 8px; font-family: Palatino, Georgia, serif; }
.tools { display: grid; gap: 8px; }
.colors, .tool-row, .sizes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch, .sizes button, .tool-row button {
  border-radius: 999px;
  border: 2px solid transparent;
  min-width: 32px;
  height: 32px;
}
.swatch { width: 32px; padding: 0; }
.swatch[aria-pressed="true"], .sizes button[aria-pressed="true"], .tool-row button[aria-pressed="true"] {
  border-color: var(--ink);
}
.sizes button { background: white; border-color: var(--line); }
.chat-panel { display: flex; flex-direction: column; min-height: 0; }
.chat {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 180px;
  max-height: 460px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat li { background: #fff; border-radius: 10px; padding: 6px 8px; line-height: 1.35; }
.chat .system { color: var(--muted); background: transparent; padding-left: 0; }
.chat .correct { color: var(--teal); font-weight: 700; }
#guess-form { display: flex; gap: 8px; margin-top: 8px; }
#guess-form input { flex: 1; }
.scoreboard { display: flex; flex-direction: column; gap: 18px; }
.scoreboard > * { margin: 0; }
.scoreboard-head { text-align: center; }
.scoreboard-head h2 { margin: 2px 0 0; font-size: 2rem; }
.results-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.results-list li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.results-list .place {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--paper);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.results-list .place-1 {
  background: #fff8ea;
  border-color: #efd08a;
}
.results-list .place-1 .place { background: var(--gold); }
.results-list .place-2 .place { background: #efe8df; }
.results-list .place-3 .place { background: #f8e6e1; color: var(--coral-dark); }
.results-list .is-you { box-shadow: inset 0 0 0 2px var(--teal); }
.result-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
}
.result-score {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 800;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}
.result-score .pts {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.scoreboard-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.scoreboard-actions .hint-note { margin: 0; text-align: center; }
.scoreboard-actions .primary { min-width: 168px; }
.ad-slot:empty { display: none; }
.ad-slot:not(:empty) { margin: 0 auto 16px; }
.home-frame > .ad-slot:not(:empty) { margin-bottom: 18px; }
.app > .ad-slot:not(:empty) { width: min(1040px, calc(100% - 32px)); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.tools.is-disabled { opacity: 0.55; }

@media (max-width: 980px) {
  .home-shell, .lobby, .play { grid-template-columns: 1fr; }
  .home-frame { padding-top: 20px; }
  .canvas-wrap, canvas { min-height: 320px; height: 58vh; }
  .chat { max-height: 240px; }
}
