:root {
  --bg: #07090a;
  --panel: #0d1214;
  --panel-2: #121a1d;
  --line: #1e2b2e;
  --line-bright: #2e4448;
  --cyan: #4ce0d2;
  --cyan-dim: #2c7d76;
  --amber: #ff8a3d;
  --red: #ff5a5a;
  --text: #e6efee;
  --text-dim: #7c9391;
  --text-faint: #4b5e5c;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ============ ambient overlays ============ */
#scanlines {
  position: fixed; inset: 0; z-index: 200; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom, rgba(255,255,255,0.018) 0px, rgba(255,255,255,0.018) 1px,
    transparent 1px, transparent 3px
  );
  mix-blend-mode: overlay;
}
#noise {
  position: fixed; inset: 0; z-index: 201; pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
@keyframes sweep { 0% { transform: translateY(-100%); } 100% { transform: translateY(100%); } }
@keyframes pulse-ring { 0% { opacity: .6; transform: scale(.85); } 100% { opacity: 0; transform: scale(1.6); } }

/* ============ boot screen ============ */
#boot-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(76,224,210,0.06), transparent 60%),
    var(--bg);
}
.boot-inner {
  width: min(480px, 88vw);
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  gap: 18px;
}
.boot-mark { color: var(--cyan); width: 52px; height: 52px; filter: drop-shadow(0 0 14px rgba(76,224,210,0.5)); }
.boot-glyph { width: 100%; height: 100%; }
.boot-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 0.04em;
  color: var(--text);
}
.boot-title span { color: var(--cyan); }
.boot-subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: -10px;
}
.boot-log {
  width: 100%;
  min-height: 96px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 14px;
  text-align: left;
  font-size: 11.5px;
  line-height: 1.9;
  color: var(--cyan-dim);
  overflow-y: auto;
  max-height: 140px;
}
.boot-line { animation: none; }
.boot-line.ok { color: var(--cyan); }
.boot-line.warn { color: var(--amber); }
.boot-line.err { color: var(--red); }

.btn-primary {
  width: 100%;
  padding: 14px 20px;
  background: var(--cyan);
  color: #06110f;
  border: none;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled {
  background: var(--panel-2);
  color: var(--text-faint);
  border: 1px solid var(--line);
  cursor: default;
}
.boot-footnote {
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

/* ============ main console layout ============ */
#console {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
}

.hud-bar {
  position: relative; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(var(--panel), rgba(13,18,20,0.92));
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.hud-bottom { border-bottom: none; border-top: 1px solid var(--line); flex-wrap: wrap; gap: 10px; }

.hud-brand { display: flex; align-items: center; gap: 10px; }
.brand-glyph { width: 26px; height: 26px; color: var(--cyan); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 14px; letter-spacing: 0.06em; }
.brand-sub { font-size: 9px; color: var(--text-dim); letter-spacing: 0.14em; }

.hud-status { display: flex; gap: 8px; }
.status-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.status-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.status-chip.on .dot { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); animation: blink 2s ease-in-out infinite; }
.status-chip.on span { color: var(--text); }
.status-chip.warn .dot { background: var(--amber); }

/* ============ stage / viewport ============ */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
#video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scaleX(-1);
}
#depth-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
#scene-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}

.frame-corner {
  position: absolute; width: 22px; height: 22px;
  border-color: var(--cyan); opacity: 0.75;
  pointer-events: none; z-index: 15;
}
.frame-corner.tl { top: 14px; left: 14px; border-top: 2px solid; border-left: 2px solid; }
.frame-corner.tr { top: 14px; right: 14px; border-top: 2px solid; border-right: 2px solid; }
.frame-corner.bl { bottom: 14px; left: 14px; border-bottom: 2px solid; border-left: 2px solid; }
.frame-corner.br { bottom: 14px; right: 14px; border-bottom: 2px solid; border-right: 2px solid; }

.center-crosshair {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 26px; height: 26px; z-index: 15; pointer-events: none; opacity: 0.5;
}
.ch-line { position: absolute; background: var(--cyan); }
.ch-h { top: 50%; left: 0; width: 100%; height: 1px; transform: translateY(-50%); }
.ch-v { left: 50%; top: 0; height: 100%; width: 1px; transform: translateX(-50%); }

