:root {
  --bg: #05070a;
  --panel: rgba(12, 16, 23, 0.84);
  --panel-strong: rgba(15, 20, 29, 0.94);
  --border: rgba(255, 190, 92, 0.14);
  --border-soft: rgba(148, 174, 214, 0.11);
  --text: #edf2fa;
  --muted: #7f8fa8;
  --dim: #4c5a70;
  --amber: #ffb547;
  --amber-glow: rgba(255, 181, 71, 0.35);
  --emerald: #35f2b6;
  --emerald-glow: rgba(53, 242, 182, 0.28);
  --coral: #ff5c72;
  --cyan: #5cc8ff;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  --sans: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 181, 71, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 181, 71, 0.03) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 35% 40%, black 25%, transparent 85%);
  z-index: 0;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 600px at 22% 42%, rgba(255, 166, 56, 0.085), transparent 65%),
    radial-gradient(700px 500px at 82% 24%, rgba(53, 242, 182, 0.05), transparent 60%),
    radial-gradient(600px 500px at 78% 84%, rgba(92, 200, 255, 0.045), transparent 60%);
  z-index: 0;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(7, 10, 15, 0.78);
  backdrop-filter: blur(16px);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-ring {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3.5px solid var(--amber);
  box-shadow: 0 0 14px var(--amber-glow), inset 0 0 8px rgba(255, 181, 71, 0.35);
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.22), transparent 55%);
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.1;
}

.brand-accent { color: var(--amber); }

.brand-sub {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 2px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill[data-state="live"] {
  border-color: rgba(53, 242, 182, 0.45);
  background: rgba(53, 242, 182, 0.09);
  color: var(--emerald);
}
.status-pill[data-state="live"] .status-dot {
  background: var(--emerald);
  box-shadow: 0 0 10px var(--emerald);
  animation: blink 1.2s ease-in-out infinite;
}

.status-pill[data-state="replay"] {
  border-color: rgba(255, 181, 71, 0.45);
  background: rgba(255, 181, 71, 0.1);
  color: var(--amber);
}
.status-pill[data-state="replay"] .status-dot {
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
}

.status-pill[data-state="standby"] {
  border-color: rgba(92, 200, 255, 0.3);
  background: rgba(92, 200, 255, 0.07);
  color: var(--cyan);
}
.status-pill[data-state="standby"] .status-dot { background: var(--cyan); }

@keyframes blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.82); }
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.025);
  font-family: var(--mono);
}

.chip-k {
  font-size: 9.5px;
  color: var(--muted);
  letter-spacing: 0.09em;
}

.chip-v {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 181, 71, 0.28);
  background: rgba(255, 181, 71, 0.08);
  color: var(--amber);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ctrl-btn:hover {
  background: rgba(255, 181, 71, 0.16);
  border-color: rgba(255, 181, 71, 0.55);
}

.ctrl-btn[aria-pressed="true"], .ctrl-btn.active {
  background: rgba(53, 242, 182, 0.15);
  border-color: rgba(53, 242, 182, 0.55);
  color: var(--emerald);
}

.ctrl-btn-ghost {
  border-color: var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.observatory {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(360px, 1.04fr) minmax(420px, 1.25fr);
  gap: 14px;
  padding: 14px 20px 10px;
  max-width: 1720px;
  width: 100%;
  margin: 0 auto;
}

.panel {
  position: relative;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.hero-panel {
  min-height: 620px;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 181, 71, 0.06), rgba(8, 11, 17, 0.94) 68%);
}

#ringCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
#ringCanvas:active { cursor: grabbing; }

.hud {
  position: absolute;
  pointer-events: none;
  padding: 14px 16px;
  max-width: 48%;
}
.hud-tl { top: 4px; left: 4px; }
.hud-tr { top: 4px; right: 4px; text-align: right; }
.hud-bl { bottom: 4px; left: 4px; }
.hud-br { bottom: 4px; right: 4px; text-align: right; min-width: 210px; }

.hud-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 7px;
}
.hud-tr .hud-label, .hud-br .hud-label { justify-content: flex-end; }

.hud-tag {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(255, 181, 71, 0.25);
  color: var(--amber);
  background: rgba(255, 181, 71, 0.07);
}

.bpm-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 2px;
}

.bpm-value {
  font-family: var(--mono);
  font-size: clamp(44px, 5vw, 64px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--amber);
  text-shadow: 0 0 28px rgba(255, 181, 71, 0.35);
  font-variant-numeric: tabular-nums;
}

