:root {
  --bg: #070a0e;
  --bg-deep: #05080b;
  --panel: #0d131a;
  --panel-raised: #101821;
  --line: rgba(148, 163, 184, 0.13);
  --line-strong: rgba(148, 163, 184, 0.24);
  --text: #e8eef6;
  --text-soft: #c3cfdb;
  --muted: #8a99ab;
  --muted-2: #5e6e80;
  --accent: #4ade80;
  --accent-bright: #86efac;
  --accent-strong: #22c55e;
  --accent-soft: rgba(74, 222, 128, 0.1);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.09);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.09);
  --cyan: #67e8f9;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shell-max: 1440px;
  --shell-pad: 24px;
  --font: "Segoe UI Variable Display", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  scrollbar-color: #273340 var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(74, 222, 128, 0.055), transparent 65%),
    radial-gradient(800px 500px at 100% 0%, rgba(103, 232, 249, 0.035), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 76%);
  mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 76%);
  pointer-events: none;
}

.ambient {
  position: fixed;
  top: -280px;
  left: -220px;
  z-index: -1;
  width: 700px;
  height: 700px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(74, 222, 128, 0.08), transparent 68%);
  filter: blur(30px);
  pointer-events: none;
}

[hidden] {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

button,
select,
input {
  font: inherit;
}

button {
  color: inherit;
}

button,
select,
summary {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid rgba(74, 222, 128, 0.85);
  outline-offset: 2px;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-xl {
  width: 48px;
  height: 48px;
  stroke-width: 1.15;
}

.eyebrow {
  margin: 0;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--muted-2);
}

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: 72px;
  padding-inline: max(var(--shell-pad), calc((100% - var(--shell-max)) / 2));
  border-bottom: 1px solid rgba(148, 163, 184, 0.09);
  background: rgba(7, 10, 14, 0.72);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  flex: none;
  border: 1px solid rgba(74, 222, 128, 0.25);
  border-radius: 11px;
  background:
    radial-gradient(circle at 30% 20%, rgba(74, 222, 128, 0.18), transparent 60%),
    #0d141b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--accent);
}

.brand-mark svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.brand-mark .lens-core {
  fill: currentColor;
  stroke: none;
  opacity: 0.9;
}

.brand-name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.brand-sub {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--muted-2);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.018);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-2);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.chip.is-on {
  border-color: rgba(74, 222, 128, 0.2);
  background: rgba(74, 222, 128, 0.055);
  color: #b6ecc9;
}

.chip.is-on .dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.11);
}

.chip.is-warn {
  border-color: rgba(251, 191, 36, 0.24);
  background: rgba(251, 191, 36, 0.055);
  color: #f5d98b;
}

.chip.is-warn .dot {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.1);
}

.chip.is-error {
  border-color: rgba(251, 113, 133, 0.24);
  background: rgba(251, 113, 133, 0.055);
  color: #fecdd3;
}

.chip.is-error .dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.1);
}

.chip-quiet {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  color: var(--muted-2);
}

/* Layout */

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 20px;
  width: min(var(--shell-max), calc(100% - var(--shell-pad) * 2));
  margin: 0 auto;
  padding: 24px 0 12px;
}

.console {
  min-width: 0;
  animation: rise 0.45s ease both;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  animation: rise 0.45s 0.06s ease both;
}

/* Stage */

.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 48%, rgba(28, 40, 51, 0.62), transparent 62%),
    var(--bg-deep);
  box-shadow:
    0 36px 90px -52px rgba(0, 0, 0, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
  background-size: 52px 52px;
  -webkit-mask-image: radial-gradient(circle at 50% 50%, #000 10%, transparent 72%);
  mask-image: radial-gradient(circle at 50% 50%, #000 10%, transparent 72%);
  opacity: 1;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.stage.has-video::before {
  opacity: 0;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

#preview {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  transform: translateZ(0);
}

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

.stage-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 42px 28px 64px;
  text-align: center;
}

.lens-visual {
  position: relative;
  display: grid;
  place-items: center;
  width: 126px;
  height: 126px;
}

.lens-orbit {
  position: absolute;
  inset: 0;
  border: 1px dashed rgba(148, 163, 184, 0.18);
  border-radius: 50%;
  animation: orbit 42s linear infinite;
}

.lens-orbit::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.65);
}

