:root {
  --bg: #111216;
  --panel: #1b1c22;
  --panel-2: #22232b;
  --line: #2e303a;
  --text: #ececf1;
  --muted: #9a9caa;
  --accent: #6ea8ff;
  --good: #5dca8a;
  --bad: #ff6b6b;
  --warn: #e6b84d;
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; }

header.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px 12px 16px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, #16324a 0%, #1a3d38 42%, #111216 100%);
  box-shadow: inset 0 -3px 0 #2ec4a5;
}
header.app-header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
header.app-header .mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(145deg, #3ee0c0, #2b7fff);
  color: #0b1220;
  font-weight: 800;
  font-size: 13px;
  display: grid;
  place-items: center;
  letter-spacing: -0.04em;
}
header.app-header h1 { font-size: 16px; font-weight: 650; margin: 0; }
header.app-header p { margin: 2px 0 0; color: #b7c4d4; font-size: 13px; }

nav { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
nav button {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
nav button.active, nav button:hover {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
}

main { flex: 1; min-height: 0; }
.tab { display: none; height: 100%; }
.tab.active { display: flex; }

.split { display: flex; min-height: 0; height: 100%; }
.capture-tab {
  flex-direction: column;
  min-height: 0;
}
.capture-main {
  flex: 1 1 auto;
  min-height: 180px;
  height: auto;
}
.capture-tab { position: relative; }
.monitor-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  flex: 0 0 auto;
  max-height: 48%;
  overflow: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
}
.monitor-panel[open] {
  background: rgba(8, 12, 18, 0.10);
  backdrop-filter: blur(8px) saturate(1.05);
  -webkit-backdrop-filter: blur(8px) saturate(1.05);
}
.monitor-panel:fullscreen,
.monitor-panel:-webkit-full-screen {
  max-height: none;
  height: 100% !important;
  background: rgba(8, 12, 18, 0.22);
}
.monitor-resizer {
  height: 8px;
  margin-top: -4px;
  cursor: ns-resize;
  background: linear-gradient(90deg, transparent, rgba(46, 196, 165, 0.55), transparent);
}
.monitor-panel > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(16, 36, 52, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-weight: 650;
}
.monitor-panel > summary::-webkit-details-marker { display: none; }
.monitor-panel > summary::after {
  content: "Show";
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
}
.monitor-panel[open] > summary::after { content: "Hide"; }
.monitor-title { letter-spacing: 0.04em; }
.monitor-summary-kpis { font-size: 12px; font-weight: 500; color: #fff3c4; }
.monitor-lead {
  margin: 0;
  padding: 10px 24px 0;
  color: var(--muted);
  font-size: 13px;
}
.monitor-panel[open] .stats-page { padding-bottom: 8px; }
.monitor-panel .api-card {
  background: rgba(20, 22, 28, 0.16);
  border-color: rgba(255, 255, 255, 0.1);
}
.monitor-panel .kv div:nth-child(odd) { background: rgba(26, 51, 68, 0.55); }
.preview {
  flex: 1;
  min-width: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.preview video {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.preview canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  transform: scaleX(-1);
  display: none;
}
.preview .badge {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(17, 18, 22, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}
.sliders label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.sliders label span { font-variant-numeric: tabular-nums; }
.sliders input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
}
.placeholder {
  color: var(--muted);
  text-align: center;
  max-width: 360px;
  padding: 24px;
}
.placeholder h2 { margin: 8px 0; color: var(--text); font-weight: 550; }

.side {
  width: 360px;
  overflow: auto;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: var(--panel);
}
label.cap { display: block; color: var(--muted); font-size: 12px; margin: 12px 0 4px; }
.value { font-size: 14px; }
select, button.action {
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}
.row { display: flex; gap: 8px; margin-top: 12px; }
.row button { flex: 1; cursor: pointer; }
button.primary { background: #2b4d86; border-color: #3b66ad; }
button.danger { background: #5a2a2a; border-color: #7a3a3a; }
.error { color: var(--bad); font-size: 13px; margin-top: 10px; white-space: pre-wrap; }
pre.debug {
  white-space: pre-wrap;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #121318;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: #d5d7e0;
}

.stack { flex-direction: column; overflow: auto; }
.doc-page {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.doc-hero {
  padding: 28px 32px 24px;
  background:
    radial-gradient(720px 180px at 12% -20%, rgba(62, 224, 192, 0.22), transparent 60%),
    linear-gradient(120deg, #12263a 0%, #163a48 48%, #1c2a22 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.doc-hero .kicker {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7ef0d2;
  font-weight: 700;
  margin-bottom: 8px;
}
.doc-hero h1 { font-size: 28px; margin: 0 0 8px; letter-spacing: -0.03em; }
.doc-hero p { margin: 0; max-width: 720px; color: #d5e2ea; line-height: 1.55; }

.doc, .drivers, .logpane {
  overflow: visible;
  padding: 24px 32px 32px;
  max-width: 920px;
}
.doc h2 {
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #7ef0d2;
  margin: 28px 0 10px;
}
.doc h2:first-child { margin-top: 0; }
.doc p, .doc li { color: #d0d2dc; line-height: 1.6; }
.doc p { margin: 0 0 12px; }
.doc code, .doc pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}
.doc code {
  background: #1e2430;
  color: #d7ecff;
  padding: 1px 6px;
  border-radius: 5px;
}
.doc pre {
  background: #121318;
  border: 1px solid var(--line);
  border-left: 4px solid #2ec4a5;
  border-radius: 10px;
  padding: 12px 14px;
  overflow: auto;
}
.doc table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 8px 0 16px; }
.doc th, .doc td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.doc th { background: #1a3344; color: #d7f6ee; }
.doc tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }

.pipeline {
  display: grid;
  gap: 8px;
  margin: 12px 0 20px;
}
.pipeline .step {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.pipeline .n {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #07151a;
  background: #2ec4a5;
}
.pipeline .step:nth-child(2) .n { background: #3db8ff; }
.pipeline .step:nth-child(3) .n { background: #7aa2ff; }
.pipeline .step:nth-child(4) .n { background: #c084fc; }
.pipeline .step:nth-child(5) .n { background: #f0b429; }
.pipeline .step:nth-child(6) .n { background: #ff8a5b; }
.pipeline .step:nth-child(7) .n { background: #ff6b8a; }
.pipeline .step:nth-child(8) .n { background: #9ae6b4; }
.pipeline h3 { margin: 0 0 4px; font-size: 15px; }
.pipeline p { margin: 0; color: var(--muted); font-size: 13px; }

.api-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 22px;
}
.api-toc a {
  text-decoration: none;
  color: #d7f6ee;
  background: #1a3344;
  border: 1px solid #2a5560;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
}
.api-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px 14px;
  margin: 0 0 16px;
}
.api-card > h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 17px;
  color: var(--text);
}
.api-card .n {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: #07151a;
  background: #2ec4a5;
  flex: 0 0 28px;
}
.api-card:nth-of-type(2) .n { background: #3db8ff; }
.api-card:nth-of-type(3) .n { background: #7aa2ff; }
.api-card:nth-of-type(4) .n { background: #c084fc; }
.api-card:nth-of-type(5) .n { background: #f0b429; }
.api-card:nth-of-type(6) .n { background: #ff8a5b; }
.api-card:nth-of-type(7) .n { background: #ff6b8a; }
.api-card:nth-of-type(8) .n { background: #9ae6b4; }
.sig {
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #10141c;
  color: #d7ecff;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 10px;
  overflow-x: auto;
}
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.pills a, .pills span {
  font-size: 12px;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid #355;
}
.pills a { color: #fff3c4; background: #2a2414; text-decoration: none; }
.pills span { color: #d7f6ee; background: #143028; }
.kv {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin: 8px 0 12px;
  font-size: 13px;
}
.kv div { padding: 7px 10px; border-top: 1px solid var(--line); }
.kv div:nth-child(-n+2) { border-top: 0; }
.kv div:nth-child(odd) {
  background: #1a3344;
  color: #d7f6ee;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.kv div:nth-child(even) { color: #d0d2dc; }

.callout {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 12px 0 16px;
}
.callout.warn { background: #3a2a12; border: 1px solid #e6b84d; }
.callout.ok { background: #143028; border: 1px solid #2ec4a5; }
.callout p { margin: 0; color: #f2efe6; }

.doc-footer, .site-footer {
  margin-top: auto;
  color: #f4f7fb;
}
.doc-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 32px;
  background: linear-gradient(90deg, #0f3d4d 0%, #1a5c4a 48%, #c45c26 100%);
  font-size: 13px;
}
.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: linear-gradient(90deg, #10263a, #145246 58%, #8a3a16);
  font-size: 12px;
  box-shadow: inset 0 3px 0 #2ec4a5;
}
.doc-footer a, .site-footer a { color: #fff3c4; }
.doc-footer strong, .site-footer strong { color: #fff; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar button { width: auto; cursor: pointer; padding: 7px 12px; }
.muted { color: var(--muted); font-size: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 10px 0;
  padding: 10px 12px;
}
.card summary { cursor: pointer; font-weight: 600; }
.card pre { margin: 10px 0 0; }

.stats-page {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.stat-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 16px 24px 8px;
}
.encode-format-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 24px 0;
  max-width: 420px;
}
.encode-format-label select { flex: 1; margin-top: 0; }
.kpi {
  background: rgba(20, 22, 28, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
}
.kpi-i { border-color: #5dca8a; }
.kpi-p { border-color: #6ea8ff; }
.kpi-b { border-color: #e6b84d; }
.frame-chip {
  position: absolute;
  right: 12px;
  top: 12px;
  min-width: 42px;
  text-align: center;
  font-weight: 800;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  color: #5dca8a;
  z-index: 4;
}
.frame-chip.P { color: #6ea8ff; }
.frame-chip.B { color: #e6b84d; }
.fs-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  width: auto;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(12, 16, 22, 0.35);
  color: #fff;
  cursor: pointer;
}
.fs-btn.inline {
  position: static;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 500;
}
.kpi label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.kpi strong { font-size: 16px; }
.plot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 8px 24px 24px;
}
.plot-grid figure {
  margin: 0;
  background: rgba(18, 19, 24, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 8px 10px 10px;
}
.plot-grid figcaption {
  font-size: 12px;
  color: #7ef0d2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.plot-grid canvas {
  width: 100%;
  height: 160px;
  display: block;
  border-radius: 8px;
}
@media (max-width: 900px) {
  .plot-grid { grid-template-columns: 1fr; }
}
.pipe-live {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 0;
  padding: 14px 24px 0;
}
.pipe-live li {
  background: rgba(20, 22, 28, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-top: 3px solid #2ec4a5;
  border-radius: 10px;
  padding: 8px 10px;
}
.pipe-live li:nth-child(2) { border-top-color: #3db8ff; }
.pipe-live li:nth-child(3) { border-top-color: #c084fc; }
.pipe-live li:nth-child(4) { border-top-color: #f0b429; }
.pipe-live li:nth-child(5) { border-top-color: #ff8a5b; }
.pipe-live span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pipe-live strong { font-size: 13px; word-break: break-word; }
.diag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 0 24px 28px;
}
.diag-grid .api-card:last-child { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .pipe-live, .diag-grid { grid-template-columns: 1fr; }
  .diag-grid .api-card:last-child { grid-column: auto; }
}

.record-page { overflow: auto; min-height: 100%; }
.record-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 16px 24px 8px;
}
.record-toolbar .action { width: auto; }
.rec-clock {
  font: 20px/1 ui-monospace, Menlo, monospace;
  color: #ff8a5b;
  min-width: 4.5rem;
}
.record-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  padding: 8px 24px 24px;
}
.record-preview video {
  width: 100%;
  max-height: 360px;
  background: #000;
  border-radius: 12px;
}
.trim-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}
.trim-row label { font-size: 12px; color: var(--muted); }
.trim-row input[type="range"] { width: 100%; display: block; }
.record-h { margin: 0 0 8px; font-size: 15px; }
.clip-list { display: flex; flex-direction: column; gap: 8px; }
.clip {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.clip.selected { border-color: #2ec4a5; }
.clip-actions { display: flex; gap: 6px; }
.clip-actions button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 8px;
  cursor: pointer;
}
.share-card { margin: 0 24px 28px; }
@media (max-width: 900px) {
  .record-layout, .trim-row { grid-template-columns: 1fr; }
}

.logline { font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.logline.ERROR { color: var(--bad); }
.logline.INFO { color: var(--text); }
.logline.DEBUG { color: var(--muted); }
