:root {
  --bg: #0b0d10;
  --surface: #12161b;
  --surface-raised: #181d24;
  --border: #2b333d;
  --border-strong: #3e4a57;
  --text: #f4f7fa;
  --muted: #9ca8b5;
  --subtle: #707d8b;
  --accent: #e43d4f;
  --accent-hover: #f04c5d;
  --cyan: #2ec4b6;
  --focus: #6dd8ce;
  --danger: #ff6b78;
  --radius: 6px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 10;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: #061513;
  background: var(--focus);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.topbar {
  height: 72px;
  padding: 0 clamp(16px, 3vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: #0e1115;
}

.brand, .server-state { display: flex; align-items: center; }
.brand { gap: 12px; }
.brand strong { display: block; font-size: 16px; line-height: 1.25; }
.brand small { color: var(--muted); font: 12px/1.4 Consolas, monospace; }
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #4f6570;
  border-radius: 4px;
  background: #172126;
}
.brand-mark::before, .brand-mark::after, .brand-mark span {
  content: "";
  display: block;
  width: 3px;
  border-radius: 1px;
  background: var(--cyan);
}
.brand-mark { grid-template-columns: repeat(3, 3px); gap: 4px; }
.brand-mark::before { height: 10px; }
.brand-mark span { height: 20px; }
.brand-mark::after { height: 14px; }

.server-state { gap: 8px; color: #cbd4dc; font-size: 13px; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 0 3px #2ec4b622; }

.workspace {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 3vw, 40px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 28px;
}

.viewer, .control-panel { min-width: 0; }
.section-heading, .panel-heading { margin-bottom: 18px; }
.section-heading { min-height: 48px; display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.eyebrow { margin: 0 0 4px; color: var(--cyan); font: 600 11px/1.2 Consolas, monospace; }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }

.live-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  white-space: nowrap;
}
.live-badge span { width: 7px; height: 7px; border-radius: 50%; background: var(--subtle); }
.live-badge.active { border-color: #a72a39; color: #ffdce0; }
.live-badge.active span { background: var(--accent); box-shadow: 0 0 0 3px #e43d4f22; }

.video-shell {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #020304;
}
video { width: 100%; height: 100%; display: block; object-fit: contain; background: #020304; }
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  background: #090c0f;
}
.empty-state.hidden { display: none; }
.empty-state strong { color: #d4dbe2; font-size: 15px; }
.empty-state span { font-size: 13px; }
.signal-icon { height: 30px; display: flex; align-items: end; gap: 4px; margin-bottom: 5px; }
.signal-icon i { display: block; width: 4px; background: var(--cyan); border-radius: 1px; }
.signal-icon i:nth-child(1) { height: 10px; opacity: .45; }
.signal-icon i:nth-child(2) { height: 19px; opacity: .7; }
.signal-icon i:nth-child(3) { height: 28px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.metrics > div { padding: 14px 16px; border-right: 1px solid var(--border); }
.metrics > div:last-child { border-right: 0; }
.metrics span, .metrics strong { display: block; }
.metrics span { margin-bottom: 5px; color: var(--subtle); font-size: 11px; }
.metrics strong { font: 500 14px/1.3 Consolas, monospace; }

.control-panel {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  align-self: start;
}

.field { margin-bottom: 20px; }
label, legend { color: #d7dee5; font-size: 13px; font-weight: 600; }
.field label { display: block; margin-bottom: 8px; }
input[type="text"], input:not([type]) {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text);
  background: #0b0e12;
}
input:invalid:not(:focus):not(:placeholder-shown) { border-color: var(--danger); }
.field small { display: block; margin-top: 7px; color: var(--subtle); font-size: 12px; }
.field .field-error { min-height: 16px; color: var(--danger); }

fieldset { margin: 0 0 22px; padding: 0; border: 0; }
legend { margin-bottom: 9px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 5px; background: #0b0e12; }
.segmented label { position: relative; min-width: 0; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-height: 38px; display: grid; place-items: center; padding: 0 5px; border-radius: 3px; color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap; transition: background 160ms ease, color 160ms ease; }
.segmented input:checked + span { color: #fff; background: #35414c; }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }

.actions { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.actions button { min-height: 46px; border-radius: 4px; font-weight: 600; transition: background 160ms ease, border-color 160ms ease; }
.primary { border: 1px solid var(--accent); color: #fff; background: var(--accent); }
.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.secondary { border: 1px solid var(--border-strong); color: #d4dbe2; background: var(--surface-raised); }
.secondary:hover:not(:disabled) { border-color: #617181; background: #202832; }
button:disabled { cursor: not-allowed; opacity: .45; }

.endpoint-block, .publish-block { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.endpoint-heading { display: flex; align-items: center; justify-content: space-between; }
.endpoint-heading > span, .publish-block > span { color: var(--muted); font-size: 12px; }
.text-button { min-width: 48px; min-height: 40px; border: 0; color: var(--cyan); background: transparent; font-size: 12px; }
code { display: block; overflow-wrap: anywhere; margin-top: 6px; color: #dce4eb; font: 12px/1.55 Consolas, monospace; }
.notice { min-height: 42px; margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--border-strong); color: var(--muted); background: #0d1115; font-size: 12px; line-height: 1.5; }
.notice.error { border-left-color: var(--danger); color: #ffc8ce; }
.notice.success { border-left-color: var(--cyan); color: #bff4ef; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .control-panel { grid-row: 1; }
}

@media (max-width: 620px) {
  .topbar { height: 64px; }
  .server-state span:last-child { display: none; }
  .workspace { padding: 16px; gap: 20px; }
  .control-panel { padding: 16px; }
  .section-heading { align-items: center; }
  h1 { font-size: 20px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics > div:nth-child(2) { border-right: 0; }
  .metrics > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .segmented { grid-template-columns: 1fr; }
  .segmented span { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