.lens-orbit-second {
  inset: 17px;
  border-style: solid;
  border-color: rgba(148, 163, 184, 0.08);
  animation-direction: reverse;
  animation-duration: 30s;
}

.lens-orbit-second::before {
  display: none;
}

.lens-disc {
  position: relative;
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 28%, rgba(255, 255, 255, 0.06), transparent 55%),
    linear-gradient(180deg, rgba(26, 38, 49, 0.8), rgba(10, 16, 22, 0.9));
  box-shadow:
    0 18px 40px -24px rgba(0, 0, 0, 0.9),
    inset 0 0 0 7px rgba(0, 0, 0, 0.13);
  color: var(--muted);
}

.empty-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empty-copy .eyebrow {
  color: rgba(74, 222, 128, 0.62);
}

.empty-copy h1 {
  margin: 1px 0 0;
  font-size: 23px;
  font-weight: 620;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.empty-copy p:last-child {
  max-width: 430px;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.75;
}

.stage-topline {
  position: absolute;
  top: 16px;
  right: 16px;
  left: 16px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.stage-pill,
.stage-meta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  background: rgba(5, 8, 11, 0.58);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: rgba(232, 238, 246, 0.75);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.stage-pill .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted-2);
}

.stage.is-preview .stage-pill .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.12);
}

.stage.is-connecting .stage-pill .dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.1);
  animation: blink 1.05s ease-in-out infinite;
}

.stage.is-live .stage-pill {
  border-color: rgba(251, 113, 133, 0.3);
  background: rgba(37, 9, 14, 0.64);
  color: #fecdd3;
}

.stage.is-live .stage-pill .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.14);
  animation: livePulse 1.7s ease-out infinite;
}

.stage.is-live .stage-meta {
  color: rgba(255, 255, 255, 0.82);
}

.stage-caption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 46px 16px 15px;
  background: linear-gradient(transparent, rgba(3, 6, 9, 0.7));
  pointer-events: none;
}

.source-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: rgba(232, 238, 246, 0.72);
  font-size: 11.5px;
}

.source-label .icon {
  width: 15px;
  height: 15px;
  opacity: 0.65;
}

.source-label span {
  overflow: hidden;
  max-width: 60vw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.icon-button:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.icon-button-dark {
  width: 32px;
  height: 32px;
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(5, 8, 11, 0.45);
  color: rgba(255, 255, 255, 0.65);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.stage:fullscreen {
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  background: #000;
}

.stage:fullscreen #preview {
  object-fit: contain;
}

/* Control bar */

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  animation: rise 0.25s ease both;
}

.notice[data-type="error"] {
  border-color: rgba(251, 113, 133, 0.22);
  background: var(--danger-soft);
}

.notice[data-type="warn"] {
  border-color: rgba(251, 191, 36, 0.22);
  background: var(--warn-soft);
}

.notice[data-type="info"] {
  border-color: rgba(103, 232, 249, 0.16);
  background: rgba(103, 232, 249, 0.04);
}

.notice-mark {
  display: flex;
  padding-top: 1px;
  color: var(--muted);
}

.notice[data-type="error"] .notice-mark {
  color: var(--danger);
}

.notice[data-type="warn"] .notice-mark {
  color: var(--warn);
}

.notice[data-type="info"] .notice-mark {
  color: var(--cyan);
}

.notice-mark .icon {
  width: 16px;
  height: 16px;
}

.notice-text {
  flex: 1;
  margin: 0;
  color: var(--text-soft);
  font-size: 11.8px;
  line-height: 1.65;
}

.notice[data-type="error"] .notice-text {
  color: #fecdd3;
}

.notice[data-type="warn"] .notice-text {
  color: #f8e3a6;
}

.notice[data-type="info"] .notice-text {
  color: #bcecf4;
}

.notice-close {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  margin: -3px -4px 0 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: currentColor;
  opacity: 0.55;
  cursor: pointer;
}

