:root {
  --paper: #f6f1e7;
  --stage: #363330;
  --on-stage: #f6f1e7;
  --on-stage-muted: #cfc8ba;
  --ink: #1a1a1a;
  --card: #ffffff;
  --accent: #c93a2a;
  --accent-dark: #a22e20;
  --accent-soft: #fde8e4;
  --gold: #ffe36b;
  --gold-dark: #f0cf4e;
  --ok: #1f7a6b;
  --danger: #c93a2a;
  --line: #1a1a1a;
  --muted: #5c5648;
  --shadow: 4px 4px 0 #1a1a1a;
  --radius: 18px 12px 22px 10px / 12px 22px 10px 18px;
  --radius-mark: 70px 16px 64px 14px / 16px 64px 14px 70px;
  --ui-font: Inter, Roboto, "Helvetica Neue", "Arial Nova", Arial, sans-serif;
  --head-font: Noteworthy, "Segoe Print", "Bradley Hand", "Comic Neue", cursive;
  --story-font: Charter, "Iowan Old Style", Georgia, serif;
  color-scheme: light;
  font-family: var(--ui-font);
  color: var(--on-stage);
  background: var(--stage);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--stage); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-dark); }
h1, h2, h3 { font-family: var(--head-font); font-weight: 700; letter-spacing: 0; }
h1 { margin: 0; font-size: 2.4rem; }
h2 { margin: 0 0 0.4rem; font-size: 1.35rem; }
h3 { margin: 0; font-size: 1.15rem; }

/* Home and small pages */

.home-body { min-height: 100vh; }
.home-frame {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 20px 20px;
}
.home-top { margin-bottom: 18px; }
.home-top .brand-name { font-size: 1.45rem; }
.pitch { max-width: 40rem; margin: 0 0 22px; }
.pitch .eyebrow { margin-bottom: 14px; color: var(--on-stage-muted); }
.pitch h1 { font-size: clamp(2rem, 4.4vw, 3.15rem); line-height: 1.05; }
.pitch .lede { margin: 12px 0 0; font-size: 1.05rem; }
.home-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(240px, 0.8fr);
  gap: 28px;
  align-items: start;
}
.home-shell.single { display: block; padding: 0 20px; }
.card {
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--ink);
  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 { margin: 0; font-family: var(--head-font); font-weight: 700; letter-spacing: 0; font-size: 2.4rem; }
