:root {
  --bg: #090715;
  --ink: #fff7ed;
  --muted: rgba(255, 247, 237, 0.68);
  --muted-2: rgba(255, 247, 237, 0.46);
  --panel: rgba(17, 24, 39, 0.78);
  --panel-strong: rgba(17, 24, 39, 0.94);
  --stroke: rgba(255, 255, 255, 0.16);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  --radius: 28px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --red: #ff3b5f;
  --blue: #22c3ff;
  --yellow: #ffd23f;
  --green: #55e576;
  --purple: #9b5cff;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font);
  background:
    radial-gradient(circle at 16% 10%, rgba(255, 59, 95, 0.34), transparent 26%),
    radial-gradient(circle at 82% 15%, rgba(34, 195, 255, 0.28), transparent 30%),
    radial-gradient(circle at 70% 88%, rgba(85, 229, 118, 0.18), transparent 28%),
    linear-gradient(135deg, #080513 0%, #17112c 45%, #070b18 100%);
}

#starfield {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  opacity: 0.78;
}
#starfield[hidden] { display: none; }

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(255, 210, 63, 0.7);
  outline-offset: 3px;
}

.katex { font-size: 1.04em; }

.setup-screen {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  place-items: center;
  padding: clamp(16px, 3vw, 34px);
  overflow: auto;
}

.setup-card {
  width: min(980px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.035)), var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 34px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  padding: clamp(22px, 4vw, 42px);
}

.setup-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 24px;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 6px;
  font-size: clamp(2.4rem, 6vw, 5.6rem);
  line-height: 0.88;
  letter-spacing: -0.08em;
}

.setup-heading p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.8vw, 1.2rem);
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.field { display: grid; gap: 8px; }
.field span, .settings-drawer h2 {
  color: var(--muted-2);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.field input {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.075);
  color: var(--ink);
  padding: 11px 14px;
  font-weight: 720;
}

.settings-drawer {
  margin-top: 14px;
  border: 1px solid var(--stroke);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.045);
  overflow: hidden;
}
.settings-drawer summary {
  cursor: pointer;
  padding: 15px 17px;
  list-style: none;
  font-weight: 850;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  line-height: 1;
}
.settings-drawer summary::-webkit-details-marker { display: none; }
.settings-drawer summary::after {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 1.2em;
  height: 1.2em;
  line-height: 1;
  color: var(--yellow);
  font-size: 1.2em;
  transform: translateY(-2px);
}
.settings-drawer[open] summary::after { content: "−"; }
.drawer-grid, .team-grid { display: grid; gap: 16px; padding: 0 16px 16px; }
.drawer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.rules-copy {
  display: grid;
  gap: 10px;
  padding: 0 16px 16px;
  color: var(--muted);
  line-height: 1.34;
  font-weight: 720;
}
.rules-copy p { margin: 0; }
.rules-copy-compact {
  padding: 0;
  max-height: 100%;
  overflow: auto;
  align-content: start;
}
.chip-grid, .team-grid { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
.chip-grid { display: grid; gap: 14px; }
.animation-grid {
  padding: 0 16px 18px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}
.animation-grid .chip-check span {
  padding: 10px 12px;
  min-height: 42px;
  display: grid;
  place-items: center;
}
.difficulty-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 14px; }

.chip-check { position: relative; display: block; }
.chip-check input { position: absolute; opacity: 0; }
.chip-check span {
  display: block;
  padding: 11px 12px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  text-align: center;
  font-weight: 760;
  cursor: pointer;
  isolation: isolate;
}
.chip-check input:checked + span {
  color: #0b1020;
  background: linear-gradient(135deg, var(--yellow), #ff9f1c);
  border-color: transparent;
}

.setup-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 22px;
  color: var(--muted-2);
}
.button-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.primary, .quiet {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  min-height: 44px;
  padding: 0 18px;
  font-weight: 900;
}
.primary {
  color: #17110a;
  background: linear-gradient(135deg, var(--yellow), #ff9f1c 72%);
  box-shadow: 0 12px 34px rgba(255, 159, 28, 0.26);
}
.quiet {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.075);
  border: 1px solid var(--stroke);
}
.quiet:hover, .primary:hover { transform: none; filter: brightness(1.04); }
.quiet.danger { color: #ffe4ea; border-color: rgba(255, 59, 95, 0.46); }

.game-screen {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}
.play-area { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr); gap: 0; }
.game-topline { display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.round-pill, .hint-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--stroke);
  color: var(--muted);
  font-weight: 850;
}
.hint-pill { color: var(--yellow); }

