/* Triplet. Black and plain: the cards carry the colour, white marks what's selected. */
:root {
  --bg: #000; --panel: #111; --line: #262626; --ink: #fff; --mute: #8a8a8a;
  --sel: #fff; --good: #34c759; --bad: #ff453a; --card: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { -webkit-tap-highlight-color: transparent; font-feature-settings: "tnum" 1; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.logo { font-weight: 700; font-size: 24px; letter-spacing: -.01em; }
.eyebrow { color: var(--mute); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; margin: 0; }
.center { text-align: center; }
.err { color: var(--bad); min-height: 1.2em; }

.big { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 12px; padding: 15px 24px;
  font-size: 18px; font-weight: 600; text-decoration: none; background: var(--ink); color: #000; }
.big:active { opacity: .8; }
.big.alt { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.ghost { background: none; border: 1px solid var(--line); color: var(--mute); border-radius: 10px; padding: 8px 14px; font-size: 14px; }
input { font: inherit; font-size: 20px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); outline: none; }
input:focus { border-color: var(--mute); }

.tiles { letter-spacing: .2em; font-weight: 700; }
.tiles i { font-style: normal; }

/* Cards */
.card { position: relative; background: var(--card); border-radius: 10px; border: 0; padding: 0;
  display: flex; align-items: center; justify-content: center; transition: opacity .2s; }
.card svg { width: 100%; height: 100%; display: block; }
.card.picked { outline: 4px solid var(--sel); outline-offset: 4px; }
.card.hint { outline: 4px dashed var(--sel); outline-offset: 4px; }

/* ---- home ---- */
.home { max-width: 480px; margin: 0 auto; padding: 64px 16px; text-align: center; }
.home .logo { font-size: 40px; }
.lede { color: var(--mute); font-size: 17px; line-height: 1.5; }
.home-cards { display: flex; gap: 12px; justify-content: center; margin: 36px 0; }
.home-cards .card { width: 80px; height: 120px; }
.home-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.home-actions > .big { width: min(320px, 100%); }
.join-code { display: flex; gap: 10px; width: min(320px, 100%); }
.join-code input { width: 140px; text-transform: uppercase; letter-spacing: .2em; text-align: center; }
.join-code .big { flex: 1; }

/* ---- TV ---- */
.tp-tv { overflow: hidden; }
.tv-head { height: 72px; display: flex; align-items: center; gap: 28px; padding: 0 32px; border-bottom: 1px solid var(--line); }
.tv-join { flex: 1; color: var(--mute); font-size: 20px; }
.tv-join b { color: var(--ink); font-weight: 600; }
.tv-code { display: flex; align-items: baseline; gap: 12px; font-size: 30px; }
.tv-code > span:first-child { font-size: 12px; letter-spacing: .12em; color: var(--mute); text-transform: uppercase; }
.tv-body { display: flex; height: calc(100vh - 72px); }
.stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; padding: 2.4vh 2vw; min-width: 0; }
.board { --gy: 2vh; --gx: 1.4vw;
  /* Fit 3 rows in the height and --cols columns in the width, whichever is tighter. */
  --h: min(calc((100vh - 72px - 4.8vh - 2 * var(--gy)) / 3),
           calc((100vw - 320px - 4vw - (var(--cols) - 1) * var(--gx)) / var(--cols) * 1.5));
  display: grid; grid-template-rows: repeat(3, var(--h)); grid-auto-flow: column; grid-auto-columns: calc(var(--h) / 1.5); gap: var(--gy) var(--gx); }
.board .card { width: 100%; height: 100%; border-radius: 1.2vh; }
.board .card.picked { outline-width: 6px; outline-offset: 6px; }
.stage.paused .card:not(.picked) { opacity: .25; }

.side { width: 320px; padding: 24px; display: flex; flex-direction: column; gap: 16px; border-left: 1px solid var(--line); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stats:empty { display: none; }
.stats div { background: var(--bg); padding: 10px 12px; }
.stats span { display: block; font-size: 11px; color: var(--mute); text-transform: uppercase; letter-spacing: .1em; }
.stats b { font-size: 26px; font-weight: 600; }
.scores { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; }
.scores li { display: flex; align-items: center; gap: 10px; padding: 14px 2px; border-bottom: 1px solid var(--line); font-size: 22px; }
.scores li.is-claim .nm { text-decoration: underline; text-underline-offset: 6px; }
.scores li.is-away { opacity: .4; }
.scores li.empty { color: var(--mute); justify-content: center; font-size: 17px; }
.scores .nm { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores b { font-size: 26px; font-weight: 700; min-width: 1.4em; text-align: right; }
.scores b.up { color: var(--good); } .scores b.down { color: var(--bad); }
.tag { font-style: normal; font-size: 12px; color: var(--mute); white-space: nowrap; }
.tag.ok { color: var(--good); }
.tag.go { color: var(--ink); }

.lobby { text-align: center; max-width: 860px; }
.lobby-qr { display: block; margin: 0 auto 16px; border-radius: 10px; width: 220px; height: 220px; }
.lobby-url { font-size: 36px; font-weight: 600; margin: 8px 0 28px; word-break: break-all; }
.lobby-code { font-size: 120px; margin: 8px 0; line-height: 1; }
.lobby-wait { font-size: 22px; color: var(--mute); margin: 28px 0 16px; }
.lobby-wait b { color: var(--ink); }
.chips { list-style: none; padding: 0; margin: 0 0 32px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chips li { padding: 8px 16px; border-radius: 99px; font-size: 18px; border: 1px solid var(--line); color: var(--mute); }
.chips li.ok { border-color: var(--ink); color: var(--ink); }
.chips li.away { opacity: .4; }
.rules { text-align: left; color: var(--mute); font-size: 18px; line-height: 1.6; max-width: 720px; margin: 0 auto; padding-left: 1.2em; }
.rules b, .rules i { color: var(--ink); }

/* Who's picking sits in the header, above the table, never over a card. */
.claim { position: fixed; top: 11px; left: calc(50% - 160px); transform: translateX(-50%); z-index: 5; height: 50px;
  display: flex; align-items: center; gap: 14px; padding: 0 6px 0 22px; border-radius: 999px; overflow: hidden;
  background: var(--ink); color: #000; font-weight: 700; font-size: 26px; }
.claim .secs { background: #000; color: var(--ink); border-radius: 999px; min-width: 64px; text-align: center; padding: 2px 14px; }
.claim .bar { position: absolute; left: 0; bottom: 0; height: 4px; width: calc(var(--p) * 100%); background: #000; transition: width .2s linear; }

.toast { position: fixed; bottom: 76px; right: 24px; width: 272px; z-index: 6; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-size: 19px; font-weight: 600; line-height: 1.3; }
.toast p { margin: 0; }
.toast.good p { color: var(--good); }
.toast.bad p { color: var(--bad); }
.toast .mini { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.toast .mini .card { width: 56px; height: 84px; border-radius: 6px; }

.over { position: absolute; inset: 8% 18%; border-radius: 16px; z-index: 2; background: var(--bg); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22px; color: var(--mute); }
.over h2 { font-size: 52px; margin: 6px 0 20px; color: var(--ink); font-weight: 700; }
.over ol, .final { list-style: none; padding: 0; margin: 0 0 20px; width: min(480px, 86%); }
.over li, .final li { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 26px; color: var(--ink); }
.over li span, .final li span { flex: 1; font-weight: 600; text-align: left; }
.rank { font-style: normal; color: var(--mute); width: 1.4em; }
.offline { position: fixed; top: 12px; right: 12px; background: var(--bad); color: #fff; padding: 6px 12px; border-radius: 8px; }

/* ---- phone ---- */
.tp-join #app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.ph-join { padding: 64px 20px; text-align: center; }
.ph-join .logo { font-size: 34px; }
.ph-join .eyebrow { margin-top: 8px; }
.ph-join form { display: flex; flex-direction: column; gap: 12px; max-width: 340px; margin: 32px auto 0; }
.ph-join input { width: 100%; }
.ph-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.ph-head .nm { font-weight: 600; font-size: 19px; }
.ph-head .pts { font-size: 26px; font-weight: 700; }
.ph-head small { font-size: 13px; color: var(--mute); font-weight: 400; }
.ph-wait, .ph-play { flex: 1; display: flex; flex-direction: column; gap: 16px; padding: 20px 16px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.ph-wait > .tiles { font-size: 40px; align-self: center; }
.ph-wait h2 { margin: 8px 0 0; text-align: center; font-size: 28px; }
.ph-wait .chips li { font-size: 15px; }
.final li { font-size: 19px; }
.final li.me span { text-decoration: underline; text-underline-offset: 5px; }
.huge { min-height: 140px; border-radius: 18px; font-size: 32px; font-weight: 700; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  background: var(--ink); color: #000; }
.huge:active { opacity: .8; }
.huge.on { background: var(--panel); color: var(--good); border-color: var(--good); }
.hint { text-align: center; color: var(--mute); margin: 0; }
.ph-wait .ghost { align-self: center; margin-top: auto; }

/* The buzzer: one big white button. */
.buzz-wrap { flex: 1; display: flex; }
.buzz { flex: 1; border: 0; border-radius: 24px; background: var(--ink); color: #000;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; transition: transform .06s; }
.buzz span { font-size: 46px; font-weight: 800; letter-spacing: -.01em; }
.buzz:active { transform: scale(.98); opacity: .85; }
.buzz:disabled { opacity: .4; }
.waiting { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--mute); }
.waiting b { color: var(--ink); font-size: 30px; font-weight: 700; }
.waiting small { font-size: 17px; }
.noset { border: 1px solid var(--line); background: var(--bg); border-radius: 16px; padding: 14px 16px; font-size: 18px; font-weight: 600;
  display: flex; flex-direction: column; gap: 4px; align-items: center; }
.noset.on { border-color: var(--good); color: var(--good); }
.noset small { color: var(--mute); font-weight: 400; font-size: 13px; }

.ph-pick { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 16px; }
.pick-top { display: flex; justify-content: space-between; align-items: center; font-size: 19px; }
.pick-top .secs { font-weight: 700; font-size: 22px; }
/* The phone reuses the TV's .board grid, sized to the phone. */
.board.ph-board { --gy: 10px; --gx: 8px; align-self: center;
  --h: min(calc((100dvh - 150px - 2 * var(--gy)) / 3),
           calc((100vw - 32px - (var(--cols) - 1) * var(--gx)) / var(--cols) * 1.5)); }
.ph-board .card { border-radius: 7px; }
.ph-board .card.picked { outline-width: 3px; outline-offset: 3px; }

.flash { position: fixed; left: 16px; right: 16px; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 9; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; font-size: 17px; font-weight: 600; }
.flash.good { color: var(--good); border-color: var(--good); font-size: 22px; }
.flash.bad { color: var(--bad); border-color: var(--bad); }

/* ---- motion: kept to the cards ---- */
/* Flip: the card turns over from a plain back. The back is an overlay that hides halfway. */
.card.flip { animation: flip .45s ease-out backwards; animation-delay: var(--d, 0ms); }
.card::after { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none;
  background: #1a1a1a; box-shadow: inset 0 0 0 1px #333; }
.card.flip::after { animation: back .45s linear both; animation-delay: var(--d, 0ms); }
@keyframes flip { from { transform: perspective(1000px) rotateY(180deg); } to { transform: perspective(1000px) rotateY(0); } }
@keyframes back { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
/* Found: a green outline, then the cards fade out before the new ones flip in. */
.card.won, .stage.paused .card.won { opacity: 1; outline: 6px solid var(--good); outline-offset: 6px; animation: won .95s ease-in forwards; }
@keyframes won { 0%, 55% { opacity: 1; transform: none; } 100% { opacity: 0; transform: scale(.92); } }
/* Wrong: a short shake with a red outline. */
.card.shake { outline: 6px solid var(--bad); outline-offset: 6px; animation: shake .4s ease-in-out; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

@media (max-width: 1100px) {
  .side { width: 250px; }
  .scores li { font-size: 18px; }
  .lobby-code { font-size: 84px; } .lobby-url { font-size: 26px; }
  .board { --h: min(calc((100vh - 72px - 4.8vh - 4vh) / 3), calc((100vw - 250px - 4vw - (var(--cols) - 1) * 1.4vw) / var(--cols) * 1.5)); }
  .toast { width: 210px; font-size: 16px; } .toast .mini .card { width: 44px; height: 66px; }
  .claim { left: calc(50% - 125px); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
