:root {
  --bg: #0d1016;
  --panel: #151a23;
  --panel2: #1c2230;
  --line: #2a3242;
  --text: #e8ecf3;
  --muted: #8b95a8;
  --gold: #f2c230;
  --red: #ff3b30;
  --green: #2fd07a;
  --blue: #3d7bff;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button { font: inherit; color: inherit; }
kbd { font: 600 10px/1 ui-monospace, Menlo, monospace; padding: 2px 4px; border-radius: 3px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15); margin-left: 4px; opacity: .8; }
.small { font-size: 12px; color: var(--muted); }

/* ---------- buttons */
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.btn:hover { border-color: #46526a; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.lit, .tt-btn.lit { background: #3a3110; border-color: var(--gold); color: var(--gold); }
.btn.flag { border-color: #6b5412; }
.btn.flag.on { background: var(--gold); color: #111; }

/* ---------- lobby */
body.lobby { overflow: auto; background: radial-gradient(1200px 600px at 20% -10%, #1b2a55 0%, transparent 60%), var(--bg); }
.lobby-main { max-width: 980px; margin: 0 auto; padding: 32px 16px 48px; }
.logo { font: 800 28px/1 "Arial Black", Arial, sans-serif; letter-spacing: .04em; display: flex; align-items: center; gap: 12px; }
.logo b { color: var(--gold); }
.rec { width: 14px; height: 14px; border-radius: 50%; background: var(--red); box-shadow: 0 0 12px var(--red); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.lobby-head p { color: var(--muted); max-width: 640px; font-size: 15px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.join { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field input { width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line); background: #0b0e14; color: var(--text); font-size: 18px; letter-spacing: .04em; }
.field input.err { border-color: var(--red); }
.field small { color: var(--muted); }
.sect { margin: 28px 0 12px; font-size: 13px; letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }
.roles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.role { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 96px; transition: border-color .15s, transform .15s; }
.role:hover { border-color: var(--gold); transform: translateY(-1px); }
.role.big { grid-column: span 2; background: linear-gradient(135deg, #1d2a4f, var(--panel)); }
.role-name { font-weight: 700; font-size: 17px; }
.role-sub { color: var(--muted); font-size: 13px; }
.role-taken { margin-top: auto; font-size: 12px; color: var(--gold); min-height: 16px; }
.role.taken { opacity: .7; }
.how { margin-top: 24px; }
.how summary { cursor: pointer; font-weight: 600; }
.how li { margin: 8px 0; color: #c9d1de; }
.lobby-foot { margin-top: 24px; color: var(--muted); font-size: 12px; }
@media (max-width: 720px) { .join { grid-template-columns: 1fr; } .roles { grid-template-columns: 1fr 1fr; } }

/* ---------- app shell */
body.app { overflow: hidden; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; display: block; }
#ui { position: fixed; inset: 0; z-index: 1; }
.vp { position: relative; }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok { color: var(--green); }
.conn.bad { color: var(--gold); }
#ui > .conn { position: absolute; top: 8px; right: 12px; }
.fatal { position: fixed; inset: 0; z-index: 10; background: rgba(5,7,10,.85); display: grid; place-items: center; }
.fatal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; max-width: 420px; }
.fatal-box .row { display: flex; gap: 8px; margin-top: 12px; }
.mv-nosig { position: absolute; inset: 0; display: none; place-items: center; font: 700 12px/1 ui-monospace, Menlo, monospace; letter-spacing: .2em; color: #5c6780; pointer-events: none; }
.mv-nosig.show { display: grid; }

/* ---------- score bug */
.bug { position: absolute; left: 3.5%; bottom: 6%; display: none; align-items: stretch; height: 7.2%; min-height: 16px; font: 800 1em/1 "Arial Black", Arial, sans-serif; font-size: clamp(7px, 1.35vw, 22px); box-shadow: 0 4px 18px rgba(0,0,0,.45); border-radius: .3em; overflow: hidden; pointer-events: none; z-index: 2; }
.bug.show { display: flex; }
.prog .bug { font-size: clamp(10px, 1.9vw, 34px); }
.pgm-return .bug, .big-cell .bug { font-size: clamp(6px, .75vw, 14px); }
.bug > div { display: flex; align-items: center; padding: 0 .6em; gap: .45em; }
.bug-team.home { background: #1a3d9e; color: #fff; }
.bug-team.away { background: #a61c1c; color: #fff; }
.bug-team .pts { background: rgba(0,0,0,.25); padding: 0 .4em; height: 100%; display: flex; align-items: center; min-width: 1.8em; justify-content: center; }
.bug-team .poss { width: .45em; height: .45em; border-radius: 50%; background: transparent; }
.bug-team .poss.on { background: var(--gold); }
.bug-clock { background: #10141d; color: #fff; }
.bug-clock span:first-child { color: var(--gold); }
.bug-down { background: #1e2533; color: #fff; font-family: Arial, sans-serif; font-weight: 700; }
.bug-replay { display: none !important; background: var(--gold); color: #111; }
.bug-replay.on { display: flex !important; }
.bug.td .bug-down { background: var(--gold); color: #111; }

/* ---------- camera station */
.role-camera .cam-view { position: absolute; inset: 0; cursor: grab; touch-action: none; }
.role-camera .cam-view:active { cursor: grabbing; }
.tally-border { position: absolute; inset: 0; border: 6px solid transparent; pointer-events: none; transition: border-color .1s; }
.tally-air .tally-border { border-color: var(--red); }
.tally-pvw .tally-border { border-color: var(--green); }
.vf-top { position: absolute; top: 14px; left: 18px; right: 18px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
.vf-name { font-size: 15px; background: rgba(0,0,0,.55); padding: 6px 10px; border-radius: 6px; }
.vf-where { display: block; font-size: 12px; color: var(--muted); }
.vf-tally { font: 800 14px/1 Arial, sans-serif; letter-spacing: .12em; padding: 8px 12px; border-radius: 6px; background: rgba(0,0,0,.55); color: var(--muted); }
.tally-air .vf-tally { background: var(--red); color: #fff; }
.tally-pvw .vf-tally { background: var(--green); color: #07130c; }
.safe { position: absolute; inset: 10% 10%; border: 1px dashed rgba(255,255,255,.18); pointer-events: none; }
.cross { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; pointer-events: none; background: linear-gradient(rgba(255,255,255,.55), rgba(255,255,255,.55)) center/1px 100% no-repeat, linear-gradient(90deg, rgba(255,255,255,.55), rgba(255,255,255,.55)) center/100% 1px no-repeat; opacity: .7; }
.vf-bottom { position: absolute; left: 18px; bottom: 16px; display: flex; gap: 10px; align-items: center; }
.zoom { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.55); padding: 7px 10px; border-radius: 6px; font-size: 11px; color: var(--muted); pointer-events: none; }
.zoom b { color: var(--text); font-size: 13px; min-width: 42px; }
.zbar { width: 140px; height: 6px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; }
.zfill { height: 100%; background: var(--gold); }
.toast { position: absolute; top: 70px; left: 50%; transform: translate(-50%, -10px); background: var(--gold); color: #111; font: 800 22px/1.2 Arial, sans-serif; padding: 12px 20px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; box-shadow: 0 8px 30px rgba(0,0,0,.5); text-align: center; max-width: 80%; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.help { position: absolute; left: 18px; bottom: 64px; background: rgba(8,10,14,.88); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: none; gap: 6px; flex-direction: column; font-size: 13px; max-width: 360px; }
.show-help .help { display: flex; }
.pgm-return { position: absolute; right: 16px; bottom: 16px; width: min(26vw, 340px); aspect-ratio: 16/9; border: 1px solid rgba(255,255,255,.25); border-radius: 4px; overflow: hidden; }
.pgm-return .vp { position: absolute; inset: 0; }
.pgm-return .lbl { position: absolute; top: 4px; left: 6px; font: 700 10px/1 ui-monospace, Menlo, monospace; background: rgba(0,0,0,.6); padding: 3px 5px; border-radius: 3px; letter-spacing: .1em; }

/* ---------- director */
.role-director #ui, .role-replay #ui { display: grid; grid-template-rows: auto 1fr auto; }
.dir-head { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 48px; }
.brand { font: 800 15px/1 "Arial Black", Arial, sans-serif; letter-spacing: .05em; white-space: nowrap; }
.brand b { color: var(--gold); }
.brand .room { font: 600 12px/1 -apple-system, Arial, sans-serif; color: var(--muted); margin-left: 8px; letter-spacing: .08em; }
.sit { flex: 1; text-align: center; font-size: 13px; color: #cfd6e4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sit .phase { color: var(--muted); }
.sit .phase.live { color: var(--red); font-weight: 700; }
.game-ctl { display: flex; align-items: center; gap: 8px; }
.sel { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; font: inherit; }
.dir-main { display: flex; flex-direction: column; gap: 8px; padding: 8px 10px; min-height: 0; }
.big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex: 1; min-height: 0; }
.big-cell { position: relative; border: 2px solid var(--line); border-radius: 4px; overflow: hidden; align-self: center; width: 100%; max-height: 100%; aspect-ratio: 16/9; margin: 0 auto; }
.big-cell .vp { position: absolute; inset: 0; }
.big-cell.pvw { border-color: var(--green); }
.big-cell.pgm { border-color: var(--red); }
.big-lbl, .mv-lbl { position: absolute; top: 0; left: 0; font: 700 11px/1 ui-monospace, Menlo, monospace; letter-spacing: .08em; padding: 5px 7px; background: rgba(0,0,0,.65); border-bottom-right-radius: 4px; pointer-events: none; }
.pvw .big-lbl { color: var(--green); }
.pgm .big-lbl { color: #ff6b61; }
.mv { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.mv-cell { position: relative; aspect-ratio: 16/9; border: 2px solid var(--line); border-radius: 4px; overflow: hidden; cursor: pointer; }
.mv-cell .vp { position: absolute; inset: 0; }
.mv-cell.pvw { border-color: var(--green); }
.mv-cell.air { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.mv-lbl .num { color: var(--gold); }
.mv-lbl .op { color: var(--muted); font-weight: 400; }
.mv-flag { position: absolute; top: 4px; right: 4px; background: var(--gold); color: #111; font: 800 10px/1 Arial; padding: 4px 6px; border-radius: 3px; display: none; }
.mv-cell.flagged .mv-flag { display: block; animation: pulse .7s infinite; }
.dir-panel { display: grid; grid-template-columns: 1.35fr 1fr; gap: 10px; padding: 0 10px 10px; }
.switcher, .talk { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.bus { display: flex; gap: 6px; align-items: center; }
.bus-lbl { width: 36px; font: 700 11px/1 ui-monospace, Menlo, monospace; color: var(--muted); }
.bus-btn { flex: 1; background: #232a38; border: 1px solid #333d51; border-radius: 5px; padding: 6px 2px; cursor: pointer; font: 700 12px/1.1 ui-monospace, Menlo, monospace; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bus-btn small { color: var(--muted); font-size: 9px; }
.bus-btn[data-bus="pgm"].lit { background: #6a1512; border-color: var(--red); color: #fff; box-shadow: 0 0 12px rgba(255,59,48,.4); }
.bus-btn[data-bus="pvw"].lit { background: #0f4a2b; border-color: var(--green); color: #fff; box-shadow: 0 0 12px rgba(47,208,122,.35); }
.trans-row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.ttype { display: flex; gap: 6px; }
.tt-btn { background: #232a38; border: 1px solid #333d51; border-radius: 5px; padding: 6px 9px; cursor: pointer; font: 700 11px/1 ui-monospace, Menlo, monospace; }
.big-btn { border-radius: 6px; padding: 8px 16px; font: 800 14px/1 Arial, sans-serif; cursor: pointer; border: 1px solid; letter-spacing: .06em; }
.big-btn.cut { background: #3b1311; border-color: #9c2a23; }
.big-btn.auto { background: #3b2f0c; border-color: #8e7221; }
.big-btn:active { transform: translateY(1px); filter: brightness(1.3); }
.tbar { display: flex; align-items: center; gap: 6px; font: 700 10px/1 ui-monospace, Menlo, monospace; color: var(--muted); }
.tbar input { width: 110px; accent-color: var(--gold); }
.rp-row { display: flex; gap: 10px; align-items: center; font-size: 12px; flex-wrap: wrap; }
.rp-status { font: 700 12px/1 ui-monospace, Menlo, monospace; color: var(--muted); }
.rp-status.cued { color: var(--gold); }
.rp-status.rolling { color: var(--red); }
.chk { display: flex; gap: 5px; align-items: center; color: var(--muted); }
.talk-head { font: 700 11px/1 ui-monospace, Menlo, monospace; color: var(--muted); letter-spacing: .1em; display: flex; justify-content: space-between; align-items: center; }
.quick { display: flex; flex-wrap: wrap; gap: 5px; }
.q-btn { background: #232a38; border: 1px solid #333d51; border-radius: 14px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.q-btn:hover { border-color: var(--gold); }
.talk-form { display: flex; gap: 6px; }
.talk-form input { flex: 1; background: #0b0e14; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; color: var(--text); font: inherit; min-width: 0; }
.log { flex: 1; min-height: 44px; max-height: 92px; overflow: auto; font: 12px/1.45 ui-monospace, Menlo, monospace; color: var(--muted); }
.log-line.me { color: #9fb6ff; }
.log-line.them { color: var(--gold); }
.log-line.play { color: #cfd6e4; }
.log-line.clickable { cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.log-line.clickable:hover { background: var(--panel2); }

/* ---------- replay */
.rp-main { display: grid; grid-template-columns: 2.2fr 1fr; gap: 10px; padding: 8px 10px; min-height: 0; }
.rp-mon { position: relative; border: 2px solid #6b5412; border-radius: 4px; overflow: hidden; aspect-ratio: 16/9; max-height: 100%; align-self: center; width: 100%; }
.rp-mon .vp { position: absolute; inset: 0; }
.rp-mon .big-lbl { color: var(--gold); }
.rp-onair { position: absolute; top: 8px; right: 8px; background: var(--red); color: #fff; font: 800 13px/1 Arial; padding: 6px 10px; border-radius: 4px; display: none; letter-spacing: .1em; }
.rp-onair.show { display: block; }
.rp-angles { display: grid; grid-template-rows: repeat(5, 1fr); gap: 6px; min-height: 0; }
.rp-angles .mv-cell { aspect-ratio: auto; min-height: 0; }
.rp-panel { display: grid; grid-template-columns: 2.2fr 1fr; grid-template-rows: auto auto; gap: 8px 10px; padding: 0 10px 10px; }
.timeline { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 6px; }
.tl-bar { position: relative; height: 34px; background: #0b0e14; border: 1px solid var(--line); border-radius: 6px; cursor: ew-resize; overflow: hidden; touch-action: none; }
.tl-clip { position: absolute; top: 0; bottom: 0; background: rgba(242,194,48,.25); border-left: 2px solid var(--gold); border-right: 2px solid var(--gold); display: none; }
.tl-marks i { position: absolute; top: 4px; bottom: 4px; width: 2px; background: #4d6bd8; }
.tl-head { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--red); box-shadow: 0 0 6px var(--red); }
.tl-labels { display: flex; justify-content: space-between; font: 11px ui-monospace, Menlo, monospace; color: var(--muted); margin-top: 4px; }
.rp-controls { grid-column: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.rp-controls .grp { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rp-side { grid-column: 2; grid-row: 1 / span 2; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; position: relative; min-height: 0; }
.clip { font-size: 12px; color: var(--muted); }
.clip b { color: var(--gold); margin-right: 4px; }
.log.plays { max-height: 130px; }
.toast.inline { position: static; transform: none; font-size: 14px; padding: 8px 10px; }
.toast.inline.show { transform: none; }

/* ---------- program */
.role-program .prog-wrap { position: absolute; inset: 0; display: grid; place-items: center; }
.role-program .prog { width: min(100vw, calc(100vh * 16 / 9)); aspect-ratio: 16/9; position: relative; }
.prog-hint { position: absolute; bottom: 6px; right: 10px; font-size: 11px; color: #444; }
