:root {
  --bg: #070814;
  --paper: #f3efe4;
  --ink: #101018;
  --muted: #9aa3c0;
  --line: #2c3358;
  --red: #ff4d6d;
  --blue: #4cc3ff;
  --gold: #ffd166;
  --mint: #5dffb2;
  --violet: #8b7cff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--paper);
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
}
body {
  background-image:
    radial-gradient(900px 420px at 12% -8%, #1c1650 0%, transparent 55%),
    radial-gradient(700px 380px at 100% 110%, #3a1230 0%, transparent 50%);
}
a { color: var(--gold); }
.wrap { max-width: 980px; margin: 0 auto; padding: 28px 20px 48px; }
.brand {
  display: flex; align-items: center; gap: 12px; letter-spacing: 0.18em;
  text-transform: uppercase; font-size: 13px; color: var(--gold);
}
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(160deg, #fff, var(--gold));
  display: grid; place-items: center; color: var(--ink); font-weight: 800;
}
h1 { font-size: clamp(32px, 6vw, 56px); line-height: 0.95; margin: 18px 0 12px; }
.lede { color: var(--muted); font-size: 18px; max-width: 42rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 28px; }
.card {
  background: linear-gradient(165deg, rgba(255,255,255,.08), rgba(14,16,40,.9));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  text-decoration: none;
  color: inherit;
  display: block;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
}
.card:hover { border-color: var(--gold); }
.card h2 { margin: 0 0 8px; font-size: 22px; }
.card p { margin: 0; color: var(--muted); }
.note {
  margin-top: 28px; padding: 16px 18px; border-left: 3px solid var(--gold);
  color: var(--muted); background: rgba(16,18,40,.75);
}
.warn {
  margin-top: 16px; padding: 16px 18px; border-left: 3px solid var(--red);
  color: var(--muted); background: rgba(40,10,18,.75);
}
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: linear-gradient(180deg, #ffe38a, var(--gold));
  color: var(--ink); font-weight: 800;
  padding: 14px 18px; border-radius: 12px; font-size: 16px;
}
.btn.ghost { background: transparent; color: var(--paper); border: 1px solid var(--line); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.tv-shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.tv-main { min-height: 0; height: 100%; }
.tv-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 28px; padding-top: calc(16px + var(--safe-top));
  border-bottom: 1px solid var(--line);
  background: rgba(8,10,24,.7);
}
.code {
  font-size: 42px; letter-spacing: 0.28em; font-weight: 800;
  color: var(--gold); text-shadow: 0 0 18px rgba(255,209,102,.35);
}
.lobby { display: grid; grid-template-columns: 320px 1fr; gap: 24px; padding: 28px; }
.qr-box {
  background: var(--paper); color: var(--ink); border-radius: 20px; padding: 18px;
  text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,.35);
}
.qr-box img, .qr-box svg { width: 100%; height: auto; display: block; }
.slots { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.slot {
  border: 1px dashed var(--line); border-radius: 16px; min-height: 110px;
  padding: 16px; display: flex; flex-direction: column; justify-content: center;
  background: rgba(12,14,32,.55);
}
.slot.on { border-style: solid; border-color: currentColor; box-shadow: inset 0 0 24px currentColor; }
.slot .who { font-size: 22px; font-weight: 700; }
.stage { position: relative; overflow: hidden; height: 100%; min-height: 62vh; }
#game { width: 100%; height: 100%; display: block; background: #05060f; }
.hud {
  position: absolute; left: 24px; right: 24px; top: 16px;
  display: flex; justify-content: space-between; pointer-events: none;
  font-size: 22px; font-weight: 700; letter-spacing: .04em;
  text-shadow: 0 2px 12px #000;
}
.tv-help { color: var(--muted); font-size: 14px; }

.pad-body {
  height: 100dvh; overflow: hidden; touch-action: none; user-select: none;
  display: grid; grid-template-rows: auto 1fr auto;
}
.pad-top, .pad-bot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
}
.pad-bot { padding-bottom: calc(10px + var(--safe-bottom)); }
.pad-mid {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; padding: 0 10px;
  align-items: stretch;
}
.stick-wrap { position: relative; }
.stick-base {
  position: absolute; inset: 8%; border-radius: 50%;
  background: #10182c; border: 2px solid var(--line);
}
.stick-knob {
  position: absolute; width: 38%; height: 38%; border-radius: 50%;
  background: var(--paper); left: 31%; top: 31%;
  box-shadow: 0 8px 18px rgba(0,0,0,.45);
}
.face {
  display: grid; grid-template-columns: 64px 64px; grid-template-rows: 64px 64px;
  gap: 10px; align-content: center; justify-content: center;
}
.abxy {
  width: 64px; height: 64px; border-radius: 50%; border: 0; color: var(--ink);
  font-weight: 800; font-size: 20px;
}
.b-a { background: var(--mint); grid-column: 2; grid-row: 1; }
.b-b { background: var(--red); grid-column: 1; grid-row: 2; }
.b-x { background: var(--blue); grid-column: 1; grid-row: 1; }
.b-y { background: var(--gold); grid-column: 2; grid-row: 2; }
.shoulder {
  min-width: 120px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: #18233d; color: var(--paper); font-weight: 700;
}
.mini {
  height: 36px; border-radius: 18px; border: 1px solid var(--line);
  background: #18233d; color: var(--paper); padding: 0 14px;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.dot.ok { background: var(--mint); }
.hint { color: var(--muted); font-size: 13px; }
.join-panel {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.field {
  width: min(420px, 100%);
  background: linear-gradient(180deg, #1a2140, #12182c);
  border: 1px solid var(--line);
  border-radius: 20px; padding: 22px;
  box-shadow: 0 18px 50px rgba(0,0,0,.4);
}
input[type="text"] {
  width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: #0b1220; color: var(--paper); font-size: 22px; letter-spacing: 0.2em;
  text-transform: uppercase; text-align: center;
}
.name-in { margin-top: 10px; letter-spacing: 0; text-transform: none; font-size: 16px; }
.err { color: var(--red); min-height: 1.2em; }
.wide { width: 100%; }

.test-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  padding: 24px;
}
.test-pads {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.tpad {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  background: rgba(12,14,32,.7);
  min-height: 220px;
}
.tpad.on { border-color: currentColor; }
.tpad .who { font-size: 22px; font-weight: 700; }
.keys { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.k {
  min-width: 36px; padding: 6px 8px; border-radius: 8px;
  background: #0b1220; color: var(--muted); font-size: 13px; text-align: center;
}
.k.lit { background: var(--gold); color: var(--ink); }
.stick-read {
  width: 88px; height: 88px; border-radius: 50%;
  border: 2px solid var(--line); position: relative; margin-top: 10px;
  background: #0b1220;
}
.stick-read i {
  position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: var(--paper); left: 50%; top: 50%; margin: -9px 0 0 -9px;
}
.ok-banner {
  margin: 0 24px 24px; padding: 16px 18px; border-radius: 14px;
  background: #12281c; color: var(--mint); font-size: 20px;
}
.ok-banner.wait { background: #121a2e; color: var(--muted); }

@media (max-width: 820px) {
  .lobby, .test-grid { grid-template-columns: 1fr; }
}
