/* ============================================================
   PartyBox

   One committed look: a warm grape ground, cream panels, chunky
   buttons with a soft bottom edge. Nothing is pure white or near
   black — every surface carries a little hue, so the screen reads
   as a party game rather than a dashboard.
   ============================================================ */

:root {
  /* Ground: deep grape, not black. */
  --ground: #4c4179;
  --ground-2: #3d3462;
  --ground-dark: #3a3160;

  /* Surfaces: warm cream and sand, never #fff. */
  --panel: #fffaf2;
  --panel-2: #f4ebdd;
  --panel-3: #e8dbc7;
  --line: #e2d5c1;
  --line-strong: #ccb99e;

  /* Ink: warm plum, softened so nothing slams against the cream. */
  --ink: #453b5e;
  --ink-2: #736887;
  --ink-3: #a297b3;

  /* Accents: saturated but friendly. */
  --green: #4faa71;
  --green-dark: #3d8c5b;
  --blue: #5d76e8;
  --blue-dark: #4a5fc4;
  --red: #e0655f;
  --red-dark: #bf4f4a;
  --amber: #e9a544;
  --amber-dark: #c68a33;
  --purple: #9a6ee0;
  --teal: #46b0b6;
  --pink: #e77ba5;

  /* Soft tints of each accent, for surfaces that should read coloured
     rather than blank. */
  --tint-blue: #e7ebfc;
  --tint-amber: #fbf0dc;
  --tint-teal: #e1f2f3;
  --tint-pink: #fbe8f0;
  --tint-green: #e3f3e8;
  --tint-red: #fbe6e4;

  --r: 15px;
  --r-sm: 11px;
  --edge: rgba(69, 55, 104, .16);
  --drop: 0 2px 0 var(--edge), 0 6px 16px rgba(48, 38, 76, .1);
  --drop-lg: 0 3px 0 var(--edge), 0 14px 34px rgba(41, 32, 66, .18);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--ground);
  background-image:
    radial-gradient(90vw 70vh at 12% -10%, rgba(154, 110, 224, .5), transparent 60%),
    radial-gradient(80vw 60vh at 92% 108%, rgba(70, 176, 182, .32), transparent 62%),
    linear-gradient(168deg, #56488a, #3b3260);
  background-attachment: fixed;
  color: var(--ink);
  font: 600 15px/1.5 Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 800; letter-spacing: -.01em; }

#app { height: 100%; }
.screen { height: 100%; }
[hidden] { display: none !important; }

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  border: 0;
  background: var(--panel-2);
  color: var(--ink);
  padding: 11px 18px;
  border-radius: var(--r-sm);
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(69, 55, 104, .14);
  transition: filter .12s ease, transform .06s ease;
}
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 -1px 0 rgba(69, 55, 104, .14);
}
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.btn-primary { background: var(--blue); color: var(--panel); box-shadow: inset 0 -3px 0 var(--blue-dark); }
.btn-primary:active:not(:disabled) { box-shadow: inset 0 -1px 0 var(--blue-dark); }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn-sm { padding: 7px 13px; font-size: 13px; box-shadow: inset 0 -2px 0 rgba(69, 55, 104, .12); }
.btn-ghost { background: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn-block { width: 100%; }

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--drop);
}

input[type="text"], input[type="number"], input:not([type]), textarea, select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel);
  outline: none;
  font-weight: 700;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
input::placeholder { color: var(--ink-3); font-weight: 600; }

.error {
  color: var(--panel);
  background: var(--red);
  box-shadow: inset 0 -2px 0 var(--red-dark);
  border-radius: var(--r-sm);
  padding: 9px 14px;
  font-weight: 800;
  font-size: 14px;
  margin: 0;
}

/* ── Home ────────────────────────────────────────────────── */

.home { display: grid; place-items: center; padding: 24px; }

.home-inner {
  width: 100%;
  max-width: 340px;
  display: grid;
  gap: 12px;
  justify-items: stretch;
}

.wordmark {
  font-size: clamp(46px, 12vw, 68px);
  color: #fff;
  text-align: center;
  letter-spacing: -.035em;
  margin-bottom: 6px;
  text-shadow: 0 3px 0 rgba(46, 36, 74, .35);
}

.home-inner input {
  text-align: center;
  font-size: 17px;
  padding: 14px;
  border-color: transparent;
  box-shadow: var(--drop);
}

.btn-play {
  background: var(--green);
  color: var(--panel);
  font-size: 24px;
  padding: 16px;
  letter-spacing: .01em;
  box-shadow: inset 0 -4px 0 var(--green-dark);
}
.btn-play:active:not(:disabled) { box-shadow: inset 0 -1px 0 var(--green-dark); }