.card-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.flip-card {
  --card-accent: var(--blue);
  --card-deep: #0f4c81;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  perspective: 1300px;
  cursor: pointer;
  isolation: isolate;
}
.card-a { --card-accent: #e879f9; --card-deep: #6b21a8; }
.card-b { --card-accent: #2dd4bf; --card-deep: #0f766e; }
.card-c { --card-accent: #60a5fa; --card-deep: #1d4ed8; }
.card-d { --card-accent: #fb923c; --card-deep: #c2410c; }

.flip-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 900ms cubic-bezier(.16, .78, .18, 1);
  transform-origin: 50% 50%;
  will-change: transform;
}
.flip-card.is-flipped .flip-inner { transform: rotateY(180deg); }
.game-screen.no-flip-animation .flip-inner { transition-duration: 1ms; }

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, auto) auto;
  align-content: center;
  justify-items: center;
  gap: clamp(7px, 1.2vh, 13px);
  overflow: hidden;
  background-clip: padding-box;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 2px solid color-mix(in srgb, var(--card-accent) 72%, white 12%);
  border-radius: var(--radius);
  background-color: #111827;
  background-image:
    radial-gradient(circle at 18% 12%, color-mix(in srgb, var(--card-accent) 52%, #111827 48%) 0, rgba(17, 24, 39, 0) 34%),
    linear-gradient(160deg, color-mix(in srgb, var(--card-deep) 88%, #111827 12%), #111827 70%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08), 0 18px 44px rgba(0,0,0,0.28);
  padding: clamp(14px, 2.3vw, 26px);
  text-align: center;
}
.card-front { transform: rotateY(0deg) translateZ(1px); }
.card-back {
  transform: rotateY(180deg) translateZ(1px);
  color: #fff;
  background-color: #080b16;
  background-image:
    radial-gradient(circle at 86% 18%, color-mix(in srgb, var(--card-accent) 32%, #080b16 68%) 0, rgba(8, 11, 22, 0) 30%),
    linear-gradient(160deg, #151827, #070a14 78%);
}
.flip-card.is-same .card-back {
  color: #070a14;
  border-color: rgba(255,255,255,0.98);
  background-color: #f8fafc;
  background-image:
    radial-gradient(circle at 86% 18%, rgba(255,255,255,0.9), rgba(248,250,252,0) 32%),
    linear-gradient(160deg, #ffffff, #dbeafe 78%);
  box-shadow: inset 0 0 0 2px rgba(7, 10, 20, 0.06), 0 0 36px rgba(255,255,255,0.14);
}
.flip-card.is-impostor .card-back {
  color: #ffffff;
  border-color: #ffffff;
  background-color: #020617;
  background-image:
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.13) 0 8px, rgba(255,255,255,0) 8px 18px),
    radial-gradient(circle at 82% 16%, rgba(255,255,255,0.28), rgba(2,6,23,0) 26%),
    linear-gradient(160deg, #020617 0%, #111827 72%);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.16), 0 0 58px rgba(255,255,255,0.28);
}
.flip-card.is-selected .card-back {
  outline: 5px solid rgba(255, 255, 255, 0.92);
  outline-offset: -9px;
}
.flip-card.is-selected.is-same .card-back {
  outline-color: rgba(2, 6, 23, 0.95);
}
.flip-card.is-selected.is-impostor .card-back {
  outline-color: rgba(255, 255, 255, 0.92);
}

.card-letter {
  position: absolute;
  top: 14px;
  left: 14px;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  background: var(--card-accent);
  color: #090715;
  font-size: 1.35rem;
  font-weight: 1000;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--card-accent) 34%, transparent);
}
.question-text {
  display: block;
  max-width: 31ch;
  font-size: clamp(1.2rem, 2.25vw, 2.5rem);
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: -0.045em;
  text-wrap: balance;
}
.answer-line, .structure-line {
  display: grid;
  gap: 5px;
  max-width: 30ch;
  font-size: clamp(1.05rem, 1.72vw, 1.85rem);
  line-height: 1.12;
  font-weight: 900;
  text-wrap: balance;
}
.answer-line small, .structure-line small {
  font-size: 0.68rem;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.13em;
}
.flip-card.is-same .answer-line small,
.flip-card.is-same .structure-line small {
  color: rgba(7, 10, 20, 0.54);
}
.flip-card.is-impostor .answer-line small,
.flip-card.is-impostor .structure-line small {
  color: rgba(255, 255, 255, 0.56);
}
.status-badge, .pick-badge {
  position: absolute;
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 1000;
}
.status-badge {
  top: 14px;
  right: 14px;
  box-shadow: 0 10px 26px rgba(0,0,0,0.22);
}
.status-same { color: #050816; background: #ffffff; border: 1px solid rgba(0,0,0,0.14); }
.status-impostor { color: #ffffff; background: #050816; border: 1px solid rgba(255,255,255,0.72); transform: scale(1.08); box-shadow: 0 0 0 4px rgba(255,255,255,0.14), 0 16px 34px rgba(0,0,0,0.28); }
.pick-badge { bottom: 14px; right: 14px; color: #ffffff; border: 1px solid rgba(255,255,255,0.55); background: rgba(255,255,255,0.16); }

.mini-diagram {
  display: block;
  width: min(43%, 240px);
  min-width: 142px;
  color: color-mix(in srgb, var(--card-accent) 80%, white 20%);
}
.mini-diagram.compact { width: min(35%, 165px); min-width: 105px; opacity: 0.9; }
.mini-diagram svg { width: 100%; height: auto; overflow: visible; }
.mini-diagram line, .mini-diagram path, .mini-diagram rect, .mini-diagram circle, .mini-diagram polyline {
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mini-diagram .shape-fill { fill: color-mix(in srgb, var(--card-accent) 18%, transparent); }
.mini-diagram .shape-fill.strong { fill: color-mix(in srgb, var(--card-accent) 34%, transparent); }
.mini-diagram .filled { fill: currentColor; }
.mini-diagram .dashed { stroke-dasharray: 6 7; }
.mini-diagram .grid { stroke-width: 1.4; opacity: 0.46; }
.mini-diagram .tick { stroke-width: 3; }
.mini-diagram text { display: none; }
.mini-diagram .axis-label { display: none; }

.side-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}
.side-section {
  border: 1px solid var(--stroke);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.075), rgba(255,255,255,0.035)), var(--panel);
  backdrop-filter: blur(14px);
  padding: 14px;
  min-height: 0;
  box-shadow: 0 14px 42px rgba(0,0,0,0.18);
}
.timer-panel { flex: 0 0 auto; display: grid; gap: 16px; }
.timer-panel-compact { grid-template-columns: 1fr auto; align-items: center; }
.compact-round { color: var(--muted); font-weight: 900; }
.timer-value {
  font-size: clamp(3rem, 8vh, 5.2rem);
  line-height: 0.88;
  letter-spacing: -0.08em;
  font-weight: 1000;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.timer-buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 2px; }
.timer-buttons .quiet { min-height: 38px; padding: 0 8px; }
.instruction-panel { flex: 1 1 auto; display: block; color: var(--muted); overflow: auto; }
.instruction-panel p { margin: 0; }

.scoreboard { flex: 0 0 clamp(200px, 32dvh, 270px); max-height: 34dvh; overflow: auto; }
.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 2px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
}
.score-row:last-child { border-bottom: 0; }
.score-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row strong { color: var(--ink); font-size: 1.35rem; }

.scoreboard-marking .score-row {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  padding: 7px 0;
}
.score-row.is-selected {
  color: var(--ink);
}
.score-adjust {
  width: 46px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.07);
  color: var(--ink);
  font-weight: 1000;
  cursor: pointer;
}
.score-add {
  border-color: rgba(85, 229, 118, 0.48);
}
.score-minus {
  border-color: rgba(255, 255, 255, 0.28);
  color: rgba(255, 247, 237, 0.8);
}
.score-adjust:active {
  filter: brightness(1.2);
}


.reveal-summary {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
.result-pill {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 12px 12px 0;
  padding: 10px 12px;
  border-radius: 18px;
  background: #050816;
  color: #ffffff;
  border: 1px solid rgba(255,255,255,0.72);
  box-shadow: 0 14px 34px rgba(0,0,0,0.26);
}
.result-pill span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--card-accent, #ffffff);
  color: #050816;
  border: 0;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.32), 0 8px 18px rgba(0,0,0,0.24);
  font-size: 1.35rem;
  font-weight: 1000;
}
.result-pill strong { text-transform: uppercase; letter-spacing: 0.1em; font-weight: 1000; }
.reveal-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.compare-block { display: grid; gap: 8px; flex: 0 0 auto; }
.compare-block h2 {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--yellow);
}
dl { display: grid; gap: 8px; margin: 0; }
dl div { display: grid; gap: 4px; }
dt {
  color: var(--muted-2);
  text-transform: uppercase;
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  font-weight: 1000;
}
dd { margin: 0; color: var(--ink); font-weight: 780; line-height: 1.14; }
.marking-block { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1 1 auto; }
.marking-block p { margin: 0; color: var(--muted); font-weight: 850; }
.team-chip-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-content: start; overflow: auto; min-height: 0; padding-right: 2px; }
.team-chip {
  min-height: 48px;
  border-radius: 15px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,0.065);
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
}
.team-chip.is-selected { color: #06110a; background: linear-gradient(135deg, var(--green), #a7f3d0); border-color: transparent; }
.marking-actions {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--stroke);
  background: rgba(7, 10, 20, 0.68);
}
.marking-actions .primary, .marking-actions .quiet { min-height: 48px; }

.table-wrap { overflow: auto; border: 1px solid var(--stroke); border-radius: 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--stroke); text-align: left; }
th { color: var(--muted-2); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; }
tr:last-child td { border-bottom: 0; }
.final-card { max-width: 760px; }
.final-hero {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
  text-align: center;
}
.final-kicker {
  justify-self: center;
  padding: 9px 15px;
  border-radius: 999px;
  background: #ffffff;
  color: #050816;
  font-weight: 1000;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: 0 16px 36px rgba(255,255,255,0.14);
}
.final-hero h1 {
  margin: 0;
  font-size: clamp(2.5rem, 7vw, 6rem);
}
.final-hero p { margin: 0; color: var(--yellow); font-weight: 1000; }
.top-score td { color: var(--ink); font-weight: 950; background: rgba(255,255,255,0.06); }
.end-actions { justify-content: flex-end; margin-top: 20px; }
.seed-note { margin: 18px 0 0; color: var(--muted); font-weight: 760; }
.seed-note strong { color: var(--ink); }
body.time-up .timer-value { color: var(--yellow); text-shadow: 0 0 30px rgba(255, 210, 63, 0.35); }

