:root {
  --bg: #f4efe1;
  --bg-deep: #ebe3cc;
  --ink: #0b3b3a;
  --ink-soft: #335c5b;
  --paper: #fffaf0;
  --accent: #e3733b;     /* warm coastal orange */
  --accent-2: #2a8a7d;   /* teal */
  --accent-3: #c9a227;   /* mustard gold */
  --good: #2a8a7d;
  --bad: #c2412d;
  --bad-deep: #a8341f;   /* darker for fill + text contrast */
  --muted: #8b8675;
  --shadow: 0 6px 0 rgba(11,59,58,.18);
  --radius: 18px;
  --radius-sm: 12px;
  /* P0 a11y: prevent iOS Safari auto-dark / Chrome auto-dark-for-web from inverting the brand palette */
  color-scheme: light only;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next Rounded", "Quicksand", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(42,138,125,.15) 0 18%, transparent 19%),
    radial-gradient(circle at 88% 8%, rgba(227,115,59,.16) 0 12%, transparent 13%),
    radial-gradient(circle at 78% 92%, rgba(201,162,39,.13) 0 16%, transparent 17%);
  background-attachment: fixed;
}

main#app {
  flex: 1 1 auto;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 22px 18px 28px;
}

.foot {
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  padding: 12px 14px 22px;
  opacity: .8;
}

/* ---------- typography ---------- */
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.1; font-weight: 800; letter-spacing: -.01em; }
h1 { font-size: clamp(34px, 7vw, 48px); }
h2 { font-size: clamp(22px, 5vw, 30px); }
h3 { font-size: clamp(18px, 4vw, 22px); }
p  { line-height: 1.45; }
.lead { font-size: 18px; color: var(--ink-soft); }

.wordmark {
  font-weight: 900;
  letter-spacing: -.02em;
  font-size: clamp(42px, 9vw, 60px);
  color: var(--ink);
  line-height: 1;
}
.wordmark .max { color: var(--accent); }
.tagline { color: var(--ink-soft); margin-top: 4px; font-size: 16px; }

/* ---------- cards ---------- */
.card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow);
  margin: 14px 0;
}
.card.tight { padding: 12px 14px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 16px 18px;
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  width: 100%;
  font-size: 18px;
  box-shadow: var(--shadow);
  transition: transform 80ms ease, box-shadow 80ms ease, background 120ms ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(11,59,58,.2); }
.btn[disabled] { opacity: .55; cursor: not-allowed; box-shadow: none; transform: none; }
.btn:active { transform: translateY(3px) scale(.98); }
.btn.primary { background: var(--accent); color: var(--paper); }
.btn.teal { background: var(--accent-2); color: var(--paper); }
.btn.gold { background: var(--accent-3); color: var(--ink); }
.btn.ghost {
  background: transparent;
  /* P0 a11y: every ghost button must hit the 44×44 touch-target minimum */
  min-width: 44px;
  min-height: 44px;
}
.btn-row { display: grid; gap: 12px; }
.btn-row.two { grid-template-columns: 1fr 1fr; }

/* ---------- inputs ---------- */
input[type="text"], input[type="number"] {
  font: inherit;
  font-size: 20px;
  padding: 14px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  width: 100%;
  background: var(--paper);
  color: var(--ink);
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
  outline: 3px solid var(--accent-3);
  outline-offset: 2px;
}