.view-label {
  position: absolute; z-index: 15;
  display: flex; align-items: center; gap: 8px;
  font-size: 10px; letter-spacing: 0.1em;
  color: var(--text-dim);
  background: rgba(7,9,10,0.55);
  padding: 5px 10px;
  border: 1px solid var(--line-bright);
  border-radius: 2px;
  backdrop-filter: blur(2px);
}
.view-label-left { top: 46px; left: 14px; }
.view-label-right { top: 46px; right: 14px; text-align: right; flex-direction: column; align-items: flex-end; gap: 2px; }
.vl-index { color: var(--cyan); font-weight: 600; }
.vl-value { color: var(--text); font-size: 12px; }

/* ============ coverage heatmap HUD ============ */
.heatmap-panel {
  position: absolute; z-index: 15; left: 14px; bottom: 14px;
  width: 140px;
  background: rgba(7,9,10,0.68);
  border: 1px solid var(--line-bright);
  border-radius: 3px;
  backdrop-filter: blur(2px);
  padding: 6px;
}
.heatmap-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 9px; letter-spacing: 0.1em; color: var(--text-dim);
  padding: 0 2px 5px;
}
.heatmap-head span:last-child { color: var(--cyan); font-weight: 600; }
#heatmap-canvas {
  display: block; width: 128px; height: 128px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 2px;
}
.heatmap-legend {
  display: flex; align-items: center; gap: 5px;
  margin-top: 5px; font-size: 8px; color: var(--text-faint); letter-spacing: 0.03em;
}
.hm-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.hm-dot.hm-you { background: var(--amber); box-shadow: 0 0 5px var(--amber); }

@media (max-width: 720px) {
  .heatmap-panel { display: none; }
}

/* ============ bottom controls ============ */
.control-cluster { display: flex; gap: 8px; flex-wrap: wrap; }
.ctrl-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.ctrl-btn:hover { border-color: var(--cyan-dim); color: var(--cyan); }
.ctrl-btn:active { transform: translateY(1px); }
.ctrl-btn.active { border-color: var(--cyan); color: var(--cyan); background: rgba(76,224,210,0.08); }
.ctrl-btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }
.ctrl-key {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  background: var(--panel); border: 1px solid var(--line-bright);
  border-radius: 2px; font-size: 9px; color: var(--text-faint);
}

.telemetry { display: flex; gap: 18px; flex-wrap: wrap; }
.tel-item { display: flex; flex-direction: column; gap: 1px; }
.tel-label { font-size: 8.5px; letter-spacing: 0.12em; color: var(--text-faint); }
.tel-value { font-size: 11px; color: var(--text); }

/* ============ side log ============ */
.side-log {
  position: absolute; top: 76px; right: 14px; z-index: 15;
  width: 220px; max-height: 38vh;
  background: rgba(7,9,10,0.62);
  border: 1px solid var(--line-bright);
  border-radius: 3px;
  backdrop-filter: blur(2px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.side-log-head {
  padding: 6px 10px; font-size: 9px; letter-spacing: 0.14em;
  color: var(--text-faint); border-bottom: 1px solid var(--line);
}
.side-log-body {
  padding: 8px 10px; overflow-y: auto; font-size: 10px;
  line-height: 1.8; color: var(--cyan-dim);
}
.side-log-body div.warn { color: var(--amber); }
.side-log-body div.err { color: var(--red); }

/* ============ toast ============ */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--cyan-dim);
  color: var(--text); padding: 10px 16px; border-radius: 3px;
  font-size: 11px; letter-spacing: 0.06em; z-index: 300;
  opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* ============ responsive ============ */
@media (max-width: 720px) {
  .hud-status { display: none; }
  .side-log { display: none; }
  .telemetry { gap: 10px; }
  .tel-item:nth-child(3) { display: none; }
  .boot-title { font-size: 22px; }

  .view-label-left {
    max-width: calc(100vw - 28px);
    overflow: hidden;
  }
  .view-label-left .vl-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .view-label-left { display: flex; }
  .view-label-right {
    top: auto;
    bottom: 14px;
    right: 14px;
  }
}
