:root {
  --bg: #14112b; --bg2: #221b4a; --card: rgba(255,255,255,.08); --fg: #fff; --muted: #b9b3e0;
  --accent: #ffd23f; --accent-fg: #1a1440; --good: #2ecc71; --bad: #ff5d73;
  --a1: #e21b3c; --a2: #1368ce; --a3: #d89e00; --a4: #26890c;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--fg); background: radial-gradient(120% 90% at 50% 0%, var(--bg2), var(--bg));
  background-attachment: fixed; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.1; }
.muted { color: var(--muted); }
.center { text-align: center; }
.card { background: var(--card); border-radius: 18px; padding: 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; font-weight: 800; color: var(--accent-fg); background: var(--accent); border: 0; border-radius: 14px;
  padding: 14px 20px; cursor: pointer; min-height: 48px; box-shadow: 0 4px 0 rgba(0,0,0,.25);
}
button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
button.secondary { background: var(--card); color: var(--fg); box-shadow: none; }
button.danger { background: var(--bad); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select {
  font: inherit; color: var(--fg); background: rgba(0,0,0,.28); border: 2px solid rgba(255,255,255,.18);
  border-radius: 12px; padding: 12px 14px; min-height: 48px; width: 100%;
}
input:focus, select:focus, button:focus-visible, a.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
select option { color: #111; }
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }

/* ---------- player (phone) ---------- */
.p-wrap { width: 100%; max-width: 520px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.p-top { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; font-weight: 700; }
.p-top > :first-child { justify-self: start; }
.p-top > :last-child { justify-self: end; }
.p-logo { height: 30px; width: auto; display: block; }
.p-top .pill { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-big { width: min(80vw, 330px); height: auto; display: block; margin: 0 auto; }
.p-top .pill { background: var(--card); padding: 6px 12px; border-radius: 999px; font-size: .9rem; }
.code-big { font-size: 3rem; letter-spacing: .25em; font-weight: 900; color: var(--accent); }
.avatars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatars button { padding: 6px 0; font-size: 1.6rem; min-height: 48px; background: var(--card); box-shadow: none; }
.avatars button[aria-pressed="true"] { outline: 3px solid var(--accent); background: rgba(255,255,255,.2); }
.plist { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--card); border-radius: 999px; padding: 6px 12px; font-weight: 700; display: inline-flex; gap: 6px; align-items: center; }
.chip.off { opacity: .45; text-decoration: line-through; }
.chip.pop { animation: pop .4s ease; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }

.timerbar { height: 10px; background: rgba(255,255,255,.15); border-radius: 99px; overflow: hidden; }
.timerbar > i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.q-text { font-size: 1.35rem; font-weight: 800; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex: 1; align-content: stretch; }
.ans {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  min-height: 110px; color: #fff; font-size: 1.05rem; padding: 10px; border-radius: 16px;
}
.ans .shape { font-size: 2rem; line-height: 1; }
.ans.s0 { background: var(--a1); } .ans.s1 { background: var(--a2); } .ans.s2 { background: var(--a3); } .ans.s3 { background: var(--a4); }
.ans.dim { opacity: .45; }
.ans[aria-disabled="true"] { cursor: default; }
.ans.mine { outline: 5px solid #fff; }
button.power { display: block; width: 100%; text-align: left; margin-top: 8px; }
button.power .sub { display: block; font-weight: 500; font-size: .85em; opacity: .85; margin-top: 2px; }
button.power.picked { outline: 4px solid var(--accent); }
button.power[disabled] { opacity: .45; }
.events { font-weight: 700; display: grid; gap: 6px; text-align: center; }
#react-layer.phone .react-float .em { font-size: 2.6rem; } #react-layer.phone .react-float .who { font-size: .8rem; }
.mgr-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; flex-wrap: wrap; } .mgr-row .nm { flex: 1; min-width: 7em; font-weight: 700; } .mgr-row button { padding: 6px 12px; width: auto; }
.card.warn { border: 2px solid var(--bad); } .invite-text { white-space: pre-line; }
.react-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.react-bar .react { padding: 8px 12px; font-size: 1.5rem; }
.ans.right { outline: 5px solid var(--good); }
.status { font-size: 1.6rem; font-weight: 900; }
.good { color: var(--good); } .bad { color: var(--bad); }
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lb li { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 10px 14px; font-weight: 700; }
.lb li.me { outline: 3px solid var(--accent); }
.lb .rk { width: 2ch; text-align: center; color: var(--accent); }
.lb .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .dl { color: var(--good); font-size: .85rem; }
.lb.surv .hl { white-space: nowrap; }
.lb.surv li.gone { opacity: .5; }
.lb.surv li.justout { outline: 3px solid var(--bad); opacity: .85; }
/* Survivor on the TV: a card per player, hearts while in, a skull once out */
.surv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15vw, 1fr)); gap: 1.2vw; max-width: 92vw; margin: 0 auto; width: 100%; }
.surv-card { background: var(--card); border-radius: 1.4vw; padding: 1vw .6vw; text-align: center; transition: opacity .6s, filter .6s; }
.surv-card .av { font-size: 3.4vw; line-height: 1.1; }
.surv-card .nm { font-size: 1.5vw; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.surv-card .hl { font-size: 1.7vw; margin-top: .3vw; min-height: 1.4em; }
.surv-card.hit { outline: .25vw solid var(--bad); }
.surv-card.gone { opacity: .35; filter: grayscale(1); }
.surv-card.justout { opacity: 1; filter: none; outline: .3vw solid var(--bad); animation: kjshake .6s ease; }
.surv-grid.dense { grid-template-columns: repeat(auto-fill, minmax(11vw, 1fr)); gap: .8vw; }
.surv-grid.dense .av { font-size: 2.4vw; } .surv-grid.dense .nm { font-size: 1.1vw; } .surv-grid.dense .hl { font-size: 1.2vw; }
.surv-grid.many { grid-template-columns: repeat(auto-fill, minmax(8.5vw, 1fr)); }
.surv-grid.many .av { font-size: 1.8vw; } .surv-grid.many .nm { font-size: .9vw; } .surv-grid.many .hl { font-size: .9vw; }
@keyframes kjshake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-.8vw); } 40% { transform: translateX(.8vw); } 60% { transform: translateX(-.5vw); } 80% { transform: translateX(.5vw); } }
.surv-win { display: flex; justify-content: center; flex-wrap: wrap; gap: 2.5vw; margin: 2vw 0; }
.surv-champ { background: var(--accent); color: var(--accent-fg); border-radius: 2vw; padding: 2vw 4vw; text-align: center; min-width: 22vw; }
.surv-champ .av { font-size: 8vw; line-height: 1.1; } .surv-champ .nm { font-size: 3.2vw; font-weight: 900; } .surv-champ .hl { font-size: 2.4vw; margin-top: .6vw; }
.err { background: var(--bad); color: #fff; padding: 10px 14px; border-radius: 12px; font-weight: 700; }
.conn { position: fixed; top: 0; left: 0; right: 0; background: var(--bad); color: #fff; text-align: center; padding: 6px; font-weight: 700; z-index: 50; }

/* ---------- TV display ---------- */
body.tv { font-size: clamp(16px, 1.7vw, 34px); cursor: none; }
.tv-wrap { flex: 1; display: flex; flex-direction: column; padding: 3vw; gap: 2vw; min-height: 100vh; position: relative; z-index: 1; }
.tv h1 { font-size: 4.2em; } .tv h2 { font-size: 2.6em; }
.tv .code-big { font-size: 9em; }
.tv-top { display: flex; justify-content: space-between; align-items: center; font-size: 1.4em; font-weight: 800; color: var(--muted); padding-right: 9vw; }
.tv-q { font-size: 2.8em; font-weight: 900; line-height: 1.15; text-align: center; margin: auto 0; }
.tv-ans { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4vw; }
.tv-ans .ans { flex-direction: row; justify-content: flex-start; padding: 1vw 2vw; min-height: 6.5vw; font-size: 1.8em; gap: 1.2vw; text-align: left; }
.tv-ans .ans .shape { font-size: 1.3em; }
.tv-ans .ans.right { outline: 8px solid var(--good); transform: scale(1.02); }
.tv-ans .ans .bar { margin-left: auto; font-weight: 900; }
.ring { position: absolute; right: 3vw; top: 3vw; width: 7vw; height: 7vw; display: grid; place-items: center; border-radius: 50%;
  font-size: 2em; font-weight: 900; background: conic-gradient(var(--accent) var(--pct, 100%), rgba(255,255,255,.15) 0); }
.ring span { background: var(--bg); width: 84%; height: 84%; border-radius: 50%; display: grid; place-items: center; }
.ring.urgent span { color: var(--bad); }
.tv-lb { display: flex; flex-direction: column; gap: .8vw; max-width: 70vw; margin: 0 auto; width: 100%; }
.tv-lb .rowx { display: flex; align-items: center; gap: 1.5vw; background: var(--card); border-radius: 1.2vw; padding: .9vw 2vw;
  /* Big for a few players; shrinks with more rows (--n is set by tv.js) so up to 8 rows always fit on the screen. */
  font-size: 1.6em; font-size: min(2.1em, max(14px, calc((62vh / var(--n, 5) - 2.6vw) / 1.25))); font-weight: 800; transition: transform .8s cubic-bezier(.2,.9,.2,1), opacity .4s; }
.tv-lb .rowx .rk { width: 2.2ch; color: var(--accent); }
.tv-lb .rowx .nm { flex: 1; }
.tv-lb .rowx .dl { color: var(--good); font-size: .65em; }
.tv-lb .rowx .mv { font-size: .6em; width: 3ch; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 2vw; min-height: 34vh; margin-top: 1vh; } /* min-height: a podium step grows to fit its name, title and score rather than cutting them off */
.podium .step { width: 20vw; padding-bottom: .8vh; border-radius: 1.2vw 1.2vw 0 0; background: var(--card); text-align: center; padding-top: 1vh; display: flex; flex-direction: column; align-items: center;
  animation: rise 1s ease both; }
.podium .step.p1 { min-height: 34vh; background: var(--accent); color: var(--accent-fg); animation-delay: 1.6s; }
.podium .step.p2 { min-height: 29vh; animation-delay: .9s; } .podium .step.p3 { min-height: 26vh; animation-delay: .2s; } /* tall enough for avatar, name, score and medal */
.tv h1.fin { font-size: 3em; }
.podium .av { font-size: 3.4em; } .podium .nm { font-weight: 900; font-size: 1.5em; } .podium .sc { font-size: 1.2em; font-weight: 800; }
@keyframes rise { from { transform: translateY(100%); opacity: 0; } to { transform: none; opacity: 1; } }
.awards { display: flex; justify-content: center; gap: 2vw; flex-wrap: wrap; font-size: 1.3em; }
.awards .card { text-align: center; min-width: 18vw; }
.qr { background: #fff; padding: 1vw; border-radius: 1vw; line-height: 0; } .qr svg { width: 14vw; height: 14vw; display: block; }
.qr.small svg { width: 9vw; height: 9vw; }
.lobby-join .qr { padding: .5vw; } .lobby-join .qr svg { width: 11vw; height: 11vw; }
.lobby-join { display: flex; align-items: center; justify-content: center; gap: 6vw; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: .6vw; }
.tv-events { display: grid; gap: .5vw; text-align: center; font-size: 1.5em; font-weight: 800; background: var(--card); border-radius: 1.2vw; padding: 1vw 2vw; max-width: 70vw; margin: 0 auto; }
.tv-lb .rowx .dl.neg { color: var(--bad); }
.podium .ttl { font-size: .75em; line-height: 1.15; font-weight: 700; opacity: .85; padding: 0 .8vw; }
#react-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.react-float { position: absolute; bottom: -12vh; display: flex; flex-direction: column; align-items: center; animation: floatup 4.2s ease-out forwards; }
.react-float .em { font-size: 4.2em; line-height: 1; } .react-float .who { font-size: .9em; font-weight: 800; background: rgba(0,0,0,.45); border-radius: 99px; padding: .1em .7em; }
@keyframes floatup { from { transform: translateY(0) scale(.7); opacity: 0; } 12% { opacity: 1; transform: translateY(-14vh) scale(1); } to { transform: translateY(-105vh) scale(1.1); opacity: 0; } }
.qr-corner.right { left: auto; right: 3vw; }
.qr-corner { position: fixed; left: 3vw; bottom: 3vw; display: flex; flex-direction: column; align-items: center; gap: .4vw; font-size: .8em; }
.joinurl { font-size: 2.2em; font-weight: 800; }
.sound-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.75); display: grid; place-items: center; z-index: 100; text-align: center; cursor: pointer; font-size: 2em; }
.media { max-height: 30vh; max-width: 62vw; object-fit: contain; border-radius: 1vw; margin: 0 auto; display: block; }
.media.big { max-height: 46vh; max-width: 80vw; }
.media.sm { max-height: 24vh; }
.tv-ans.compact { grid-template-columns: repeat(4, 1fr); gap: 1vw; }
.tv-ans.compact .ans { min-height: 0; padding: .6vw 1vw; font-size: 1.1em; gap: .6vw; }
.tv-ans.compact .ans .shape { font-size: 1.1em; }
.media.blur { filter: blur(20px); animation: sharpen 20s linear forwards; }
@keyframes sharpen { from { filter: blur(20px); } 85% { filter: blur(0); } to { filter: blur(0); } }
.zoomwrap { overflow: hidden; border-radius: 1vw; margin: 0 auto; width: fit-content; max-width: 80vw; line-height: 0; }
.media.zoomout { transform: scale(3.2); animation: zoomout 20s linear forwards; }
@keyframes zoomout { from { transform: scale(3.2); } 90% { transform: scale(1); } to { transform: scale(1); } }
.media.sm.blur, .media-fig .media { filter: none; animation: none; }
.media-fig { margin: 0 auto; text-align: center; }
/* anagram puzzles (TV only): a hint and the jumbled letters as tiles */
.anagram { text-align: center; }
.anagram .hint { display: inline-block; background: rgba(255,255,255,.14); border-radius: 999px; padding: .2em .9em; font-size: 1.3em; font-weight: 800; color: #ffd23f; margin-bottom: 1.2vh; }
.anagram .tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.6vw 2.4vw; }
.anagram .word { display: flex; gap: .5vw; }
.anagram .tile { display: inline-flex; align-items: center; justify-content: center; width: 5.6vw; height: 6.8vw; max-width: 11vh; border-radius: .7vw; background: #ffd23f; color: #14112b; font-size: 3.2em; font-weight: 900; box-shadow: 0 .5vw 0 rgba(0,0,0,.35); }
.odd { text-align: center; }
.oddgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 1vw 1.4vw; width: min(56vw, 96vh); margin: 0 auto; }
.oddgrid.rev { width: min(44vw, 68vh); }
.tv-q.odd-why { font-size: 1.6em; line-height: 1.2; }
.oddpic { margin: 0; position: relative; border-radius: .8vw; overflow: hidden; background: #000; border: .35vw solid rgba(255,255,255,.2); }
.oddpic img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.oddpic figcaption { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; gap: .6vw; }
.oddpic .letter { flex: none; background: #ffd23f; color: #14112b; font-weight: 900; font-size: 2.2em; line-height: 1; padding: .12em .4em; border-top-right-radius: .6vw; }
.oddpic .nm { background: rgba(0,0,0,.72); color: #fff; font-weight: 800; font-size: 1.05em; line-height: 1.15; padding: .2em .6em; border-radius: .4vw; margin-bottom: .3vw; min-width: 0; }
.oddpic.right { border-color: var(--good); box-shadow: 0 0 0 .3vw var(--good); }
.oddpic.dim { opacity: .55; }
.odd .credit { font-size: .55em; color: var(--muted); margin-top: .4vh; }
.media-fig .credit { font-size: .6em; color: var(--muted); margin-top: .4vh; }
.fall { position: fixed; top: -10vh; font-size: 3em; animation: fall linear forwards; z-index: 0; pointer-events: none; }
@keyframes fall { to { transform: translateY(115vh) rotate(360deg); } }

/* ---------- themed background (client/js/scene.js) ---------- */
#kj-scene { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 0; overflow: hidden; pointer-events: none; }
html.has-scene { background: var(--bg); }
html.has-scene body { background: transparent; }
#kj-scene { background: linear-gradient(180deg, var(--bg2), var(--bg)); } /* the theme's own gradient overrides this */
html.has-scene #app, html.has-scene .site { position: relative; z-index: 1; }
#kj-scene > * { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
.sc-glow { opacity: .55; }
.sc-img { background-size: cover; background-position: center; opacity: 0; transition: opacity .8s; }
.sc-img.on { opacity: 1; }
.sc-horizon { top: auto !important; right: 0; bottom: 0; left: 0; }
.sc-horizon svg { display: block; width: 100%; height: 100%; }
.sc-parts { overflow: hidden; }
.sc-p { position: absolute; left: var(--x); top: 0; font-size: var(--s); opacity: .75; will-change: transform;
  animation-duration: var(--d); animation-delay: var(--w); animation-iteration-count: infinite; animation-timing-function: linear; }
.sc-p.fall { animation-name: sc-fall; }
.sc-p.rise { top: auto; bottom: 0; animation-name: sc-rise; }
.sc-p.drift { top: var(--y); animation-name: sc-drift; animation-timing-function: ease-in-out; }
.sc-p.twinkle { top: var(--y); animation-name: sc-twinkle; animation-timing-function: ease-in-out; }
@keyframes sc-fall { from { transform: translate3d(0, -12vh, 0) rotate(0); } 50% { transform: translate3d(var(--sway), 52vh, 0) rotate(180deg); } to { transform: translate3d(0, 112vh, 0) rotate(360deg); } }
@keyframes sc-rise { from { transform: translate3d(0, 12vh, 0); opacity: 0; } 15% { opacity: .8; } to { transform: translate3d(var(--sway), -112vh, 0); opacity: 0; } }
@keyframes sc-drift { 0%, 100% { transform: translate3d(0, 0, 0) rotate(-8deg); } 50% { transform: translate3d(var(--sway), -3vh, 0) rotate(8deg); } }
@keyframes sc-twinkle { 0%, 100% { opacity: .15; transform: scale(.7); } 50% { opacity: .95; transform: scale(1.15); } }

@media (prefers-reduced-motion: reduce) {
  .surv-card.justout { animation: none; }
  .media.blur { animation: none; filter: blur(6px); }
  .media.zoomout { animation: none; transform: scale(1.8); }
  .react-float { animation-duration: 2s; }
  .sc-p { animation: none; opacity: .5; }
  .sc-p.fall, .sc-p.rise { top: var(--y); bottom: auto; }
  .chip.pop, .podium .step, .fall { animation: none; }
  .tv-lb .rowx { transition: none; }
}

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* A message from the server (a restart is coming), above everything else on phones and the TV */
.server-notice { position: fixed; left: 0; right: 0; top: 0; z-index: 200; padding: 12px 16px; background: var(--bad, #c0392b); color: #fff; font-weight: 700; text-align: center; box-shadow: 0 2px 12px rgba(0,0,0,.4); }