.notice-close:hover {
  background: rgba(255, 255, 255, 0.06);
  opacity: 1;
}

.notice-close .icon {
  width: 14px;
  height: 14px;
}

.controlbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(16, 24, 33, 0.86), rgba(10, 15, 21, 0.92));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

.controlbar-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.005em;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

.btn .icon {
  width: 17px;
  height: 17px;
}

.btn-primary {
  min-width: 144px;
  background: var(--accent);
  color: #04130a;
  box-shadow: 0 10px 28px -16px rgba(74, 222, 128, 0.75);
}

.btn-primary:hover {
  background: var(--accent-bright);
  box-shadow: 0 12px 30px -14px rgba(74, 222, 128, 0.7);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary.is-stop {
  background: rgba(251, 113, 133, 0.03);
  border-color: rgba(251, 113, 133, 0.35);
  color: #fda4af;
  box-shadow: none;
}

.btn-primary.is-stop:hover {
  background: var(--danger-soft);
  border-color: rgba(251, 113, 133, 0.5);
}

.btn-ghost {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.018);
  color: var(--muted);
  font-weight: 500;
}

.btn-ghost:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.btn:disabled,
.tool:disabled,
.icon-button:disabled,
.copy-btn:disabled,
.mini-copy:disabled,
select:disabled,
input:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none;
}

.controlbar-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.device-select {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  max-width: 206px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.16);
  color: var(--muted);
  cursor: pointer;
}

.device-select > .icon {
  width: 15px;
  height: 15px;
  opacity: 0.7;
}

.device-select .icon-chevron {
  width: 14px;
  height: 14px;
  margin-left: -2px;
  pointer-events: none;
  opacity: 0.55;
}

.device-select select {
  min-width: 0;
  max-width: 154px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-soft);
  font-size: 11.5px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  text-overflow: ellipsis;
}

.device-select select option {
  background: #0d131a;
  color: var(--text);
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.tool:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.tool[aria-pressed="true"] {
  border-color: rgba(74, 222, 128, 0.15);
  background: var(--accent-soft);
  color: #a9ebc0;
}

.tool .icon {
  width: 16px;
  height: 16px;
}

.tool .icon-off {
  display: none;
}

.tool[aria-pressed="false"] .icon-on {
  display: none;
}

.tool[aria-pressed="false"] .icon-off {
  display: block;
}

/* Signal chain */

.chain {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-top: 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(14, 21, 29, 0.72), rgba(9, 14, 20, 0.8));
  animation: rise 0.45s 0.1s ease both;
}

.chain-node {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 11px;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chain-node[data-state="on"] {
  border-color: rgba(74, 222, 128, 0.13);
  background: rgba(74, 222, 128, 0.032);
}

.chain-node[data-state="active"] {
  border-color: rgba(251, 191, 36, 0.12);
  background: rgba(251, 191, 36, 0.03);
}

.chain-node[data-state="error"] {
  border-color: rgba(251, 113, 133, 0.14);
  background: rgba(251, 113, 133, 0.035);
}

.chain-icon {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.17);
  color: var(--muted);
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.chain-icon .icon {
  width: 16px;
  height: 16px;
}

.chain-node[data-state="on"] .chain-icon {
  border-color: rgba(74, 222, 128, 0.2);
  background: var(--accent-soft);
  color: var(--accent);
}

.chain-node[data-state="active"] .chain-icon {
  border-color: rgba(251, 191, 36, 0.18);
  background: var(--warn-soft);
  color: var(--warn);
}

.chain-node[data-state="error"] .chain-icon {
  border-color: rgba(251, 113, 133, 0.2);
  background: var(--danger-soft);
  color: var(--danger);
}

.chain-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.chain-kicker {
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 7.5px;
  font-weight: 500;
  letter-spacing: 0.13em;
}

.chain-text strong {
  overflow: hidden;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chain-detail {
  overflow: hidden;
  color: var(--muted-2);
  font-size: 9.5px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chain-node[data-state="on"] .chain-detail {
  color: #8fcfa6;
}

.chain-node[data-state="error"] .chain-detail {
  color: #d79ba4;
}

.chain-state {
  width: 5px;
  height: 5px;
  flex: none;
  margin-left: auto;
  border-radius: 50%;
  background: var(--muted-2);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.chain-node[data-state="on"] .chain-state {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.08);
}

.chain-node[data-state="active"] .chain-state {
  background: var(--warn);
  animation: blink 1.15s ease-in-out infinite;
}

.chain-node[data-state="error"] .chain-state {
  background: var(--danger);
}

.chain-link {
  display: flex;
  align-items: center;
  gap: 1px;
  width: 42px;
  flex: none;
  color: var(--muted-2);
}

.chain-link > span {
  flex: 1;
  height: 1px;
  background: repeating-linear-gradient(90deg, rgba(148, 163, 184, 0.24) 0 3px, transparent 3px 7px);
}

.chain-link .icon {
  width: 12px;
  height: 12px;
  opacity: 0.42;
  transform: rotate(-90deg);
}

/* Sidebar cards */

.card {
  position: relative;
  padding: 17px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 17px;
  background:
    linear-gradient(180deg, rgba(16, 24, 32, 0.88), rgba(10, 15, 21, 0.94));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  right: 22px;
  left: 22px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.075), transparent);
  pointer-events: none;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 15px;
}

.card-head h2 {
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tag {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.mini-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10.5px;
}

.mini-state .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted-2);
}

