/* Trivia Night: a game-show stage. Dark ink backdrop, category-tinted light
   blobs, a slow sunburst, chunky display type and four loud answer tiles. */

:root {
  --ink: #120d24;
  --ink-2: #1d1640;
  --ink-3: #2a2158;
  --paper: #fff8ec;
  --muted: rgba(255, 248, 236, 0.7);
  --faint: rgba(255, 248, 236, 0.14);
  --glass: rgba(29, 22, 64, 0.62);
  --glass-edge: rgba(255, 248, 236, 0.16);

  --a: #ff7a1a;
  --b: #14c9b0;
  --c: #ff3d8b;
  --d: #ffd23f;
  --good: #3ddc84;
  --bad: #ff5a5f;

  --cat1: #ff3d8b;
  --cat2: #ffd23f;
  --cat3: #14c9b0;

  --font-display: "Bricolage Grotesque", "Arial Black", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, sans-serif;

  --radius: 28px;
  --radius-sm: 16px;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}

body[data-cat="Film & TV"]          { --cat1: #ff4d6d; --cat2: #ffb703; --cat3: #ff8fab; }
body[data-cat="Music"]              { --cat1: #ff5fa2; --cat2: #c77dff; --cat3: #ffd23f; }
body[data-cat="Sport"]              { --cat1: #06d6a0; --cat2: #ffd166; --cat3: #118ab2; }
body[data-cat="Science & Nature"]   { --cat1: #4cc9f0; --cat2: #80ffdb; --cat3: #7209b7; }
body[data-cat="Geography"]          { --cat1: #52b788; --cat2: #48cae4; --cat3: #f9c74f; }
body[data-cat="History"]            { --cat1: #e76f51; --cat2: #f4a261; --cat3: #e9c46a; }
body[data-cat="Food & Drink"]       { --cat1: #ff8fab; --cat2: #ffc300; --cat3: #fb5607; }
body[data-cat="Tech & Internet"]    { --cat1: #3a86ff; --cat2: #00f5d4; --cat3: #8338ec; }
body[data-cat="Pop Culture"]        { --cat1: #ff006e; --cat2: #fb5607; --cat3: #ffbe0b; }
body[data-cat="General Knowledge"]  { --cat1: #ffbe0b; --cat2: #3a86ff; --cat3: #ff3d8b; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--d); text-underline-offset: 3px; }
a:hover { color: var(--paper); }
:focus-visible { outline: 3px solid var(--d); outline-offset: 3px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
kbd {
  font-family: var(--font-body);
  font-size: 0.72em;
  font-weight: 700;
  padding: 0.15em 0.5em;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.22);
  letter-spacing: 0.02em;
}

/* ---------- stage background ---------- */

.stage-bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: radial-gradient(120% 90% at 50% 110%, var(--ink-3), var(--ink) 60%); }
.sunburst {
  position: absolute; left: 50%; top: 55%; width: 220vmax; height: 220vmax;
  transform: translate(-50%, -50%);
  background: repeating-conic-gradient(from 0deg, rgba(255, 248, 236, 0.035) 0deg 7deg, transparent 7deg 18deg);
  mask-image: radial-gradient(circle, #000 0%, transparent 55%);
  animation: spin 160s linear infinite;
}
.blob { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.55; transition: background 1.2s ease; will-change: transform; }
.blob-1 { width: 55vmax; height: 55vmax; left: -18vmax; top: -22vmax; background: var(--cat1); animation: drift1 26s ease-in-out infinite alternate; }
.blob-2 { width: 48vmax; height: 48vmax; right: -16vmax; top: 10vh; background: var(--cat2); opacity: 0.42; animation: drift2 32s ease-in-out infinite alternate; }
.blob-3 { width: 40vmax; height: 40vmax; left: 25vw; bottom: -26vmax; background: var(--cat3); opacity: 0.35; animation: drift3 29s ease-in-out infinite alternate; }
.grain {
  position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  opacity: 0.09; mix-blend-mode: overlay;
  animation: grain 1.2s steps(6) infinite;
}
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes drift1 { to { transform: translate(14vw, 10vh) scale(1.12); } }
@keyframes drift2 { to { transform: translate(-12vw, 16vh) scale(0.9); } }
@keyframes drift3 { to { transform: translate(-10vw, -12vh) scale(1.15); } }
@keyframes grain { 0% { transform: translate(0, 0); } 33% { transform: translate(-4%, 3%); } 66% { transform: translate(3%, -5%); } 100% { transform: translate(0, 0); } }

/* ---------- shared bits ---------- */

.display, .wordmark, h1, h2 { font-family: var(--font-display); font-optical-sizing: auto; letter-spacing: -0.02em; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.8rem; font-weight: 700; color: var(--d); margin: 0 0 0.6rem; }
.lede { color: var(--muted); font-size: 1.1rem; max-width: 34ch; margin: 0.4rem 0 1.6rem; }
.hl { color: var(--d); text-shadow: 0.04em 0.04em 0 var(--c); }

.btn {
  --btn-bg: var(--glass);
  --btn-fg: var(--paper);
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.6em;
  font: 700 1rem/1 var(--font-body);
  padding: 0.95em 1.4em; border-radius: 999px;
  background: var(--btn-bg); color: var(--btn-fg);
  box-shadow: inset 0 0 0 1.5px var(--glass-edge), 0 6px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.18s var(--spring), box-shadow 0.18s ease, opacity 0.2s ease, filter 0.2s ease;
  text-decoration: none; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: inset 0 0 0 1.5px var(--glass-edge), 0 2px 0 rgba(0, 0, 0, 0.35); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: inset 0 0 0 1.5px var(--glass-edge); }
.btn-primary { --btn-bg: linear-gradient(135deg, var(--c), var(--a)); box-shadow: 0 6px 0 #9e1f52, 0 14px 40px rgba(255, 61, 139, 0.35); }
.btn-primary:active:not(:disabled) { box-shadow: 0 2px 0 #9e1f52; }
.btn-go { --btn-bg: var(--d); --btn-fg: var(--ink); box-shadow: 0 6px 0 #a88410, 0 14px 40px rgba(255, 210, 63, 0.25); }
.btn-go:active:not(:disabled) { box-shadow: 0 2px 0 #a88410; }
.btn-go kbd, .btn-go kbd { background: rgba(18, 13, 36, 0.12); border-color: rgba(18, 13, 36, 0.25); }
.btn-ghost { --btn-bg: rgba(255, 248, 236, 0.07); }
.btn-xl { font-size: 1.25rem; padding: 1.05em 1.8em; }
.btn-icon { padding: 0.95em; }

.code-chip {
  font-family: var(--font-display); font-weight: 800; letter-spacing: 0.14em;
  padding: 0.35em 0.75em; border-radius: 10px;
  background: var(--paper); color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.pop-in { animation: popIn 0.7s var(--spring) both; animation-delay: calc(var(--d, 0) * 90ms); }
@keyframes popIn { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }

/* ---------- simple pages (landing, dashboard, error) ---------- */

.simple-wrap { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 32px 16px; }
.hero, .dash, .simple-card { width: min(640px, 100%); }
.simple-card { background: var(--glass); border: 1px solid var(--glass-edge); border-radius: var(--radius); padding: clamp(24px, 5vw, 48px); backdrop-filter: blur(18px); }
.simple-card .display { font-size: clamp(2rem, 6vw, 3rem); margin: 0 0 0.3rem; line-height: 1; }

.wordmark { margin: 0; line-height: 0.82; font-weight: 800; font-size: clamp(4.2rem, 18vw, 9.5rem); }
.wm-line { display: block; }
.wm-accent { color: var(--d); text-shadow: 0.035em 0.035em 0 var(--c), 0.07em 0.07em 0 var(--a); padding-bottom: 0.08em; }
.wm-q { display: inline-block; color: var(--b); text-shadow: 0.035em 0.035em 0 var(--ink); animation: wobble 2.8s ease-in-out infinite; transform-origin: 50% 85%; }
@keyframes wobble { 0%, 60%, 100% { transform: rotate(0); } 70% { transform: rotate(14deg); } 80% { transform: rotate(-10deg); } 90% { transform: rotate(5deg); } }

.join { display: flex; gap: 12px; flex-wrap: wrap; }
.code-input {
  flex: 1 1 200px; min-width: 0;
  font: 800 1.9rem/1 var(--font-display); letter-spacing: 0.3em; text-transform: uppercase; text-align: center;
  padding: 0.5em 0.6em; border-radius: 18px;
  color: var(--ink); background: var(--paper); border: 0;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}
.code-input::placeholder { color: rgba(18, 13, 36, 0.3); }
.small-links { color: var(--muted); font-size: 0.95rem; margin-top: 1.6rem; }
.small-links .sep { opacity: 0.35; margin: 0 0.4em; }

.dash .display { font-size: clamp(2.3rem, 7vw, 4rem); line-height: 0.98; margin: 0 0 1.6rem; }
.toast-inline { min-height: 1.4em; color: var(--bad); font-weight: 600; }
.recent { margin-top: 1.4rem; }
.recent h2 { font-size: 1.1rem; color: var(--muted); font-weight: 700; margin: 0 0 0.6rem; }
.recent ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recent a {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--glass); border: 1px solid var(--glass-edge);
  color: var(--paper); text-decoration: none;
  transition: transform 0.2s var(--spring), border-color 0.2s;
}
.recent a:hover { transform: translateX(6px); border-color: var(--d); }
.recent .when { color: var(--muted); flex: 1; }
.status { font-weight: 700; font-size: 0.9rem; }
.status-finished { color: var(--good); }

/* ---------- pips ---------- */

.pips { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; justify-content: center; flex-wrap: wrap; }
.pip {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--faint);
  transition: background 0.4s ease, border-color 0.4s ease, transform 0.4s var(--spring);
}
.pip.done { background: var(--cat1); border-color: transparent; }
.pip.current { transform: scale(1.45); border-color: var(--paper); background: var(--paper); box-shadow: 0 0 0 0 rgba(255, 248, 236, 0.6); animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { to { box-shadow: 0 0 0 10px rgba(255, 248, 236, 0); } }
.pips-sm { gap: 6px; padding: 4px 16px 0; }
.pips-sm .pip { width: 10px; height: 10px; }

/* ---------- host layout ---------- */

.page-host { overflow: hidden; }
.host { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; padding: 18px 28px 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; font: 800 1.35rem/1 var(--font-display); color: var(--paper); text-decoration: none; letter-spacing: -0.01em; }
.brand-dot { display: grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 10px; background: var(--c); color: var(--paper); transform: rotate(-8deg); box-shadow: 0 4px 0 #9e1f52; }
.brand-sm { font-size: 1.05rem; }
.join-chip {
  justify-self: end; display: inline-flex; align-items: center; gap: 12px;
  padding: 8px 16px 8px 8px; border-radius: 18px; border: 1px solid var(--glass-edge);
  background: var(--glass); color: var(--paper); cursor: pointer; backdrop-filter: blur(12px);
  transition: transform 0.2s var(--spring);
}
.join-chip:hover { transform: scale(1.04); }
.join-chip-qr { width: 58px; height: 58px; background: var(--paper); border-radius: 10px; padding: 4px; }
.join-chip-text { display: grid; text-align: left; line-height: 1.1; }
.join-chip-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--muted); }
.join-chip-code { font: 800 1.35rem/1.1 var(--font-display); letter-spacing: 0.12em; }
.page-host.at-intro .join-chip { visibility: hidden; }

.arena { position: relative; display: grid; place-items: center; padding: 16px clamp(20px, 4vw, 64px); min-height: 0; perspective: 1600px; }
.controls { display: flex; justify-content: center; align-items: center; gap: 14px; padding: 0 20px 26px; flex-wrap: wrap; }
.controls .btn { font-size: 1.05rem; }
.btn-reveal { font-size: 1.2rem !important; padding: 1em 1.8em; }
.btn.armed { --btn-bg: var(--c); --btn-fg: var(--paper); animation: armed 0.9s ease-in-out infinite; }
@keyframes armed { 50% { transform: scale(1.05); } }
.skip-note { font-weight: 700; font-size: 0.9rem; color: var(--d); max-width: 14ch; line-height: 1.2; }

/* ---------- question card ---------- */

.card {
  width: min(1320px, 100%);
  max-height: 100%;
  display: flex; flex-direction: column; gap: clamp(14px, 2.2vh, 28px);
  padding: clamp(22px, 3.6vh, 44px) clamp(24px, 3.4vw, 56px);
  border-radius: 36px;
  background: linear-gradient(160deg, rgba(42, 33, 88, 0.78), rgba(18, 13, 36, 0.72));
  border: 1px solid var(--glass-edge);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(22px);
  position: relative;
}
.card::before {
  content: ""; position: absolute; inset: -2px; border-radius: inherit; padding: 2px;
  background: linear-gradient(120deg, var(--cat1), transparent 30%, transparent 70%, var(--cat2));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; opacity: 0.8; pointer-events: none;
}
.meta { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cat-badge {
  font: 800 clamp(0.85rem, 1.3vw, 1.05rem)/1 var(--font-display); letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0.55em 1em; border-radius: 999px; color: var(--ink);
  background: linear-gradient(120deg, var(--cat1), var(--cat2));
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}
.qnum { font-weight: 700; color: var(--muted); font-size: clamp(0.95rem, 1.4vw, 1.15rem); }
.diff { margin-left: auto; display: inline-flex; gap: 5px; align-items: center; color: var(--muted); font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; }
.diff i { width: 10px; height: 10px; border-radius: 3px; background: var(--faint); transform: rotate(45deg); }
.diff i.on { background: var(--d); }
.prompt {
  margin: 0; font-weight: 800; line-height: 1.04; text-wrap: balance;
  font-size: clamp(2rem, 4.2vw, 4.4rem);
}
.card.long .prompt { font-size: clamp(1.8rem, 3.4vw, 3.5rem); }

.choices { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: clamp(12px, 1.6vw, 20px); }
.choice {
  --tile: var(--a);
  display: flex; align-items: center; gap: 18px;
  padding: clamp(14px, 2.2vh, 24px) clamp(16px, 1.6vw, 24px);
  border-radius: 22px; background: var(--tile); color: var(--ink);
  font: 700 clamp(1.2rem, 2.1vw, 2rem)/1.15 var(--font-display);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.32);
  animation: tileIn 0.6s var(--spring) both; animation-delay: calc(250ms + var(--i) * 110ms);
  transition: opacity 0.5s ease, filter 0.5s ease, transform 0.5s var(--spring), box-shadow 0.5s ease;
  position: relative;
}
.choice[data-letter="B"] { --tile: var(--b); }
.choice[data-letter="C"] { --tile: var(--c); }
.choice[data-letter="D"] { --tile: var(--d); }
.letter {
  flex: none; display: grid; place-items: center;
  width: 1.9em; height: 1.9em; border-radius: 14px;
  background: var(--ink); color: var(--tile);
  font-weight: 800; font-size: 0.95em;
}
@keyframes tileIn { from { opacity: 0; transform: translateY(30px) scale(0.9) rotate(-2deg); } to { opacity: 1; transform: none; } }

.card.revealed .choice:not(.correct) { opacity: 0.28; filter: grayscale(0.7); transform: scale(0.97); }
.card.revealed .choice.correct { transform: scale(1.03); box-shadow: 0 8px 0 rgba(0, 0, 0, 0.32), 0 0 0 5px var(--paper), 0 0 60px var(--tile); animation: winner 0.9s var(--spring); z-index: 1; }
.choice.correct::after {
  content: "\2713"; position: absolute; right: -14px; top: -14px;
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--good); color: var(--ink); font-size: 1.5rem; font-weight: 800;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  transform: scale(0); animation: stamp 0.5s var(--spring) 0.35s forwards;
}
.card:not(.revealed) .choice.correct::after { display: none; }
@keyframes winner { 0% { transform: scale(1); } 35% { transform: scale(1.09) rotate(-1deg); } 65% { transform: scale(1.01) rotate(0.6deg); } 100% { transform: scale(1.03); } }
@keyframes stamp { to { transform: scale(1) rotate(-8deg); } }

.open-hint {
  display: inline-flex; align-items: center; gap: 14px; align-self: flex-start;
  padding: 16px 24px; border-radius: 20px; border: 2px dashed var(--glass-edge);
  color: var(--muted); font-weight: 700; font-size: clamp(1.05rem, 1.6vw, 1.4rem);
  animation: tileIn 0.6s var(--spring) 0.3s both;
}
.open-hint .pencil { font-size: 1.6em; animation: scribble 1.6s ease-in-out infinite; display: inline-block; }
@keyframes scribble { 0%, 100% { transform: rotate(-10deg); } 50% { transform: rotate(10deg) translateX(4px); } }

.answer-panel { display: grid; gap: 12px; }
.answer-panel[hidden] { display: none; }
.answer-reveal {
  display: inline-flex; align-items: baseline; gap: 18px; flex-wrap: wrap; justify-self: start;
  padding: 18px 28px; border-radius: 22px;
  background: var(--good); color: var(--ink);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3), 0 0 60px rgba(61, 220, 132, 0.4);
  transform-origin: top center;
  animation: flipIn 0.8s var(--spring) both;
}
.answer-reveal .label { font-weight: 800; text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.85rem; }
.answer-reveal .text { font: 800 clamp(1.8rem, 3.6vw, 3.4rem)/1 var(--font-display); }
@keyframes flipIn { from { opacity: 0; transform: rotateX(-85deg) translateY(-10px); } to { opacity: 1; transform: none; } }
.fun-fact {
  margin: 0; display: flex; gap: 12px; align-items: flex-start;
  color: var(--paper); font-size: clamp(1rem, 1.5vw, 1.35rem); max-width: 70ch;
  animation: slideUp 0.7s var(--ease-out) 0.45s both;
}
.fun-fact b { flex: none; color: var(--d); font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.8em; padding-top: 0.2em; }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* card transitions */
.card.enter { animation: cardIn 0.75s var(--ease-out) both; }
.card.enter-back { animation: cardInBack 0.65s var(--ease-out) both; }
.card.leave { animation: cardOut 0.38s ease-in both; }
.card.leave-back { animation: cardOutBack 0.38s ease-in both; }
.card.swipe { animation: swipe 0.5s cubic-bezier(0.55, 0, 0.8, 0.2) both; }
.card.enter-swap { animation: swapIn 0.7s var(--spring) both; }
@keyframes cardIn { from { opacity: 0; transform: translateX(80px) rotateY(-12deg) scale(0.95); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes cardInBack { from { opacity: 0; transform: translateX(-80px) rotateY(12deg) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes cardOut { to { opacity: 0; transform: translateX(-90px) rotateY(12deg) scale(0.95); filter: blur(6px); } }
@keyframes cardOutBack { to { opacity: 0; transform: translateX(90px) rotateY(-12deg) scale(0.95); } }
@keyframes swipe { to { opacity: 0; transform: translate(-40vw, -6vh) rotate(-16deg); } }
@keyframes swapIn { from { opacity: 0; transform: translateY(60px) scale(0.85) rotate(3deg); } to { opacity: 1; transform: none; } }

.skip-stamp {
  position: absolute; left: 50%; top: 40%; z-index: 5; pointer-events: none;
  font: 800 clamp(3rem, 8vw, 7rem)/1 var(--font-display); color: var(--c);
  border: 8px solid var(--c); border-radius: 20px; padding: 0.1em 0.4em;
  transform: translate(-50%, -50%) rotate(-12deg) scale(2); opacity: 0;
  animation: skipStamp 0.9s var(--spring) forwards;
}
@keyframes skipStamp {
  30% { opacity: 1; transform: translate(-50%, -50%) rotate(-12deg) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) rotate(-12deg) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(-12deg) scale(0.9); }
}

/* ---------- intro ---------- */

.intro { width: min(1200px, 100%); display: grid; grid-template-columns: auto 1fr; gap: clamp(28px, 5vw, 80px); align-items: center; }
.intro-qr {
  position: relative; padding: 18px; border-radius: 32px; background: var(--paper);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: popIn 0.9s var(--spring) both;
}
@property --ring { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
.intro-qr {
  border: 10px solid transparent;
  background: linear-gradient(var(--paper), var(--paper)) padding-box,
              conic-gradient(from var(--ring), var(--a), var(--d), var(--b), var(--c), var(--a)) border-box;
  animation: popIn 0.9s var(--spring) both, ring 5s linear infinite;
}
@keyframes ring { to { --ring: 360deg; } }
.intro-qr img { display: block; width: clamp(220px, 32vh, 380px); height: auto; background: var(--paper); border-radius: 12px; }
.intro-copy .eyebrow { font-size: 1rem; }
.intro-copy h1 { margin: 0; font-size: clamp(3rem, 7vw, 6.4rem); line-height: 0.9; font-weight: 800; }
.intro-code { display: flex; gap: 10px; margin: 26px 0 16px; flex-wrap: wrap; }
.intro-code span {
  display: grid; place-items: center; width: 1.3em; height: 1.45em; border-radius: 14px;
  font: 800 clamp(2.6rem, 5vw, 4.4rem)/1 var(--font-display);
  background: var(--paper); color: var(--ink); box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
  animation: tileIn 0.6s var(--spring) both; animation-delay: calc(300ms + var(--i) * 90ms);
}
.intro-code span:nth-child(4n+1) { background: var(--a); }
.intro-code span:nth-child(4n+2) { background: var(--b); }
.intro-code span:nth-child(4n+3) { background: var(--c); }
.intro-code span:nth-child(4n+4) { background: var(--d); }
.intro-url { color: var(--muted); font-size: 1.15rem; word-break: break-all; margin: 0 0 10px; }
.intro-sheets { color: var(--muted); }

/* ---------- finale / answer key ---------- */

.finale { width: min(1400px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.finale-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.finale h1 { margin: 0; font-size: clamp(2.6rem, 5.6vw, 5.2rem); line-height: 0.9; font-weight: 800; }
.finale h1 .bounce { display: inline-block; animation: bounceIn 0.8s var(--spring) both; animation-delay: calc(var(--i) * 45ms); }
@keyframes bounceIn { from { opacity: 0; transform: translateY(-60px) rotate(-10deg); } to { opacity: 1; transform: none; } }
.finale-sub { color: var(--muted); margin: 6px 0 0; font-size: 1.15rem; }

@keyframes keyIn { from { opacity: 0; transform: translateX(-30px) scale(0.96); } to { opacity: 1; transform: none; } }

/* ---------- toast + modal ---------- */

.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translate(-50%, 30px); opacity: 0;
  padding: 14px 22px; border-radius: 16px; background: var(--paper); color: var(--ink);
  font-weight: 700; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4); pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s var(--spring); z-index: 20; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.qr-modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(18, 13, 36, 0.8); backdrop-filter: blur(10px); padding: 16px; }
.qr-modal-card { background: var(--paper); color: var(--ink); border-radius: 32px; padding: 28px; text-align: center; display: grid; gap: 8px; justify-items: center; }
.qr-modal-card img { width: min(60vh, 80vw); height: auto; }
.qr-modal-code { font: 800 3rem/1 var(--font-display); letter-spacing: 0.2em; margin: 6px 0 0; }
.qr-modal-url { margin: 0 0 8px; color: #5a5270; word-break: break-all; }
.qr-modal .btn-ghost { --btn-bg: var(--ink); }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

/* ---------- player (phone) ---------- */

.page-play { overflow-x: hidden; }
.play { width: min(560px, 100%); margin: 0 auto; padding: 0 0 40px; min-height: 100dvh; }
.play-top { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 10px; }
#view { padding: 14px 16px 0; display: grid; gap: 16px; }
.p-card {
  border-radius: 26px; padding: 20px; display: grid; gap: 14px;
  background: linear-gradient(160deg, rgba(42, 33, 88, 0.82), rgba(18, 13, 36, 0.78));
  border: 1px solid var(--glass-edge); backdrop-filter: blur(18px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  animation: popIn 0.6s var(--spring) both;
}
.p-card .meta { gap: 10px; }
.p-card .cat-badge { font-size: 0.75rem; }
.p-card .qnum { font-size: 0.9rem; }
.p-prompt { margin: 0; font: 800 1.55rem/1.12 var(--font-display); text-wrap: balance; }
.p-choices { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.p-choice {
  --tile: var(--a);
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: 16px; border: 0; cursor: pointer;
  background: var(--tile); color: var(--ink);
  font: 700 1.05rem/1.2 var(--font-display);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.2s var(--spring), opacity 0.4s ease, filter 0.4s ease, box-shadow 0.3s ease;
  animation: tileIn 0.5s var(--spring) both; animation-delay: calc(120ms + var(--i) * 70ms);
  -webkit-tap-highlight-color: transparent;
}
.p-choice:active { transform: scale(0.97); }
.p-choice[data-letter="B"] { --tile: var(--b); }
.p-choice[data-letter="C"] { --tile: var(--c); }
.p-choice[data-letter="D"] { --tile: var(--d); }
.p-choice .letter { width: 1.9em; height: 1.9em; border-radius: 10px; font-size: 0.9em; }
.p-choice.picked { box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3), 0 0 0 4px var(--paper); }
.p-card.revealed .p-choice:not(.correct) { opacity: 0.3; filter: grayscale(0.7); }
.p-card.revealed .p-choice.correct { box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3), 0 0 0 4px var(--good), 0 0 30px var(--tile); }
.p-answer { display: grid; gap: 6px; }
.p-answer label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.p-input {
  width: 100%; font: 700 1.2rem/1.2 var(--font-body); padding: 14px 16px;
  border-radius: 14px; border: 2px solid transparent; background: var(--paper); color: var(--ink);
}
.p-input:focus { outline: none; border-color: var(--d); }
.p-input:disabled { opacity: 0.75; }
.p-saved { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; transition: opacity 0.3s; }
.p-reveal { display: grid; gap: 6px; padding: 14px 16px; border-radius: 16px; background: var(--good); color: var(--ink); animation: flipIn 0.7s var(--spring) both; transform-origin: top; }
.p-reveal .label { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.p-reveal .text { font: 800 1.45rem/1.1 var(--font-display); }
.p-fact { margin: 0; color: var(--muted); font-size: 0.98rem; animation: slideUp 0.6s var(--ease-out) 0.3s both; }
.p-fact b { color: var(--d); }

.p-wait { text-align: center; padding: 34px 20px; }
.p-wait h1 { margin: 0 0 8px; font-size: 2.3rem; line-height: 1; }
.dots { display: inline-flex; gap: 8px; margin: 18px 0 8px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--a); animation: hop 1.1s ease-in-out infinite; }
.dots i:nth-child(2) { background: var(--b); animation-delay: 0.12s; }
.dots i:nth-child(3) { background: var(--c); animation-delay: 0.24s; }
.dots i:nth-child(4) { background: var(--d); animation-delay: 0.36s; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-14px); } }

.p-sheet summary { cursor: pointer; font-weight: 700; color: var(--muted); padding: 6px 0; list-style: none; }
.p-sheet summary::-webkit-details-marker { display: none; }
.p-sheet summary::before { content: "\25B8"; display: inline-block; margin-right: 8px; transition: transform 0.2s; }
.p-sheet[open] summary::before { transform: rotate(90deg); }
.p-sheet ol { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.p-sheet li { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; border-radius: 12px; background: var(--glass); }
.p-sheet li .n { font-weight: 800; color: var(--d); min-width: 1.6em; }
.p-sheet li .v { word-break: break-word; }
.p-sheet li .v.empty { color: var(--muted); font-style: italic; }

.p-score {
  position: sticky; top: 8px; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-radius: 20px;
  background: var(--paper); color: var(--ink); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: popIn 0.6s var(--spring) both;
}
.p-score .big { font: 800 2.4rem/1 var(--font-display); }
.p-score .big.bump { animation: bump 0.4s var(--spring); }
@keyframes bump { 50% { transform: scale(1.25); } }

.conn { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); padding: 8px 14px; border-radius: 999px; background: var(--paper); color: var(--ink); font-weight: 700; font-size: 0.9rem; }

/* ---------- players (host intro + counter) ---------- */

.intro-players-title { margin: 14px 0 8px; font-weight: 700; color: var(--paper); font-size: 1.1rem; }
.player-chips { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; max-height: 22vh; overflow: auto; }
.player-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--glass-edge); font-weight: 700;
  animation: chipIn 0.55s var(--spring) both; animation-delay: calc(var(--i) * 40ms);
}
.player-chip .emo { display: grid; place-items: center; width: 1.9em; height: 1.9em; border-radius: 50%; background: var(--paper); font-size: 1rem; }
.player-chip .emo.initial { color: var(--ink); font-family: var(--font-display); font-weight: 800; background: var(--d); }
@keyframes chipIn { from { opacity: 0; transform: scale(0.4) translateY(20px); } to { opacity: 1; transform: none; } }
.answered-chip {
  font-weight: 800; padding: 0.6em 1em; border-radius: 999px; background: var(--paper); color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3); font-variant-numeric: tabular-nums;
}

/* ---------- results walkthrough (host) ---------- */

.card.refresh { animation: none; }
.result-card { gap: clamp(10px, 1.8vh, 20px); }
.result-card .answer-reveal { align-self: flex-start; }
.result-card .tally { margin-left: auto; font-weight: 800; color: var(--d); }
.result-q { margin: 0; color: var(--muted); font: 700 clamp(1.2rem, 2vw, 1.8rem)/1.2 var(--font-display); text-wrap: balance; }
.entries { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; max-height: 38vh; overflow: auto; padding: 4px; }
.entry {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; gap: 2px 10px; align-items: center;
  text-align: left; padding: 10px 14px; border-radius: 16px; cursor: pointer; font: inherit; color: var(--paper);
  border: 2px solid transparent; background: var(--glass);
  animation: tileIn 0.5s var(--spring) both; animation-delay: calc(350ms + var(--i) * 70ms);
  transition: transform 0.2s var(--spring), border-color 0.3s, background 0.3s;
}
.entry:hover:not(:disabled) { transform: translateY(-2px); }
.entry:disabled { cursor: default; opacity: 0.6; }
.entry.right { border-color: var(--good); background: rgba(61, 220, 132, 0.14); }
.entry.wrong { border-color: rgba(255, 90, 95, 0.55); background: rgba(255, 90, 95, 0.1); }
.entry-who { font-weight: 800; font-size: 0.95rem; }
.entry-ans { grid-row: 2; font-size: 1.05rem; word-break: break-word; }
.entry.blank .entry-ans { font-style: italic; color: var(--muted); }
.entry-mark {
  grid-column: 2; grid-row: 1 / span 2; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; color: var(--ink); background: var(--bad);
}
.entry.right .entry-mark { background: var(--good); }

/* ---------- leaderboard (host) ---------- */

.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; overflow: auto; min-height: 0; }
.board-row {
  display: grid; grid-template-columns: 3.2rem minmax(8rem, 16rem) 1fr 3.5rem; align-items: center; gap: 14px;
  padding: 10px 16px; border-radius: 18px; background: var(--glass); border: 1px solid var(--glass-edge);
  animation: keyIn 0.6s var(--spring) both; animation-delay: calc(500ms + var(--i) * 260ms);
}
.board-rank { font: 800 1.6rem/1 var(--font-display); text-align: center; }
.board-name { font: 800 clamp(1.1rem, 1.8vw, 1.6rem)/1.1 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-bar { height: 18px; border-radius: 999px; background: linear-gradient(90deg, var(--c), var(--a), var(--d)); transform-origin: left; transform: scaleX(0);
  width: calc(var(--w) * 100%); animation: grow 0.9s var(--ease-out) forwards; animation-delay: calc(700ms + var(--i) * 260ms); }
.board-score { font: 800 clamp(1.4rem, 2.2vw, 2rem)/1 var(--font-display); text-align: right; font-variant-numeric: tabular-nums; }
.board-row.rank-1 { border-color: var(--d); box-shadow: 0 0 40px rgba(255, 210, 63, 0.35); }
.board-row.rank-1 .board-name { color: var(--d); }
@keyframes grow { to { transform: scaleX(1); } }

/* ---------- phone: join, locked results, leaderboard ---------- */

.join-card { gap: 12px; }
.p-label { margin: 6px 0 0; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji {
  aspect-ratio: 1; border-radius: 12px; border: 2px solid transparent; background: var(--glass); font-size: 1.35rem; cursor: pointer;
  transition: transform 0.2s var(--spring), border-color 0.2s, background 0.2s; padding: 0;
}
.emoji.on { border-color: var(--d); background: rgba(255, 210, 63, 0.18); transform: scale(1.12); }
.join-error { color: var(--bad); font-weight: 700; min-height: 1.2em; margin: 0; }
.linkish { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; cursor: pointer; justify-self: center; padding: 8px; }
.p-me { margin: 0; color: var(--muted); }
.p-me b { color: var(--paper); }
.p-locked { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 14px; background: var(--paper); color: var(--ink); font-weight: 700; }
.p-card.result .q { margin: 0; color: var(--muted); font: 700 1.15rem/1.25 var(--font-display); }
.p-mine { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 14px; font-weight: 700; animation: slideUp 0.5s var(--ease-out) 0.3s both; }
.p-mine.right { background: rgba(61, 220, 132, 0.16); border: 2px solid var(--good); }
.p-mine.wrong { background: rgba(255, 90, 95, 0.12); border: 2px solid var(--bad); }
.p-mine .verdict { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--ink); font-weight: 800; }
.p-mine.right .verdict { background: var(--good); }
.p-mine.wrong .verdict { background: var(--bad); }
.p-running { margin: 0; text-align: center; color: var(--muted); font-weight: 700; }
.p-board { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.p-board li {
  display: grid; grid-template-columns: 2.2rem 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 14px;
  background: var(--glass); border: 1px solid var(--glass-edge); animation: keyIn 0.5s var(--spring) both; animation-delay: calc(var(--i) * 70ms);
}
.p-board li.me { border-color: var(--d); background: rgba(255, 210, 63, 0.14); }
.p-board .r { font: 800 1.2rem/1 var(--font-display); text-align: center; }
.p-board .n { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-board .s { font: 800 1.3rem/1 var(--font-display); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .page-host { overflow: auto; }
  .host { height: auto; min-height: 100dvh; }
  .topbar { grid-template-columns: 1fr auto; padding: 14px 16px 0; }
  .topbar .pips { grid-column: 1 / -1; grid-row: 2; }
  .choices { grid-template-columns: 1fr; }
  .intro { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .intro-code { justify-content: center; }
  .controls { position: sticky; bottom: 0; padding: 12px 16px 16px; background: linear-gradient(transparent, var(--ink) 40%); }
  .controls kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
  .sunburst, .blob, .grain { animation: none !important; }
}

