:root {
  --bg: #120a24;
  --bg2: #1e1240;
  --ink: #f4f1ff;
  --dim: #a99fd0;
  --pink: #ff3d7f;
  --yellow: #ffd23f;
  --green: #3ddc84;
  --red: #ff4d4d;
  --cyan: #3de0ff;
  --orange: #ff9f1c;
  /* party mode: bubble numbers on the TV match the phone buttons */
  --c1: var(--pink);
  --c2: var(--cyan);
  --c3: var(--orange);
  --bubble: #ffffff;
  --bubble-ink: #111111;
  --px: 4px;
  --font: 'Press Start 2P', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.6;
  min-height: 100vh;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 2px, transparent 2px 4px),
    radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 1100px; margin: 0 auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; }
a { color: var(--cyan); }
h2, h3 { font-size: 14px; color: var(--yellow); text-align: center; margin: 18px 0 10px; }
h3 { font-size: 11px; }
.small { font-size: 9px; color: var(--dim); }

.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.logo { background: none; border: 0; font-size: 18px; cursor: pointer; padding: 6px 0; letter-spacing: 1px;
  text-shadow: 3px 3px 0 var(--pink); }
.logo span { color: var(--yellow); }
.icon-btn { background: var(--bg2); border: 3px solid var(--ink); width: 40px; height: 40px; font-size: 16px; cursor: pointer; }
.icon-btn.off { opacity: .4; text-decoration: line-through; }

.btn {
  display: inline-block; font-size: 12px; padding: 12px 16px; cursor: pointer;
  background: var(--pink); color: #fff; border: 0;
  box-shadow: 0 var(--px) 0 #9a1b48, inset 0 0 0 3px #fff;
  transition: transform .05s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #9a1b48, inset 0 0 0 3px #fff; }
.btn.big { font-size: 15px; padding: 16px 22px; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 3px var(--dim); color: var(--dim); }
.btn.small-btn { font-size: 10px; padding: 10px 12px; }
.btn:focus-visible, .bubble:focus-visible, .picker button:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 3px; }