.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; font-weight: 700; color: var(--accent); }
.lede, .hint-note, .scoring-note { color: var(--muted); line-height: 1.5; }
.lede { color: var(--on-stage-muted); }
.hint-note { margin: 0; font-size: 0.92rem; }
.hero { display: grid; gap: 14px; align-content: start; }
.sample { margin: 0; display: grid; gap: 12px; align-content: start; }
.sample-top { display: flex; align-items: center; justify-content: space-between; }
.sample-kicker { margin: 0; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.75rem; color: var(--muted); }
.sample-timer { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); font-size: 1.35rem; }
.sample-prompt { margin: 0; font-family: var(--story-font); font-size: 1.25rem; line-height: 1.5; }
.sample-ballot { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sample-ballot li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
  font-family: var(--story-font);
  line-height: 1.4;
}
.sample-ballot span { font-weight: 700; }
.sample-ballot strong { font-family: var(--ui-font); font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.sample-ballot .win { border-color: var(--accent); background: var(--accent-soft); }
.sample-ballot .win strong { color: var(--accent-dark); }
.sample figcaption { margin: 0; color: var(--muted); line-height: 1.45; }
.steps {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.steps li {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  line-height: 1.45;
}
.steps strong { display: block; margin-bottom: 4px; }
.steps p { margin: 0; color: var(--muted); }
.legal h1 { font-size: 2rem; }
.legal h2 { margin-top: 1.35rem; font-size: 1.2rem; }
.legal p { 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(--on-stage-muted); }
.status-list { display: grid; gap: 12px; margin: 18px 0 0; }
.status-list div { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.status-list dt { color: var(--muted); font-weight: 600; }
.status-list dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

/* Forms and buttons */

label { display: grid; gap: 6px; font-size: 0.92rem; font-weight: 600; }
input, select, textarea {
  width: 100%;
  border: 2px solid var(--ink);
  background: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-weight: 500;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.45; }
select:disabled { opacity: 1; color: var(--muted); background: var(--paper); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .piece:focus-visible {
  outline: 3px solid rgba(201, 58, 42, 0.45);
  outline-offset: 2px;
}
button, .button-link {
  border: 0;
  border-radius: 24px 16px 26px 14px / 16px 26px 14px 24px;
  padding: 12px 18px;
  font-weight: 700;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.primary, .secondary { border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-dark); }
.secondary { background: var(--gold); color: var(--ink); }
.secondary:hover { background: var(--gold-dark); }
.ghost { background: var(--card); color: var(--ink); border: 2px solid var(--ink); }
.ghost:hover { background: #fff; }
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; margin: 0; color: var(--danger); font-weight: 700; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-status { font-size: 1.2rem; }
.gate-links { display: flex; gap: 14px; align-items: center; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Room frame */

.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.topbar .status-pill { margin-right: auto; }
.topbar-privacy { color: var(--on-stage-muted); font-size: 0.85rem; font-weight: 600; text-decoration: none; }
.topbar-privacy:hover { text-decoration: underline; }
.status-pill { color: var(--ink); }
.status-pill, .badge {
  margin: 0;
  border-radius: 999px;
  padding: 3px 9px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-pill.warn { background: #fff4d6; }
.badge.host { background: var(--gold); border-color: var(--ink); }
.badge.you { background: var(--accent-soft); border-color: var(--ink); }
.badge.off { background: var(--accent-soft); }
.badge.ok { background: #e3f3ee; border-color: #8fc9ba; color: #17594e; }
.badge.wait { background: var(--gold); border-color: var(--ink); color: var(--ink); }
.toast {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto 10px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 14px;
}
.tabs { display: none; gap: 6px; padding: 0 12px 10px; }
.tabs button {
  flex: 1;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-size: 0.95rem;
}
.tabs button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.tab-count { font-variant-numeric: tabular-nums; opacity: 0.75; }
.unread {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 1px 7px;
}

.room {
  width: min(1380px, calc(100% - 24px));
  margin: 0 auto 16px;
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr) minmax(260px, 320px);
  gap: 14px;
  align-items: start;
}
.panel { padding: 18px; }
.players-panel, .chat-panel { position: sticky; top: 12px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.muted-count { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 700; }

/* Players */

.player-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.player-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.player-list .is-away { opacity: 0.6; }
.player-list .name { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.player-list .score { font-weight: 800; font-variant-numeric: tabular-nums; }
.player-list .tags { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-left: 18px; }
.player-list .remove {
  margin-left: auto;
  padding: 3px 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.2;
}
.player-list .remove:hover { color: var(--danger); border-color: #f0c2ba; background: #fff4f1; }
.dot { width: 10px; height: 10px; border-radius: 999px; flex: none; display: inline-block; }

/* Stage */

.stage { min-height: 540px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stage-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.stage-head h2 { margin: 2px 0 0; font-size: clamp(1.45rem, 2.4vw, 1.95rem); }
.timer {
  margin: 0;
  min-width: 60px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 1.7rem;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: var(--radius);
  background: var(--paper);
}
.timer.low { background: var(--accent); color: #fff; }
.timebar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.timebar span { display: block; height: 100%; background: var(--accent); transform-origin: left center; }
.timebar.low span { background: var(--accent); }
.view { display: grid; gap: 16px; align-content: start; }

.prompt {
  margin: 0;
  padding: 18px 20px;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  background: #fff;
  font-family: var(--story-font);
  font-size: clamp(1.35rem, 2.3vw, 1.8rem);
  line-height: 1.5;
}
.prompt .trail { color: var(--muted); }
.story-line { margin: 0; font-family: var(--story-font); font-size: 1.2rem; line-height: 1.5; }

/* Lobby */

.invite {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 2px dashed var(--ink);
  border-radius: var(--radius);
  background: #fff8e0;
}
.invite button { justify-self: start; }
.settings { display: grid; gap: 12px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.lock-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-weight: 700;
  cursor: pointer;
}
.lock-row input { width: auto; flex: none; margin-top: 3px; accent-color: var(--accent); }
.lock-copy { display: grid; gap: 3px; }
.lock-help { color: var(--muted); font-size: 0.84rem; font-weight: 500; line-height: 1.4; }
.start-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.scoring-note { margin: 0; font-size: 0.9rem; }

/* Writing */

.entry-form { display: grid; gap: 10px; }
.entry-form textarea { font-family: var(--story-font); font-size: 1.2rem; min-height: 112px; }
.entry-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.counter.near { color: var(--danger); font-weight: 700; }
.entry-locked {
  display: grid;
  gap: 8px;
  justify-items: start;
  padding: 14px 16px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}

/* Voting */

.ballot { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ballot-card {
  width: 100%;
  display: block;
  text-align: left;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  background: #fff;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 14px 16px;
  font-family: var(--story-font);
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.5;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.ballot-card:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.ballot-card[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); border-radius: var(--radius-mark); box-shadow: 3px 3px 0 var(--accent); }
.ballot-card .before, .winner-text .before { color: var(--muted); }
.ballot-card .entry, .winner-text .entry { font-weight: 700; color: var(--ink); }
/* Reveal */

.winner-text { margin: 0; font-family: var(--story-font); font-size: clamp(1.25rem, 2.1vw, 1.6rem); line-height: 1.5; }
.byline { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; color: var(--muted); font-weight: 700; }
.reveal-note { margin: 0; color: var(--muted); line-height: 1.5; }
.reveal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.reveal-list li { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.reveal-list li.chosen { border-color: var(--accent); background: var(--accent-soft); }
.row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-head .votes { margin-left: auto; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.row-head .points { font-weight: 800; color: var(--ok); font-variant-numeric: tabular-nums; }
.row-text { margin: 4px 0 0; font-family: var(--story-font); font-size: 1.05rem; line-height: 1.45; }
.reveal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

/* Results */

.final-story { padding: 24px 26px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.story { margin: 0; font-family: var(--story-font); font-size: clamp(1.3rem, 2.2vw, 1.65rem); line-height: 1.8; }
.piece { padding: 0 1px; border-radius: 4px; cursor: pointer; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.piece.by-game { color: var(--muted); font-style: italic; }
.piece.by-player { background: rgba(31, 27, 45, 0.05); border-bottom: 2px solid var(--c); }
@supports (background: color-mix(in srgb, red 50%, transparent)) {
  .piece.by-player { background: color-mix(in srgb, var(--c) 13%, transparent); }
}
.story.animate .piece { opacity: 0; animation: fade-in 0.7s ease forwards; }
.after-story { display: grid; gap: 14px; }
.after-story.animate { opacity: 0; animation: rise-in 0.6s ease forwards; }
.credit { margin: 16px 0 0; color: var(--muted); font-size: 0.9rem; text-align: right; }
.credit strong { color: var(--accent); font-family: var(--head-font); }
.story-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.scoreboard { display: grid; gap: 10px; }
.winner-line { margin: 4px 0 0; font-size: 1.6rem; text-align: center; }
.results-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.results-list li {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px 8px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.results-list .place {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--paper);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.results-list .place-1 { background: #fff8e0; border-color: var(--ink); }
.results-list .place-1 .place { background: var(--gold); }
.results-list .place-2 .place { background: #e7ebf0; }
.results-list .place-3 .place { background: var(--accent-soft); color: var(--accent-dark); }
.results-list .is-you { box-shadow: inset 0 0 0 2px var(--accent); }
.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.3rem; 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 { text-align: center; }
.scoreboard-actions .primary { min-width: 168px; }

/* Chat */

.chat-panel { display: flex; flex-direction: column; height: calc(100vh - 96px); min-height: 420px; max-height: 860px; }
.chat-panel h2 { margin-bottom: 10px; }
.chat {
  list-style: none;
  margin: 0;
  padding: 0 2px 0 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat li { line-height: 1.4; overflow-wrap: anywhere; }
.chat .message { padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.chat .system { padding: 0 2px; color: var(--muted); font-size: 0.86rem; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; min-width: 0; }
.chat-form button { padding: 10px 14px; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 1180px) {
  .room { grid-template-columns: 210px minmax(0, 1fr) 250px; }
}
@media (max-width: 980px) {
  .home-shell, .steps { grid-template-columns: 1fr; }
  .home-frame { padding-top: 20px; }
}
@media (max-width: 900px) {
  .tabs { display: flex; }
  .room { grid-template-columns: minmax(0, 1fr); }
  .room[data-tab="game"] > .panel:not([data-panel="game"]),
  .room[data-tab="players"] > .panel:not([data-panel="players"]),
  .room[data-tab="chat"] > .panel:not([data-panel="chat"]) { display: none; }
  .players-panel, .chat-panel { position: static; }
  .chat-panel { height: calc(100vh - 150px); height: calc(100dvh - 150px); min-height: 360px; }
  .stage { min-height: 0; }
  .topbar-privacy { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar .brand strong { display: none; }
  .settings-grid { grid-template-columns: 1fr; }
  .panel { padding: 14px; }
  .final-story { padding: 18px; }
  .prompt { padding: 14px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .story.animate .piece, .after-story.animate { opacity: 1; animation: none; }
  .ballot-card { transition: none; }
  .ballot-card:hover:not(:disabled) { transform: none; }
}
