:root {
  --bg: #0e1020;
  --bg-2: #141830;
  --panel: #1b2038;
  --panel-2: #232a49;
  --ink: #f4f6ff;
  --muted: #9aa3c9;
  --line: #2e365c;
  --accent: #6ea0ff;
  --accent-2: #7be0ff;
  --accent-ink: #0b0d18;
  --danger: #ff6b8b;
  --good: #4be3a8;
  --lock: #262c48;
  --radius: 18px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --press: 0 6px 0 rgba(0, 0, 0, 0.35);
  --tap: 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

body[data-mode="classic"] { --accent: #6ea0ff; --accent-2: #7be0ff; --accent-ink: #0b0d18; }
body[data-mode="rude"]    { --accent: #ff5d8f; --accent-2: #ff9d5c; --accent-ink: #1a0710; }
body[data-mode="blitz"]   { --accent: #ffd23f; --accent-2: #ff8a3d; --accent-ink: #1a1400; }
body[data-mode="doubletrouble"] { --accent: #b07bff; --accent-2: #6ea0ff; --accent-ink: #0b0d18; }

@property --pct { syntax: "<number>"; inherits: true; initial-value: 1; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background:
    radial-gradient(120% 90% at 12% -10%, rgba(110, 160, 255, 0.16), transparent 55%),
    radial-gradient(120% 90% at 100% 0%, rgba(176, 123, 255, 0.14), transparent 50%),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

#app { max-width: 520px; margin: 0 auto; padding: 22px 16px calc(36px + env(safe-area-inset-bottom)); min-height: 100vh; }

.screen { display: flex; flex-direction: column; gap: 16px; animation: screen-in 300ms var(--tap) both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

h1, h2, h3 { margin: 0; }
h1:focus, h2:focus { outline: none; }
h2 { font-size: 1.45rem; letter-spacing: 0.01em; }
h3 { font-size: 1.15rem; text-align: center; }

.tagline, .hint { color: var(--muted); margin: 0; line-height: 1.5; }
.tagline { text-align: center; }
.center { text-align: center; }
.section-label { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; color: var(--muted); font-weight: 700; margin: 0; }

/* icons */
.icon { display: inline-flex; }
.icon svg { width: 1.2em; height: 1.2em; display: block; }
.mode-icon svg { width: 30px; height: 30px; }
.logo-mark svg { width: 46px; height: 46px; color: var(--accent); filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4)); }
.cta-icon svg { width: 16px; height: 16px; }
.adult-icon svg { width: 42px; height: 42px; color: var(--accent); }

/* hero */
.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 0 2px; text-align: center; }
.logo-mark { animation: bob 3.6s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-7px) rotate(6deg); } }
.wordmark {
  font-size: clamp(2.6rem, 13vw, 3.6rem); font-weight: 900; letter-spacing: 0.06em;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
  transform: rotate(-1.5deg);
}

/* buttons */
input, select, button { font: inherit; }
button { cursor: pointer; border: 0; border-radius: var(--radius); padding: 16px; font-size: 1.05rem; color: var(--ink); transition: transform var(--tap), filter var(--tap), box-shadow var(--tap); }
button:active { transform: translateY(2px) scale(0.99); }
button.primary { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: var(--accent-ink); font-weight: 800; box-shadow: var(--shadow); }
button.primary:active { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
button.primary:disabled { filter: grayscale(0.5) brightness(0.7); opacity: 0.55; cursor: not-allowed; box-shadow: none; }
button.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
button.ghost:active { background: rgba(255, 255, 255, 0.04); }
button.good-cta { background: linear-gradient(120deg, var(--good), #37c9d6); color: #05231a; }
button.danger-cta { background: linear-gradient(120deg, var(--danger), #ff9d5c); color: #2a0713; }

.big-cta { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 20px; font-size: 1.3rem; flex: 1; }
.big-cta .cta-sub { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 700; opacity: 0.9; }
.settings-link { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 0.95rem; color: var(--muted); padding: 12px; }
.settings-link .gear svg { width: 18px; height: 18px; }

.row { display: flex; gap: 12px; }
.row > button { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* home quick row */
.quick-row { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.inline-stepper { display: flex; align-items: center; justify-content: center; gap: 16px; background: var(--panel); border: 1.5px solid var(--line); border-radius: 999px; padding: 6px; align-self: center; }
.inline-val { min-width: 108px; text-align: center; font-weight: 800; font-size: 1.05rem; }

/* mode cards */
.mode-wrap { display: flex; flex-direction: column; gap: 10px; }
.mode-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.mode-card { position: relative; background: var(--panel); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 104px; justify-content: center; color: var(--ink); }
.mode-card .mode-icon { color: var(--muted); transition: color var(--tap), transform var(--tap); }
.mode-card .mode-name { font-weight: 800; font-size: 1rem; }
.mode-card.selected { border-color: transparent; box-shadow: 0 0 0 2px var(--accent), 0 10px 24px rgba(0, 0, 0, 0.3); }
.mode-card.selected .mode-icon { color: var(--accent); transform: scale(1.08); }
.mode-tick { position: absolute; top: 8px; left: 8px; width: 20px; height: 20px; border-radius: 50%; background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: var(--accent-ink); display: none; align-items: center; justify-content: center; }
.mode-tick svg { width: 13px; height: 13px; }
.mode-card.selected .mode-tick { display: flex; }
.mode-badge { position: absolute; top: 8px; right: 8px; background: var(--danger); color: #fff; font-size: 0.6rem; font-weight: 800; padding: 2px 6px; border-radius: 999px; letter-spacing: 0.05em; }
.mode-blurb { color: var(--muted); text-align: center; font-size: 0.95rem; min-height: 1.4em; }

/* fields / settings */
.topbar { display: flex; align-items: center; gap: 12px; }
.back { background: var(--panel); border: 1.5px solid var(--line); border-radius: 12px; width: 44px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.back svg { width: 20px; height: 20px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-weight: 700; font-size: 1rem; }
.field-hint { color: var(--muted); font-size: 0.85rem; }

.stepper { display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; padding: 8px; width: fit-content; }
.step-btn { background: var(--panel-2); min-width: 46px; height: 46px; padding: 0; border-radius: 11px; font-size: 1.4rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.stepper-val { min-width: 40px; text-align: center; font-size: 1.4rem; font-weight: 800; }

.seg { display: inline-flex; background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg-btn { flex: 1; background: transparent; padding: 12px 14px; border-radius: 10px; font-weight: 700; font-size: 0.95rem; color: var(--muted); }
.seg-btn.on { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel); border: 1.5px solid var(--line); color: var(--muted); min-height: 44px; padding: 10px 14px; border-radius: 999px; font-size: 0.88rem; font-weight: 600; }
.chip.on { color: var(--ink); border-color: transparent; box-shadow: inset 0 0 0 1.5px var(--accent); background: rgba(110, 160, 255, 0.14); }
.chip-all.on { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: var(--accent-ink); box-shadow: none; }

.switch-field { background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-text { display: flex; flex-direction: column; gap: 2px; }
.toggle { position: relative; width: 58px; height: 34px; border-radius: 999px; background: var(--lock); padding: 0; flex: 0 0 auto; transition: background var(--tap); }
.toggle .knob { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: transform var(--tap); }
.toggle.on { background: linear-gradient(120deg, var(--accent), var(--accent-2)); }
.toggle.on .knob { transform: translateX(24px); }

.sticky-cta { position: sticky; bottom: 0; padding: 10px 0 calc(6px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 60%, transparent); }
.sticky-cta button { width: 100%; }

/* loading */
.loading { align-items: center; text-align: center; padding-top: 60px; gap: 20px; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid var(--lock); border-top-color: var(--accent); animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* reveal */
.progress-dots { display: flex; gap: 7px; justify-content: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--lock); transition: background var(--tap), transform var(--tap); }
.dot.done { background: linear-gradient(120deg, var(--accent), var(--accent-2)); transform: scale(1.15); }

.seat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.seat { background: var(--panel); border: 1.5px solid var(--line); border-radius: var(--radius); min-height: 84px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.seat .seat-num { font-size: 1.5rem; font-weight: 800; }
.seat .seat-tag { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.seat.locked { background: var(--lock); color: var(--muted); border-style: dashed; }
.seat.locked .seat-num { color: var(--muted); }

/* overlay / sheet */
.overlay { position: fixed; inset: 0; background: rgba(6, 8, 16, 0.9); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; animation: fade 180ms ease both; backdrop-filter: blur(3px); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet { background: var(--panel); border: 1.5px solid var(--line); border-radius: 24px; padding: 20px; width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); animation: sheet-in 240ms var(--tap) both; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }
.small-cancel { padding: 10px; font-size: 0.9rem; color: var(--muted); }

/* reveal pad: idle geometry is IDENTICAL for every seat.
   The secret word is display:none while idle (out of layout), so word
   length can never shift anything and give the imposter away. */
.reveal-pad { position: relative; user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none; background: radial-gradient(120% 120% at 50% 0%, var(--panel-2), var(--bg-2)); border: 2px dashed var(--line); border-radius: 18px; min-height: 240px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 18px; overflow: hidden; transition: border-color var(--tap); }
.reveal-pad.arming { border-color: var(--accent); }
.reveal-pad.holding { border-color: var(--accent); border-style: solid; }
.hold-ring { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.hold-ring svg { width: 150px; height: 150px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--lock); stroke-width: 6; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; }
.hold-prompt { position: relative; z-index: 2; color: var(--muted); font-size: 1.05rem; font-weight: 600; }
.hold-prompt.hidden { display: none; }
.word-wrap { position: absolute; inset: 0; z-index: 2; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 16px; }
.word-wrap.show { display: flex; animation: pop 200ms var(--tap) both; }
.word { font-size: 2.1rem; font-weight: 900; line-height: 1.1; }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.role-hint { color: var(--danger); font-weight: 700; font-size: 0.95rem; }

/* discuss */
.order-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.order-chip { background: var(--panel); border: 1.5px solid var(--line); border-radius: 999px; padding: 8px 13px; font-weight: 700; font-size: 0.9rem; transition: background var(--tap), color var(--tap); }
.order-chip.first { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: var(--accent-ink); border-color: transparent; }
.order-arrow { color: var(--muted); }
.danger-cta.pulse { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 139, 0.5); } 50% { box-shadow: 0 0 0 10px rgba(255, 107, 139, 0); } }

.timer-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 6px 0; }
.timer-ring { --pct: 1; width: 150px; height: 150px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: radial-gradient(closest-side, var(--panel) 79%, transparent 80% 100%), conic-gradient(var(--accent) calc(var(--pct) * 360deg), var(--lock) 0); transition: --pct 950ms linear; }
.timer-ring.warn { background: radial-gradient(closest-side, var(--panel) 79%, transparent 80% 100%), conic-gradient(var(--danger) calc(var(--pct) * 360deg), var(--lock) 0); animation: shake 500ms ease-in-out infinite; }
.timer-ring.done { background: radial-gradient(closest-side, var(--panel) 79%, transparent 80% 100%), conic-gradient(var(--danger) 360deg, var(--danger) 0); }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.timer-num { font-size: 2.6rem; font-weight: 900; }
.timer-label { color: var(--muted); font-weight: 700; text-align: center; }
.timer-btn { flex: 1; }

/* result */
.result { position: relative; }
.result-h { text-align: center; font-size: 2rem; letter-spacing: 0.02em; }
.result-h.win { color: var(--good); }
.result-h.lose { color: var(--danger); }
.big { font-size: 1.3rem; font-weight: 800; margin: 0; }
.word-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wcard { border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 6px; border: 1.5px solid var(--line); }
.wcard-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.wcard-word { font-size: 1.3rem; font-weight: 800; }
.wcard.civ { background: rgba(75, 227, 168, 0.1); box-shadow: inset 0 0 0 1.5px rgba(75, 227, 168, 0.4); }
.wcard.imp { background: rgba(255, 107, 139, 0.1); box-shadow: inset 0 0 0 1.5px rgba(255, 107, 139, 0.4); }

.roles { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.role-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 60px; padding: 8px 10px; border-radius: 12px; border: 1.5px solid var(--line); }
.role-cell .role-seat { font-weight: 800; }
.role-cell .role-tag { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.role-cell.imposter { background: rgba(255, 107, 139, 0.12); border-color: rgba(255, 107, 139, 0.4); }
.role-cell.imposter .role-tag { color: var(--danger); }

.scoreline { display: flex; justify-content: space-between; gap: 10px; background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 16px; font-weight: 700; font-size: 0.9rem; }
.score-civ { color: var(--good); }
.score-imp { color: var(--danger); }

.burst { position: absolute; top: 0; left: 0; right: 0; height: 0; display: flex; justify-content: center; pointer-events: none; z-index: 3; }
.burst-bit { position: absolute; color: var(--accent); animation: burst 1000ms ease-out both; }
.burst-bit .icon svg { width: 22px; height: 22px; }
.burst-bit:nth-child(1) { animation-delay: 0ms; transform: translate(-130px, 20px); }
.burst-bit:nth-child(2) { animation-delay: 40ms; transform: translate(-95px, 0); }
.burst-bit:nth-child(3) { animation-delay: 80ms; transform: translate(-60px, 30px); }
.burst-bit:nth-child(4) { animation-delay: 20ms; transform: translate(-25px, -10px); }
.burst-bit:nth-child(5) { animation-delay: 60ms; transform: translate(10px, 22px); }
.burst-bit:nth-child(6) { animation-delay: 30ms; transform: translate(45px, 5px); }
.burst-bit:nth-child(7) { animation-delay: 70ms; transform: translate(80px, 26px); }
.burst-bit:nth-child(8) { animation-delay: 50ms; transform: translate(115px, 6px); }
.burst-bit:nth-child(9) { animation-delay: 90ms; transform: translate(-45px, 40px); }
.burst-bit:nth-child(10) { animation-delay: 15ms; transform: translate(60px, 40px); }
@keyframes burst { 0% { opacity: 0; transform: translateY(60px) scale(0.4); } 40% { opacity: 1; } 100% { opacity: 0; transform: translateY(-46px) scale(1.1); } }

.adult-sheet { text-align: center; }

/* a11y */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:focus-visible { outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

.error { text-align: center; gap: 12px; padding-top: 40px; }