.mini-state[data-state="preview"] .dot {
  background: var(--accent);
}

.mini-state[data-state="live"] {
  color: #fda4af;
}

.mini-state[data-state="live"] .dot {
  background: var(--danger);
  animation: livePulse 1.7s ease-out infinite;
}

.mini-state[data-state="connecting"] .dot {
  background: var(--warn);
  animation: blink 1s ease-in-out infinite;
}

.hero-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  min-height: 58px;
}

.bitrate {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 34px;
  font-weight: 680;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.bitrate small {
  color: var(--muted-2);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.hero-label {
  margin: 7px 0 0;
  color: var(--muted-2);
  font-size: 10.5px;
}

.spark {
  width: 112px;
  height: 45px;
  flex: none;
  overflow: visible;
}

.spark-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.spark-area {
  fill: url(#sparkFill);
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin-top: 17px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--line);
}

.metrics-grid > div {
  min-width: 0;
  padding: 10px 11px;
  background: rgba(9, 14, 19, 0.94);
}

.metrics-grid span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted-2);
  font-size: 9.5px;
}

.metrics-grid strong {
  display: block;
  overflow: hidden;
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-foot {
  margin: 12px 0 0;
  color: var(--muted-2);
  font-size: 10px;
  line-height: 1.6;
}

/* Addresses */

.addr {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(74, 222, 128, 0.13);
  border-radius: 11px;
  background:
    linear-gradient(90deg, rgba(74, 222, 128, 0.04), transparent 70%),
    rgba(0, 0, 0, 0.16);
}

.addr-main {
  min-width: 0;
  flex: 1;
}

.addr-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.addr code,
.addr-row code,
.phone-copy code {
  display: block;
  color: #a9ebc0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.addr code.is-empty,
.addr-row code.is-empty,
.phone-copy code.is-empty {
  color: var(--muted-2);
}

.addr-note {
  margin: 8px 1px 0;
  color: var(--muted-2);
  font-size: 10px;
  line-height: 1.6;
}

.copy-btn,
.mini-copy {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.copy-btn:hover,
.mini-copy:hover {
  border-color: rgba(74, 222, 128, 0.28);
  background: var(--accent-soft);
  color: var(--accent);
}

.copy-btn .icon,
.mini-copy .icon {
  width: 15px;
  height: 15px;
}

.copy-btn .icon-check,
.mini-copy .icon-check {
  display: none;
}

.copy-btn.copied,
.mini-copy.copied {
  border-color: rgba(74, 222, 128, 0.3);
  background: var(--accent-soft);
  color: var(--accent);
}

.copy-btn.copied .icon-copy,
.mini-copy.copied .icon-copy {
  display: none;
}

.copy-btn.copied .icon-check,
.mini-copy.copied .icon-check {
  display: block;
}

.phone-access {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.016);
  transition: border-color 0.2s ease, opacity 0.2s ease;
}

.phone-access.is-disabled {
  opacity: 0.6;
}

.phone-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.15);
  color: var(--muted);
}

