/* ===== Tokens ===== */
:root {
  --bg: #f4f1e9;
  --bg-glow: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0ece3;
  --text: #161b2b;
  --muted: #646b80;
  --border: #ddd8cc;
  --hub: #2a74ba;          /* center circle and seating bars */
  --ink-next: #4a8fd0;     /* the next bar to be revealed */
  --font-display: "Cinzel", "Trajan Pro", Georgia, serif;
  --font-body: "EB Garamond", Garamond, Georgia, serif;
  --hub-text: #ffffff;
  --red: #b22234;
  --accent: #1f3a6e;
  --accent-text: #ffffff;
  --good: #2e7d4f;
  --good-bg: #e3f3e8;
  --bad: #b22234;
  --bad-bg: #fbe6e8;
  --dem: #2a5bd7;
  --rep: #c8313e;
  --ind: #7a5bb5;
  --shadow: 0 1px 2px rgba(20, 25, 40, .08), 0 8px 24px rgba(20, 25, 40, .10);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d111c;
    --bg-glow: #182036;
    --surface: #182030;
    --surface-2: #222b3d;
    --text: #e8eaf0;
    --muted: #9aa1b4;
    --border: #2e3648;
    --hub: #2f7cc4;
    --ink-next: #5296d6;
    --accent: #5b7fd6;
    --good: #5cc48a;
    --good-bg: #183323;
    --bad: #ef6b78;
    --bad-bg: #3a1d22;
    --dem: #6f95f2;
    --rep: #f06a75;
    --ind: #b69cf0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

/* ===== Hard round theme =====
   Registered so the colors can animate: switching rounds fades the chart to a
   light red and the background to a more muted tone. */
@property --hub { syntax: "<color>"; inherits: true; initial-value: #2a74ba; }
@property --ink-next { syntax: "<color>"; inherits: true; initial-value: #4a8fd0; }
@property --bg { syntax: "<color>"; inherits: true; initial-value: #f4f1e9; }
@property --bg-glow { syntax: "<color>"; inherits: true; initial-value: #ffffff; }
@property --accent { syntax: "<color>"; inherits: true; initial-value: #1f3a6e; }
@property --surface { syntax: "<color>"; inherits: true; initial-value: #ffffff; }
@property --surface-2 { syntax: "<color>"; inherits: true; initial-value: #f0ece3; }
@property --border { syntax: "<color>"; inherits: true; initial-value: #ddd8cc; }
body {
  transition: --hub .9s ease, --ink-next .9s ease, --bg .9s ease, --bg-glow .9s ease, --accent .9s ease,
              --surface .9s ease, --surface-2 .9s ease, --border .9s ease;
}
body.round-hard {
  --hub: #dc6a71;
  --ink-next: #eb9da1;
  --bg: #e7e1de;
  --bg-glow: #f1ece9;
  --accent: #8e2f37;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body.round-hard {
    --hub: #c75860;
    --ink-next: #dc858b;
    --bg: #151113;
    --bg-glow: #221a1d;
    --accent: #d06871;
    --surface: #221a1d;
    --surface-2: #2e2327;
    --border: #3d3034;
  }
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 40%, var(--bg-glow), var(--bg) 70%) fixed, var(--bg);
  color: var(--text);
  font: 17px/1.45 var(--font-body);
  overflow: hidden;
  height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); font-size: .92em; }
.no-anim *, .no-anim *::before, .no-anim *::after { transition: none !important; }

/* ===== Seating chart ===== */
.stage { position: fixed; inset: 0; overflow: hidden; z-index: 1; pointer-events: none; }
.chart {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  transition: transform .9s cubic-bezier(.65, 0, .35, 1);
  will-change: transform;
}
#chart-svg { position: absolute; left: -800px; top: -800px; overflow: visible; }
.seats { transition: transform .65s cubic-bezier(.45, 0, .2, 1); }
/* A revealed bar is wiped away from its outer end toward the circle, like the
   Skip button's fill (bars point along +x before rotation, so that's inset from the right). */
.seat .bar {
  fill: var(--hub);
  clip-path: inset(0 0 0 0);
  transition: clip-path .6s cubic-bezier(.45, 0, .55, 1) var(--d, 0ms), fill .3s;
}
.seat.next .bar { fill: var(--ink-next); }
.seat.gone .bar { clip-path: inset(0 100% 0 0); }
.hub { fill: var(--hub); }

/* Seats sweep in when the title screen appears. */
.mode-title .seat .bar { animation: seat-in .55s cubic-bezier(.2, .7, .3, 1) backwards; animation-delay: calc(var(--i) * 55ms + 100ms); }
.mode-title .hub { animation: hub-in .5s ease-out backwards; }
@keyframes seat-in { from { transform: translateX(80px); opacity: 0; } }
@keyframes hub-in { from { opacity: 0; } }

.hub-label {
  position: absolute; left: 0; top: 0; width: 280px; height: 280px;
  transform: translate(-50%, -50%);
  /* Equal outer rows keep the number exactly at the circle's center. */
  display: grid; grid-template-rows: 1fr auto 1fr; justify-items: center;
  color: var(--hub-text); text-align: center; line-height: 1.1; font-family: var(--font-display);
  transition: opacity .4s ease .5s;
}
.mode-title .hub-label { opacity: 0; transition-delay: 0s; }
.hub-small { font-size: 30px; font-weight: 700; letter-spacing: .08em; opacity: .92; }
.hub-small:first-child { align-self: end; padding-bottom: 18px; }
.hub-small:last-child { align-self: start; padding-top: 20px; }
.hub-big { font-size: 128px; font-weight: 700; line-height: .78; font-variant-numeric: lining-nums; }

/* ===== Top bar ===== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
}
.mini-logo {
  border: none; background: none; cursor: pointer; padding: 4px 2px;
  font: 700 1.3rem/1 var(--font-display); letter-spacing: .04em; color: var(--text);
}
.mini-logo span, .logo span { color: var(--red); }
.tabs { display: flex; gap: 6px; }
.tab {
  padding: 6px 14px; border-radius: 0; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font: 700 .8rem/1.2 var(--font-display); letter-spacing: .06em;
  display: flex; align-items: center; gap: 6px;
}
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.tab-status { font-size: .9em; }
.tab-status:empty { display: none; }
.tab-status.won { color: var(--good); }
.tab-status.lost { color: var(--bad); }
.tab.active .tab-status { color: inherit; }
.topbar-right { margin-left: auto; display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 0;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; font-weight: 700; font-size: 1.05rem;
}
.icon-btn:hover { background: var(--surface-2); }
a.icon-btn { color: var(--text); text-decoration: none; }
/* Plain text-style button (e.g. "Credits" links). */
.link-btn {
  border: none; background: none; padding: 0; cursor: pointer;
  color: var(--accent); text-decoration: underline; text-underline-offset: 2px; font: inherit;
}
.mini-logo, .tabs { transition: opacity .4s ease .5s, transform .4s ease .5s; }
.mode-title .mini-logo, .mode-title .tabs { opacity: 0; transform: translateY(-8px); pointer-events: none; transition-delay: 0s; }

/* ===== Title screen ===== */
.title-screen {
  position: fixed; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  padding: 56px 16px 28px; pointer-events: none;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
.mode-play .title-screen { opacity: 0; visibility: hidden; }
.mode-title .title-screen { transition: opacity .5s ease .35s, visibility 0s; }
.title-head { text-align: center; }
.logo {
  margin: 0; font: 700 clamp(2.4rem, 8vw, 4.4rem)/1 var(--font-display);
  letter-spacing: .06em;
}
.tagline { margin: 10px 0 0; color: var(--muted); font-size: clamp(1rem, 2.6vw, 1.2rem); font-style: italic; }
.chart-slot { flex: 1; width: 100%; min-height: 120px; }
.title-foot { text-align: center; }
.btn.play-btn {
  pointer-events: auto;
  padding: 14px 40px; border-radius: 999px; border: none; cursor: pointer;
  background: var(--red); color: #fff; font: 700 1.15rem/1.2 var(--font-display); letter-spacing: .06em;
  box-shadow: 0 6px 18px rgba(178, 34, 52, .35);
  transition: transform .15s, box-shadow .15s;
}
.btn.play-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(178, 34, 52, .4); }
.btn.play-btn:disabled { background: var(--muted); box-shadow: none; cursor: default; }
.meta { margin: 12px 0 0; color: var(--muted); font-size: .9rem; }
.meta .link-btn { pointer-events: auto; color: inherit; }
.meta strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ===== Play-screen countdown (bottom left) ===== */
.play-countdown {
  position: fixed; left: 24px; bottom: calc(16px + var(--panel-h, 0px)); z-index: 4; margin: 0;
  color: var(--muted); font-size: .9rem; pointer-events: none;
  transition: opacity .4s ease .6s;
}
.play-countdown strong { color: var(--text); font-variant-numeric: tabular-nums; }
.mode-title .play-countdown { opacity: 0; transition-delay: 0s; }
/* On phones it sits just above the guess panel, over the bars, so give it a backing. */
body:not(.wide) .play-countdown {
  left: 0; bottom: var(--panel-h, 0px); font-size: .8rem;
  padding: 3px 10px; background: var(--surface); border: 1px solid var(--border); border-bottom: none; border-left: none;
}

/* ===== Clue stack ===== */
.clue-stack {
  position: fixed; inset: 0; z-index: 0; margin: 0; padding: 0; list-style: none;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent calc(var(--fade-top, 60px) - 4px), #000 calc(var(--fade-top, 60px) + 70px));
          mask-image: linear-gradient(to bottom, transparent calc(var(--fade-top, 60px) - 4px), #000 calc(var(--fade-top, 60px) + 70px));
  transition: opacity .3s;
}
.mode-title .clue-stack { opacity: 0; }
.clue-stack.switching { opacity: 0; }
.seats.instant, .seats.instant .bar { transition: none !important; }
.clue-card {
  position: absolute;
  transform: translateY(calc(-50% - var(--off, 0px)));
  transition: transform .6s cubic-bezier(.45, 0, .2, 1);
}
.clue-card[data-cover="opening"] { transition: transform .6s cubic-bezier(.45, 0, .2, 1), clip-path .6s cubic-bezier(.45, 0, .55, 1); }
.clue-inner {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; border-radius: 0;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: background-color .4s, border-color .4s, box-shadow .4s, padding .4s;
}
/* Earlier clues: plain lines, guesses at the end of the line. */
.clue-card:not(.latest) .clue-inner {
  background: transparent; border-color: transparent; box-shadow: none;
  padding: 1px 4px; gap: 8px; align-items: baseline;
}
.clue-card:not(.latest) .clue-num {
  display: inline-block; width: auto; height: auto; background: none; color: var(--muted); font-size: .8rem;
}
.clue-card:not(.latest) .clue-num::after { content: "."; }
.clue-card:not(.latest) .clue-text { display: inline; font-size: 1rem; line-height: 1.3; }
.clue-card:not(.latest) .clue-guesses { display: inline; margin: 0; }
.clue-card:not(.latest) .g { display: inline; background: none; padding: 0; margin-left: 10px; font-size: .9rem; white-space: nowrap; }
.clue-card.latest .clue-inner { border-color: var(--hub); box-shadow: 0 0 0 1px var(--hub), var(--shadow); }
.clue-card.pending { visibility: hidden; }
.clue-num {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
  background: var(--muted); color: #fff; font-family: var(--font-display);
}
.clue-card.latest .clue-num { background: var(--hub); }
.clue-body { flex: 1; min-width: 0; }
.clue-text { margin: 1px 0 0; font-size: 1.2rem; line-height: 1.3; }
.clue-guesses { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.clue-guesses:not(:empty) { margin-top: 6px; }
.g { font-size: .85rem; padding: 2px 8px; border-radius: 0; }
.g.wrong { background: var(--bad-bg); color: var(--bad); }
.g.right { background: var(--good-bg); color: var(--good); font-weight: 600; }
.g.skip { background: var(--surface-2); color: var(--muted); }

/* ===== Guess panel ===== */
.panel {
  position: fixed; z-index: 3;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 18px;
  transition: opacity .45s ease .55s, transform .45s cubic-bezier(.2, .7, .3, 1) .55s;
}
.wide .panel { left: 24px; border-radius: 0; }
body:not(.wide) .panel {
  left: 0; right: 0; bottom: 0; border-radius: 0; border-bottom: none;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
}
.mode-title .panel { opacity: 0; pointer-events: none; transition-delay: 0s; }
.mode-title.wide .panel { transform: translateX(-24px); }
.mode-title:not(.wide) .panel { transform: translateY(24px); }

.panel-title { margin: 0 0 12px; font: 700 1.2rem/1.25 var(--font-display); letter-spacing: .03em; }
body:not(.wide) .panel-title { font-size: 1.1rem; margin-bottom: 8px; }
.guess-form { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; min-width: 0; }
#guess-input {
  width: 100%; padding: 11px 12px; border-radius: 0;
  border: 1px solid var(--border); background: var(--surface);
}
#guess-input:focus { outline: 2px solid var(--hub); outline-offset: 1px; }
.guess-photo {
  position: absolute; left: 7px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); pointer-events: none;
}
#guess-input.has-photo { padding-left: 46px; }
/* Results open upward from the bottom panel, downward from the side panel. */
.results {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 4px);
  max-height: min(300px, 45vh); overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 0;
  box-shadow: var(--shadow); z-index: 20;
}
.wide .results { top: calc(100% + 4px); bottom: auto; }
/* Let the list run under the Guess button so names and tags have room. */
.results { right: calc(-1 * var(--guess-btn-w, 0px)); }
.result-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 0; cursor: pointer;
}
.result-item:hover, .result-item.active { background: var(--surface-2); }
.result-item.guessed { opacity: .45; cursor: not-allowed; text-decoration: line-through; }
.r-photo {
  flex: none; width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
}
.r-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-tag { color: var(--muted); font-size: .9rem; white-space: nowrap; margin-left: auto; }
.no-results { padding: 10px; color: var(--muted); text-align: center; }
/* Portraits are taller than wide: crop circles from near the top to keep faces in frame. */
.r-photo, .guess-photo, .answer-photo { object-position: 50% 20%; }
.dot { margin: 0 5px; opacity: .6; }
.party { font-weight: 700; }
.party-D { color: var(--dem); }
.party-R { color: var(--rep); }
.party-I { color: var(--ind); }

.actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }

/* ===== Buttons ===== */
.btn {
  padding: 10px 16px; border-radius: 0; cursor: pointer; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface);
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--accent); }

/* Press-and-hold buttons: a bar fills while held, then the action fires. */
.btn.hold {
  position: relative; overflow: hidden; isolation: isolate;
  font-weight: 500; font-size: .92rem; padding: 8px 14px; color: var(--muted);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
.btn.hold:hover { color: var(--text); }
.hold-fill {
  position: absolute; inset: 0; z-index: -1; transform-origin: left;
  transform: scaleX(0); background: var(--hub); opacity: .25;
  transition: transform .15s ease-out;
}
.btn.hold.danger .hold-fill { background: var(--bad); }
.btn.hold.holding { color: var(--text); }
.btn.hold.holding .hold-fill { transform: scaleX(1); transition: transform var(--hold-ms, 800ms) linear; }

/* ===== Result (inside the panel) ===== */
.result-head { margin: 0 0 12px; font-size: 1.02rem; }
.answer-card {
  display: flex; align-items: center; gap: 14px;
  padding: 12px; border-radius: 0; background: var(--surface-2);
}
.result.won .answer-card { background: var(--good-bg); }
.answer-photo {
  flex: none; width: 84px; height: 84px; border-radius: 50%; object-fit: cover;
  border: 3px solid var(--surface); box-shadow: var(--shadow);
}
.result.won .answer-photo { border-color: var(--good); }
.answer-info { min-width: 0; }
.answer-name { font: 700 1.2rem/1.2 var(--font-display); letter-spacing: .02em; }
.answer-meta { color: var(--muted); font-size: .88rem; }
.answer-link { display: inline-block; margin-top: 4px; color: var(--accent); font-size: .9rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.result-actions .btn { flex: 1; white-space: nowrap; }
body:not(.wide) .answer-photo { width: 60px; height: 60px; }
body:not(.wide) .result-head { margin-bottom: 8px; }

/* ===== Modals ===== */
.modal {
  width: min(92vw, 460px); max-height: 90dvh; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 22px; box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(10, 14, 25, .5); }
.modal h2 { margin-top: 0; font-family: var(--font-display); letter-spacing: .04em; }
.modal ul { padding-left: 20px; }
.modal .close { position: absolute; top: 12px; right: 12px; border: none; font-size: 1.4rem; }
.stats-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.chip { padding: 5px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stat-num { font: 700 1.8rem/1.1 var(--font-display); }
.stat-label { font-size: .75rem; color: var(--muted); }
.modal h3 { font-size: .95rem; margin: 18px 0 8px; }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-label { width: 18px; text-align: right; font-size: .85rem; color: var(--muted); }
.bars .bar {
  background: var(--muted); color: #fff; border-radius: 4px; min-width: 24px;
  text-align: right; padding: 1px 6px; font-size: .8rem; font-weight: 600;
}
.bars .bar.today { background: var(--good); }
.share-btn { width: 100%; margin-top: 18px; }
.modal-wide { width: min(92vw, 620px); }
.modal a { color: var(--accent); }
.credits-filter {
  width: 100%; padding: 8px 10px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 0; background: var(--surface);
}
.credits-list {
  list-style: none; margin: 0; padding: 8px 0 0 !important; columns: 3 150px; column-gap: 16px;
  max-height: 34vh; overflow-y: auto; font-size: .92rem; border-top: 1px solid var(--border);
}
.credits-list li { break-inside: avoid; padding: 1px 0; }
.countdown-line { text-align: center; margin: 12px 0 0; }
.countdown-line strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 64px; left: 50%; transform: translate(-50%, -10px);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px;
  font-weight: 600; font-size: .92rem; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== Small screens ===== */
@media (max-width: 520px) {
  /* The play-screen logo and tabs are invisible on the title screen; free their space. */
  .mode-title .mini-logo, .mode-title .tabs { display: none; }
}
@media (max-width: 440px) {
  .mode-play .extra-link { display: none; }
}
@media (max-width: 520px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .mini-logo { font-size: .95rem; letter-spacing: .02em; }
  .tabs { gap: 4px; }
  .tab { padding: 4px 9px; font-size: .68rem; letter-spacing: .04em; }
  .icon-btn { width: 34px; height: 34px; }
  .clue-inner { padding: 9px 11px; gap: 9px; }
  .clue-text { font-size: .9rem; }
  .clue-card:not(.latest) .clue-text { font-size: .9rem; }
  .clue-card:not(.latest) .g { font-size: .8rem; margin-left: 6px; }
  .clue-num { width: 24px; height: 24px; font-size: .78rem; }
  .stat-num { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; transition-delay: 0s !important; }
}
