:root {
  --bg: #0b1020;
  --card: rgba(24, 30, 64, .72);
  --line: rgba(255, 255, 255, .09);
  --text: #eef1ff;
  --muted: #9aa3c7;
  --gold: #ffb020;
  --cyan: #22d3ee;
  --grad: linear-gradient(135deg, #ffd04a, #ff8a3d 55%, #ff5a5f);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--text);
  color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  background:
    radial-gradient(900px 600px at 10% -10%, rgba(124, 58, 237, .35), transparent 60%),
    radial-gradient(800px 600px at 110% 25%, rgba(34, 211, 238, .16), transparent 60%),
    radial-gradient(700px 500px at 50% 120%, rgba(255, 106, 61, .22), transparent 60%),
    var(--bg);
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; }
a { color: var(--cyan); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
h2 { margin: 0; }

/* screens */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  opacity: 0; visibility: hidden; transform: translateY(14px) scale(.985);
  transition: opacity .25s, transform .25s, visibility .25s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; }
.screen.center { justify-content: center; align-items: center; }

.logo { text-align: center; line-height: .88; filter: drop-shadow(0 6px 24px rgba(255, 138, 61, .35)); }
.logo span { display: block; font-weight: 800; letter-spacing: .55em; margin-left: .55em; font-size: 14px; color: #cfd6ff; }
.logo b {
  display: block; font-size: 64px; font-weight: 900; font-style: italic; letter-spacing: -.02em; padding: 0 .1em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .12); border-top-color: var(--gold); animation: spin2 .8s linear infinite; }
@keyframes spin2 { to { transform: rotate(360deg); } }

/* buttons & inputs */
.btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 14px 16px; border-radius: 16px; font-weight: 800; font-size: 16px;
  background: rgba(255, 255, 255, .07); border: 1px solid var(--line);
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn small { font-weight: 600; font-size: 12px; opacity: .75; margin-top: 2px; }
.btn.primary { background: var(--grad); color: #1f1000; border: 0; box-shadow: 0 8px 26px rgba(255, 120, 50, .35), inset 0 1px 0 rgba(255, 255, 255, .5); }
.btn.big { padding: 17px 20px; font-size: 18px; border-radius: 20px; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(255, 77, 94, .14); border-color: rgba(255, 77, 94, .35); color: #ff9aa5; }
.icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 14px; background: rgba(255, 255, 255, .06); border: 1px solid var(--line); font-size: 20px; }
.icon-spacer { width: 44px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
input[type=text], input:not([type]) {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .28); color: var(--text); font-size: 17px; font-weight: 700; outline: none;
  user-select: text; -webkit-user-select: text;
}
input:not([type]):focus { border-color: var(--gold); }

.card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; padding: 22px; border-radius: 26px; background: var(--card); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.card p { margin: 0; text-align: center; }
.avatars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.avb { aspect-ratio: 1; border-radius: 14px; font-size: 26px; background: rgba(255, 255, 255, .05); border: 2px solid transparent; transition: transform .1s; }
.avb.on { border-color: var(--gold); background: rgba(255, 176, 32, .15); transform: scale(1.06); }

/* home */
#s-home { align-items: center; }
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h2 { font-size: 18px; }
.me { display: flex; align-items: center; gap: 10px; padding: 5px 16px 5px 5px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 800; max-width: 70%; }
.me span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .av { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #262f66; font-size: 21px; }
.demo-wrap { perspective: 900px; flex: 1; min-height: 0; display: grid; place-items: center; pointer-events: none; }
#h-demo {
  width: min(70vw, 340px, 34vh); aspect-ratio: 1;
  transform: rotateX(50deg) rotateZ(0deg); animation: tilt-spin 80s linear infinite;
  filter: drop-shadow(0 30px 30px rgba(0, 0, 0, .6));
}
@keyframes tilt-spin { to { transform: rotateX(50deg) rotateZ(360deg); } }
.menu { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.join { display: flex; gap: 10px; }
.join input { flex: 1; min-width: 0; text-align: center; letter-spacing: .4em; font-size: 20px; font-weight: 900; text-transform: uppercase; }
.join .btn { flex: none; width: 42%; }

.top-icons { display: flex; gap: 8px; }
.row-btn { flex-direction: row; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: rgba(74, 222, 128, .16); color: #4ade80; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #ff4d5e; box-shadow: 0 0 8px #ff4d5e; }
.center { text-align: center; }

/* modes */
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.mode-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 2px; border-radius: 14px;
  font-size: 12px; font-weight: 800; color: var(--muted); background: var(--card); border: 1px solid var(--line); transition: transform .1s;
}
.mode-btn span { font-size: 22px; line-height: 1.2; }
.mode-btn.on { color: var(--text); border-color: var(--gold); background: rgba(255, 176, 32, .14); box-shadow: 0 0 16px rgba(255, 176, 32, .22); }
.mode-btn:active { transform: scale(.96); }
.mode-btn:disabled:not(.on) { opacity: .4; }
.mode-desc { text-align: center; margin: 0; min-height: 2.8em; line-height: 1.4; }

/* lobby */
.code-card { text-align: center; padding: 18px; border-radius: 24px; background: var(--card); border: 1px solid var(--line); }
.code { font-size: 58px; font-weight: 900; letter-spacing: .2em; margin: 2px 0 12px; padding-left: .2em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; cursor: pointer; }
.slots { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.slot { display: flex; align-items: center; gap: 10px; padding: 9px 12px; min-height: 60px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.slot.empty { opacity: .5; border-style: dashed; }
.slot .av { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #262f66; font-size: 24px; }
.slot .nm { flex: 1; min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot i { color: var(--muted); font-style: normal; font-weight: 600; }
.tag { font-size: 11px; font-weight: 900; padding: 3px 8px; border-radius: 99px; background: rgba(255, 176, 32, .18); color: var(--gold); white-space: nowrap; }
.tag.bot { background: rgba(34, 211, 238, .15); color: var(--cyan); }
.tag.off { background: rgba(255, 255, 255, .08); color: var(--muted); }
.x { width: 34px; height: 34px; flex: none; border-radius: 10px; background: rgba(255, 255, 255, .07); }
.addf { width: 32px; height: 32px; flex: none; border-radius: 10px; font-size: 14px; background: rgba(34, 211, 238, .14); color: var(--cyan); }
#s-lobby { overflow-y: auto; }
#l-host { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
#l-bots .btn { padding: 12px 6px; font-size: 13px; }
.wait { text-align: center; margin-top: auto; }

/* game */
#s-game { gap: 8px; padding-left: 8px; padding-right: 8px; }
.g-top { display: flex; gap: 6px; align-items: stretch; }
#g-players { flex: 1; min-width: 0; display: flex; gap: 6px; }
.pc {
  --c: #fff; --t: 0;
  position: relative; flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
  padding: 5px 8px 5px 5px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); transition: box-shadow .2s, border-color .2s, opacity .2s;
}
.pc.turn { border-color: var(--c); box-shadow: 0 0 0 1px var(--c), 0 0 20px -4px var(--c); }
.pc.off { opacity: .45; }
.pc .av { width: 38px; height: 38px; flex: none; padding: 3px; border-radius: 50%; background: color-mix(in srgb, var(--c) 45%, transparent); }
.pc.turn .av { background: conic-gradient(var(--c) calc(var(--t) * 360deg), rgba(255, 255, 255, .1) 0); }
.pc .av span { width: 100%; height: 100%; display: grid; place-items: center; border-radius: 50%; background: #1b2152; font-size: 19px; }
.pc .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pc .info b { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pwm { font-size: 10px; letter-spacing: 1px; white-space: nowrap; overflow: hidden; }
.pc .sc { font-weight: 900; font-size: 19px; color: var(--c); font-variant-numeric: tabular-nums; }
.pc .sc small, .results b small { font-size: .6em; opacity: .6; }
.side { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .55); vertical-align: -1px; }
.side.s0 { background: #fffaf0; }
.side.s1 { background: #111; }
.side-pill { grid-column: 1 / -1; height: 58px; display: flex; align-items: center; justify-content: center; gap: 4px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); font-weight: 700; color: var(--muted); }
.side-pill b { color: var(--text); }
.qb { position: absolute; top: -9px; right: -3px; font-size: 16px; animation: bob .6s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-3px); } }
@media (max-width: 480px) { #g-players[data-n="4"] .info, #g-players[data-n="3"] .info b { display: none; } }
.bubble { position: absolute; left: 50%; top: 100%; z-index: 5; font-size: 34px; pointer-events: none; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .5)); animation: bubble 2.6s ease forwards; }
@keyframes bubble {
  0% { transform: translate(-50%, -10px) scale(.2); opacity: 0; }
  15% { transform: translate(-50%, 8px) scale(1.25); opacity: 1; }
  25% { transform: translate(-50%, 6px) scale(1); }
  80% { opacity: 1; }
  100% { transform: translate(-50%, 34px); opacity: 0; }
}

.board-wrap { flex: 1; min-height: 0; display: grid; place-items: end center; } /* hug the controls */
.board-box { position: relative; }
#board { display: block; border-radius: 16px; touch-action: none; box-shadow: 0 22px 60px rgba(0, 0, 0, .65), 0 0 0 1px rgba(255, 255, 255, .05); }
#g-banner {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; opacity: 0;
  font-size: clamp(30px, 10vw, 52px); font-weight: 900; font-style: italic; text-align: center;
  color: #fff; text-shadow: 0 4px 24px rgba(0, 0, 0, .7), 0 0 30px rgba(255, 176, 32, .5);
}
#g-banner.power { color: #ffe39a; text-shadow: 0 4px 24px rgba(0, 0, 0, .7), 0 0 40px rgba(192, 132, 252, .9); }
#g-banner.show { animation: banner 1.4s ease forwards; }
@keyframes banner {
  0% { opacity: 0; transform: scale(2.2); }
  15%, 70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.92) translateY(-20px); }
}

.g-controls { position: relative; display: flex; flex-direction: column; gap: 6px; }
#g-status { text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); min-height: 18px; }
#g-status.hurry { color: #ff8a8a; animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .55; } }
#g-slider { -webkit-appearance: none; appearance: none; width: 100%; height: 40px; margin: 0; background: transparent; }
#g-slider::-webkit-slider-runnable-track { height: 10px; border-radius: 99px; background: linear-gradient(90deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .2), rgba(255, 255, 255, .06)); }
#g-slider::-moz-range-track { height: 10px; border-radius: 99px; background: rgba(255, 255, 255, .14); }
#g-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 38px; height: 38px; margin-top: -14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #cdd5e6); box-shadow: 0 4px 12px rgba(0, 0, 0, .5), 0 0 0 4px var(--gold);
}
#g-slider::-moz-range-thumb { width: 34px; height: 34px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px var(--gold); }
#g-slider:disabled::-webkit-slider-thumb { box-shadow: 0 4px 12px rgba(0, 0, 0, .5), 0 0 0 4px rgba(255, 255, 255, .15); }
.g-bottom { display: flex; gap: 8px; align-items: center; }
#g-powers { flex: 1; display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: 8px; }
#g-powers.many { gap: 5px; }
#g-powers.many small { display: none; }
#g-clock {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%); z-index: 2; padding: 5px 14px; border-radius: 99px;
  font-weight: 900; font-variant-numeric: tabular-nums; background: #141a3a; border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
#g-clock.low { color: #ff8a8a; border-color: rgba(255, 77, 94, .5); animation: pulse .5s ease-in-out infinite alternate; }
.pw-btn {
  height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 16px; background: var(--card); border: 1px solid var(--line); transition: transform .15s, box-shadow .15s, background .15s;
}
.pw-btn span { font-size: 24px; line-height: 1; }
.pw-btn small { font-size: 10px; font-weight: 800; color: var(--muted); }
.pw-btn.empty { border-style: dashed; opacity: .3; }
.pw-btn:disabled { opacity: .5; }
.pw-btn.armed { background: linear-gradient(135deg, rgba(168, 85, 247, .5), rgba(34, 211, 238, .35)); border-color: #c084fc; box-shadow: 0 0 22px rgba(192, 132, 252, .65); transform: translateY(-3px); }
.pw-btn.armed small { color: #fff; }
#g-emote { width: 58px; height: 58px; font-size: 26px; border-radius: 16px; }
#g-emotes {
  position: absolute; right: 0; bottom: 66px; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 8px; border-radius: 18px; background: rgba(16, 21, 48, .97); border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0, 0, 0, .5); animation: tin .15s ease;
}
#g-emotes button { width: 50px; height: 50px; border-radius: 12px; font-size: 28px; }
#g-emotes button:active { background: rgba(255, 255, 255, .1); }

/* friends */
.myid { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, .05); }
.myid b { color: var(--gold); font-size: 18px; }
.addrow { margin-bottom: 4px; }
.addrow input { letter-spacing: normal; font-size: 16px; font-weight: 700; text-transform: none; text-align: left; }
.addrow .btn { width: auto; flex: none; padding: 0 22px; }
.fl { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fl li { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 14px; background: rgba(255, 255, 255, .05); }
.fl .ic { padding: 7px 9px; }
.fl .av { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #262f66; font-size: 20px; }
.fl .nm { flex: 1; min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl .nm small { display: block; font-weight: 600; font-size: 12px; color: var(--muted); }
.btn.small { flex: none; padding: 8px 12px; font-size: 13px; border-radius: 12px; }

/* toasts */
#toasts { position: fixed; z-index: 50; top: calc(max(12px, env(safe-area-inset-top)) + 62px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { padding: 9px 16px; border-radius: 999px; background: rgba(12, 16, 38, .94); border: 1px solid var(--line); font-weight: 700; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .45); animation: tin .25s ease; transition: opacity .4s, transform .4s; }
.toast.bad { border-color: rgba(255, 77, 94, .5); color: #ffb3bb; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { opacity: 0; transform: translateY(-10px) scale(.95); } }
#net { position: fixed; z-index: 60; bottom: calc(env(safe-area-inset-bottom) + 14px); left: 50%; transform: translateX(-50%); padding: 8px 16px; border-radius: 99px; background: #4a1d24; color: #ffc2c8; font-weight: 800; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); }

/* modals */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; padding: 10px; background: rgba(4, 6, 16, .62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom)); border-radius: 26px;
  background: linear-gradient(180deg, #1c2455, #121838); border: 1px solid rgba(255, 255, 255, .1); box-shadow: 0 -10px 60px rgba(0, 0, 0, .5);
  animation: up .3s cubic-bezier(.2, .9, .3, 1.15);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 600px) { .modal { align-items: center; } }
.sheet h2 { font-size: 22px; margin-bottom: 12px; }
.sheet h3 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.sheet p { line-height: 1.45; }
.sheet > .btn { width: 100%; margin-top: 14px; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions > * { flex: 1; }
.actions.col { flex-direction: column; }
.actions p { margin: 0; align-self: center; text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; font-weight: 800; color: var(--muted); }
.sheet .avatars { margin-bottom: 12px; }
.toggles { display: flex; gap: 10px; margin: 14px 0; }
.tg { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-radius: 14px; background: rgba(255, 255, 255, .05); border: 1px solid var(--line); font-weight: 800; }
.tg input { order: 2; flex: none; appearance: none; -webkit-appearance: none; position: relative; width: 42px; height: 24px; margin: 0; border-radius: 99px; background: rgba(255, 255, 255, .15); transition: background .2s; }
.tg input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; }
.tg input:checked { background: var(--cyan); }
.tg input:checked::after { left: 21px; }
.links { text-align: center; }
.over-title { text-align: center; font-size: 30px !important; font-style: italic; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.results li, .hist li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, .05); }
.results li.mine { background: rgba(255, 176, 32, .14); box-shadow: inset 0 0 0 1px rgba(255, 176, 32, .4); }
.results .medal, .hist .medal { font-size: 22px; width: 28px; text-align: center; }
.results .av { font-size: 22px; }
.results .nm { flex: 1; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results b { font-size: 20px; font-variant-numeric: tabular-nums; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tiles div { padding: 14px; border-radius: 16px; background: rgba(255, 255, 255, .05); text-align: center; }
.tiles b { display: block; font-size: 28px; font-weight: 900; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tiles small { color: var(--muted); font-weight: 700; }
.hist { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.hist .opp { font-weight: 700; font-size: 14px; }
.hist small { color: var(--muted); }
.help { padding-left: 20px; margin: 0; display: grid; gap: 8px; line-height: 1.4; }
.powers-help { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.powers-help li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, .05); }
.powers-help span { font-size: 28px; }
.powers-help b, .powers-help small { display: block; }
.powers-help small { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  #h-demo { animation: none; }
  .screen { transition: none; }
}