.btn-quiet {
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 13px;
  padding: 9px;
  box-shadow: none;
  font-weight: 700;
}
.btn-quiet:hover:not(:disabled) { background: rgba(255, 255, 255, .26); filter: none; }
.btn-quiet:active:not(:disabled) { transform: translateY(1px); }

/* ── Room shell ──────────────────────────────────────────── */

.room { display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  background: linear-gradient(180deg, rgba(255, 250, 242, .1), transparent) var(--ground-dark);
  color: var(--panel);
  border-bottom: 2px solid rgba(20, 14, 38, .3);
  flex: none;
}
.logo {
  border: 0; background: none; color: #fff; cursor: pointer;
  font-weight: 800; font-size: 18px; letter-spacing: -.02em; padding: 0;
}
.room-code { display: flex; align-items: center; gap: 8px; }
.room-code .label {
  font-size: 11px; color: rgba(255, 255, 255, .65);
  font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
}
.room-code .code {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: .18em;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  border: 0;
  border-radius: var(--r-sm);
  padding: 5px 9px 5px 13px;
  cursor: pointer;
}
.room-code .code:hover { background: rgba(255, 255, 255, .26); }

.round-info { margin-left: auto; font-weight: 800; font-size: 14px; color: rgba(255, 255, 255, .92); }
.round-info + .timer { margin-left: 12px; }
.timer:first-of-type { margin-left: auto; }

.timer { position: relative; width: 40px; height: 40px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 4; }
.timer-track { stroke: rgba(255, 255, 255, .25); }
.timer-fill {
  stroke: #fff;
  stroke-linecap: round;
  stroke-dasharray: 100.5;
  transition: stroke-dashoffset .25s linear, stroke .3s ease;
}
.timer.urgent .timer-fill { stroke: #f9b8b3; }
#timer-text {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: #fff;
}
.chat-toggle { display: none; color: #fff; }
.chat-toggle:hover { background: rgba(255, 255, 255, .18); }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 250px;
  gap: 10px;
  padding: 10px;
}

/* ── Players ─────────────────────────────────────────────── */

