:root {
  --bg: #0d1020;
  --bg2: #151a33;
  --surface: rgba(255,255,255,.05);
  --surface-hi: rgba(255,255,255,.09);
  --text: #f2f3fa;
  --muted: #9aa0bf;
  --accent: #8fb0ff;
  --border: rgba(255,255,255,.10);
  --glow: rgba(110,120,255,.45);
  --pink: #ff3df2;
  --cyan: #00f0ff;
  --sun1: #ffe66d;
  --sun2: #ff3d8b;
  --ui: 1;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(47,111,228,.35), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(123,63,228,.30), transparent 60%),
    var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

.back {
  position: fixed; top: 10px; left: 12px; z-index: 50;
  color: var(--accent); text-decoration: none; font-weight: 600; font-size: .9rem;
  padding: 8px 12px; border-radius: 999px; background: rgba(13,16,32,.6); border: 1px solid var(--border);
  min-height: 44px; display: inline-flex; align-items: center;
}
.back:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.view { position: fixed; inset: 0; }
.page { display: grid; place-items: center; padding: 70px 16px 24px; overflow-y: auto; }

/* ---------- buttons ---------- */
.btn {
  border-radius: 999px; padding: 10px 18px; min-height: 44px; font-weight: 700; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover, .btn:focus-visible { background: var(--surface-hi); transform: translateY(-2px); }
.btn:focus-visible, .btn:focus { outline: 3px solid var(--accent); outline-offset: 3px; }
.btn.primary { background: linear-gradient(135deg, #8fd8ff, #a98bff); color: #0d1020; border: 0; box-shadow: 0 10px 30px -12px var(--glow); }
.btn.big { padding: 14px 26px; font-size: 1.1rem; min-height: 54px; }
.btn.icon { padding: 6px 10px; min-width: 44px; font-size: 1.1rem; }
.btn.sel { border-color: rgba(143,176,255,.8); background: rgba(143,176,255,.18); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ---------- synthwave sky (home + join) ---------- */
.sky { position: fixed; inset: 0; overflow: hidden; z-index: -1; background: linear-gradient(#0d1020 0%, #24104a 45%, #5a1660 62%, #0d1020 62.2%); }
.sky.dim { opacity: .55; }
.sun {
  position: absolute; left: 50%; top: 62%; width: min(70vw, 460px); aspect-ratio: 1; transform: translate(-50%, -88%);
  border-radius: 50%;
  background: linear-gradient(var(--sun1), #ff9a3d 45%, var(--sun2));
  -webkit-mask: repeating-linear-gradient(#000 0 14px, transparent 14px 20px) bottom / 100% 48% no-repeat, linear-gradient(#000, #000) top / 100% 52% no-repeat;
          mask: repeating-linear-gradient(#000 0 14px, transparent 14px 20px) bottom / 100% 48% no-repeat, linear-gradient(#000, #000) top / 100% 52% no-repeat;
  filter: drop-shadow(0 0 40px rgba(255,61,139,.6));
}
.floor {
  position: absolute; left: -50%; right: -50%; top: 62%; bottom: -10%;
  background:
    linear-gradient(90deg, rgba(255,61,242,.55) 2px, transparent 2px) center / 70px 100%,
    linear-gradient(rgba(0,240,255,.5) 2px, transparent 2px) 0 0 / 100% 50px;
  transform: perspective(300px) rotateX(62deg); transform-origin: top;
  animation: floor 1.6s linear infinite;
  -webkit-mask: linear-gradient(transparent, #000 30%); mask: linear-gradient(transparent, #000 30%);
}
@keyframes floor { to { background-position: center, 0 50px; } }

.logo {
  margin: 0; font-size: clamp(4rem, 22vw, 9rem); font-weight: 900; letter-spacing: .08em; line-height: 1;
  font-style: italic;
  background: linear-gradient(#e9f7ff 0%, #8fd8ff 42%, #3b1d6e 50%, #ff7ad9 58%, #ffe0f7 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255,61,242,.55)) drop-shadow(0 0 2px #fff);
}
.logo.small { font-size: 3.2rem; }
.home-inner { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 560px; }
.tag { margin: 0; font-size: 1.15rem; font-weight: 700; color: #fff; text-shadow: 0 2px 10px rgba(13,16,32,.95), 0 0 18px rgba(255,61,242,.7); }
.home-buttons { display: flex; flex-direction: column; gap: 12px; width: min(100%, 360px); margin-top: 10px; }
.hint { color: #c9cde6; font-size: .92rem; margin: 6px 0 0; text-shadow: 0 1px 6px #0d1020; }

.card { background: rgba(21,26,51,.86); border: 1px solid var(--border); border-radius: 22px; padding: 22px; backdrop-filter: blur(8px); }
.join-card { width: min(100%, 380px); display: flex; flex-direction: column; gap: 14px; }
.join-card h2 { margin: 0; letter-spacing: -.02em; }
.join-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--muted); font-size: .9rem; }
.join-card input {
  background: rgba(0,0,0,.3); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; font-size: 1.2rem; color: var(--text); min-height: 50px;
}
.join-card input:focus { outline: 3px solid var(--accent); outline-offset: 2px; }
#codeIn { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.swatch { aspect-ratio: 1; min-height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; box-shadow: 0 0 12px currentColor; }
.swatch[aria-checked="true"] { border-color: #fff; transform: scale(1.12); }
.swatch:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.err { color: #ff8fa3; margin: 0; min-height: 1.2em; }

/* ---------- screen (TV) ---------- */
#arena { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud-top { position: absolute; top: 14px; left: 0; right: 0; display: flex; justify-content: center; }
.timer {
  font-weight: 900; font-size: 2.2rem; letter-spacing: .06em; font-variant-numeric: tabular-nums;
  color: #fff; text-shadow: 0 0 14px var(--cyan), 0 0 2px #fff;
}
.timer.hot { color: #ffd0e0; text-shadow: 0 0 18px #ff3d6e, 0 0 2px #fff; animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
.board {
  position: absolute; top: 78px; right: 16px; width: 250px; display: flex; flex-direction: column; gap: 4px;
  background: rgba(13,16,32,.5); border: 1px solid var(--border); border-radius: 18px; padding: 10px 12px;
}
.board:empty { display: none; }
.brow { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .95rem; white-space: nowrap; }
.brow .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.brow .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.brow .sc { font-variant-numeric: tabular-nums; }
.brow.bot { opacity: .6; font-weight: 500; }
.brow.dead { opacity: .45; }
.feed { position: absolute; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 4px; }
.feed div { background: rgba(13,16,32,.62); border-radius: 999px; padding: 4px 12px; font-weight: 600; font-size: .95rem; animation: fadeout 6s forwards; }
@keyframes fadeout { 0%,80% { opacity: 1; } 100% { opacity: 0; } }
.banner {
  position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-weight: 900; font-style: italic;
  font-size: 4.5rem; letter-spacing: .06em; color: #fff; opacity: 0; transform: scale(.8);
  text-shadow: 0 0 30px var(--pink), 0 0 6px #fff; transition: opacity .2s, transform .2s;
}
.banner.on { opacity: 1; transform: scale(1); }
.banner small { display: block; font-size: 1.6rem; font-style: normal; letter-spacing: 0; text-shadow: 0 0 12px rgba(0,0,0,.8); }
.roomtag { position: absolute; left: 16px; top: 62px; color: var(--muted); font-weight: 700; font-size: .9rem; }
.panel {
  position: absolute; left: 4vw; top: 50%; transform: translateY(-50%); width: min(520px, 92vw);
  background: rgba(13,16,32,.93); border: 1px solid rgba(255,61,242,.35); border-radius: 26px; padding: 26px; backdrop-filter: blur(6px);
  box-shadow: 0 0 60px -10px rgba(255,61,242,.45), inset 0 0 40px rgba(0,240,255,.06);
  display: flex; flex-direction: column; gap: 16px; max-height: 92vh; overflow: auto;
}
.results-panel { left: 50%; transform: translate(-50%, -50%); }
.panel h2 { margin: 0; font-size: 2rem; letter-spacing: -.02em; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .9rem; }
.joinbox { display: flex; gap: 18px; align-items: center; }
.qr { width: 150px; height: 150px; border-radius: 14px; background: #fff; padding: 6px; flex: none; }
.joinurl { margin: 0; font-weight: 700; color: var(--accent); word-break: break-all; }
.code { margin: 0; font-size: 3rem; font-weight: 900; letter-spacing: .18em; text-shadow: 0 0 14px var(--cyan); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 700; }
.chip .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #0d1020; font-weight: 900; font-size: .85rem; box-shadow: 0 0 10px currentColor; }
.chip.off { opacity: .45; }
.settings { display: flex; flex-direction: column; gap: 10px; }
.setting { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting > span { min-width: 140px; color: var(--muted); font-weight: 600; }
.results { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.results li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 14px; background: var(--surface); font-weight: 700; }
.results li.first { background: linear-gradient(90deg, rgba(255,212,94,.25), rgba(255,61,242,.12)); border: 1px solid rgba(255,212,94,.5); }
.results .pl { width: 2em; font-size: 1.2rem; color: var(--muted); }
.results .nm { flex: 1; }
.results .k { color: var(--muted); font-weight: 600; font-size: .9rem; }
.results li.bot { opacity: .6; }
.mute { position: absolute; right: 16px; bottom: 16px; }
.soundgate { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); }

/* ---------- TV scale ---------- */
html.tv body { font-size: 26px; }
html.tv .back { top: 4vh; left: 3vw; font-size: 22px; }
html.tv .panel { left: 5vw; width: 760px; padding: 36px; }
html.tv .results-panel { left: 50%; }
html.tv .qr { width: 230px; height: 230px; }
html.tv .code { font-size: 4.2rem; }
html.tv .board { top: 9vh; right: 3vw; width: 360px; }
html.tv .brow { font-size: 1.05rem; }
html.tv .timer { font-size: 3rem; }
html.tv .hud-top { top: 4vh; }
html.tv .feed { left: 3vw; bottom: 5vh; }
html.tv .roomtag { left: 3vw; top: 11vh; }
html.tv .mute { right: 3vw; bottom: 5vh; }
html.tv .btn:focus { box-shadow: 0 0 0 6px rgba(143,176,255,.35); transform: scale(1.05); }
html.tv #playHereBtn { display: none; }

/* ---------- phone controller ---------- */
#phone { display: flex; flex-direction: column; touch-action: none; user-select: none; -webkit-user-select: none; background: radial-gradient(120% 80% at 50% 100%, rgba(255,61,242,.18), transparent 60%), var(--bg); }
#phone .status { display: flex; align-items: center; gap: 10px; padding: 62px 14px 8px; }
.me-dot { width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: 0 0 12px currentColor; }
.me-name { flex: 1; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.1; min-width: 44px; }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; }
.pups { display: flex; gap: 8px; padding: 0 14px; min-height: 30px; flex-wrap: wrap; }
.pup { border-radius: 999px; padding: 2px 10px; font-weight: 800; font-size: .85rem; color: #0d1020; }
.pad { flex: 1; position: relative; margin: 8px 12px; border-radius: 26px; border: 1px solid rgba(0,240,255,.25);
  background:
    linear-gradient(90deg, rgba(255,61,242,.10) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(rgba(0,240,255,.10) 1px, transparent 1px) 0 0 / 34px 34px,
    rgba(0,0,0,.2);
  overflow: hidden; }
.pad-ring { position: absolute; width: 150px; height: 150px; margin: -75px 0 0 -75px; left: 50%; top: 50%; border-radius: 50%;
  border: 2px solid rgba(0,240,255,.5); box-shadow: 0 0 24px rgba(0,240,255,.3), inset 0 0 24px rgba(255,61,242,.2); transition: opacity .2s; }
.pad-knob { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--knob, #ff3df2) 45%, #2a0b3d 100%); box-shadow: 0 0 24px var(--knob, #ff3df2); }
.pad-hint { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; color: var(--muted); margin: 0; font-size: .9rem; }
.boost {
  margin: 4px 12px calc(14px + env(safe-area-inset-bottom)); min-height: 84px; border-radius: 24px; border: 0;
  font-weight: 900; font-size: 1.6rem; letter-spacing: .2em; font-style: italic; color: #0d1020; cursor: pointer;
  background: linear-gradient(135deg, #ffe66d, #ff3d8b); box-shadow: 0 10px 40px -10px rgba(255,61,139,.8);
  touch-action: none;
}
.boost.on { filter: brightness(1.3); transform: scale(.98); box-shadow: 0 0 40px rgba(255,230,109,.9); }
.boost.free { background: linear-gradient(135deg, #ff6bd6, #00f0ff); }
.boost:disabled { opacity: .4; }
.phone-card, .dead {
  position: absolute; left: 12px; right: 12px; top: 110px; padding: 18px; border-radius: 22px;
  background: rgba(21,26,51,.94); border: 1px solid rgba(255,61,242,.35); display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px -20px rgba(255,61,242,.5); max-height: calc(100% - 230px); overflow: auto;
}
.phone-card h2, .dead h2 { margin: 0; font-size: 1.4rem; }
.phone-card p, .dead p { margin: 0; color: var(--muted); }
.phone-card .setting > span { min-width: 0; width: 100%; }
.phone-card.peek { pointer-events: none; opacity: .9; top: auto; bottom: 110px; }
.dead { text-align: center; align-items: center; pointer-events: none; }
.dead .big { font-size: 3rem; font-weight: 900; color: #fff; text-shadow: 0 0 20px #ff3d6e; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #151a33; border: 1px solid var(--border); padding: 10px 16px; border-radius: 999px; font-weight: 600; opacity: 0; transition: opacity .2s; z-index: 60; pointer-events: none; }
.toast.on { opacity: 1; }

@media (max-width: 700px) {
  .panel { left: 50%; transform: translate(-50%, -50%); }
  .board { width: 190px; }
  .banner { font-size: 2.6rem; }
}

/* In a party, party.js draws its Party button top-right. */
html.party #phone .status { padding-top: 66px; }
html.party.tv .board { top: 12vh; }
