:root {
  --bg: #0d1020;
  --bg2: #151a33;
  --card: #1a2040;
  --card2: #222a52;
  --line: #2e3766;
  --text: #f2f3fa;
  --muted: #9aa0bf;
  --accent: #8fb0ff;
  --grad: linear-gradient(135deg, #8fd8ff, #a98bff);
  --red: #ff5d73;
  --blue: #4dabf7;
  --green: #51cf66;
  --yellow: #ffd45e;
  --radius: 20px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  background:
    radial-gradient(900px 600px at 10% -10%, rgba(120, 100, 255, 0.18), transparent 60%),
    radial-gradient(800px 600px at 110% 10%, rgba(80, 180, 255, 0.14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
h1, h2, h3 { margin: 0 0 0.4em; font-weight: 800; letter-spacing: -0.01em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  min-height: 48px; padding: 0.7em 1.3em; border-radius: 14px; border: 0;
  background: var(--grad); color: #111428; font-weight: 800; font-size: 1.05rem;
  box-shadow: 0 6px 20px rgba(140, 150, 255, 0.25);
  transition: transform 0.12s, filter 0.12s, opacity 0.2s;
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.ghost { background: var(--card2); color: var(--text); box-shadow: none; border: 1px solid var(--line); }
.btn.danger { background: #ff6b81; }
.btn.small { min-height: 44px; padding: 0.45em 0.9em; font-size: 0.95rem; }
.btn.block { width: 100%; }
.btn:focus-visible, .focusable:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

.back-link { position: fixed; left: 14px; bottom: 10px; font-size: 0.8rem; color: var(--muted); text-decoration: none; opacity: 0.7; z-index: 5; }
.back-link:hover, .back-link:focus { opacity: 1; color: var(--accent); }

.chip { display: inline-flex; align-items: center; gap: 0.45em; padding: 0.3em 0.75em 0.3em 0.35em; border-radius: 999px; background: var(--card2); font-weight: 700; white-space: nowrap; }
.dot { width: 1.4em; height: 1.4em; border-radius: 50%; display: inline-grid; place-items: center; font-size: 0.75em; font-weight: 900; color: #111; flex: none; }
.chip.off { opacity: 0.45; }
.chip.wait { animation: pulse 1.4s infinite; }

@keyframes pop { from { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.06); opacity: 1; } to { transform: scale(1); } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pulse { 50% { opacity: 0.55; } }
@keyframes flip { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes glow { 50% { box-shadow: 0 0 0 6px rgba(255, 212, 94, 0.35); } }
@keyframes float { 50% { transform: translateY(-10px); } }
.pop { animation: pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.rise { animation: rise 0.5s ease both; }
.shake { animation: shake 0.4s; }

/* ---------- landing ---------- */
.landing { max-width: 760px; margin: 0 auto; padding: 48px 16px 80px; text-align: center; }
.logo { width: 96px; height: 96px; margin: 0 auto 12px; filter: drop-shadow(0 10px 30px rgba(140, 120, 255, 0.4)); animation: float 4s ease-in-out infinite; }
.landing h1 { font-size: clamp(2rem, 6vw, 3.4rem); }
.choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 28px; text-align: left; }
.choice .card h2 { font-size: 1.4rem; }
.code-input { width: 100%; text-transform: uppercase; letter-spacing: 0.4em; text-align: center; font-size: 2rem; font-weight: 900; padding: 0.4em; border-radius: 14px; border: 2px solid var(--line); background: var(--bg2); color: var(--text); }
.game-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 30px; text-align: left; }
.game-list .card { padding: 14px; }

/* ---------- TV ---------- */
body.tv { overflow: hidden; height: 100vh; }
.tv-root { position: fixed; inset: 0; padding: 3.2vh 3.5vw; display: flex; flex-direction: column; font-size: clamp(14px, 1.15vw, 30px); }
.tv-top { display: flex; align-items: center; gap: 1.2em; min-height: 3.4em; }
.tv-top .title { font-size: 1.7em; font-weight: 900; }
.tv-top .phase { font-size: 1.15em; color: var(--accent); font-weight: 800; }
.tv-top .code-badge { margin-left: auto; font-weight: 900; letter-spacing: 0.15em; background: var(--card2); padding: 0.3em 0.8em; border-radius: 12px; }
.tv-main { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.tv-bottom { display: flex; align-items: center; gap: 0.8em; min-height: 3em; flex-wrap: wrap; }
.tv-tools { position: fixed; right: 2vw; bottom: 2vh; display: flex; gap: 0.5em; z-index: 10; }
.tv-tools button { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 0.4em 0.7em; font-size: 1.1em; min-width: 44px; min-height: 44px; }
.timer { position: relative; width: 3.2em; height: 3.2em; flex: none; }
.timer svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 900; font-size: 1.05em; }
.timer.low span { color: var(--red); animation: pulse 0.6s infinite; }
.waiting-row { display: flex; gap: 0.5em; flex-wrap: wrap; align-items: center; }

.lobby { display: grid; grid-template-columns: 1.05fr 1fr; gap: 2.5vw; flex: 1; min-height: 0; }
.lobby .join-card { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.lobby .qr { background: #fff; padding: 1em; border-radius: 1.2em; width: min(36vh, 26vw); aspect-ratio: 1; }
.lobby .qr img, .lobby .qr svg { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.big-code { font-size: 4.2em; font-weight: 900; letter-spacing: 0.18em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1.1; }
.lobby .players { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.7em; align-content: start; }
.player-tile { display: flex; align-items: center; gap: 0.6em; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 0.6em 0.8em; font-weight: 800; font-size: 1.2em; }
.player-tile .dot { font-size: 1em; width: 2em; height: 2em; }
.player-tile .host { margin-left: auto; font-size: 0.7em; color: var(--yellow); }
.game-pill { display: flex; align-items: center; gap: 1em; background: var(--card); border: 2px solid var(--accent); border-radius: var(--radius); padding: 1em 1.2em; }
.game-pill .icon { font-size: 2.6em; }
.settings-line { color: var(--muted); font-size: 0.95em; margin-top: 0.3em; }

.scoreboard { max-width: 60em; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 0.6em; }
.score-row { display: flex; align-items: center; gap: 0.8em; background: var(--card); border-radius: 16px; padding: 0.6em 1em; font-size: 1.35em; font-weight: 800; }
.score-row .rank { width: 2em; text-align: center; font-size: 1.1em; color: var(--muted); }
.score-row.first { border: 2px solid var(--yellow); background: linear-gradient(90deg, rgba(255, 212, 94, 0.18), var(--card)); }
.score-row .pts { margin-left: auto; font-variant-numeric: tabular-nums; }
.score-bar { height: 0.35em; border-radius: 1em; background: var(--grad); margin-top: 0.2em; transition: width 1s; }
.banner { font-size: 3em; font-weight: 900; text-align: center; margin: 0.3em 0; }
.subbanner { font-size: 1.5em; text-align: center; color: var(--muted); }
.big-word { font-size: 5em; font-weight: 900; text-align: center; }

/* ---------- phone ---------- */
body.phone { min-height: 100dvh; }
.ph-root { max-width: 520px; margin: 0 auto; padding: 12px 16px 90px; min-height: 100dvh; display: flex; flex-direction: column; }
.ph-top { display: flex; align-items: center; gap: 10px; padding: 4px 0 10px; min-height: 52px; }
.ph-top .me { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.ph-top .me .dot { width: 32px; height: 32px; font-size: 0.9rem; }
.ph-top .room { margin-left: auto; color: var(--muted); font-weight: 700; font-size: 0.9rem; }
.ph-main { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.ph-timer { height: 6px; background: var(--card2); border-radius: 6px; overflow: hidden; }
.ph-timer div { height: 100%; background: var(--grad); transition: width 0.25s linear; }
.ph-host { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(13, 16, 32, 0.92); backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); display: flex; gap: 8px; justify-content: center; z-index: 20; }
.ph-host .label { align-self: center; font-size: 0.75rem; color: var(--yellow); font-weight: 800; margin-right: auto; }
.prompt { font-size: 1.35rem; font-weight: 800; line-height: 1.3; }
.text-in { width: 100%; padding: 14px 16px; font-size: 1.2rem; border-radius: 14px; border: 2px solid var(--line); background: var(--bg2); color: var(--text); }
.text-in:focus { border-color: var(--accent); outline: none; }
.err { color: var(--red); font-weight: 700; min-height: 1.3em; }
.ok-big { font-size: 3rem; text-align: center; }
.done-msg { text-align: center; padding: 30px 10px; }
.done-msg .ok-big { animation: pop 0.5s both; }
.option-list { display: flex; flex-direction: column; gap: 10px; }
.option { min-height: 56px; padding: 12px 16px; border-radius: 14px; background: var(--card); border: 2px solid var(--line); text-align: left; font-weight: 700; font-size: 1.1rem; width: 100%; }
.option.sel { border-color: var(--accent); background: var(--card2); box-shadow: 0 0 0 3px rgba(143, 176, 255, 0.25); }
.option:disabled { opacity: 0.4; }
.colour-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.colour-pick button { aspect-ratio: 1; border-radius: 50%; border: 3px solid transparent; min-height: 44px; }
.colour-pick button.sel { border-color: #fff; transform: scale(1.1); }
.colour-pick button:disabled { opacity: 0.2; }
.seg { display: flex; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 10px; font-weight: 700; font-size: 0.9rem; padding: 0 8px; }
.seg button.sel { background: var(--card2); color: var(--accent); box-shadow: 0 0 0 1px var(--line); }
.game-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.game-pick button { text-align: left; padding: 10px 12px; border-radius: 14px; background: var(--card); border: 2px solid var(--line); min-height: 64px; }
.game-pick button.sel { border-color: var(--accent); background: var(--card2); }
.game-pick button:disabled { opacity: 0.45; }
.game-pick b { display: block; font-size: 1rem; }
.game-pick small { color: var(--muted); }
.plist { display: flex; flex-direction: column; gap: 6px; }
.plist .p { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 6px 8px; font-weight: 700; }
.plist .p .tools { margin-left: auto; display: flex; gap: 4px; }
.plist .p .tools button { min-width: 40px; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); }
.secret { background: var(--card2); border: 2px dashed var(--accent); border-radius: 18px; padding: 22px; text-align: center; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.secret .word { font-size: 2.2rem; font-weight: 900; }
.toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); background: var(--card2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 50; font-weight: 700; animation: rise 0.3s; }
.conn { position: fixed; top: 0; left: 0; right: 0; background: #b3263e; color: #fff; text-align: center; font-weight: 700; padding: 6px; z-index: 60; font-size: 0.9rem; }

@media (max-width: 340px) {
  .game-pick { grid-template-columns: 1fr; }
}
.no-anim .pop, .no-anim .rise, .no-anim .score-row, .no-anim .flipin { animation: none !important; }

/* word grid (Signal) */
.wgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.6em; }
.wcard { position: relative; border-radius: 0.7em; background: #e9e2cf; color: #1b1d2b; font-weight: 900; text-transform: uppercase; display: grid; place-items: center; text-align: center; padding: 0.4em 0.2em; min-height: 3.6em; letter-spacing: 0.02em; border: 3px solid transparent; transition: transform 0.15s; word-break: break-word; line-height: 1.05; }
.wcard.k-red { background: #e8475f; color: #fff; }
.wcard.k-blue { background: #3d8fe0; color: #fff; }
.wcard.k-neutral { background: #8c8670; color: #f4f1e6; }
.wcard.k-blackout { background: #111; color: #ff5d73; }
.wcard.k-target { background: #37b24d; color: #fff; }
.wcard.k-trap { background: #9c36b5; color: #fff; }
.wcard.rev { opacity: 0.95; }
.wcard.rev.dim { opacity: 0.35; }
.wcard.flipin { animation: flip 0.5s ease both; }
.wcard.prop { border-color: var(--yellow); animation: glow 1.2s infinite; }
.wcard .props { position: absolute; top: -0.5em; right: -0.3em; display: flex; }
.wcard .props .dot { width: 1.3em; height: 1.3em; font-size: 0.7em; border: 2px solid #0d1020; margin-left: -0.35em; }
.wcard.keyed { box-shadow: inset 0 -0.45em 0 var(--kc); }
.wcard.sel { border-color: #fff; transform: scale(1.05); }
.ph-root .wgrid { gap: 5px; }
.ph-root .wcard { font-size: 0.62rem; min-height: 52px; border-radius: 8px; padding: 2px; }
.tv-root .wcard { font-size: 1.25em; }
.tv-root .wcard.long { font-size: 1.05em; }
.ph-root .wcard.long { font-size: 0.5rem; letter-spacing: 0; }

/* clue cards (Unique) */
.clues { display: flex; flex-wrap: wrap; gap: 0.8em; justify-content: center; }
.clue-card { background: #fffbe8; color: #1b1d2b; border-radius: 0.8em; padding: 0.6em 1.2em; font-weight: 900; font-size: 2em; min-width: 5em; text-align: center; box-shadow: 0 0.3em 0 rgba(0,0,0,0.25); animation: pop 0.45s both; }
.clue-card .by { display: block; font-size: 0.4em; font-weight: 700; color: #666; margin-top: 0.2em; }
.clue-card.blank { background: repeating-linear-gradient(45deg, #2a3160, #2a3160 10px, #232a52 10px, #232a52 20px); color: transparent; }
.clue-card.struck { opacity: 0.45; text-decoration: line-through; background: #bbb; }
.ph-root .clue-card { font-size: 1.1rem; min-width: 0; padding: 8px 12px; }
.vote-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--card); border: 2px solid var(--line); width: 100%; text-align: left; font-weight: 800; font-size: 1.1rem; min-height: 52px; }
.vote-item.on { border-color: var(--red); background: #3a1f33; }
.vote-item.auto { opacity: 0.5; }
.vote-item small { margin-left: auto; color: var(--muted); font-weight: 600; font-size: 0.8rem; }
