:root {
  --bg: #0b1026; --ink: #f5f7ff; --muted: #aab3d6; --accent: #ffd54a; --team: #ffd54a;
  --glass: rgba(11, 16, 38, .72); --line: rgba(255, 255, 255, .16);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; }
.hidden { display: none !important; }

#cam { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; background: #000; }
#sky { position: fixed; inset: 0; z-index: 0; display: none;
  background: radial-gradient(ellipse at 50% 120%, #2a2f6b 0%, #0b1026 60%), #0b1026; }
#sky::after { content: ''; position: absolute; inset: 0; opacity: .7;
  background-image: radial-gradient(1px 1px at 20% 30%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 70% 60%, #fff 50%, transparent 51%),
  radial-gradient(1.5px 1.5px at 40% 80%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 85% 20%, #fff 50%, transparent 51%),
  radial-gradient(1px 1px at 10% 70%, #fff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 55% 15%, #fff 50%, transparent 51%);
  background-size: 180px 180px; }
body.nocam #sky { display: block; } body.nocam #cam { display: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
#hud::before { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 0 var(--team); transition: box-shadow .3s; }
body.carrying #hud::before { box-shadow: inset 0 0 40px 8px var(--team); }
body.draining #hud::before { box-shadow: inset 0 0 50px 10px rgba(255, 40, 80, .75); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.topbar { position: absolute; top: calc(10px + var(--safe-top)); left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; }
.chip { background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 15px; backdrop-filter: blur(6px); }
.team-chip { color: var(--team); }
.timer { margin-left: auto; background: var(--glass); border-radius: 12px; padding: 6px 12px; font: 700 20px/1 ui-monospace, monospace; border: 1px solid var(--line); }
.scorebar { position: absolute; top: calc(54px + var(--safe-top)); left: 10px; right: 10px; display: flex; gap: 6px; font-size: 13px; }
.scorebar .s { flex: 1; background: var(--glass); border-radius: 10px; padding: 4px 8px; border-left: 4px solid var(--c); display: flex; justify-content: space-between; }
.scorebar .s.me { outline: 2px solid var(--c); }
.scorebar .hiddenmsg { flex: 1; text-align: center; background: var(--glass); border-radius: 10px; padding: 4px 8px; color: var(--accent); font-weight: 700; }

.reticle { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; transform: translate(-50%, -50%); }
.reticle .ring { position: absolute; inset: 0; border: 2px solid rgba(255, 255, 255, .7); border-radius: 50%; transition: transform .15s, border-color .15s; }
.reticle .dot { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: #fff; }
.reticle.on .ring { transform: scale(.75); border-color: var(--accent); border-width: 3px; }
.reticle.locked .ring { border-color: var(--team); border-width: 4px; }

#arrows .arrow { position: absolute; width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent; border-bottom: 26px solid var(--c, #fff);
  filter: drop-shadow(0 0 6px var(--c, #fff)); transform-origin: 50% 60%; }
#arrows .arrow span { position: absolute; top: 28px; left: -40px; width: 80px; text-align: center; font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000; }

.banner { position: absolute; top: 30%; left: 12px; right: 12px; text-align: center; padding: 12px 14px; border-radius: 16px; font-weight: 800; font-size: 20px;
  background: rgba(255, 213, 74, .92); color: #1b1300; box-shadow: 0 6px 30px rgba(255, 213, 74, .5); }
.banner.alert { background: rgba(235, 40, 75, .95); color: #fff; animation: beatpulse .8s infinite; }
@keyframes beatpulse { 50% { transform: scale(1.03); } }
.banner.team { background: var(--team); color: #0b1026; }
.banner small { display: block; font-weight: 600; font-size: 14px; }

.hint { position: absolute; left: 0; right: 0; margin: 0 auto; width: fit-content; max-width: calc(100% - 24px); top: 64%; text-align: center; font-weight: 700; font-size: 17px; }
.hint:not(:empty) { background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px; backdrop-filter: blur(6px); }

.bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 10px calc(14px + var(--safe-bottom)); pointer-events: none; }
.bottom > * { pointer-events: auto; }
.powered { pointer-events: none !important; text-align: center; font-size: 11px; letter-spacing: .04em; color: rgba(255, 255, 255, .72); margin-top: 6px; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.powered b { color: #fff; font-weight: 700; }
.carry { background: var(--glass); border: 2px solid var(--team); border-radius: 20px; padding: 12px; display: grid; grid-template-columns: 74px 1fr; gap: 6px 12px; align-items: center; backdrop-filter: blur(8px); }
.carry-orb { position: relative; width: 74px; height: 74px; grid-row: span 1; }
.carry-orb svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.carry-orb .track { fill: none; stroke: rgba(255, 255, 255, .15); stroke-width: 6; }
.carry-orb .fade { fill: none; stroke: var(--team); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 276.5; stroke-dashoffset: 0; }
.gem { position: absolute; inset: 18px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff, #9ee7ff 40%, #3d7bff 75%, transparent 76%); box-shadow: 0 0 20px #9ee7ff; animation: spin 3s linear infinite; }
.gem.gold { background: radial-gradient(circle at 40% 35%, #fff, #ffe680 40%, #ffb300 75%, transparent 76%); box-shadow: 0 0 24px #ffd54a; }
@keyframes spin { to { filter: hue-rotate(40deg); } }
.carry-text b { display: block; font-size: 17px; } .carry-text span { color: var(--muted); font-size: 14px; }
.launch { grid-column: 1 / -1; font-size: 18px; font-weight: 800; padding: 14px; border-radius: 14px; border: 0; background: var(--team); color: #0b1026; animation: pulse 1s infinite; }
.linkbtn { grid-column: 1 / -1; background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 13px; padding: 4px; }
.role-panel { background: var(--glass); border-radius: 16px; padding: 10px 14px; font-size: 14px; color: var(--muted); border: 1px solid var(--line); backdrop-filter: blur(6px); }
.role-panel b { color: var(--ink); }
.role-panel .cool { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .15); margin-top: 6px; overflow: hidden; }
.role-panel .cool i { display: block; height: 100%; background: var(--accent); }

.star-lock { position: absolute; left: 50%; top: 50%; width: 150px; height: 150px; transform: translate(-50%, -50%); }
.star-lock svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.star-lock .track { fill: none; stroke: rgba(255, 255, 255, .2); stroke-width: 5; }
.star-lock .prog { fill: none; stroke: var(--team); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 276.5; stroke-dashoffset: 276.5; transition: stroke-dashoffset .2s; }
.star-count { position: absolute; left: 50%; transform: translateX(-50%); top: 106%; white-space: nowrap; text-align: center; font-weight: 800; font-size: 17px; background: var(--glass); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; }

.meter { position: absolute; top: calc(86px + var(--safe-top)); left: 10px; right: 10px; background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px; backdrop-filter: blur(6px); }
.meter-label { display: flex; justify-content: space-between; font-weight: 800; margin-bottom: 4px; }
.meter-bar { height: 18px; border-radius: 9px; background: rgba(255, 255, 255, .15); overflow: hidden; display: flex; border: 1px solid var(--line); }
.meter-bar i { display: block; height: 100%; }
.beat { position: absolute; left: 50%; top: 50%; width: 120px; height: 120px; margin: -60px; border-radius: 50%; border: 4px solid var(--accent); opacity: 0; }

#toasts { position: fixed; z-index: 5; left: 12px; right: 12px; top: calc(96px + var(--safe-top)); display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: rgba(255, 255, 255, .95); color: #0b1026; border-radius: 12px; padding: 10px 12px; font-weight: 700; box-shadow: 0 4px 20px rgba(0, 0, 0, .4); animation: tin .25s ease-out; }
.toast.bad { background: #ff5d73; color: #fff; } .toast.gold { background: #ffd54a; }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } }
#flash { position: fixed; inset: 0; z-index: 4; pointer-events: none; background: #fff; opacity: 0; transition: opacity .4s; }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom)); text-align: center; overflow-y: auto; touch-action: pan-y;
  background: radial-gradient(ellipse at 50% 0%, #27306e, #0b1026 70%); }
.screen.glass { background: rgba(11, 16, 38, .82); backdrop-filter: blur(4px); }
.screen h1 { font-size: 40px; margin: 0; letter-spacing: .5px; } .screen h2 { margin: 0; font-size: 26px; }
.screen p { margin: 0; color: var(--muted); }
.small { font-size: 14px; color: var(--muted); } .err { color: #ff8b9a; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.logo-star { font-size: 72px; color: var(--accent); text-shadow: 0 0 30px var(--accent); animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(8deg); } }
button { font: inherit; color: inherit; cursor: pointer; }
.big { min-width: 240px; min-height: 56px; font-size: 20px; font-weight: 800; border: 0; border-radius: 16px; background: var(--accent); color: #1b1300; box-shadow: 0 6px 24px rgba(255, 213, 74, .35); }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; min-height: 48px; }
input { font: inherit; }
#nameInput, #codeInput { width: 100%; max-width: 320px; font-size: 22px; padding: 14px; border-radius: 14px; border: 2px solid var(--line); background: rgba(255, 255, 255, .08); color: var(--ink); text-align: center; -webkit-user-select: text; user-select: text; }
.check { display: flex; gap: 10px; align-items: center; max-width: 320px; text-align: left; color: var(--muted); font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.team-big { font-size: 22px; font-weight: 800; color: var(--team); padding: 8px 18px; border: 2px solid var(--team); border-radius: 999px; }
.scanframe { width: 62vw; max-width: 280px; aspect-ratio: 1; border-radius: 20px; position: relative; box-shadow: 0 0 0 9999px rgba(11, 16, 38, .55); }
.scanframe::before { content: ''; position: absolute; inset: 0; border: 3px solid var(--team); border-radius: 20px; }
.scanframe div { position: absolute; left: 8%; right: 8%; height: 3px; background: var(--team); top: 10%; animation: scan 2s ease-in-out infinite alternate; box-shadow: 0 0 12px var(--team); }
@keyframes scan { to { top: 88%; } }
#s-calibrate { background: transparent; backdrop-filter: none; justify-content: space-between; }
.calcard { position: relative; z-index: 1; background: var(--glass); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; backdrop-filter: blur(8px); max-width: 360px; }
.calcard p { color: var(--ink); }
.role-card { background: rgba(255, 255, 255, .07); border: 1px solid var(--line); border-radius: 16px; padding: 14px; max-width: 360px; text-align: left; }
.role-card b { font-size: 20px; color: var(--accent); display: block; margin-bottom: 4px; }
.standings { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 8px; }
.standings .row { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; background: rgba(255, 255, 255, .06); border-radius: 12px; padding: 8px 10px; border-left: 5px solid var(--c); text-align: left; }
.standings .row.me { outline: 2px solid var(--c); }
.standings .row .bar { grid-column: 2 / -1; height: 6px; border-radius: 3px; background: var(--c); }
.awards { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 380px; }
.awards div { background: rgba(255, 213, 74, .12); border: 1px solid rgba(255, 213, 74, .4); border-radius: 12px; padding: 6px 10px; font-size: 13px; }
.mystats { font-size: 14px; color: var(--muted); }
dialog { border: 0; border-radius: 20px; background: #161c3f; color: var(--ink); width: min(92vw, 360px); text-align: center; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin: 4px 0; } dialog .row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
dialog .row button { min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0; } #codeOk { background: var(--accent); color: #1b1300; font-weight: 800; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