/* shared styling for the in-card text submission area (caption / lingo) */
.subtext {
  width: 100%;
  padding: 14px;
  font: inherit;
  font-size: 17px;
  line-height: 1.45;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(11,59,58,.12);
  resize: vertical;
  min-height: 84px;
}
.subcount {
  display: block;
  text-align: right;
  margin-top: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.subcount.short { color: var(--accent); }
.subcount.full  { color: var(--bad-deep); }

/* screen-reader-only utility for the live region */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
label { font-weight: 700; display: block; margin-bottom: 8px; }
.field { margin: 12px 0; }
.code-input {
  letter-spacing: .35em;
  text-transform: uppercase;
  text-align: center;
  font-weight: 900;
  font-size: 32px;
}

/* ---------- lobby ---------- */
.room-code {
  text-align: center;
  font-weight: 900;
  font-size: clamp(48px, 14vw, 86px);
  letter-spacing: .12em;
  background: var(--ink);
  color: var(--paper);
  padding: 18px 8px;
  border-radius: 16px;
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
}
.join-url {
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 8px;
  word-break: break-all;
}
.player-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 4px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 520px) {
  .player-list { grid-template-columns: 1fr 1fr; }
}
.player-list li {
  background: var(--bg-deep);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 700;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 12px;
  align-items: center;
  box-shadow: 0 3px 0 rgba(11,59,58,.12);
}
.player-list li.me { background: var(--accent-3); }
.player-list .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--good);
  border: 2px solid var(--ink);
  flex: 0 0 auto;
  animation: breathe 2.4s ease-in-out infinite;
}
.player-list .dot.away { background: var(--muted); animation: none; }
.player-list .avatar {
  width: 40px; height: 40px;
  font-size: 26px;
  line-height: 1;
  display: grid; place-items: center;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.player-list .name { font-weight: 800; font-size: 16px; }
.player-list .state {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: .12em;
  color: var(--ink-soft);
  text-transform: uppercase;
  margin-top: 2px;
}
@keyframes breathe {
  0%, 100% { opacity: .55; transform: scale(.92); }
  50%      { opacity: 1;   transform: scale(1.08); }
}

/* lobby flock hero card — promotes "the flock is gathering" */
.flock-hero {
  text-align: center;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  font-weight: 900;
  font-size: 19px;
  letter-spacing: -.005em;
}
.flock-hero .glyph {
  display: block;
  font-size: 30px;
  letter-spacing: .35em;
  margin: 0 0 6px;
  filter: saturate(.9);
}

/* tap-to-copy join-link pill */
.copy-pill {
  display: block;
  width: 100%;
  margin-top: 10px;
  border: 2px dashed var(--ink);
  background: transparent;
  color: var(--ink);
  font: 800 13px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 14px 12px;
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
}
.copy-pill.ok {
  background: var(--accent-3);
  border-style: solid;
}

/* avatar picker grid on join screen */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}
@media (max-width: 420px) {
  .avatar-grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }
}
.avatar-pick {
  appearance: none;
  border: 2px solid var(--ink);
  background: var(--paper);
  border-radius: 14px;
  padding: 12px 4px;
  min-width: 44px;
  min-height: 48px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: transform 80ms ease, background 120ms ease, box-shadow 120ms ease;
}
.avatar-pick:active { transform: translateY(2px); }
.avatar-pick.selected {
  background: var(--accent-3);
  /* shape-based affordance (not just color) — survives color-vision deficiencies */
  box-shadow: inset 0 0 0 3px var(--ink), 0 3px 0 rgba(11,59,58,.22);
  transform: translateY(-1px);
}

/* avatar inline next to a name in scoreboard / rankings */
.row-avatar {
  display: inline-block;
  margin-right: 6px;
  font-size: 16px;
  line-height: 1;
}

/* ---------- question ---------- */
.timer {
  height: 14px;
  background: var(--bg-deep);
  border: 2px solid var(--ink);
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 14px;
  position: relative;
}
.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent-2);
  /* compositor-only animation — no layout work */
  transform-origin: left center;
  transform: scaleX(var(--p, 1));
  transition: transform 200ms linear, background 220ms ease;
}
/* color phases match the existing Sound.tick() audio cadence */
.timer-bar.warn { background: var(--accent); }
.timer-bar.crit {
  background: var(--bad);
  animation: timerPulse 600ms ease-in-out infinite;
}
@keyframes timerPulse {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.25); }
}
/* wind-up on phase enter (0 → resting%) before per-tick updates take over */
.timer-bar.windup { animation: windup 420ms cubic-bezier(.4,.9,.3,1) both; }
@keyframes windup {
  from { transform: scaleX(0); }
  to   { transform: scaleX(var(--p, 1)); }
}
.q-meta {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: var(--ink-soft); margin-bottom: 4px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
}
.q-prompt { font-size: clamp(22px, 5.6vw, 30px); font-weight: 800; line-height: 1.18; margin: 6px 0 18px; }
.choices { display: grid; gap: 10px; }
.choice {
  text-align: left;
  padding: 16px 14px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 60px;
}
.choice .letter {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 16px; flex: 0 0 auto;
}
.choice:active { transform: translateY(3px) scale(.98); box-shadow: 0 3px 0 rgba(11,59,58,.2); }
.choice.selected {
  background: var(--accent-3);
  animation: choicePop 320ms cubic-bezier(.3,.8,.4,1.6);
}
@keyframes choicePop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}
.choice.correct { background: var(--good); color: var(--paper); }
.choice.correct .letter { background: var(--paper); color: var(--good); }
.choice.wrong { background: var(--bad-deep); color: var(--paper); }
.choice.wrong .letter { background: var(--paper); color: var(--bad-deep); }
.choice[disabled] { cursor: default; }

/* ===== reveal punchline staging ===== */
.choice[disabled]:not(.correct):not(.wrong) {
  transform: scale(.94);
  opacity: .55;
  filter: saturate(.85);
  transition: transform 240ms ease, opacity 240ms ease, filter 240ms ease;
}
.choice.correct {
  transform: translateY(-4px) scale(1.04);
  box-shadow: 0 10px 0 rgba(11,59,58,.22), inset 0 0 0 4px var(--accent-3);
  animation: choicePunch 520ms cubic-bezier(.2,.9,.2,1.2) 180ms both;
  position: relative;
  z-index: 1;
}
.choice.wrong { animation: choiceShake 360ms ease-out both; }
@keyframes choicePunch {
  0%   { transform: translateY(8px) scale(.96); opacity: 0; }
  60%  { transform: translateY(-6px) scale(1.06); opacity: 1; }
  100% { transform: translateY(-4px) scale(1.04); }
}
@keyframes choiceShake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}