.screen { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card { width: 100%; max-width: 520px; background: rgba(0,0,0,.35); border: 3px solid var(--dim); padding: 18px 16px; text-align: center; }
.eyebrow { color: var(--pink); margin: 0 0 6px; }
.today { font-size: 13px; margin: 0 0 14px; color: var(--yellow); }
.stats { display: flex; justify-content: space-around; margin-top: 16px; }
.stats div { display: flex; flex-direction: column; gap: 6px; }
.stats b { font-size: 18px; color: var(--cyan); }
.stats span { font-size: 8px; color: var(--dim); }

.hero { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 16px 0 8px; }
.howto { max-width: 520px; width: 100%; font-size: 10px; color: var(--dim); }
.howto summary { cursor: pointer; text-align: center; padding: 8px; }
.howto li { margin: 8px 0; line-height: 1.8; }

/* Pixel speech bubble */
.bubble {
  position: relative;
  background: var(--bubble); color: var(--bubble-ink);
  font-family: var(--font); font-size: 11px; line-height: 1.55; text-align: left;
  padding: 10px 12px; border: 0; cursor: pointer;
  /* chunky stepped border */
  box-shadow:
    0 calc(-1 * var(--px)) 0 0 #000, 0 var(--px) 0 0 #000,
    calc(-1 * var(--px)) 0 0 0 #000, var(--px) 0 0 0 #000,
    var(--px) calc(2 * var(--px)) 0 0 rgba(0,0,0,.45);
  transform: rotate(var(--tilt, 0deg));
}
.bubble::after { /* tail */
  content: ''; position: absolute; left: 18px; bottom: calc(-4 * var(--px));
  width: calc(3 * var(--px)); height: calc(3 * var(--px));
  background: var(--bubble);
  box-shadow: calc(-1 * var(--px)) 0 0 #000, var(--px) 0 0 #000, 0 var(--px) 0 #000;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.bubble.demo { font-size: 10px; animation: pop .35s steps(5) both; }
.bubble.demo:nth-child(2) { animation-delay: .3s; }
.bubble.demo:nth-child(3) { animation-delay: .6s; }
.bubble.demo.liar { background: var(--yellow); }
.bubble.demo.liar::after { background: var(--yellow); }
.bubble .num { display: inline-block; background: #000; color: var(--yellow); padding: 2px 5px; margin-right: 6px; font-size: 9px; }

@keyframes pop {
  0% { transform: scale(0) rotate(var(--tilt, 0deg)); }
  60% { transform: scale(1.18) rotate(var(--tilt, 0deg)); }
  100% { transform: scale(1) rotate(var(--tilt, 0deg)); }
}
@keyframes poof {
  to { transform: scale(0) rotate(var(--tilt, 0deg)); opacity: 0; }
}
@keyframes shake {
  0%, 100% { translate: 0 0; } 25% { translate: -4px 0; } 75% { translate: 4px 0; }
}

/* Game */
.game { gap: 10px; }
.hud { width: 100%; display: flex; justify-content: space-between; gap: 10px; font-size: 10px; color: var(--dim); }
.hud #hud-title { color: var(--yellow); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud b { color: var(--cyan); }
.stage { width: 100%; max-width: calc(72vh * 16 / 9); margin: 0 auto; position: relative; }
.game .hud, .game .meter { max-width: calc(72vh * 16 / 9); }
.video-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border: 3px solid var(--ink); }
.video-wrap iframe, #player, #party-player { position: absolute; inset: 0; width: 100%; height: 100%; }
.clock-mode { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--dim); }
.start-overlay { position: absolute; inset: 0; background: rgba(18,10,36,.75); border: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 3; }

/* Phone / narrow: bubbles stacked under the video */
.bubbles { display: flex; flex-direction: column; gap: 18px; padding: 14px 6px 10px; min-height: 270px; }
.bubbles .bubble { animation: pop .3s steps(5) both; width: 100%; }
.bubbles .bubble:nth-child(2) { animation-delay: .25s; }
.bubbles .bubble:nth-child(3) { animation-delay: .5s; }

/* Wide: bubbles float over the video like the show */
@media (min-width: 760px) and (min-height: 520px) {
  .bubbles { position: absolute; inset: 0; padding: 0; min-height: 0; display: block; pointer-events: none; z-index: 2; }
  .bubbles .bubble { position: absolute; width: min(36%, 340px); pointer-events: auto; font-size: clamp(11px, 1.15vw, 18px); }
  .bubbles .bubble.slot0 { left: 4%; top: 6%; }
  .bubbles .bubble.slot1 { right: 4%; top: 30%; }
  .bubbles .bubble.slot2 { left: 6%; bottom: 10%; }
  .bubbles .note { position: absolute; left: 45%; right: 3%; bottom: 4%; pointer-events: auto; }
}

.bubble.picked { outline: 4px solid var(--cyan); outline-offset: 4px; }
.bubble.is-lie { background: var(--yellow); }
.bubble.is-lie::after { background: var(--yellow); }
.bubble.is-lie::before { content: 'LIE!'; position: absolute; top: -18px; right: -6px; background: var(--red); color: #fff; padding: 4px 6px; font-size: 9px; transform: rotate(6deg); }
.bubble.is-true { opacity: .55; }
.bubble.wrong { animation: shake .3s steps(4) 2; }
.bubbles.resolved .bubble { animation: none; cursor: default; }
.bubbles.fading .bubble, .bubbles.fading .note { animation: poof .3s steps(4) forwards; }

.note {
  background: #000; color: var(--ink); border: 3px solid var(--yellow);
  padding: 10px 12px; font-size: 10px; line-height: 1.7; animation: pop .25s steps(4) both;
}
.note b { color: var(--yellow); }
.note .pts { float: right; margin-left: 8px; }
.note .pts.plus { color: var(--green); } .note .pts.minus { color: var(--red); } .note .pts.zero { color: var(--dim); }

.meter { width: 100%; height: 8px; background: rgba(255,255,255,.1); }
#meter-fill { height: 100%; width: 0; background: var(--yellow); }
.dots { display: flex; gap: 8px; font-size: 16px; min-height: 24px; }
.game-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Picker */
.picker { list-style: none; padding: 0; margin: 0; width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 10px; }
.picker button { width: 100%; text-align: left; background: rgba(0,0,0,.35); border: 3px solid var(--dim); padding: 14px; cursor: pointer; font-size: 11px; line-height: 1.7; }
.picker button:hover { border-color: var(--yellow); }
.picker .meta { display: block; color: var(--dim); font-size: 9px; }

/* Results */
.grid { font-size: 26px; letter-spacing: 4px; margin: 6px 0; font-family: system-ui, sans-serif; }
.score-big { font-size: 14px; margin: 6px 0; }
.score-big b { font-size: 26px; color: var(--cyan); }
.share { background: #000; padding: 10px; font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; text-align: left; margin: 12px 0; border: 2px dashed var(--dim); }
.factlist { width: 100%; max-width: 760px; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; counter-reset: f; }
.factlist li { background: rgba(0,0,0,.3); border-left: 6px solid var(--green); padding: 10px 12px; font-size: 10px; line-height: 1.8; }
.factlist li.lie { border-left-color: var(--red); }
.factlist .tag { font-size: 8px; padding: 2px 5px; margin-right: 6px; background: var(--green); color: #000; }
.factlist li.lie .tag { background: var(--red); color: #fff; }
.factlist .corr { display: block; color: var(--yellow); margin-top: 4px; }
.factlist a { font-size: 8px; word-break: break-all; }
.factlist .batch-head { background: none; border: 0; color: var(--dim); font-size: 9px; padding: 8px 0 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.foot { margin-top: 30px; text-align: center; font-size: 8px; color: var(--dim); line-height: 1.8; }

/* ---------- Party mode ---------- */
.center { text-align: center; }
.err { color: var(--yellow); }
.row .btn.party-entry { color: var(--cyan); box-shadow: inset 0 0 0 3px var(--cyan); }
.join-form label { display: block; text-align: left; font-size: 10px; color: var(--dim); margin: 0 0 14px; }
.join-form input, .pick select {
  display: block; width: 100%; margin-top: 6px; font-family: var(--font); font-size: 16px; /* 16px: no iOS zoom */
  color: var(--ink); background: #000; border: 3px solid var(--dim); padding: 12px; border-radius: 0;
}
.join-form #join-code { font-size: 26px; letter-spacing: 10px; text-transform: uppercase; text-align: center; color: var(--yellow); }
.join-form input:focus, .pick select:focus { outline: none; border-color: var(--yellow); }
.join-form .btn { width: 100%; }

/* Numbered bubbles, colour-coded like the phone buttons */
.bubble .num.n1 { background: var(--c1); color: #000; }
.bubble .num.n2 { background: var(--c2); color: #000; }
.bubble .num.n3 { background: var(--c3); color: #000; }

/* TV: full width, type sized for across the room */
body.party-tv #app { max-width: none; padding: 1.2vh 2.2vw 2vh; }
body.party-tv { font-size: clamp(12px, 1.05vw, 26px); }
body.party-tv .foot, body.party-phone .foot { display: none; }
.party-tv-screen h2 { font-size: 1.4em; }
.party-tv-screen h3 { font-size: 1.05em; }
.party-tv-screen .small { font-size: .8em; }
.party-tv-screen .btn.big { font-size: 1.3em; padding: .9em 1.4em; }
.party-tv-screen .btn.small-btn { font-size: .8em; }

.lobby { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4vw; align-items: start; margin-top: 2vh; }
.lobby-join { display: flex; flex-direction: column; align-items: center; text-align: center; }
.lobby-join .eyebrow { font-size: 1.1em; }
.qr { width: clamp(170px, 19vw, 400px); height: auto; image-rendering: pixelated; border: 6px solid var(--ink); box-shadow: 8px 8px 0 var(--pink); margin: .6em 0 1em; background: #fff; }
.join-url { font-size: 1em; color: var(--cyan); margin: 0 0 .8em; word-break: break-all; }
.code-label { margin: .6em 0 0; color: var(--dim); font-size: .9em; }
.room-code { font-size: clamp(56px, 9vw, 190px); line-height: 1.1; margin: .1em 0 0; letter-spacing: .12em; color: var(--yellow); text-shadow: .06em .06em 0 var(--pink); }
.lobby-side { display: flex; flex-direction: column; gap: 1em; align-items: stretch; }
.lobby-side h2 { margin: 0; text-align: left; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .7em; min-height: 3em; }
.chip { background: #000; border: 3px solid var(--c1); padding: .55em .8em; font-size: 1.05em; }
.chip.pop { border-width: 3px; }
.chip.c0 { border-color: var(--c1); } .chip.c1 { border-color: var(--c2); } .chip.c2 { border-color: var(--c3); }
.chip.away { opacity: .4; }
.pick { display: block; color: var(--dim); font-size: .85em; }
.pick select { font-size: max(16px, .95em); cursor: pointer; }
#lobby-start:disabled { opacity: .4; cursor: default; }

.tv-hud { font-size: .95em; }
.hud-join { color: var(--dim); white-space: nowrap; }
.hud-join b { color: var(--yellow); letter-spacing: .1em; font-size: 1.25em; }
.tv-grid { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) clamp(240px, 23vw, 520px); gap: 1.6vw; align-items: start; }
.tv-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.party-stage { max-width: calc(76vh * 16 / 9); }
.tv-main .meter { max-width: calc(76vh * 16 / 9); margin: 0 auto; }
.tv-main .game-actions { align-items: center; }
.paused-flag { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; background: var(--red); color: #fff; padding: .4em .8em; font-size: 1.1em; }
.dots { align-items: center; }
.dot { font-size: 14px; color: var(--dim); font-family: var(--font); }
.dot.live { color: var(--yellow); } .dot.done { color: var(--green); } .dot.skipped { opacity: .3; }
.party-tv .bubbles .bubble { cursor: default; }
@media (min-width: 760px) and (min-height: 520px) {
  .party-tv .bubbles .bubble { width: min(40%, 560px); font-size: clamp(12px, 1.25vw, 28px); }
  .party-tv .bubbles .bubble.slot2 { left: 4%; bottom: 7%; }
  .party-tv .bubbles .note { font-size: clamp(11px, 1vw, 22px); left: 50%; right: 3%; bottom: 4%; }
}
.party-tv .bubble .num { font-size: .95em; padding: .15em .45em; }
.party-tv .bubble.is-lie::before { font-size: .8em; padding: .35em .5em; top: -1.6em; }
.party-tv .bubble.is-true { opacity: .45; }

.tv-side { background: rgba(0,0,0,.35); border: 3px solid var(--dim); padding: .8em; min-width: 0; }
.tv-side h3 { margin: 0 0 .8em; text-align: left; }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45em; }
.board li { display: flex; align-items: center; gap: .6em; padding: .45em .5em; background: rgba(255,255,255,.04); }
.board .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .rk { color: var(--dim); min-width: 2.6em; font-size: .85em; }
.board .sc { color: var(--cyan); min-width: 3.2em; text-align: right; }
.board .delta { font-size: .85em; }
.board .delta.plus { color: var(--green); } .board .delta.minus { color: var(--red); } .board .delta.zero { color: var(--dim); }
.board .away { opacity: .45; }
.buzzrow .tick { width: 1.4em; text-align: center; color: var(--dim); font-family: system-ui, sans-serif; font-weight: 900; }
.buzzrow.did { background: rgba(61,220,132,.14); }
.buzzrow.did .tick { color: var(--green); }

/* Final standings */
#screen-final { padding-top: 2vh; }
.winner { text-align: center; }
.win-label { color: var(--pink); font-size: 1.2em; margin: .2em 0; }
.win-name { font-size: clamp(28px, 5vw, 100px); color: var(--yellow); margin: .15em 0; text-shadow: .06em .06em 0 var(--pink); line-height: 1.2; word-break: break-word; animation: pop .45s steps(5) both; }
.win-score { color: var(--cyan); font-size: 1.4em; margin: .2em 0 .6em; }
.final-board { width: 100%; max-width: 900px; font-size: 1.15em; }
.final-board li.first { background: rgba(255,210,63,.14); }
.final-board .grid-s { font-family: system-ui, sans-serif; letter-spacing: 2px; }

/* Phone: a buzzer, thumb-sized and colour-coded like the TV */
body.party-phone #app { padding-top: 6px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
body.party-phone .top { margin-bottom: 4px; }
.phone { gap: 10px; }
.phone-bar { width: 100%; display: flex; justify-content: space-between; gap: 8px; font-size: 11px; padding: 8px 10px; background: rgba(0,0,0,.4); border: 3px solid var(--dim); }
.phone-bar #ph-name { color: var(--yellow); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-bar b { color: var(--cyan); }
.ph-panel { width: 100%; min-height: calc(100vh - 190px); min-height: calc(100dvh - 190px); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 0 6px; }
.ph-big { font-size: 22px; color: var(--yellow); margin: 0 0 14px; line-height: 1.5; text-shadow: 3px 3px 0 var(--pink); }
.ph-sub { font-size: 11px; color: var(--dim); line-height: 1.9; white-space: pre-line; margin: 0; }
.buzzer { width: 100%; height: calc(100vh - 160px); height: calc(100dvh - 160px); min-height: 330px; display: grid; grid-template-rows: repeat(3, 1fr); gap: 14px; padding-bottom: 4px; }
.buzz {
  font-family: var(--font); font-size: clamp(48px, 15vw, 96px); color: #000; border: 0; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  box-shadow: 0 6px 0 rgba(0,0,0,.55), inset 0 0 0 4px #fff, inset 0 0 0 8px rgba(0,0,0,.25);
}
.buzz.b1 { background: var(--c1); } .buzz.b2 { background: var(--c2); } .buzz.b3 { background: var(--c3); }
.buzz:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.55), inset 0 0 0 4px #fff; }
.buzz:disabled { cursor: default; }
.buzzer.locked .buzz:not(.chosen), .buzzer.paused .buzz { opacity: .22; filter: grayscale(.6); }
.buzzer.locked .buzz.chosen { outline: 6px solid var(--ink); outline-offset: -16px; }
.ph-status { min-height: 18px; margin: 0; color: var(--yellow); font-size: 11px; }
.result .ph-verdict { font-size: 30px; margin: 0 0 10px; }
.result.right .ph-verdict { color: var(--green); } .result.wrong .ph-verdict { color: var(--red); } .result.miss .ph-verdict { color: var(--dim); }
.ph-points { font-size: 22px; color: var(--cyan); margin: 0 0 18px; }
.result.wrong .ph-points { color: var(--red); }

@media (max-width: 900px) {
  .lobby, .tv-grid { grid-template-columns: 1fr; }
  .lobby-side h2 { text-align: center; }
}

/* Big screens / TV */
@media (min-width: 1400px) {
  #app { max-width: 1500px; }
  body { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .bubble, .note { animation-duration: .01s !important; }
}