.phone-icon .icon {
  width: 15px;
  height: 15px;
}

.phone-copy {
  min-width: 0;
  flex: 1;
}

.phone-copy .addr-label {
  margin-bottom: 3px;
}

.cert-note {
  margin: 7px 1px 0;
  color: var(--muted-2);
  font-size: 9.5px;
  line-height: 1.65;
}

.cert-note a {
  color: #9bdfb2;
  text-decoration: underline;
  text-decoration-color: rgba(74, 222, 128, 0.3);
  text-underline-offset: 2px;
}

.cert-note a:hover {
  color: var(--accent-bright);
}

.mini-copy {
  width: 28px;
  height: 28px;
  border-color: transparent;
}

.more {
  margin-top: 10px;
  border-top: 1px solid var(--line);
}

.more summary,
.advanced summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 1px 2px;
  color: var(--muted);
  font-size: 10.5px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.more summary::-webkit-details-marker,
.advanced summary::-webkit-details-marker {
  display: none;
}

.more summary:hover,
.advanced summary:hover {
  color: var(--text-soft);
}

.summary-chevron {
  display: inline-flex;
  transition: transform 0.2s ease;
}

.summary-chevron .icon {
  width: 14px;
  height: 14px;
}

details[open] > summary .summary-chevron {
  transform: rotate(180deg);
}

.more-body {
  display: grid;
  gap: 7px;
  padding-top: 9px;
  animation: unfold 0.2s ease both;
}

.addr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid rgba(148, 163, 184, 0.08);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.13);
}

.addr-row > div {
  min-width: 0;
}

.addr-row .addr-label {
  margin-bottom: 4px;
}

.addr-row code {
  color: var(--text-soft);
  font-size: 10px;
}

/* EasyNVR steps */

.steps {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: flex;
  gap: 11px;
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  margin-top: 1px;
  border: 1px solid rgba(74, 222, 128, 0.16);
  border-radius: 7px;
  background: rgba(74, 222, 128, 0.045);
  color: #8de7ac;
  font-family: var(--mono);
  font-size: 9.5px;
}

.steps strong {
  display: block;
  margin-bottom: 2px;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 600;
}

.steps span {
  display: block;
  color: var(--muted-2);
  font-size: 10.5px;
  line-height: 1.6;
}

.hint {
  margin-top: 13px;
  padding: 9px 10px;
  border: 1px solid rgba(103, 232, 249, 0.1);
  border-radius: 9px;
  background: rgba(103, 232, 249, 0.035);
  color: #93a9b8;
  font-size: 10px;
  line-height: 1.65;
}

.hint strong {
  color: #b9d4dc;
  font-weight: 600;
}

.hint code,
.prose code {
  padding: 1px 4px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.22);
  color: #a9ebc0;
  font-family: var(--mono);
  font-size: 9px;
  overflow-wrap: anywhere;
}

.prose {
  display: grid;
  gap: 9px;
  padding: 2px 1px 0;
}

.prose p {
  margin: 0;
  color: var(--muted-2);
  font-size: 10.5px;
  line-height: 1.7;
}

.prose strong {
  color: var(--muted);
  font-weight: 600;
}

/* Footer */

.page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(var(--shell-max), calc(100% - var(--shell-pad) * 2));
  margin: 0 auto;
  padding: 12px 0 28px;
  color: var(--muted-2);
  font-size: 9.8px;
}

.page-footer > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.page-footer .icon {
  width: 13px;
  height: 13px;
  opacity: 0.7;
}