.players { overflow-y: auto; padding: 6px; }
.player {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 7px;
  border-radius: var(--r-sm);
}
.player + .player { border-top: 1px solid var(--panel-3); }
.player.me { background: var(--panel-2); }
.player.away { opacity: .4; }
.player.done .pname::after { content: " ✓"; color: var(--green); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 12px;
}
.pname { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname .host { color: var(--amber); }
.pscore { font-weight: 800; font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ── Chat ────────────────────────────────────────────────── */

.chat { display: flex; flex-direction: column; min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 9px; display: grid; align-content: start; gap: 4px; }
.msg { font-size: 13.5px; line-height: 1.45; word-break: break-word; font-weight: 600; }
.msg b { font-weight: 800; }
.msg.system { color: var(--ink-3); font-size: 12.5px; }
.chat-form { display: flex; gap: 6px; padding: 7px; border-top: 2px solid var(--panel-3); }
.chat-form input { padding: 8px 10px; border-width: 1px; }

/* ── Stage ───────────────────────────────────────────────── */

.stage { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.card {
  background: var(--panel);
  background-image: radial-gradient(120% 80% at 50% 0%, rgba(154, 110, 224, .07), transparent 70%);
  border: 2px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--drop-lg);
  padding: 24px 22px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.card-center { align-items: center; justify-content: center; text-align: center; gap: 16px; }

.prompt { font-size: clamp(19px, 2.6vw, 26px); font-weight: 800; line-height: 1.3; margin: 0; }
.prompt.big { font-size: clamp(26px, 4.5vw, 40px); letter-spacing: .04em; }
.prompt.huge { font-size: clamp(40px, 9vw, 76px); letter-spacing: .08em; line-height: 1.2; }
.subprompt { color: var(--ink-2); font-size: 15px; margin: 0; }
.tag {
  display: inline-block;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em;
  color: var(--purple); background: var(--tint-blue);
  box-shadow: inset 0 0 0 2px rgba(154, 110, 224, .22);
  border-radius: 999px; padding: 4px 11px;
}
.hint { color: var(--ink-3); font-size: 13px; margin: 0; }

.media { display: grid; place-items: center; width: 100%; min-height: 0; flex: 1; }
.media img {
  max-width: 100%; max-height: 44vh; display: block;
  border-radius: var(--r-sm);
  box-shadow: 0 6px 18px rgba(48, 38, 76, .16);
}
.media.contain img { object-fit: contain; background: var(--panel); padding: 10px; }

.cropbox {
  width: min(100%, 440px);
  aspect-ratio: 4 / 3;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--panel-2);
  box-shadow: 0 6px 18px rgba(48, 38, 76, .16);
}
.cropbox img {
  width: 100%; height: 100%;
  object-fit: cover;
  transform-origin: var(--cx, 50%) var(--cy, 50%);
  transform: scale(var(--zoom, 3));
  max-height: none;
  border-radius: 0;
}

/* ── Answer inputs ───────────────────────────────────────── */

.options { display: grid; gap: 9px; width: 100%; max-width: 700px; }
.options.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opt {
  text-align: left;
  padding: 15px 18px;
  border: 0;
  background: var(--panel-2);
  border-radius: var(--r-sm);
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(69, 55, 104, .1);
  transition: filter .12s ease, transform .06s ease;
}
.opt:hover:not(:disabled) { filter: brightness(.97); transform: translateY(-1px); }
.opt:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 -1px 0 var(--edge); }
.opt.big { font-size: 19px; padding: 24px; text-align: center; }

/* Each answer slot gets its own hue, so a question never reads as a
   stack of identical grey bars. Overrides below win on source order. */
.opt:nth-of-type(4n + 1) { background: var(--tint-blue);  box-shadow: inset 0 -3px 0 rgba(93, 118, 232, .32); }
.opt:nth-of-type(4n + 2) { background: var(--tint-amber); box-shadow: inset 0 -3px 0 rgba(233, 165, 68, .34); }
.opt:nth-of-type(4n + 3) { background: var(--tint-teal);  box-shadow: inset 0 -3px 0 rgba(70, 176, 182, .32); }
.opt:nth-of-type(4n + 4) { background: var(--tint-pink);  box-shadow: inset 0 -3px 0 rgba(231, 123, 165, .32); }

.opt.picked { background: var(--blue); color: var(--panel); box-shadow: inset 0 -3px 0 var(--blue-dark); }
.opt.right { background: var(--green); color: var(--panel); box-shadow: inset 0 -3px 0 var(--green-dark); }
.opt.wrong { background: var(--red); color: var(--panel); box-shadow: inset 0 -3px 0 var(--red-dark); }
.opt:disabled { cursor: default; }
.opt:disabled:not(.right):not(.picked) { opacity: .72; }

.answer-form { display: flex; gap: 8px; width: 100%; max-width: 500px; }
.answer-form input { font-size: 17px; text-align: center; }
.answer-form.num input { font-family: var(--mono); }
.locked-note { color: var(--green); font-weight: 800; margin: 0; }

.clues { display: grid; gap: 8px; width: 100%; max-width: 600px; text-align: left; }
.clue {
  background: var(--tint-blue);
  border-left: 4px solid var(--blue);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  font-size: 15px;
}

/* ── Reveal ──────────────────────────────────────────────── */

.reveal-answer {
  font-size: clamp(24px, 4vw, 36px);
  font-weight: 800;
  color: var(--green-dark);
  background: var(--tint-green);
  border-radius: var(--r-sm);
  padding: 8px 18px;
  margin: 0;
  overflow-wrap: anywhere;
}
.detail { color: var(--ink-2); font-size: 14px; max-width: 620px; margin: 0; font-weight: 600; }

.results { width: 100%; max-width: 600px; display: grid; gap: 4px; }
.result {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--panel-2);
  text-align: left;
}
.result.correct { background: var(--tint-green); box-shadow: inset 0 0 0 2px rgba(79, 170, 113, .3); }
.result.miss { opacity: .55; }
.result .who { font-weight: 800; font-size: 14px; }
.result .said { color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.result .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.result .pts.zero { color: var(--ink-3); }
.result .best { color: var(--amber); }

.comparison { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 540px; }
.cmp { padding: 16px; border-radius: var(--r-sm); background: var(--panel-2); }
.cmp { box-shadow: inset 0 -3px 0 var(--edge); }
.cmp.win { background: var(--green); color: var(--panel); box-shadow: inset 0 -3px 0 var(--green-dark); }
.cmp b { display: block; font-size: 15px; }
.cmp span { font-size: 21px; font-weight: 800; opacity: .85; }

.split { width: 100%; max-width: 600px; display: grid; gap: 10px; }
.split-row { display: grid; gap: 5px; }
.split-row .lbl { display: flex; justify-content: space-between; font-weight: 800; font-size: 14px; }
.bar { height: 26px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--blue); border-radius: 999px; transition: width .5s ease; }
.split-row.win .bar i { background: var(--green); }

