:root {
  --bg: #04070b;
  --panel: rgba(8, 14, 22, 0.72);
  --line: rgba(0, 229, 255, 0.16);
  --line-strong: rgba(0, 229, 255, 0.45);
  --text: #dfeaf2;
  --muted: #6f8597;
  --cyan: #00e5ff;
  --cyan-dim: rgba(0, 229, 255, 0.12);
  --green: #3dffb4;
  --amber: #ffb347;
  --red: #ff3d71;
  --violet: #9d7bff;
  --ice: #a8ecff;
  --limbus: #ffcf5a;
  --pupil: #3dffb4;
  --display: "Rajdhani", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 var(--display); letter-spacing: .02em;
  overflow-x: hidden;
}
.bg-grid {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(0, 229, 255, 0.10), transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(157, 123, 255, 0.10), transparent 50%),
    linear-gradient(rgba(0, 229, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.045) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--muted); }
.muted { color: var(--muted); }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0, 229, 255, 0.05), transparent);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--cyan); }
.brand .name { font-weight: 700; font-size: 20px; letter-spacing: .14em; color: var(--text); }
.brand .name em { color: var(--cyan); font-style: normal; }
.brand .sub { font-size: 11px; letter-spacing: .28em; color: var(--muted); margin-left: 6px; }
.sys { display: flex; gap: 8px; align-items: center; font-size: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--panel);
  color: var(--muted); letter-spacing: .08em; text-transform: uppercase; font-size: 11px;
}
.chip b { color: var(--text); font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot.ok { background: var(--green); box-shadow: 0 0 10px var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------- layout ---------- */
main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; padding: 14px 18px 24px; }
@media (max-width: 980px) { main { grid-template-columns: 1fr; } }

/* ---------- toolbar ---------- */
.toolbar { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
select, .btn, input[type=number] {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 4px;
  padding: 6px 12px; font: 600 12px var(--display); letter-spacing: .12em; text-transform: uppercase; cursor: pointer;
}
input[type=number] { width: 62px; cursor: text; font-family: var(--mono); padding: 3px 6px; letter-spacing: 0; }
.btn:hover, select:hover { border-color: var(--line-strong); box-shadow: 0 0 12px var(--cyan-dim); }
.btn.sm { padding: 4px 10px; font-size: 11px; }
.btn.icon { width: 40px; padding: 6px 0; text-align: center; }
.chip.tog { cursor: pointer; user-select: none; }
.chip.tog input { display: none; }
.chip.tog:has(input:checked) { color: var(--cyan); border-color: var(--line-strong); box-shadow: inset 0 0 12px var(--cyan-dim); }

/* ---------- stage ---------- */
.stage {
  position: relative; background: #000; overflow: hidden; width: 100%;
  aspect-ratio: 4 / 3; max-height: 70vh; border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 0 40px rgba(0, 229, 255, 0.08);
  cursor: crosshair;
}
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scan {
  position: absolute; inset: 0; pointer-events: none; mix-blend-mode: overlay; opacity: .35;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.06) 0 1px, transparent 1px 3px);
}
.corner { position: absolute; width: 22px; height: 22px; border: 2px solid var(--cyan); opacity: .8; pointer-events: none; }
.corner.tl { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.corner.tr { top: 8px; right: 8px; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: 8px; left: 8px; border-right: 0; border-top: 0; }
.corner.br { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }
.hud { position: absolute; padding: 6px 10px; background: rgba(4, 7, 11, .62); border: 1px solid var(--line); pointer-events: none; font-size: 12px; backdrop-filter: blur(4px); }
.hud.tl { top: 18px; left: 18px; }
.hud.tr { top: 18px; right: 18px; display: flex; gap: 8px; align-items: center; }
.hud.bl { bottom: 18px; left: 18px; font-size: 11px; color: var(--cyan); }
.hud.br { bottom: 18px; right: 18px; font-size: 10px; letter-spacing: .18em; }
.hud .lbl { font-size: 10px; letter-spacing: .28em; color: var(--muted); }
.hud .val { font-size: 17px; font-weight: 700; letter-spacing: .06em; }
.hud .val.unsure { color: var(--amber); }
.rec { width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 10px var(--red); animation: pulse 1.2s infinite; }
.toast {
  position: absolute; left: 50%; top: 56px; transform: translateX(-50%);
  padding: 6px 14px; background: rgba(0, 229, 255, .12); border: 1px solid var(--line-strong); color: var(--cyan);
  font: 600 12px var(--mono); letter-spacing: .1em; opacity: 0; transition: opacity .3s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- player ---------- */
.player { display: flex; align-items: center; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.player input[type=range] { flex: 1; min-width: 0; accent-color: var(--cyan); }

/* ---------- timelines ---------- */
.timeline-wrap { margin-top: 10px; }
.tl-row { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
.tl-row span { width: 100px; flex: none; color: var(--muted); font-size: 10px; letter-spacing: .2em; }
.tl-row canvas { flex: 1; min-width: 0; height: 16px; background: var(--panel); border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; margin-right: 5px; vertical-align: -1px; }
.note { font-size: 11px; color: var(--muted); margin: 8px 0 0; }

/* ---------- cards ---------- */
.right { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); padding: 12px 14px; position: relative;
  backdrop-filter: blur(6px);
}
.card::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; background: linear-gradient(var(--ice), transparent); }
.card h2 { font-size: 12px; margin: 0 0 8px; letter-spacing: .26em; color: var(--ice); font-weight: 600; }
.card h2 small { letter-spacing: .14em; font-weight: 500; color: var(--muted); margin-left: 6px; font-size: 10px; }
.big { font-size: 22px; font-weight: 700; letter-spacing: .04em; }
.big.unsure { color: var(--amber); }
.meter { height: 5px; background: rgba(255,255,255,.06); margin: 6px 0; overflow: hidden; }
.meter div { height: 100%; width: 0; background: linear-gradient(90deg, var(--ice), var(--violet)); box-shadow: 0 0 8px var(--ice); transition: width .2s; }
.kvlist { list-style: none; padding: 0; margin: 4px 0 0; font-size: 12px; color: var(--muted); font-family: var(--mono); }
.kvlist li { display: flex; justify-content: space-between; }

.rot-row { display: flex; justify-content: space-between; align-items: flex-start; }
.rot-big { font-size: 40px; font-weight: 600; line-height: 1; color: var(--ice); text-shadow: 0 0 18px rgba(168, 236, 255, .55); }
.rot-dir { font-size: 11px; letter-spacing: .2em; color: var(--muted); margin-top: 4px; }
.lock { font: 600 11px var(--mono); letter-spacing: .18em; padding: 4px 8px; border: 1px solid currentColor; color: var(--amber); }
.lock.LOCKED { color: var(--ice); box-shadow: 0 0 12px rgba(168, 236, 255, .25); }
.lock.OCCLUDED { color: var(--amber); }
.lock.SEARCHING { color: var(--red); }
#rotPlot { width: 100%; height: 90px; margin: 10px 0 6px; background: rgba(0,0,0,.25); border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 11px; color: var(--muted); }
.kv b { color: var(--text); font-weight: 400; }

.slider { display: grid; grid-template-columns: 90px 1fr 46px; align-items: center; gap: 8px; margin: 6px 0; font-size: 10px; letter-spacing: .2em; color: var(--muted); }
.slider input { accent-color: var(--ice); width: 100%; }
.slider b { text-align: right; color: var(--text); font-weight: 400; font-size: 11px; letter-spacing: 0; }
.legend-ticks { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 10px; font-size: 10px; color: var(--muted); }
.legend-ticks span { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.legend-ticks i { display: block; width: 2px; background: var(--ice); box-shadow: 0 0 6px var(--ice); }

.row-btns { display: flex; justify-content: space-between; align-items: center; }
.sys-card { font-size: 11px; color: var(--muted); }
.sys-card #perf { color: var(--text); font-size: 11px; }

/* ---------- digital twin ---------- */
.twin-card h2 { display: flex; align-items: center; }
.twin-card h2 .expand { margin-left: auto; padding: 2px 8px; font-size: 12px; }
.twin-wrap { position: relative; aspect-ratio: 1 / 1; border: 1px solid var(--line); background: radial-gradient(ellipse at 50% 40%, rgba(0,229,255,.08), transparent 60%), #03060a; overflow: hidden; cursor: grab; }
.twin-wrap:active { cursor: grabbing; }
.twin-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.twin-hud { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; justify-content: space-between; font-size: 10px; letter-spacing: .16em; color: var(--ice); pointer-events: none; text-shadow: 0 0 8px rgba(168,236,255,.6); }
.twin-btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.twin-btns .btn.sm { padding: 3px 8px; font-size: 10px; }
.twin-btns .chip.tog { padding: 3px 8px; font-size: 10px; }
.iris-colors { display: inline-flex; gap: 5px; margin-left: auto; }
.iris-colors i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--line-strong); cursor: pointer; }
.iris-colors i:hover { box-shadow: 0 0 8px var(--ice); }
body.twin-max .twin-card { position: fixed; inset: 18px; z-index: 50; display: flex; flex-direction: column; background: rgba(4,7,11,.96); }
body.twin-max .twin-wrap { flex: 1; aspect-ratio: auto; }