.bpm-unit {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.pulse-heart {
  font-size: 20px;
  color: var(--coral);
  opacity: 0.45;
  transform: scale(1);
  transition: transform 0.14s ease-out, opacity 0.2s ease-out;
}
.pulse-heart.beat {
  opacity: 1;
  transform: scale(1.42);
  text-shadow: 0 0 16px rgba(255, 92, 114, 0.8);
}

.temp-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 4px;
}

.temp-value {
  font-family: var(--mono);
  font-size: clamp(28px, 3.2vw, 40px);
  font-weight: 700;
  line-height: 1;
  color: var(--cyan);
  text-shadow: 0 0 22px rgba(92, 200, 255, 0.3);
  font-variant-numeric: tabular-nums;
}

.temp-unit {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
}

.hud-metrics {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
}

.mk { color: var(--muted); font-size: 10px; letter-spacing: 0.06em; }
.mv { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.mv-emerald { color: var(--emerald); }

.hud-sub {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
}

.motion-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.04);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.motion-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.motion-pill[data-state="still"] {
  border-color: rgba(53, 242, 182, 0.4);
  background: rgba(53, 242, 182, 0.09);
  color: var(--emerald);
}
.motion-pill[data-state="still"] .motion-dot {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.motion-pill[data-state="moving"] {
  border-color: rgba(255, 92, 114, 0.45);
  background: rgba(255, 92, 114, 0.11);
  color: var(--coral);
}
.motion-pill[data-state="moving"] .motion-dot {
  background: var(--coral);
  box-shadow: 0 0 8px var(--coral);
}

.coherence-bar {
  margin-top: 7px;
  height: 7px;
  width: 100%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.coherence-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--coral), var(--amber), var(--emerald));
  transition: width 0.35s ease;
}

.scope-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.scope-panel, .mini-panel {
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text);
  white-space: nowrap;
}

.badge {
  font-size: 9px;
  font-weight: 500;
  color: var(--muted);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
  white-space: nowrap;
}

.panel-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.dot-amber { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot-emerald { background: var(--emerald); box-shadow: 0 0 8px var(--emerald); }
.dot-cyan { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.axis-legend {
  display: flex;
  gap: 12px;
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.leg-x { color: var(--amber); }
.leg-y { color: var(--emerald); }
.leg-z { color: var(--cyan); }
.axis-legend b { font-weight: 600; }

.canvas-wrap {
  position: relative;
  width: 100%;
}
.canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.scope-hr-wrap { height: 185px; }
.scope-acm-wrap { height: 175px; }

.lower-grid {
  display: grid;
  grid-template-columns: 0.92fr 1.08fr;
  gap: 14px;
  flex: 1;
}

.poincare-wrap { height: 220px; }
.temp-wrap { height: 108px; }

.wire-feed {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding: 7px 12px;
  height: 112px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.55;
  color: var(--muted);
}

.wire-row {
  display: flex;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wire-ts { color: var(--dim); }
.wire-hex { color: var(--amber); opacity: 0.85; }
.wire-desc { color: var(--text); }
.wire-row.bad .wire-desc { color: var(--coral); }
.wire-row.good .wire-desc { color: var(--emerald); }

.wire-empty {
  color: var(--dim);
  padding: 20px 0;
  text-align: center;
}

.footbar {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 20px 14px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
  max-width: 1720px;
  width: 100%;
  margin: 0 auto;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(3, 5, 9, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }

.modal-card {
  width: min(920px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 18px;
  border: 1px solid rgba(255, 181, 71, 0.3);
  background: var(--panel-strong);
  padding: 22px 24px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.75);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.03em;
}
.modal-head p {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.matrix-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 16px;
}

.matrix-col h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 13px;
  font-family: var(--mono);
  letter-spacing: 0.05em;
}

.matrix-col ul {
  margin: 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #c5d1e3;
}

.matrix-col code {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--amber);
  background: rgba(255, 181, 71, 0.09);
  padding: 1px 4px;
  border-radius: 4px;
}

@media (max-width: 1120px) {
  .observatory {
    grid-template-columns: 1fr;
  }
  .hero-panel {
    min-height: 460px;
  }
}

@media (max-width: 680px) {
  .lower-grid, .matrix-grid {
    grid-template-columns: 1fr;
  }
  .topbar { padding: 10px 14px; }
  .observatory { padding: 10px 14px; }
}
