:root {
  --bg: #05060a;
  --panel: rgba(12, 16, 30, 0.82);
  --text: #e8ecff;
  --dim: #8a93b8;
  --blue: #2f7bff;
  --red: #ff3048;
  --ok: #3ddc84;
  --warn: #ffc542;
  --bad: #ff5468;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
.hidden { display: none !important; }
.dim { color: var(--dim); }

button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; color: #fff; }
.big-btn, .mid-btn { display: block; width: 100%; font-weight: 800; letter-spacing: 0.04em; background: #2b3352; }
.big-btn { padding: 28px 16px; font-size: 1.35rem; background: linear-gradient(135deg, #3d5afe, #7c4dff); }
.mid-btn { padding: 16px; font-size: 1.1rem; }
.mid-btn.secondary { background: #2b3352; }
.small-btn { padding: 6px 12px; font-size: 0.8rem; background: #2b3352; font-weight: 600; }
.small-btn.active { background: #3d5afe; }
.warning { background: rgba(255, 197, 66, 0.12); border: 1px solid rgba(255, 197, 66, 0.4); color: var(--warn); padding: 10px 12px; border-radius: 8px; font-size: 0.9rem; }
.error { color: var(--bad); font-weight: 600; }

/* ======================================================================== */
/* TV                                                                       */
/* ======================================================================== */
body.tv { overflow: hidden; }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }

.hud, .swing-panel, .help, .banner, .feedback, .countdown, .paused, .debug-panel { position: fixed; z-index: 2; }

.hud { top: 16px; left: 16px; background: var(--panel); padding: 12px 16px; border-radius: 10px; font-size: 1.05rem; line-height: 1.45; }
.hud .stats b { font-size: 1.2rem; }
.hud .stats .dim { font-size: 0.8rem; }
.hud .conn { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.1); font-size: 0.9rem; }
.conn-line::before { content: ''; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; background: var(--blue); }
.conn-line.ok { color: var(--ok); }
.conn-line.warn { color: var(--warn); }
.conn-line.bad { color: var(--bad); }

.swing-panel { top: 16px; right: 16px; display: flex; gap: 10px; }
.sp-side { background: var(--panel); padding: 10px 14px; border-radius: 10px; min-width: 150px; font-size: 0.85rem; line-height: 1.5; border-top: 3px solid var(--blue); }
.sp-title { font-weight: 800; letter-spacing: 0.08em; }
.sp-arrow { font-size: 2rem; line-height: 1.1; }

.help { bottom: 12px; left: 16px; color: var(--dim); font-size: 0.8rem; display: flex; gap: 12px; align-items: center; }

.banner { top: 16px; left: 50%; transform: translateX(-50%); background: rgba(255, 48, 72, 0.9); color: #fff; font-weight: 800; letter-spacing: 0.06em; padding: 10px 22px; border-radius: 8px; }

.feedback { top: 26%; left: 50%; transform: translate(-50%, -50%) scale(0.9); font-size: 2.2rem; font-weight: 900; opacity: 0; transition: opacity 0.15s, transform 0.15s; pointer-events: none; text-shadow: 0 0 18px rgba(0, 0, 0, 0.8); white-space: nowrap; }
.feedback.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.feedback.hit { color: var(--ok); }
.feedback.miss { color: var(--bad); }
.feedback.wrong, .feedback.weak { color: var(--warn); font-size: 1.5rem; }

.countdown { inset: 0; display: grid; place-items: center; font-size: 22vh; font-weight: 900; pointer-events: none; text-shadow: 0 0 40px rgba(61, 90, 254, 0.8); }
.countdown.pop { animation: pop 0.8s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 30% { transform: scale(1); opacity: 1; } to { opacity: 0.2; } }
.paused { inset: 0; display: grid; place-items: center; font-size: 3rem; font-weight: 900; background: rgba(0, 0, 0, 0.45); }

/* Debug columns sit at the screen edges so the track and sabers stay visible. */
.debug-panel { inset: 0; pointer-events: none; }
.debug-panel pre { position: absolute; width: min(430px, 31vw); margin: 0; background: rgba(0, 0, 0, 0.78); padding: 10px 12px; border-radius: 8px; font: 11px/1.45 var(--mono); white-space: pre-wrap; overflow: hidden; }
#debugSaber { right: 16px; top: 156px; border-left: 3px solid var(--blue); }
#debugLog { left: 16px; bottom: 44px; max-height: 22vh; }

.lobby { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px; background: radial-gradient(ellipse at center, rgba(14, 18, 40, 0.94), rgba(5, 6, 10, 0.98)); overflow: auto; }
.lobby > :first-child { margin-top: auto; } /* centred when it fits, scrollable when it doesn't */
.lobby > :last-child { margin-bottom: auto; }
.lobby h1 { margin: 0; font-size: 2.2rem; letter-spacing: 0.18em; }
.lobby .sub { margin: 0; color: var(--dim); }
.qr-row { display: flex; gap: 48px; flex-wrap: wrap; justify-content: center; }
.qr-card { width: min(380px, 80vw); text-align: center; background: var(--panel); padding: 16px 20px; border-radius: 16px; border-top: 6px solid var(--blue); }
.qr-title { font-size: 1.6rem; font-weight: 900; letter-spacing: 0.1em; color: var(--blue); }
.qr-sub { color: var(--dim); margin-bottom: 12px; }
.qr { width: min(100%, 300px, 36vh); aspect-ratio: 1; background: #fff; border-radius: 10px; padding: 8px; }
.qr-status { margin-top: 12px; font-size: 1.25rem; font-weight: 700; }
.qr-status.ok { color: var(--ok); }
.qr-status.bad { color: var(--bad); }
.qr-url { margin-top: 8px; font: 11px var(--mono); color: var(--dim); word-break: break-all; }
.lobby-footer { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 760px; text-align: center; }
.lobby-footer .mid-btn { width: auto; padding: 12px 28px; background: linear-gradient(135deg, #3d5afe, #7c4dff); }
.net-row select { font: 13px var(--mono); padding: 4px; background: #11152a; color: var(--text); border: 1px solid #2b3352; border-radius: 6px; }

/* ======================================================================== */
/* Phone                                                                    */
/* ======================================================================== */
body.phone { min-height: 100%; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
body.phone { --side: var(--blue); }
body.phone.unlinked { --side: #555c7a; }

.side-header { position: sticky; top: 0; z-index: 3; padding: calc(14px + env(safe-area-inset-top)) 16px 12px; background: linear-gradient(180deg, var(--side), color-mix(in srgb, var(--side) 35%, var(--bg))); }
.side-label { font-size: 2rem; font-weight: 900; letter-spacing: 0.12em; text-align: center; }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.conn-status { font-size: 0.85rem; font-weight: 600; }
.conn-status.ok { color: #d6ffe6; }
.conn-status.warn { color: #fff1c9; }
.conn-status.bad { color: #ffe0e4; }
.side-header .small-btn { background: rgba(0, 0, 0, 0.35); flex-shrink: 0; }

.phone-main { padding: 18px 16px calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.phone-main section { display: flex; flex-direction: column; gap: 14px; }
.connected-title { font-size: 1.6rem; font-weight: 900; text-align: center; color: var(--ok); letter-spacing: 0.06em; }
.hint { text-align: center; font-size: 1.05rem; }
.hint.small { font-size: 0.85rem; color: var(--dim); margin: 0; }

.swing-indicator { text-align: center; padding: 12px; border-radius: 14px; background: var(--panel); border: 2px solid var(--side); }
.swing-arrow { font-size: 4.5rem; line-height: 1; height: 4.5rem; }
.swing-text { font-weight: 800; font-size: 1.1rem; letter-spacing: 0.06em; margin-top: 4px; }
.swing-indicator.pulse { animation: swingpulse 0.45s ease-out; }
@keyframes swingpulse { from { background: var(--side); } to { background: var(--panel); } }

.debug-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; background: var(--panel); border-radius: 12px; padding: 12px 14px; font: 13px/1.4 var(--mono); }
.debug-grid > div:not([id]):not(.dg-head) { color: var(--dim); }
.debug-grid .dg-head { grid-column: 1 / -1; margin-top: 8px; font-family: system-ui, sans-serif; font-weight: 800; font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--side); }
.debug-grid .dg-head:first-child { margin-top: 0; }

.tuning { background: var(--panel); border-radius: 12px; padding: 10px 14px; }
.tuning summary { font-weight: 700; cursor: pointer; }
.tune-row { display: grid; grid-template-columns: 1fr 1.3fr 3.2em; align-items: center; gap: 8px; margin: 10px 0; font-size: 0.85rem; }
.tune-row input[type='range'] { width: 100%; }
.tune-row output { font: 12px var(--mono); text-align: right; }
.tune-row select { grid-column: 2 / -1; padding: 4px; background: #11152a; color: var(--text); border: 1px solid #2b3352; border-radius: 6px; font-size: 0.9rem; }

.flash { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; font-size: 3.4rem; font-weight: 900; pointer-events: none; opacity: 0; transition: opacity 0.25s; }
.flash.show { opacity: 1; transition: none; }
.flash.hit { background: rgba(61, 220, 132, 0.35); }
.flash.wrong { background: rgba(255, 197, 66, 0.3); }
.flash.miss { background: rgba(255, 84, 104, 0.3); }