@media (max-width: 1000px) {
  body { overflow: auto; }
  .game-screen { height: auto; min-height: 100dvh; grid-template-columns: 1fr; overflow: visible; }
  .side-panel { overflow: visible; }
  .setup-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .card-grid { grid-template-columns: 1fr; grid-template-rows: repeat(4, minmax(190px, 1fr)); }
  .drawer-grid, .setup-grid { grid-template-columns: 1fr; }
}

/* Stage 14 refinements */
.settings-drawer summary::after {
  transform: translateY(-4px);
}
.pick-badge {
  background: rgba(2, 6, 23, 0.86);
  color: #ffffff;
  border-color: rgba(255,255,255,0.74);
  box-shadow: 0 10px 24px rgba(2,6,23,0.26);
}
.flip-card.is-same .pick-badge {
  background: #050816;
  color: #ffffff;
  border-color: rgba(2,6,23,0.64);
}
.flip-card.is-impostor .pick-badge {
  background: #ffffff;
  color: #050816;
  border-color: rgba(255,255,255,0.88);
}
.side-panel {
  gap: 14px;
}
.side-section {
  border: 2px solid rgba(255,255,255,0.18);
  background:
    radial-gradient(circle at 8% 0%, rgba(232, 121, 249, 0.18), transparent 30%),
    radial-gradient(circle at 100% 16%, rgba(45, 212, 191, 0.16), transparent 34%),
    linear-gradient(165deg, rgba(15,23,42,0.96), rgba(3,7,18,0.90));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06), 0 18px 52px rgba(0,0,0,0.24);
}
.timer-panel {
  border-color: rgba(255,159,28,0.32);
}
.scoreboard {
  border-color: rgba(96,165,250,0.34);
}
.score-row {
  border-bottom-color: rgba(255,255,255,0.12);
  padding-inline: 6px;
}
.score-row span {
  color: rgba(255,247,237,0.82);
  font-weight: 820;
}
.score-row strong {
  font-size: 1.52rem;
  text-shadow: 0 0 24px rgba(255,255,255,0.12);
}
.score-adjust {
  border: 2px solid rgba(255,255,255,0.24);
  background: linear-gradient(135deg, rgba(255,255,255,0.13), rgba(255,255,255,0.05));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
}
.score-add { border-color: rgba(85,229,118,0.46); }
.score-minus { border-color: rgba(255,255,255,0.26); }
.reveal-summary {
  border-color: rgba(232,121,249,0.34);
}
.result-pill {
  border: 2px solid rgba(255,255,255,0.86);
  background: linear-gradient(135deg, #020617, #050816 70%);
}
.reveal-scroll dt {
  color: rgba(255,210,63,0.78);
}
.reveal-scroll dd {
  font-weight: 910;
  font-size: 1.04rem;
}
.marking-actions {
  background: linear-gradient(180deg, rgba(15,23,42,0.72), rgba(2,6,23,0.94));
}
.marking-actions .primary {
  min-height: 54px;
  font-size: 1.02rem;
}


/* Stage 15 refinements */
.card-d { --card-accent: #fb923c; --card-deep: #c2410c; }
.flip-card.is-same .pick-badge {
  background: #050816;
  color: #ffffff;
  border-color: rgba(2,6,23,0.8);
  box-shadow: 0 12px 26px rgba(2,6,23,0.24);
}
.flip-card.is-impostor .pick-badge {
  background: #ffffff;
  color: #050816;
  border-color: rgba(255,255,255,0.95);
  box-shadow: 0 12px 26px rgba(255,255,255,0.16);
}

/* Stage 16 refinements */
.side-section {
  background: linear-gradient(180deg, rgba(12, 18, 34, 0.98), rgba(7, 11, 24, 0.98));
  border: 2px solid rgba(255,255,255,0.16);
  box-shadow: none;
  backdrop-filter: none;
}
.timer-panel,
.scoreboard,
.reveal-summary {
  border-color: rgba(255,255,255,0.18);
  box-shadow: none;
}
.result-pill {
  box-shadow: none;
  background: #020617;
}
.score-adjust,
.primary,
.quiet {
  box-shadow: none;
}
.score-row strong {
  text-shadow: none;
}
.reveal-scroll dt {
  color: var(--yellow);
}
.marking-actions {
  background: rgba(2, 6, 23, 0.9);
}

/* Stage 18 refinements */
.question-text .katex,
.answer-value .katex,
.structure-line .katex,
.reveal-summary .katex {
  margin-inline: 0.055em;
}
.question-text {
  overflow-wrap: normal;
  word-break: normal;
}
.answer-line {
  max-width: min(34ch, 96%);
}
.answer-value {
  display: block;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.12;
}
.final-hero {
  margin-bottom: 24px;
}

/* Stage 18 timer and diagram refinements */
@keyframes timerExpiredFlash {
  0%, 100% { color: var(--yellow); filter: brightness(1); transform: scale(1); }
  50% { color: #ffffff; filter: brightness(1.6); transform: scale(1.035); }
}
body.time-up .timer-value {
  animation: timerExpiredFlash 0.72s ease-in-out infinite;
  text-shadow: 0 0 34px rgba(255, 210, 63, 0.5);
}
.mini-diagram .tick {
  stroke-linecap: round;
}

/* Stage 22 text wrapping refinements */
.math-punct {
  white-space: nowrap;
  display: inline-block;
}
.question-text .katex,
.answer-value .katex,
.structure-line .katex,
.reveal-summary .katex {
  white-space: nowrap;
}

/* Stage 23 layout and readability refinements */
.timer-panel {
  flex: 0 0 auto;
  min-height: clamp(158px, 23dvh, 245px);
  align-content: center;
}
.timer-panel-compact {
  min-height: 104px;
  grid-template-columns: 1fr;
}
.timer-buttons-primary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.timer-buttons-management {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.timer-buttons-management .quiet {
  min-height: 40px;
}
.scoreboard {
  flex: 0 0 clamp(160px, 24dvh, 215px);
  max-height: 26dvh;
}
.instruction-panel,
.reveal-summary {
  flex: 1 1 auto;
  min-height: 0;
}
.mini-diagram svg {
  overflow: visible;
}
.question-text {
  text-wrap: balance;
}
.question-text .katex + .katex,
.question-text .katex + .math-punct,
.question-text .math-punct + .katex {
  margin-left: 0.05em;
}
@media (max-width: 900px) {
  html, body { height: auto; min-height: 100%; overflow: auto; }
  .game-screen {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    grid-template-columns: 1fr;
  }
  .play-area { min-height: auto; }
  .card-grid {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
  .flip-card { min-height: 260px; }
  .side-panel { overflow: visible; }
  .scoreboard { max-height: none; flex-basis: auto; }
  .timer-panel { min-height: auto; }
}


/* Stage 27 refinements */
.instruction-panel {
  flex: 0 0 clamp(92px, 14dvh, 128px);
  min-height: 0;
}
.instruction-panel .rules-copy-compact {
  max-height: 100%;
  overflow: auto;
  gap: 7px;
  font-size: 0.92rem;
  line-height: 1.18;
}
.scoreboard {
  flex: 0 0 clamp(196px, 30dvh, 270px);
  max-height: 32dvh;
}
.score-row {
  min-height: 42px;
}
@media (max-width: 900px) {
  .instruction-panel { flex-basis: auto; }
  .scoreboard { max-height: none; flex-basis: auto; }
}


/* Stage 27 layout: timer and leaderboard use the space they need; instructions fill the remainder. */
.side-panel { align-items: stretch; }
.timer-panel { flex: 0 0 auto; }
.scoreboard { flex: 0 0 auto; max-height: none; }
.instruction-panel { flex: 1 1 0; min-height: 140px; }
.game-screen:not(.is-revealed) .instruction-panel { display: flex; }
.game-screen:not(.is-revealed) .instruction-panel .rules-copy-compact { flex: 1 1 auto; }

/* Stage 28 refinements */
/* Switch to stacked/mobile layout earlier so the four question cards are not squashed in narrow browser widths. */
@media (max-width: 1180px) {
  html, body { height: auto; min-height: 100%; overflow: auto; }
  .game-screen {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .play-area { min-height: auto; }
  .card-grid {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
  .flip-card { min-height: 270px; }
  .side-panel { overflow: visible; }
  .scoreboard { max-height: none; flex-basis: auto; }
  .timer-panel { min-height: auto; }
}

/* Keep the large-screen side panel using timer/leaderboard natural height, with instructions filling the rest. */
.game-screen:not(.is-revealed) .instruction-panel { flex: 1 1 0; min-height: 150px; }

/* Allow selected diagram text only for rotation labels. */
.mini-diagram text.diagram-label {
  display: block;
  fill: currentColor;
  stroke: none;
  font-family: inherit;
  font-weight: 950;
  font-size: 13px;
  letter-spacing: -0.02em;
}
.mini-diagram .rotation-arrow {
  stroke-width: 2.2;
}
.mini-diagram .parallel-arrow {
  stroke-width: 3.0;
}

/* Stage 30 refinements */
@media (max-width: 1320px) {
  html, body { height: auto; min-height: 100%; overflow: auto; }
  .game-screen {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .play-area { min-height: auto; }
  .card-grid {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
  .flip-card { min-height: 285px; }
  .side-panel { overflow: visible; }
  .scoreboard { max-height: none; flex-basis: auto; }
  .timer-panel { min-height: auto; }
}
.mini-diagram .marker-fill {
  fill: currentColor;
  stroke: none;
}
.final-card {
  max-width: 820px;
  padding-top: clamp(18px, 3vw, 30px);
  padding-bottom: clamp(18px, 3vw, 30px);
}
.final-hero {
  margin-bottom: 14px;
}
.final-hero h1 {
  font-size: clamp(2.25rem, 6vw, 5rem);
}
.final-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin: 0 0 14px;
  flex-wrap: wrap;
}
.final-toolbar .seed-note {
  margin: 0;
}
.final-toolbar .primary {
  min-height: 42px;
}


/* Stage 32 refinements */
.final-card { max-width: 900px; }
.final-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.final-header .final-kicker { justify-self: auto; }
.final-header .final-toolbar { margin: 0; }
.final-hero { margin-bottom: 12px; }
.final-hero h1 { font-size: clamp(2rem, 5.3vw, 4.4rem); }
@media (max-width: 620px) {
  .final-header { justify-content: center; text-align: center; }
  .final-toolbar { justify-content: center; }
}
.mini-diagram .parallel-arrow { stroke-width: 3.2; }


/* Stage 32 final refinements */
.final-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.final-header .seed-note { margin: 0; text-align: center; }
.final-header .primary { min-height: 42px; }
@media (max-width: 620px) {
  .final-header { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}
.mini-diagram .parallel-arrow { stroke-width: 2.9; }


/* Stage 32 refinements */
.final-kicker {
  background: transparent;
  color: var(--yellow);
  border: 0;
  box-shadow: none;
  padding-inline: 0;
}
.final-header {
  grid-template-columns: minmax(0, 1fr) auto auto;
}
.final-header .seed-note { text-align: left; }
.scoreboard-marking .score-row { gap: 6px; }
.mini-diagram .parallel-arrow { stroke-width: 3.1; }


/* Stage 32 final refinements */
.score-controls { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }
.score-adjust { width: 44px; height: 34px; }
.score-minus { border-color: rgba(255,255,255,0.30); }
.score-add { border-color: rgba(85,229,118,0.50); }
.score-row.is-selected { background: linear-gradient(90deg, rgba(85,229,118,0.13), transparent 86%); }
.final-header { grid-template-columns: minmax(0, 1fr) auto auto; }
.final-header .seed-note { text-align: left; }
.final-kicker {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  color: var(--yellow) !important;
  padding: 0 !important;
  border-radius: 0 !important;
}
.mini-diagram .parallel-arrow { stroke-width: 3.0; }
@media (max-width: 620px) {
  .final-header { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .final-header .seed-note { text-align: center; }
}

/* Stage 32 cleanup refinements */
.score-adjust {
  width: 44px;
  height: 34px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: var(--ink);
  font-weight: 1000;
  border: 2px solid rgba(255,255,255,0.24);
  cursor: pointer;
  box-shadow: none;
}
.score-adjust:hover { transform: none; filter: brightness(1.08); }
.score-minus { border-color: rgba(255,255,255,0.28); color: rgba(255,247,237,0.78); }
.score-add { border-color: rgba(85,229,118,0.48); }
.final-header {
  grid-template-columns: minmax(0, 1fr) auto auto;
}
.final-header .seed-note { text-align: left; }
.final-kicker {
  background: transparent;
  color: var(--yellow);
  box-shadow: none;
  border: 0;
  padding: 0;
  border-radius: 0;
}
.mini-diagram .parallel-arrow {
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Stage 33 refinements */
.final-header {
  grid-template-columns: minmax(0, 1fr) auto !important;
  margin-bottom: 6px;
}
.final-header .seed-note { text-align: left; }
.final-hero {
  align-items: center;
  justify-items: center;
  margin-bottom: 12px;
}
.final-hero .final-kicker {
  display: block;
  text-align: center;
  margin: 0 0 2px;
}
.final-hero h1 { line-height: 0.9; }
@media (max-width: 620px) {
  .final-header { grid-template-columns: 1fr !important; justify-items: center; text-align: center; }
  .final-header .seed-note { text-align: center; }
}

/* Stage 34 refinements */
.final-header {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}
.final-header .seed-note { justify-self: start; text-align: left; margin: 0; }
.final-header .final-kicker { justify-self: center; text-align: center; }
.final-header .primary { justify-self: end; }
.final-hero { margin-bottom: 12px; }
.final-hero h1 { line-height: 0.92; }
@media (max-width: 620px) {
  .final-header { grid-template-columns: 1fr !important; justify-items: center; text-align: center; }
  .final-header .seed-note, .final-header .primary, .final-header .final-kicker { justify-self: center; text-align: center; }
}

/* Stage 44: optional round-change animation with a short overlap delay */
.play-area {
  position: relative;
  z-index: 1;
  overflow: visible;
  isolation: isolate;
  perspective: 1600px;
}
.side-panel {
  position: relative;
  z-index: 6;
}
.card-grid.cards-exit,
.card-grid.cards-enter {
  pointer-events: none;
}
.card-grid.card-grid-outgoing {
  position: absolute;
  inset: 0;
  z-index: 4;
}
.card-grid:not(.card-grid-outgoing) {
  position: relative;
  z-index: 2;
}
.card-grid.cards-exit .flip-card,
.card-grid.cards-enter .flip-card {
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}
.card-grid.cards-exit .flip-card {
  animation: card-throw-left 1180ms cubic-bezier(.28, .02, .20, 1) both;
}
.card-grid.cards-enter .flip-card {
  animation-name: card-fly-in-right;
  animation-duration: 980ms;
  animation-timing-function: cubic-bezier(.16, .82, .22, 1);
  animation-fill-mode: both;
}
.card-grid.cards-exit .flip-card:nth-child(1) { --exit-y: -7vh; --exit-rot: -9deg; animation-delay: 0ms; }
.card-grid.cards-exit .flip-card:nth-child(2) { --exit-y: 4vh; --exit-rot: -6deg; animation-delay: 24ms; }
.card-grid.cards-exit .flip-card:nth-child(3) { --exit-y: -2vh; --exit-rot: -12deg; animation-delay: 48ms; }
.card-grid.cards-exit .flip-card:nth-child(4) { --exit-y: 7vh; --exit-rot: -8deg; animation-delay: 72ms; }
.card-grid.cards-enter .flip-card:nth-child(1) { --enter-y: 5vh; --enter-rot: 7deg; animation-delay: 170ms; }
.card-grid.cards-enter .flip-card:nth-child(2) { --enter-y: -4vh; --enter-rot: 5deg; animation-delay: 190ms; }
.card-grid.cards-enter .flip-card:nth-child(3) { --enter-y: 7vh; --enter-rot: 8deg; animation-delay: 210ms; }
.card-grid.cards-enter .flip-card:nth-child(4) { --enter-y: -6vh; --enter-rot: 6deg; animation-delay: 230ms; }

@keyframes card-throw-left {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotateZ(0deg) scale(1);
  }
  68% {
    opacity: 1;
    transform: translate3d(calc(-82vw - 110px), calc(var(--exit-y, -5vh) * .62), 0) rotateZ(calc(var(--exit-rot, -10deg) * .62)) scale(.995);
  }
  100% {
    opacity: 0;
    transform: translate3d(calc(-136vw - 300px), var(--exit-y, -5vh), 0) rotateZ(var(--exit-rot, -10deg)) scale(.985);
  }
}

@keyframes card-fly-in-right {
  0% {
    opacity: 0;
    transform: translate3d(calc(112vw + 220px), var(--enter-y, 5vh), 0) rotateZ(var(--enter-rot, 7deg)) scale(.99);
  }
  6% { opacity: 1; }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotateZ(0deg) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-grid.cards-exit .flip-card,
  .card-grid.cards-enter .flip-card {
    animation-duration: 1ms;
    animation-delay: 0ms;
  }
}

@media (max-width: 1320px) {
  .play-area { overflow: hidden; }
}