.ordered-list { width: 100%; max-width: 500px; display: grid; gap: 5px; }
.ordered-list .row {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; background: var(--panel-2); border-radius: var(--r-sm); text-align: left;
}
.ordered-list .num { font-weight: 800; color: var(--ink-3); }
.ordered-list .val { font-weight: 800; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ── Scoreboard ──────────────────────────────────────────── */

.scoreboard { width: 100%; max-width: 460px; display: grid; gap: 5px; }
.score-row {
  display: grid; grid-template-columns: 26px 30px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: var(--r-sm); background: var(--panel-2);
}
.score-row .rank { font-weight: 800; color: var(--ink-3); text-align: center; }
.score-row.top { background: var(--amber); color: var(--panel); box-shadow: inset 0 -3px 0 var(--amber-dark); }
.score-row.top .rank { color: rgba(255, 250, 242, .82); }
.score-row .nm { font-weight: 800; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row .sc { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ── Lobby ───────────────────────────────────────────────── */

.lobby { display: grid; gap: 12px; grid-template-rows: auto 1fr auto; height: 100%; }
.lobby-head h2 { font-size: 20px; }
.lobby-head p { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; font-weight: 600; }

.game-groups { overflow-y: auto; display: grid; gap: 16px; padding-right: 4px; }
.cat-group h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-3); margin-bottom: 8px;
}
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 7px; }
.game-tile {
  text-align: left;
  padding: 11px 13px;
  border: 0;
  background: var(--panel-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  display: grid;
  gap: 2px;
  box-shadow: inset 0 -3px 0 rgba(69, 55, 104, .08);
}
.game-tile:hover:not(:disabled) { filter: brightness(.96); }
.game-tile:nth-of-type(4n + 1) { background: var(--tint-blue); }
.game-tile:nth-of-type(4n + 2) { background: var(--tint-amber); }
.game-tile:nth-of-type(4n + 3) { background: var(--tint-teal); }
.game-tile:nth-of-type(4n + 4) { background: var(--tint-pink); }
.game-tile.on { background: var(--blue); color: var(--panel); box-shadow: inset 0 -3px 0 var(--blue-dark); }
.game-tile.on span, .game-tile.on em { color: rgba(255, 250, 242, .84); }
.game-tile b { font-size: 14px; }
.game-tile span { font-size: 12px; color: var(--ink-2); line-height: 1.35; font-weight: 600; }
.game-tile em { font-size: 11px; color: var(--ink-3); font-style: normal; font-weight: 800; }
.game-tile:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

.lobby-foot {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding-top: 11px; border-top: 2px solid var(--panel-3);
}
.lobby-settings { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; flex: 1; }
.setting { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.setting select, .setting input { width: auto; padding: 7px 10px; border-width: 1px; }

/* Lock toggle: open rooms take quick-play joiners, locked ones don't. */
.btn.lock.on { background: var(--ink); color: var(--panel); box-shadow: inset 0 -2px 0 rgba(26, 18, 44, .7); }

/* ── Word grid ───────────────────────────────────────────── */

.wgrid { display: grid; gap: 5px; justify-content: center; }
.wrow { display: grid; grid-template-columns: repeat(5, 52px); gap: 5px; }
.wcell {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border: 2px solid var(--line);
  border-radius: 6px;
  font-size: 25px; font-weight: 800;
  text-transform: uppercase;
  background: var(--panel);
}
.wcell.filled { border-color: var(--line-strong); }
.wcell.correct { background: var(--green); border-color: var(--green-dark); color: var(--panel); }
.wcell.present { background: var(--amber); border-color: var(--amber-dark); color: var(--panel); }
.wcell.absent { background: var(--ink-3); border-color: var(--ink-3); color: var(--panel); }

.keyboard { display: grid; gap: 5px; justify-content: center; }
.krow { display: flex; gap: 4px; justify-content: center; }
.key {
  min-width: 30px; padding: 12px 8px;
  border: 0; background: var(--panel-2);
  border-radius: 5px; font-weight: 800; font-size: 13px; cursor: pointer;
  text-transform: uppercase;
  box-shadow: inset 0 -2px 0 rgba(69, 55, 104, .12);
}
.key.wide { min-width: 54px; }
.key.correct { background: var(--green); color: var(--panel); }
.key.present { background: var(--amber); color: var(--panel); }
.key.absent { background: var(--ink-3); color: var(--panel); }

.rivals { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.rival { display: grid; gap: 3px; justify-items: center; }
.rival .nm { font-size: 11px; font-weight: 800; color: var(--ink-2); }
.rival .mini { display: grid; gap: 2px; }
.mini-row { display: flex; gap: 2px; }
.mini-cell { width: 8px; height: 8px; border-radius: 2px; background: var(--panel-3); }
.mini-cell.correct { background: var(--green); }
.mini-cell.present { background: var(--amber); }
.mini-cell.absent { background: var(--ink-3); }

/* ── Connections ─────────────────────────────────────────── */

.cgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; width: 100%; max-width: 540px; }
.ctile {
  aspect-ratio: 5 / 3;
  display: grid; place-items: center; text-align: center;
  padding: 6px;
  border: 0;
  background: var(--panel-2);
  border-radius: var(--r-sm);
  font-weight: 800; font-size: clamp(10px, 1.6vw, 13px);
  cursor: pointer;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  box-shadow: inset 0 -3px 0 rgba(69, 55, 104, .08);
}
.ctile.sel { background: var(--ink); color: var(--panel); box-shadow: inset 0 -3px 0 rgba(26, 18, 44, .7); }
.found { padding: 11px; border-radius: var(--r-sm); text-align: center; color: #fff; font-weight: 800; font-size: 13px; }
.found small { display: block; font-weight: 800; opacity: .88; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; }
.found.l0 { background: var(--amber); }
.found.l1 { background: var(--green); }
.found.l2 { background: var(--blue); }
.found.l3 { background: var(--purple); }
.lives { display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.life { width: 11px; height: 11px; border-radius: 50%; background: var(--ink-2); }
.life.gone { background: var(--panel-3); }

/* ── Ranking ─────────────────────────────────────────────── */

.ranklist { width: 100%; max-width: 440px; display: grid; gap: 5px; }
.rankitem {
  display: grid; grid-template-columns: 26px 1fr auto auto; gap: 8px; align-items: center;
  padding: 10px 12px; background: var(--panel-2); border-radius: var(--r-sm);
  font-weight: 800; text-align: left;
}
.rankitem .num { color: var(--ink-3); }
.rankitem button {
  border: 0; background: var(--panel); border-radius: 6px;
  width: 28px; height: 28px; cursor: pointer; font-weight: 800;
  box-shadow: inset 0 -2px 0 rgba(69, 55, 104, .12);
}
.rankitem button:disabled { opacity: .3; cursor: default; box-shadow: none; }

/* ── Drawing ─────────────────────────────────────────────── */

.draw-wrap { display: grid; gap: 10px; justify-items: center; width: 100%; }
.canvas-shell { position: relative; width: 100%; max-width: 600px; }
canvas.pad {
  width: 100%; aspect-ratio: 4 / 3;
  background: #fff; border: 2px solid var(--line);
  border-radius: var(--r-sm); touch-action: none; cursor: crosshair;
  display: block;
}
.tools { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; justify-content: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--ink); transform: scale(1.14); }
.sizes { display: flex; gap: 4px; }
.sizedot {
  width: 30px; height: 30px; border-radius: 6px; border: 0; background: var(--panel-2);
  cursor: pointer; display: grid; place-items: center;
  box-shadow: inset 0 -2px 0 rgba(69, 55, 104, .12);
}
.sizedot.on { background: var(--blue); }
.sizedot.on i { background: var(--panel); }
.sizedot i { display: block; border-radius: 50%; background: var(--ink); }

.chain { display: grid; gap: 9px; width: 100%; max-width: 540px; }
.chain-step { display: grid; gap: 5px; padding: 10px; border-radius: var(--r-sm); background: var(--panel-2); }
.chain-step .by { font-size: 12px; font-weight: 800; color: var(--ink-2); }
.chain-step img { width: 100%; border-radius: 6px; background: #fff; }
.chain-step .said { font-size: 17px; font-weight: 800; }
.chain-step.missed { opacity: .5; }

/* ── Voting ──────────────────────────────────────────────── */

.entries { display: grid; gap: 7px; width: 100%; max-width: 600px; }
.entry {
  text-align: left; padding: 14px 16px; border: 0;
  background: var(--panel-2); border-radius: var(--r-sm);
  font-weight: 700; cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(69, 55, 104, .08);
}
.entry:hover:not(:disabled) { filter: brightness(.97); transform: translateY(-1px); }
.entry:nth-of-type(4n + 1) { background: var(--tint-blue); }
.entry:nth-of-type(4n + 2) { background: var(--tint-amber); }
.entry:nth-of-type(4n + 3) { background: var(--tint-teal); }
.entry:nth-of-type(4n + 4) { background: var(--tint-pink); }
.entry.own { opacity: .5; cursor: default; box-shadow: none; }
.entry.picked { background: var(--blue); color: var(--panel); box-shadow: inset 0 -3px 0 var(--blue-dark); }
.entry-result { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; cursor: default; }
.entry-result .meta { font-size: 12px; color: var(--ink-2); font-weight: 800; }
.entry-result .vcount { font-weight: 800; font-size: 19px; }

/* ── Map ─────────────────────────────────────────────────── */

.map-wrap { display: grid; gap: 10px; width: 100%; }
.map { width: 100%; height: min(44vh, 360px); border-radius: var(--r-sm); z-index: 0; }
.leaflet-container { background: var(--panel-2); font: inherit; }

/* ── Mafia ───────────────────────────────────────────────── */

.role-card { padding: 20px 26px; border-radius: var(--r); text-align: center; background: var(--panel-2); }
.role-card .role { font-size: 30px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.role-card.mafia { background: var(--red); color: var(--panel); box-shadow: inset 0 -4px 0 var(--red-dark); }
.role-card.detective { background: var(--blue); color: var(--panel); box-shadow: inset 0 -4px 0 var(--blue-dark); }
.role-card.villager { background: var(--green); color: var(--panel); box-shadow: inset 0 -4px 0 var(--green-dark); }
.role-card.mafia .detail, .role-card.detective .detail, .role-card.villager .detail { color: rgba(255, 250, 242, .9); }
.role-card .hint { color: inherit; opacity: .8; }

.targets { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 7px; width: 100%; max-width: 540px; }
.target {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border: 0;
  background: var(--panel-2); border-radius: var(--r-sm);
  font-weight: 800; cursor: pointer; text-align: left;
  box-shadow: inset 0 -3px 0 rgba(69, 55, 104, .08);
}
.target:hover:not(:disabled) { filter: brightness(.96); }
.target.picked { background: var(--blue); color: var(--panel); box-shadow: inset 0 -3px 0 var(--blue-dark); }
.target.out { opacity: .35; text-decoration: line-through; cursor: default; box-shadow: none; }

.notes { width: 100%; max-width: 440px; display: grid; gap: 5px; }
.note { padding: 9px 12px; background: var(--tint-blue); border-left: 4px solid var(--blue); border-radius: var(--r-sm); font-size: 13.5px; text-align: left; }

.log { width: 100%; max-width: 500px; display: grid; gap: 3px; }
.log div { font-size: 13px; color: var(--ink-2); text-align: left; font-weight: 600; }

/* ── Taboo ───────────────────────────────────────────────── */

.taboo-card {
  padding: 18px 24px; border-radius: var(--r); text-align: center;
  background: linear-gradient(165deg, #5a4d86, #40376a);
  color: var(--panel);
  box-shadow: inset 0 -4px 0 rgba(26, 18, 44, .35);
}
.taboo-card .hint { color: rgba(255, 250, 242, .68); }
.taboo-word { font-size: 30px; font-weight: 800; letter-spacing: .03em; }
.taboo-banned { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.taboo-banned span { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 999px; background: var(--red); color: var(--panel); }
.feed { width: 100%; max-width: 540px; display: grid; gap: 4px; max-height: 34vh; overflow-y: auto; }
.feed .line { text-align: left; font-size: 14px; padding: 6px 11px; border-radius: 6px; background: var(--panel-2); font-weight: 600; }
.feed .line.foul { background: var(--red); color: var(--panel); font-weight: 800; }
.feed .line.win { background: var(--green); color: var(--panel); font-weight: 800; }
.feed .line.clue { font-weight: 800; }

/* ── Typing ──────────────────────────────────────────────── */

.type-text {
  width: 100%; max-width: 700px;
  font-family: var(--mono); font-size: 17px; line-height: 1.75;
  background: var(--panel-2);
  border-radius: var(--r-sm); padding: 16px; text-align: left;
  overflow-wrap: anywhere; font-weight: 400;
}
.type-text .ok { color: var(--green-dark); }
.type-text .bad { background: var(--tint-red); color: var(--red-dark); border-radius: 2px; }
.type-text .cur { border-bottom: 3px solid var(--blue); }
.type-input { width: 100%; max-width: 700px; font-family: var(--mono); min-height: 90px; resize: none; font-weight: 400; }
.type-stats { display: flex; gap: 18px; font-weight: 800; color: var(--ink-2); font-size: 14px; }

/* ── Misc ────────────────────────────────────────────────── */

.waiting { color: var(--ink-3); font-weight: 800; margin: 0; }
.submitted-note { color: var(--green); font-weight: 800; margin: 0; }
.progress-pills { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.pill { width: 9px; height: 9px; border-radius: 50%; background: var(--panel-3); }
.pill.on { background: var(--green); }

.statements { display: grid; gap: 8px; width: 100%; max-width: 500px; }
.statement-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.statement-row .lie-btn {
  border: 0; background: var(--panel-2); border-radius: var(--r-sm);
  padding: 9px 12px; font-size: 12px; font-weight: 800; cursor: pointer; white-space: nowrap;
  box-shadow: inset 0 -2px 0 rgba(69, 55, 104, .12);
}
.statement-row .lie-btn.on { background: var(--red); color: var(--panel); box-shadow: inset 0 -2px 0 var(--red-dark); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel);
  padding: 11px 18px; border-radius: 999px; font-weight: 800; font-size: 14px;
  box-shadow: var(--drop); z-index: 50; max-width: 90vw; text-align: center;
}

/* ── Countdown ───────────────────────────────────────────
   Two separate things. The 3-2-1 before a round is a phase of its
   own (.cd, below) and owns the whole stage. The last five seconds
   of an answering phase are a soft nudge (.countdown) parked low on
   the screen, clear of the question and deaf to clicks.
   ─────────────────────────────────────────────────────────── */

.countdown {
  position: fixed;
  left: 0; right: 0; bottom: 4vh;
  z-index: 60;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.countdown-num {
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  /* It lands on the cream card, not the ground, so it is inked in the
     urgency colour with a soft halo to lift it off the text below. */
  color: var(--red);
  text-shadow:
    0 0 18px var(--panel), 0 0 34px var(--panel),
    0 3px 0 rgba(191, 79, 74, .3);
}
.countdown-tick .countdown-num {
  font-size: clamp(64px, 11vw, 120px);
  animation: countTick 1s cubic-bezier(.2, .9, .3, 1) both;
}

/* The pre-round countdown screen. */
.cd { display: grid; justify-items: center; gap: 6px; }
.cd-label {
  margin: 0;
  font-size: 13px; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ink-3);
}
.cd-num {
  font-size: clamp(120px, 24vw, 230px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.05em;
  color: var(--purple);
  animation: countIn .9s cubic-bezier(.2, .9, .3, 1) both;
}
.cd-num.go { color: var(--green); font-size: clamp(80px, 16vw, 150px); }
.cd-ready { margin: 0; font-size: 15px; font-weight: 800; color: var(--ink-2); }

/* Confetti layer. */
.fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 70;
}

/* ── Motion ──────────────────────────────────────────────── */

@keyframes countTick {
  0%   { opacity: 0; transform: scale(1.5); }
  22%  { opacity: .92; transform: scale(1); }
  78%  { opacity: .92; transform: scale(1); }
  100% { opacity: 0; transform: scale(.9); }
}
@keyframes countIn {
  0%   { opacity: 0; transform: scale(1.6); }
  18%  { opacity: 1; transform: scale(1); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px) scale(.99); }
  to   { opacity: 1; transform: none; }
}
@keyframes riseIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes popIn {
  0%   { opacity: 0; transform: scale(.82); }
  62%  { opacity: 1; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes correctPulse {
  0%, 100% { transform: none; }
  40%      { transform: scale(1.025); }
}
@keyframes urgentPulse {
  0%, 100% { transform: none; }
  50%      { transform: scale(1.14); }
}
@keyframes crownBob {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50%      { transform: translateY(-5px) rotate(6deg); }
}

/* A new phase animates in once; live updates inside a phase do not. */
.stage.phase-in .card { animation: cardIn .34s cubic-bezier(.2, .9, .3, 1) both; }
.stage.phase-in .prompt { animation: riseIn .34s .04s ease both; }
.stage.phase-in .reveal-answer { animation: popIn .44s .14s cubic-bezier(.2, .9, .3, 1) both; }
.stage.phase-in .media,
.stage.phase-in .cropbox { animation: popIn .4s .08s ease both; }

.stage.phase-in .opt,
.stage.phase-in .entry,
.stage.phase-in .result,
.stage.phase-in .split-row,
.stage.phase-in .ctile,
.stage.phase-in .target,
.stage.phase-in .ordered-list .row,
.stage.phase-in .scoreboard .score-row { animation: riseIn .32s ease both; }

.stage.phase-in :is(.options, .entries, .results, .split, .cgrid, .targets, .ordered-list, .scoreboard) > :nth-child(1) { animation-delay: .06s; }
.stage.phase-in :is(.options, .entries, .results, .split, .cgrid, .targets, .ordered-list, .scoreboard) > :nth-child(2) { animation-delay: .1s; }
.stage.phase-in :is(.options, .entries, .results, .split, .cgrid, .targets, .ordered-list, .scoreboard) > :nth-child(3) { animation-delay: .14s; }
.stage.phase-in :is(.options, .entries, .results, .split, .cgrid, .targets, .ordered-list, .scoreboard) > :nth-child(4) { animation-delay: .18s; }
.stage.phase-in :is(.options, .entries, .results, .split, .cgrid, .targets, .ordered-list, .scoreboard) > :nth-child(5) { animation-delay: .22s; }
.stage.phase-in :is(.options, .entries, .results, .split, .cgrid, .targets, .ordered-list, .scoreboard) > :nth-child(6) { animation-delay: .26s; }
.stage.phase-in :is(.options, .entries, .results, .split, .cgrid, .targets, .ordered-list, .scoreboard) > :nth-child(n + 7) { animation-delay: .3s; }

.result.correct { animation: correctPulse .5s .3s ease; }
.timer.urgent { animation: urgentPulse 1s ease-in-out infinite; }
.pill { transition: background .25s ease, transform .25s ease; }
.pill.on { transform: scale(1.25); }
.toast { animation: popIn .28s cubic-bezier(.2, .9, .3, 1) both; }

/* ── Final leaderboard ───────────────────────────────────── */

.final { gap: 14px; }
.prompt.winner { font-size: clamp(24px, 4.4vw, 38px); }

.podium {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: 10px;
  width: 100%;
  max-width: 440px;
}
.step { display: grid; align-content: end; justify-items: center; gap: 9px; min-width: 0; }
.step-who { display: grid; justify-items: center; gap: 3px; min-width: 0; width: 100%; }
.step-name {
  font-weight: 800; font-size: 14px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.step-score { font-weight: 800; font-size: 16px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.crown { font-size: 26px; line-height: 1; animation: crownBob 2.4s ease-in-out infinite; }

.step-block {
  width: 100%;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  color: var(--panel);
  font-weight: 800;
  font-size: 22px;
  text-shadow: 0 2px 0 rgba(46, 32, 74, .25);
}
.p1 .step-block { height: 100px; background: linear-gradient(180deg, #f3c163, var(--amber)); box-shadow: inset 0 -5px 0 var(--amber-dark); }
.p2 .step-block { height: 72px; background: linear-gradient(180deg, #cfc6dd, #ada1c1); box-shadow: inset 0 -5px 0 #9184a8; }
.p3 .step-block { height: 54px; background: linear-gradient(180deg, #dda286, #c4866a); box-shadow: inset 0 -5px 0 #a86f55; }

/* Third steps up first, the winner last. */
.stage.phase-in .step { animation: riseIn .46s cubic-bezier(.2, .9, .3, 1) both; }
.stage.phase-in .step.p3 { animation-delay: .06s; }
.stage.phase-in .step.p2 { animation-delay: .26s; }
.stage.phase-in .step.p1 { animation-delay: .5s; }

.score-row.you { box-shadow: inset 0 0 0 2px var(--blue); }
.placing { margin: 0; font-weight: 800; font-size: 14px; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 900px) {
  .layout { grid-template-columns: 150px minmax(0, 1fr); }
  .chat { position: fixed; inset: auto 10px 10px 10px; height: 45vh; z-index: 30; }
  .chat-toggle { display: inline-flex; }
  .options.cols-2 { grid-template-columns: 1fr; }
  .comparison { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; padding: 8px; gap: 8px; }
  .players { display: flex; gap: 6px; overflow-x: auto; padding: 6px; max-height: 58px; }
  .players .player { grid-template-columns: 26px auto; flex: none; border-top: 0; }
  .players .pscore { display: none; }
  .card { padding: 16px 14px; }
  .wrow { grid-template-columns: repeat(5, 44px); }
  .wcell { width: 44px; height: 44px; font-size: 21px; }
  .topbar { gap: 10px; padding: 8px 11px; }
  .logo { font-size: 15px; }
  .round-info { font-size: 12px; }
  .podium { max-width: 100%; gap: 6px; }
  .p1 .step-block { height: 80px; }
  .p2 .step-block { height: 58px; }
  .p3 .step-block { height: 44px; }
  .step-name { font-size: 12px; }
}