.locked {
  margin-top: 16px;
  text-align: center;
  font-weight: 800;
  font-size: 18px;
  color: var(--ink-soft);
}

/* ---------- reveal ---------- */
.explain {
  margin-top: 14px;
  padding: 14px;
  background: var(--bg-deep);
  border: 2px dashed var(--ink);
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.45;
}
.vote-tally {
  font-variant-numeric: tabular-nums;
  background: rgba(11,59,58,.08);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-soft);
  margin-left: auto;
  font-weight: 700;
}
.choice.correct .vote-tally,
.choice.wrong .vote-tally {
  background: rgba(255,250,240,.85);
  color: var(--ink);
}

/* "called it" polaroid plinth shown under correct MC answer */
.reveal-plinth {
  margin-top: 14px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  transform: rotate(-.6deg);
}
.reveal-plinth .av { font-size: 28px; line-height: 1; }
.reveal-plinth .label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.reveal-plinth .who { font-weight: 900; font-size: 17px; }
.reveal-plinth .votes {
  margin-left: auto;
  background: var(--accent-3);
  border: 2px solid var(--ink);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ---------- scoreboard ---------- */
.scoreboard {
  list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px;
}
.scoreboard li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(11,59,58,.12);
}
.scoreboard li .rank { font-weight: 900; font-size: 18px; text-align: center; }
.scoreboard li.me { background: var(--accent-3); }
.scoreboard li.first { background: var(--accent); color: var(--paper); }
.scoreboard li.first .rank { color: var(--paper); }
.delta { font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.delta.up { color: var(--good); }

/* ---------- final ---------- */
.winner {
  text-align: center;
  background: var(--accent);
  color: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 26px 22px 24px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  min-height: 280px;
}
.winner .stamp {
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  font-size: 66px;
  border-radius: 50%;
  background: var(--paper);
  border: 4px solid var(--accent-3);
  box-shadow: 0 0 0 4px var(--ink), 0 8px 0 rgba(11,59,58,.28);
  margin: 8px auto 14px;
  line-height: 1;
}
.winner .who {
  font-size: clamp(30px, 7vw, 44px);
  font-weight: 900;
  margin: 4px 0 2px;
  letter-spacing: -.01em;
}
.winner .champion {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  opacity: .85;
  margin-top: 4px;
}
.winner .pts {
  display: inline-block;
  margin-top: 12px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
/* confetti — 14 squares dropping once on phase enter */
.winner .conf { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.winner .conf i {
  position: absolute;
  width: 8px; height: 8px;
  top: -10px;
  animation: confDrop 1400ms cubic-bezier(.3,.7,.4,1) forwards;
}
@keyframes confDrop {
  to { transform: translateY(360px) rotate(540deg); opacity: 0; }
}

/* designed highlight cards — replaces monospace <pre> recap */
.highlight-card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 0 rgba(11,59,58,.12);
  display: grid;
  gap: 6px;
}
.highlight-card .kind {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.highlight-card .kind.caption { color: var(--accent); }
.highlight-card .kind.bluff   { color: var(--accent-2); }
.highlight-card .kind.likely  { color: var(--accent-3); }
.highlight-card .quote {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.3;
}
.highlight-card .byline {
  font-size: 14px;
  color: var(--ink-soft);
}
.highlight-card .byline b { color: var(--ink); font-weight: 900; }

.awards { display: grid; gap: 10px; margin-top: 14px; }
.award {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex; align-items: baseline; gap: 8px;
  font-weight: 700;
}
.award .label { color: var(--ink-soft); margin-right: 6px; }
.award .name { font-weight: 900; }

/* ---------- utility ---------- */
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tag {
  display: inline-block;
  background: var(--ink); color: var(--paper);
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
}
.tag.gold { background: var(--accent-3); color: var(--ink); }
.tag.teal { background: var(--accent-2); }
.tag.orange { background: var(--accent); }
hr.div { border: 0; border-top: 2px dashed var(--ink); opacity: .25; margin: 16px 0; }

.error {
  background: #fde6e1;
  border: 2px solid var(--bad);
  color: var(--bad);
  padding: 10px 12px;
  border-radius: 10px;
  margin: 10px 0;
  font-weight: 700;
}

/* staggered phase-enter cascade — every direct child of #app fades up in sequence */
.fade-in {
  animation: fade .32s cubic-bezier(.2,.9,.2,1) both;
  animation-delay: calc(var(--i, 0) * 55ms);
}
@keyframes fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* honor system motion preference — kill every keyframe & transition */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
