:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --text: #111114;
  --muted: #6b6b75;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #3b82f6;
  --accent-text: #ffffff;
  --preview-bg: #0b0b0e;
  --scope: #60a5fa;
  --scope-grid: rgba(255, 255, 255, 0.08);
  --meter-track: rgba(255, 255, 255, 0.08);
  --meter-ok: #22c55e;
  --meter-hot: #f59e0b;
  --meter-clip: #ef4444;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --panel: #18181c;
    --text: #f4f4f5;
    --muted: #9a9aa5;
    --line: rgba(255, 255, 255, 0.08);
    --accent: #60a5fa;
    --accent-text: #0b0b0e;
    --preview-bg: #050507;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

/* The display rules on .panels and .settings would otherwise beat the UA's
   display:none for [hidden]. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100dvh;
}

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.head h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.head p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 60ch;
}

main { flex: 1; }

/* Start gate */

.gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 72px 20px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  text-align: center;
}

.gate p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 120ms ease, filter 120ms ease;
}

.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-stop {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.btn-stop:hover { border-color: var(--danger); color: var(--danger); }

/* Panels */

.panels {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.select-wrap {
  position: relative;
  flex: 1 1 200px;
  max-width: 100%;
}

.select-wrap svg {
  position: absolute;
  right: 10px;
  top: 50%;
  translate: 0 -50%;
  pointer-events: none;
  color: var(--muted);
  width: 16px;
  height: 16px;
}

select {
  width: 100%;
  appearance: none;
  padding: 8px 34px 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

select:disabled { opacity: 0.5; cursor: default; }

/* Previews */

.preview {
  position: relative;
  border-radius: 12px;
  background: var(--preview-bg);
  overflow: hidden;
}

.video-box { aspect-ratio: 16 / 9; }

.audio-box { height: 180px; }

video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

video.mirrored { transform: scaleX(-1); }

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}

.overlay-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.btn-ghost[aria-pressed="false"] { opacity: 0.6; }

.badge-right {
  left: auto;
  right: 10px;
  color: rgba(255, 255, 255, 0.7);
}

/* Camera settings */

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 24px;
  padding: 4px 2px;
}

.settings-empty {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.ctl {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
}

.ctl-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.ctl-head span:first-child { font-weight: 500; }

.ctl-head output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ctl select { font-size: 13px; padding-top: 6px; padding-bottom: 6px; }

.ctl input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

.ctl input[type="range"]:disabled { opacity: 0.4; }

.settings-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.btn-text {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.btn-text:hover { background: var(--bg); }

/* Level meter */

.meter {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  height: 8px;
  border-radius: 999px;
  background: var(--meter-track);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--meter-ok) 0 65%, var(--meter-hot) 65% 88%, var(--meter-clip) 88%);
  clip-path: inset(0 100% 0 0);
  transition: clip-path 60ms linear;
}

.meter-peak {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 2px;
  background: #fff;
  opacity: 0.8;
  transition: left 60ms linear;
}

.msg {
  margin: 0;
  font-size: 14px;
  color: var(--danger);
}

.foot {
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.foot p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  .btn-primary, .meter-fill, .meter-peak { transition: none; }
}
