@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;800&family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #08090b;
  --panel: #111318;
  --panel-2: #181b22;
  --line: #262a33;
  --text: #e8e6e1;
  --dim: #8b8f99;
  --accent: #ffb347;      /* phosphor amber */
  --accent-2: #7cffb2;    /* phosphor green */
  --live: #ff3b4a;
  --ok: #36d27a;
  --warn: #e8c547;
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #1a1712 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 15px; letter-spacing: .02em; }
.mono { font-family: var(--mono); }
.dim { color: var(--dim); }
.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(8, 9, 11, .85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-family: var(--mono); font-weight: 800; letter-spacing: .14em; text-transform: uppercase; font-size: 13px; color: var(--accent); text-shadow: 0 0 12px rgba(255, 179, 71, .45); white-space: nowrap; }
.brand small { color: var(--dim); text-shadow: none; font-weight: 400; letter-spacing: .08em; margin-left: 6px; }
.topbar .spacer { flex: 1; }
.pill { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: rgba(54, 210, 122, .4); }
.pill.bad { color: var(--live); border-color: rgba(255, 59, 74, .4); }
.pill.live { color: #fff; background: var(--live); border-color: var(--live); }
.pill.warn { color: var(--warn); border-color: rgba(232, 197, 71, .4); }

/* ---- layout ---- */
main { padding: 20px; max-width: 1600px; margin: 0 auto; }
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head .spacer { flex: 1; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---- controls ---- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 8px 12px; border-radius: 8px; font: 600 13px Inter, system-ui, sans-serif; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: #3a404c; background: #1e222b; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #1a1206; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #ff8a93; border-color: rgba(255, 59, 74, .35); }
.btn.danger:hover { background: rgba(255, 59, 74, .12); }
.btn.on { background: rgba(255, 179, 71, .15); border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.icon { padding: 5px 8px; }
input, select {
  background: #0c0e12; color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: 13px Inter, system-ui, sans-serif; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
input[type="range"] { padding: 0; accent-color: var(--accent); }

/* ---- feed cards ---- */
.feed { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.feed.program { border-color: rgba(255, 59, 74, .55); box-shadow: 0 0 0 1px rgba(255, 59, 74, .25), 0 0 24px rgba(255, 59, 74, .08); }
.feed .media { position: relative; aspect-ratio: 16 / 9; background: #000; display: grid; place-items: center; }
.feed .media.audio { aspect-ratio: auto; height: 120px; }
.feed .media video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.feed .media .overlay { position: absolute; inset: 8px 8px auto 8px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.feed .media .audio-only { color: var(--dim); font-family: var(--mono); font-size: 12px; text-align: center; }
.feed .media .audio-only b { display: block; font-size: 30px; color: var(--accent); margin-bottom: 6px; }
.feed .media .waiting { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-family: var(--mono); font-size: 12px; background: repeating-linear-gradient(0deg, rgba(255, 255, 255, .02) 0 2px, transparent 2px 4px); }
.feed canvas.meter { width: 100%; height: 6px; display: block; background: #050607; }
.feed .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.feed .title { display: flex; align-items: center; gap: 8px; }
.feed .title input { flex: 1; background: transparent; border-color: transparent; padding: 4px 6px; font-weight: 600; }
.feed .title input:hover, .feed .title input:focus { border-color: var(--line); }
.feed .title .name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .stats { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.feed .id { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.kind-badge { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; padding: 2px 6px; border-radius: 4px; background: #222630; color: var(--accent-2); }

.quality { border-top: 1px dashed var(--line); padding-top: 10px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quality .wide { grid-column: span 3; }

/* ---- add-feed buttons ---- */
.adders { display: flex; gap: 10px; flex-wrap: wrap; }
.adder { flex: 1 1 180px; text-align: left; padding: 14px; border-radius: var(--radius); border: 1px dashed #343a46; background: transparent; color: var(--text); cursor: pointer; font: inherit; }
.adder:hover { border-color: var(--accent); background: rgba(255, 179, 71, .05); }
.adder b { display: block; font-size: 15px; margin-bottom: 2px; }
.adder span { color: var(--dim); font-size: 12px; }

/* ---- host column in control room ---- */
.host { margin-bottom: 22px; }
.host-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.host-head h2 { font-size: 18px; }

/* ---- gate / landing ---- */
.center { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 20px; }
.card { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.card h1 { font-family: var(--mono); letter-spacing: .1em; text-transform: uppercase; font-size: 18px; color: var(--accent); text-shadow: 0 0 14px rgba(255, 179, 71, .4); }
.card p { margin: 0; color: var(--dim); }
.tips { font-size: 12px; color: var(--dim); }
.tips li { margin: 4px 0; }

/* ---- toasts ---- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #1d2027; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
.toast span { flex: 1; }
.toast.bad { border-left-color: var(--live); }
.toast .x { background: none; border: 0; color: var(--dim); font-size: 18px; cursor: pointer; }

details.obs > summary { cursor: pointer; list-style: none; }
details.obs > summary::-webkit-details-marker { display: none; }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); display: inline-block; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

@media (max-width: 640px) {
  main { padding: 14px 16px; }
  .topbar { padding: 10px 16px; }
  .quality { grid-template-columns: 1fr 1fr; }
  .quality .wide { grid-column: span 2; }
}

/* =========================================================================
   Studio view (host page): cameras + mics on the left, the stage on the right
   ========================================================================= */
body.studio-body { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.studio { flex: 1; min-height: 0; display: grid; grid-template-columns: 280px 1fr; gap: 12px; padding: 12px; }

.side { background: #3a0710; background: linear-gradient(180deg, #2a0710 0%, #17060a 100%); border: 1px solid #4a1520; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-height: 0; }
.side-title { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #ff9aa8; display: flex; align-items: center; gap: 8px; }
.side-title .spacer { flex: 1; }
.tile { background: #0b0507; border: 1px solid #3d121b; border-radius: 10px; overflow: hidden; }
.tile.speaking { border-color: var(--accent-2); box-shadow: 0 0 0 1px rgba(124, 255, 178, .35); }
.tile .cam { position: relative; aspect-ratio: 16 / 9; background: #050304; display: grid; place-items: center; }
.tile .cam video { width: 100%; height: 100%; object-fit: cover; }
.tile .cam video.mirror { transform: scaleX(-1); }
.tile .avatar { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font: 800 20px var(--mono); color: #1a1206; background: var(--accent); }
.tile .cam .tag { position: absolute; left: 6px; bottom: 6px; display: flex; gap: 4px; }
.tile .cam .tag span { font: 600 11px Inter, sans-serif; background: rgba(0, 0, 0, .65); padding: 2px 7px; border-radius: 4px; }
.tile .cam .tag .muted { background: var(--live); }
.tile canvas.meter { width: 100%; height: 4px; display: block; background: #050304; }
.tile .ctl { padding: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tile .ctl .btn { flex: 1; justify-content: center; }
.tile .ctl input[type="range"] { flex: 1; }
.btn.off { color: #ff8a93; border-color: rgba(255, 59, 74, .45); background: rgba(255, 59, 74, .1); }

.stage-wrap { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tabs { display: flex; align-items: flex-end; gap: 4px; padding: 0 8px; overflow-x: auto; scrollbar-width: thin; flex-shrink: 0; }
.tab { position: relative; display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px 9px; border: 1px solid var(--line); border-bottom: none; border-radius: 10px 10px 0 0; background: #101217; color: var(--dim); font: 600 13px Inter, sans-serif; cursor: pointer; white-space: nowrap; max-width: 260px; }
.tab:hover { color: var(--text); background: #151820; }
.tab.active { background: #133d25; color: #fff; border-color: #1f6b40; }
.tab .who { font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--accent-2); }
.tab .lbl { overflow: hidden; text-overflow: ellipsis; }
.tab .lbl[contenteditable="true"] { outline: 1px dashed var(--accent); padding: 0 3px; color: #fff; }
.tab .air { width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 8px var(--live); }
.tab.add { color: var(--accent); border-style: dashed dashed none; background: transparent; }
.tabs .spacer { flex: 1; }
.tabs .follow { margin-bottom: 6px; }

.stage { flex: 1; min-height: 0; background: #0f2a1b; background: radial-gradient(900px 500px at 50% 40%, #12351f 0%, #0a1d12 100%); border: 1px solid #1f6b40; border-radius: 0 12px 12px 12px; display: flex; gap: 6px; padding: 6px; position: relative; }
.pane { position: relative; flex: 1; min-width: 0; background: #000; border-radius: 8px; overflow: hidden; display: grid; place-items: center; }
.pane video { width: 100%; height: 100%; object-fit: contain; }
.pane .bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 24px 10px 10px; background: linear-gradient(transparent, rgba(0, 0, 0, .8)); opacity: 0; transition: opacity .2s; }
.pane:hover .bar, .pane .bar.pinned { opacity: 1; }
.pane .bar .title { font-weight: 700; }
.pane .bar .spacer { flex: 1; }
.pane .bar select { padding: 5px 8px; }
.pane .bar input[type="range"] { width: 110px; }
.pane .note { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font: 12px var(--mono); pointer-events: none; }
.pane .badge { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; }
.stage .empty { margin: auto; text-align: center; color: #bfe8cf; max-width: 420px; }
.stage .empty h2 { font-size: 20px; margin-bottom: 6px; }
.stage .empty p { color: #8fbfa2; margin: 0 0 16px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }

@media (max-width: 860px) {
  body.studio-body { height: auto; overflow: auto; }
  .studio { grid-template-columns: 1fr; padding: 10px 16px; }
  .side { flex-direction: row; overflow-x: auto; }
  .side .tile { flex: 0 0 220px; }
  .side-title { display: none; }
  .stage { min-height: 56vw; }
}