.footer-meta {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Dialog */

dialog {
  width: min(568px, calc(100% - 30px));
  max-height: calc(100dvh - 36px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 19px;
  background:
    radial-gradient(500px 200px at 100% 0%, rgba(74, 222, 128, 0.05), transparent 70%),
    #0c1219;
  color: var(--text);
  box-shadow: 0 40px 120px -30px rgba(0, 0, 0, 0.9);
}

dialog::backdrop {
  background: rgba(2, 5, 8, 0.7);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
}

dialog[open] {
  animation: dialogIn 0.2s ease both;
}

#settingsForm {
  display: flex;
  max-height: calc(100dvh - 38px);
  flex-direction: column;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 0;
}

.dialog-head h2 {
  margin: 5px 0 0;
  font-size: 19px;
  font-weight: 620;
  letter-spacing: -0.015em;
}

.dialog-body {
  padding: 17px 22px 4px;
  overflow-y: auto;
}

.settings-lock {
  margin: 0 0 14px;
  padding: 9px 11px;
  border: 1px solid rgba(251, 191, 36, 0.16);
  border-radius: 8px;
  background: var(--warn-soft);
  color: #eacb83;
  font-size: 10.5px;
  line-height: 1.6;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
}

.field {
  min-width: 0;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10.5px;
}

.field select,
.field input {
  width: 100%;
  height: 39px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  background: rgba(0, 0, 0, 0.19);
  color: var(--text-soft);
  font-size: 11.5px;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.field select {
  cursor: pointer;
}

.field input::placeholder {
  color: #4f5d6d;
}

.field select:focus,
.field input:focus {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(0, 0, 0, 0.25);
}

.field select:disabled,
.field input:disabled {
  color: var(--muted-2);
}

.field-hint,
.field-error {
  margin: 6px 1px 0;
  color: var(--muted-2);
  font-size: 9.5px;
  line-height: 1.6;
}

.field-error {
  color: #fda4af;
}

.advanced {
  margin-top: 16px;
  border-top: 1px solid var(--line);
}

.advanced summary {
  padding: 13px 1px;
  font-size: 11px;
}

.advanced-body {
  display: grid;
  gap: 13px;
  padding: 2px 1px 2px;
}

.field input[type="url"] {
  font-family: var(--mono);
  font-size: 10px;
}

.dialog-footnote {
  margin: 17px 0 16px;
  color: var(--muted-2);
  font-size: 9.5px;
  line-height: 1.65;
}

.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.12);
}

.dialog-actions {
  display: flex;
  gap: 8px;
}

.dialog-foot .btn {
  height: 38px;
  min-width: 80px;
  padding: 0 14px;
  font-size: 12px;
}

.dialog-actions .btn-primary {
  min-width: 96px;
}

/* Toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 100;
  max-width: min(480px, calc(100vw - 32px));
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: rgba(16, 24, 32, 0.95);
  box-shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.9);
  color: var(--text-soft);
  font-size: 11.5px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Keys */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes unfold {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes orbit {
  to {
    transform: rotate(360deg);
  }
}

@keyframes blink {
  50% {
    opacity: 0.35;
  }
}

@keyframes livePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.35);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(251, 113, 133, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(251, 113, 133, 0);
  }
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translateY(9px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Responsive */

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .easynvr-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  :root {
    --shell-pad: 16px;
  }

  .topbar {
    height: 64px;
  }

  .brand-sub,
  .chip-quiet {
    display: none;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-name {
    font-size: 15px;
  }

  .chip {
    height: 30px;
    padding: 0 10px;
    font-size: 10.5px;
  }

  .shell {
    padding-top: 16px;
  }

  .stage {
    border-radius: 16px;
  }

  .stage-empty {
    gap: 18px;
    padding: 30px 20px 54px;
  }

  .lens-visual {
    width: 102px;
    height: 102px;
  }

  .lens-disc {
    width: 66px;
    height: 66px;
  }

  .lens-disc .icon-xl {
    width: 40px;
    height: 40px;
  }

  .empty-copy h1 {
    font-size: 19px;
  }

  .empty-copy p:last-child {
    max-width: 360px;
    font-size: 11.5px;
  }

  .controlbar {
    gap: 9px;
  }

  .sidebar {
    grid-template-columns: minmax(0, 1fr);
  }

  .easynvr-card {
    grid-column: auto;
  }

  .card {
    padding: 16px;
  }

  .page-footer {
    padding-bottom: 22px;
  }
}

@media (max-width: 620px) {
  :root {
    --shell-pad: 12px;
  }

  .topbar {
    gap: 10px;
    height: 60px;
  }

  .brand {
    gap: 9px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }

  .brand-mark svg {
    width: 22px;
    height: 22px;
  }

  .brand-name {
    font-size: 14px;
  }

  .chip {
    height: 28px;
    font-size: 10px;
  }

  .stage-topline {
    top: 10px;
    right: 10px;
    left: 10px;
  }

  .stage-pill,
  .stage-meta {
    height: 23px;
    padding: 0 8px;
    font-size: 8.5px;
  }

  .stage-meta {
    max-width: 46%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stage-caption {
    padding: 34px 10px 10px;
  }

  .source-label {
    font-size: 10.5px;
  }

  .stage-empty {
    padding: 24px 16px 46px;
    gap: 13px;
  }

  .lens-visual {
    width: 82px;
    height: 82px;
  }

  .lens-disc {
    width: 56px;
    height: 56px;
  }

  .lens-disc .icon-xl {
    width: 33px;
    height: 33px;
  }

  .empty-copy h1 {
    font-size: 16.5px;
  }

  .empty-copy p:last-child {
    display: none;
  }

  .empty-copy .eyebrow {
    font-size: 8.5px;
  }

  .controlbar {
    padding: 8px;
    border-radius: 14px;
  }

  .controlbar-main {
    width: 100%;
  }

  .controlbar-main .btn {
    flex: 1;
    min-width: 0;
    height: 41px;
    padding: 0 11px;
    font-size: 12px;
  }

  .btn-primary {
    min-width: 0;
  }

  .controlbar-tools {
    width: 100%;
    margin-left: 0;
    gap: 3px;
  }

  .device-select {
    min-width: 0;
    flex: 1;
    max-width: none;
    height: 35px;
  }

  .device-select select {
    max-width: none;
    flex: 1;
    font-size: 10.5px;
  }

  .tool {
    padding: 0 7px;
    font-size: 10.5px;
  }

  .tool .icon {
    width: 15px;
    height: 15px;
  }

  .chain {
    flex-direction: column;
    gap: 0;
    padding: 7px;
  }

  .chain-node {
    padding: 8px 9px;
  }

  .chain-link {
    width: 100%;
    height: 15px;
    flex-direction: column;
    justify-content: center;
  }

  .chain-link > span {
    width: 1px;
    height: 100%;
    background: repeating-linear-gradient(180deg, rgba(148, 163, 184, 0.24) 0 3px, transparent 3px 7px);
  }

  .chain-link .icon {
    display: none;
  }

  .chain-kicker {
    display: none;
  }

  .chain-text strong {
    font-size: 11px;
  }

  .chain-detail {
    font-size: 9px;
  }

  .card {
    padding: 15px;
    border-radius: 15px;
  }

  .hero-row {
    min-height: 52px;
  }

  .bitrate {
    font-size: 30px;
  }

  .spark {
    width: 98px;
    height: 40px;
  }

  .metrics-grid > div {
    padding: 9px 10px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  dialog {
    width: calc(100% - 20px);
    max-height: calc(100dvh - 20px);
    border-radius: 16px;
  }

  #settingsForm {
    max-height: calc(100dvh - 22px);
  }

  .dialog-head {
    padding: 17px 17px 0;
  }

  .dialog-body {
    padding: 14px 17px 0;
  }

  .dialog-foot {
    padding: 12px 17px;
  }

  .dialog-foot .btn {
    height: 37px;
    padding: 0 12px;
  }

  .dialog-actions {
    flex: 1;
    justify-content: flex-end;
  }

  .page-footer {
    display: grid;
    gap: 6px;
    font-size: 9px;
  }
}

@media (max-width: 380px) {
  .tool span:not(.icon) {
    display: none;
  }

  .empty-copy h1 {
    font-size: 15px;
  }
}

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