:root {
  --bg: #0b1016;
  --surface: #121b25;
  --surface-2: #182532;
  --line: #233343;
  --text: #e8f1f8;
  --muted: #8fa3b6;
  --accent: #22d3ee;
  --accent-2: #6ee7b7;
  --warn: #fbbf24;
  --danger: #fb7185;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 15% -10%, #16293a 0%, var(--bg) 55%) no-repeat, var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.app { max-width: 1180px; margin: 0 auto; padding: 18px 18px 48px; }

/* file:// 打开时的防呆指引 */
.notice {
  margin-bottom: 18px; padding: 16px 18px; border-radius: var(--radius);
  border: 1px solid #fbbf2466; background: #fbbf2410;
}
.notice[hidden] { display: none; }
.notice strong { display: block; font-size: 15px; color: var(--warn); margin-bottom: 8px; }
.notice p { font-size: 13px; line-height: 1.7; margin: 6px 0; color: var(--text); }
.notice p.muted, .notice .muted { color: var(--muted); }
.notice code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; background: #00000038; padding: 2px 6px; border-radius: 5px; color: var(--accent-2);
}
.notice-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.notice-actions a, .notice-actions button, .notice button {
  font: inherit; font-size: 13px; cursor: pointer; text-decoration: none;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
}
.notice-actions a.primary {
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: #06212b; font-weight: 700; border-color: transparent;
}
.notice-actions button:hover { border-color: var(--accent); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  box-shadow: 0 0 22px #22d3ee44;
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 9px;
  border: 2px solid #06212b; border-radius: 50%;
}
.brand strong { display: block; font-size: 17px; letter-spacing: .5px; }
.brand small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.pill {
  font-size: 12px; padding: 7px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.pill.live { color: var(--accent-2); border-color: #6ee7b755; background: #6ee7b712; }
.pill.error { color: var(--danger); border-color: #fb718555; background: #fb718512; }

.grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 18px 40px #00000030;
}
.stage-card { grid-column: 1; grid-row: 1 / span 2; }
.data-card { grid-column: 2; grid-row: 1; }
.controls-card { grid-column: 2; grid-row: 2; padding: 18px; }
.setup-card { grid-column: 1 / -1; padding: 18px; }

.stage {
  position: relative; width: 100%; aspect-ratio: 3 / 4;
  max-height: 66vh; background: #060b11; overflow: hidden;
}
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { object-fit: cover; }
.stage.mirrored video, .stage.mirrored canvas { transform: scaleX(-1); }
.stage canvas { pointer-events: none; }

.guide { position: absolute; inset: 0; pointer-events: none; display: grid; place-items: center; }
.guide-box {
  width: 72%; height: 74%; border: 1.5px dashed #6ee7b766; border-radius: 18px;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 10px;
  background: linear-gradient(#6ee7b708, transparent 30%);
}
.guide-box span { font-size: 11px; color: #6ee7b7cc; background: #0b1016aa; padding: 3px 8px; border-radius: 6px; }
.stage-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; gap: 8px; }
.chip {
  font-size: 11px; padding: 5px 9px; border-radius: 8px;
  background: #0b1016cc; border: 1px solid #ffffff18; color: #cbd5e1;
  backdrop-filter: blur(6px);
}
.chip.ok { color: var(--accent-2); border-color: #6ee7b755; }
.chip.bad { color: var(--warn); border-color: #fbbf2455; }
.stage-bottom {
  position: absolute; bottom: 12px; left: 12px; right: 12px;
  font-size: 12px; color: #e2e8f0; background: #0b1016cc;
  border: 1px solid #ffffff18; border-radius: 9px; padding: 8px 10px;
  text-align: center; backdrop-filter: blur(6px);
}
.flash {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 96px; font-weight: 800; color: var(--accent-2);
  text-shadow: 0 0 40px #6ee7b799; opacity: 0; pointer-events: none;
}
.flash.go { animation: pop .55s ease-out; }
@keyframes pop { 0% { opacity: 0; transform: scale(.6); } 30% { opacity: 1; transform: scale(1.05); } 100% { opacity: 0; transform: scale(1.3); } }

.stage-meta {
  display: flex; gap: 14px; flex-wrap: wrap; padding: 10px 14px;
  font-size: 11px; color: var(--muted); border-top: 1px solid var(--line);
}

.data-card { display: grid; grid-template-columns: 190px 1fr; }
.count-block {
  padding: 20px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: center;
}
.count-num {
  font-size: clamp(64px, 9vw, 104px); line-height: .95; font-weight: 800;
  letter-spacing: -4px; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff, #7dd3fc); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.count-num.up { background: linear-gradient(180deg, #fff, #6ee7b7); -webkit-background-clip: text; background-clip: text; }
.count-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stats { display: flex; gap: 14px; margin-top: 22px; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 15px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 10px; color: var(--muted); margin-top: 2px; }

.chart-block { padding: 18px; min-width: 0; }
.chart-title { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.chart-title small { font-variant-numeric: tabular-nums; color: var(--accent); }
#chart { width: 100%; height: 132px; display: block; margin-top: 10px; }
.chart-legend { display: flex; gap: 14px; font-size: 10px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 5px; }
.sw-line { background: var(--accent); }
.sw-high { background: var(--accent-2); }
.sw-low { background: var(--warn); }

h2 { font-size: 13px; margin: 0 0 14px; color: #cbd5e1; letter-spacing: .5px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; min-width: 0; }
.field label { font-size: 11px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select, input[type="range"] { width: 100%; }
select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 10px; font-size: 13px; outline: none;
}
select:focus { border-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); margin: 8px 0 0; }
.muted { color: var(--muted); }
.preset-hint { font-size: 11px; line-height: 1.6; color: var(--muted); margin: -4px 0 14px; }
.switches { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 12px; color: #cbd5e1; margin-bottom: 14px; }
.switches label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.switches input { accent-color: var(--accent); }
.thresholds {
  font-size: 11px; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font-variant-numeric: tabular-nums; margin-bottom: 14px;
}
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
button {
  flex: 1 1 auto; min-width: 92px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-size: 13px; cursor: pointer; transition: .15s;
}
button:hover { border-color: var(--accent); }
button.primary { background: linear-gradient(135deg, #0ea5e9, #22d3ee); border-color: transparent; color: #04121a; font-weight: 700; }
button.primary.running { background: linear-gradient(135deg, #fb7185, #f97316); }
button.ghost { flex: 0 0 auto; min-width: 70px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.calibrating { border-color: var(--warn); color: var(--warn); }
.toast { font-size: 11px; color: var(--accent-2); min-height: 16px; margin-top: 10px; }

.setup-body { display: grid; grid-template-columns: 240px 1fr; gap: 20px; align-items: center; }
.setup-figure { width: 100%; border-radius: 10px; }
.setup-text p { font-size: 12px; line-height: 1.75; color: #cbd5e1; margin: 0 0 8px; }
.setup-text b { color: var(--warn); font-weight: 600; }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .stage-card, .data-card, .controls-card, .setup-card { grid-column: 1; grid-row: auto; }
  .stage { max-height: 56vh; }
  .data-card { grid-template-columns: 150px 1fr; }
  .setup-body { grid-template-columns: 1fr; }
  .setup-figure { max-width: 320px; }
}
@media (max-width: 480px) {
  .app { padding: 12px 12px 36px; }
  .stage { aspect-ratio: 3 / 4; max-height: 50vh; }
  .data-card { grid-template-columns: 1fr; }
  .count-block { border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; align-items: center; gap: 16px; padding: 14px; }
  .count-num { font-size: 62px; }
  .count-sub { align-self: flex-start; margin-top: 12px; }
  .stats { margin-top: 0; margin-left: auto; gap: 10px; }
  .chart-block { padding: 14px; }
  #chart { height: 100px; }
}
