:root {
  --bg: #0b0d12; --panel: #141821; --panel2: #1c2130; --line: #272e3f;
  --text: #e9ecf2; --muted: #8b94a8; --accent: #4f8cff;
  --pgm: #e5243b; --pvw: #1fbf5b; --warn: #f5a524; --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box }
html, body { margin: 0; height: 100% }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent }
a { color: var(--accent) }
[hidden] { display: none !important }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px }
.muted { color: var(--muted) }
.hint { color: var(--muted); font-size: 13px; margin: 0 }
.error { color: #ff6b7d; margin: 0 }
.spacer { flex: 1 }
.grow { flex: 1; min-width: 0 }
small { color: var(--muted); font-size: 12px }
kbd { font: 11px ui-monospace, monospace; background: #0006; border: 1px solid #fff3; border-radius: 4px; padding: 1px 5px }
.brand { font-weight: 800; letter-spacing: .02em; color: var(--text); text-decoration: none; white-space: nowrap }

input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; min-width: 0 }
input[type=range] { padding: 0; accent-color: var(--accent) }
input[type=checkbox] { width: auto; accent-color: var(--accent); margin: 0 }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted) }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px }
label.check.small { font-size: 13px; gap: 6px }
.row { display: flex; gap: 10px; align-items: end }
.row > * { flex: 1 }

.btn { font: inherit; font-weight: 600; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 14px; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; white-space: nowrap }
.btn:hover { border-color: #3d4760 }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff }
.btn.big { padding: 14px; font-size: 16px }
.btn.small { padding: 5px 9px; font-size: 13px }
.btn.icon { width: 48px; height: 48px; padding: 0; font-size: 20px; border-radius: 50%; background: #0008; border-color: #fff3 }
.btn:disabled { opacity: .6; cursor: wait }
.btn.ok { border-color: var(--pvw) }
.btn.active { background: var(--pgm); border-color: var(--pgm); color: #fff }
.btn.pvw.active { background: var(--pvw); border-color: var(--pvw); color: #04130a }

.dot { width: 10px; height: 10px; border-radius: 50%; background: #555; display: inline-block; flex: none }
.dot.on { background: var(--pvw) }
.dot.wait { background: var(--warn) }
.dot-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: #fffc }
.dot-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #666 }
.dot-label.on::before { background: var(--pvw) }
.dot-label.wait::before { background: var(--warn) }

.join { min-height: 100%; display: grid; place-items: center; padding: 20px 16px }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; display: grid; gap: 14px; width: min(420px, 100%) }
.card h1 { margin: 0; font-size: 24px }
.card p { margin: 0 }

.toast-wrap { position: fixed; left: 50%; bottom: 140px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 300; pointer-events: none }
.toast { background: #000d; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; text-align: center }
.fatal { position: fixed; inset: 0; background: #000e; display: grid; place-items: center; text-align: center; padding: 24px; z-index: 400; font-size: 17px }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(460px, calc(100% - 32px)); max-height: calc(100% - 32px) }
dialog::backdrop { background: #0009 }
dialog form { display: grid; gap: 14px }
dialog h2 { margin: 0; font-size: 18px }

/* Push-to-talk */
.ptt { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 100px; height: 100px; border-radius: 50%; border: 3px solid #fff6; background: #ffffff1f; color: #fff; font-size: 30px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; flex: none }
.ptt span { font-size: 9px; font-weight: 800; letter-spacing: .04em; text-align: center; line-height: 1.1; max-width: 80px }
.ptt.active { background: var(--pgm); border-color: #fff; box-shadow: 0 0 0 8px #e5243b55 }
.ptt.wide { flex-direction: row; width: auto; height: auto; border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 800; gap: 8px; border-width: 1px; background: var(--panel2); border-color: var(--line) }
.ptt.wide.active { background: var(--pgm) }
.ptt.huge { width: 200px; height: 200px; font-size: 56px; margin: 8px auto }
.ptt.huge span { font-size: 12px; max-width: 140px }

.talkers { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; z-index: 5 }
.talkers.inline { position: static; transform: none }
.talker { background: var(--pgm); color: #fff; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; animation: pulse 1s infinite alternate }
@keyframes pulse { to { opacity: .7 } }

/* ---------- Kamera ---------- */
.page-camera #cam-screen { position: fixed; inset: 0; background: #000; overflow: hidden; user-select: none; -webkit-user-select: none }
#preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain }
#preview.mirror { transform: scaleX(-1) }
.tally-frame { position: absolute; inset: 0; pointer-events: none; border: 0 solid transparent; transition: border-width .15s }
.tally-pgm .tally-frame { border: 10px solid var(--pgm) }
.tally-pvw .tally-frame { border: 10px solid var(--pvw) }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 20px) 14px calc(env(safe-area-inset-left) + 20px); background: linear-gradient(#000b, transparent) }
.tally-pill { font-weight: 800; font-size: 13px; letter-spacing: .06em; padding: 5px 10px; border-radius: 6px; background: #fff2 }
.tally-pgm .tally-pill { background: var(--pgm) }
.tally-pvw .tally-pill { background: var(--pvw); color: #04130a }
.cam-name { font-weight: 700 }
.cam-bottom { position: absolute; bottom: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px calc(env(safe-area-inset-right) + 20px) calc(env(safe-area-inset-bottom) + 18px) calc(env(safe-area-inset-left) + 20px); background: linear-gradient(transparent, #000b) }
.side { display: flex; gap: 8px; flex: 1 }
.side.replies { justify-content: flex-end }
.reply { background: #000a; border-color: #fff3; padding: 10px 14px }
.reply.warn { color: var(--warn) }
.cue-overlay { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #000d; border: 3px solid var(--warn); border-radius: 16px; padding: 16px 30px; text-align: center; max-width: 80%; z-index: 10 }
.cue-overlay small { display: block; margin-bottom: 4px }
.cue-overlay span { font-size: 36px; font-weight: 800; color: var(--warn); line-height: 1.15 }
.flash { animation: pop .35s }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.25) } }
.rotate-hint { position: absolute; top: 28%; left: 50%; transform: translateX(-50%); background: #000b; padding: 10px 16px; border-radius: 10px; pointer-events: none; white-space: nowrap }
.zoom { position: absolute; right: calc(env(safe-area-inset-right) + 18px); top: 50%; transform: translateY(-50%); height: 45% }
.zoom input { writing-mode: vertical-lr; direction: rtl; width: 32px; height: 100% }

/* ---------- Switcher ---------- */
.page-director #app { display: grid; grid-template-rows: auto 1fr; height: 100% }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap }
.room-tag { color: var(--muted); font-size: 14px }
.room-tag b { color: var(--text) }
.vol { display: flex; align-items: center; gap: 6px; font-size: 16px }
.vol input { width: 90px }
.director-main { display: grid; grid-template-columns: 1fr 290px; min-height: 0 }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; padding: 12px; overflow: auto; align-content: start }
.empty { grid-column: 1 / -1; padding: 60px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius) }
.tile { background: var(--panel); border: 3px solid var(--line); border-radius: var(--radius); overflow: hidden }
.tile.is-pvw { border-color: var(--pvw) }
.tile.is-pgm { border-color: var(--pgm) }
.tile.speaking { box-shadow: 0 0 0 3px #e5243b88 }
.tile-video { position: relative; aspect-ratio: 16 / 9; background: #000 }
.tile-video video { width: 100%; height: 100%; object-fit: contain; display: block }
.tile-conn { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px }
.tile-label { position: absolute; top: 8px; left: 8px; background: #000b; padding: 3px 9px; border-radius: 6px; font-weight: 600; font-size: 13px }
.tile-label b { color: var(--accent); margin-right: 2px }
.is-pgm .tile-label { background: var(--pgm) }
.is-pgm .tile-label b, .is-pvw .tile-label b { color: inherit }
.is-pvw .tile-label { background: var(--pvw); color: #04130a }
.tile-talk { position: absolute; top: 8px; right: 8px; background: var(--pgm); border-radius: 999px; padding: 2px 8px; display: none; animation: pulse 1s infinite alternate }
.tile.speaking .tile-talk { display: block }
.tile-stat { position: absolute; bottom: 8px; left: 8px; font-size: 12px; background: #000b; padding: 2px 8px; border-radius: 6px }
.tile-stat:empty { display: none }
.low { color: #ff6b7d; font-weight: 700 }
.tile-reply { position: absolute; bottom: 8px; right: 8px; background: var(--warn); color: #000; font-weight: 700; padding: 4px 10px; border-radius: 6px }
.tile-bar { display: flex; gap: 6px; padding: 8px; flex-wrap: wrap }
.tile-bar .cue { flex: 1; min-width: 100px; padding: 7px 8px }
.side-panel { border-left: 1px solid var(--line); padding: 4px 16px 16px; overflow: auto; background: var(--panel) }
.crew, .log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px }
.crew li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--panel2) }
.crew li.speaking { outline: 2px solid var(--pgm) }
.log li { font-size: 13px }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px }
.log .warn { color: var(--warn) }
.log .reply { color: #9ec1ff }
.keys { margin-top: 18px; line-height: 2 }
.invite-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; text-align: center }
.invite-grid > div { display: grid; gap: 8px }
.invite-grid input { font-size: 12px; padding: 6px 8px }
.qr { background: #fff; border-radius: 8px; display: grid; place-items: center; aspect-ratio: 1 }
.qr svg { width: 100%; height: auto }
@media (max-width: 860px) {
  .director-main { grid-template-columns: 1fr }
  .side-panel { border-left: 0; border-top: 1px solid var(--line) }
  .grid { grid-template-columns: 1fr; overflow: visible }
  .page-director #app { height: auto }
}

/* ---------- Intercom ---------- */
.talk-app { max-width: 520px; margin: 0 auto; padding: 16px; display: grid; gap: 16px }
.talk-head { display: flex; align-items: center; gap: 12px }
.onair { text-align: center; padding: 10px; border-radius: 10px; background: var(--panel2); font-weight: 700 }
.onair.live { background: var(--pgm) }

/* ---------- Landing ---------- */
.landing { max-width: 860px; margin: 0 auto; padding: 48px 16px; display: grid; gap: 20px }
.big-brand { font-size: 34px; margin: 0 }
.big-brand, .brand { }
.lead { font-size: 17px; color: var(--muted); margin: 0 }
.card.wide { width: 100% }
.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px }
.role { display: grid; gap: 6px; padding: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text) }
.role:hover { border-color: var(--accent) }
.role i { font-style: normal; font-size: 30px }
.role b { font-size: 17px }
.role span { color: var(--muted); font-size: 14px }
details summary { cursor: pointer }
details ol { margin: 12px 0 0; padding-left: 20px; display: grid; gap: 6px }
