:root {
  --bg-0: #040711;
  --bg-1: #091022;
  --bg-2: #0f1a33;
  --panel-bg: rgba(10, 17, 36, 0.88);
  --border: rgba(56, 242, 255, 0.22);
  --border-soft: rgba(148, 163, 184, 0.16);
  --cyan: #38f2ff;
  --gold: #ffd166;
  --magenta: #ff4d94;
  --violet: #a78bfa;
  --emerald: #34d399;
  --text: #e6f0ff;
  --muted: #8ea4c8;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at 22% 14%, #0d1836 0%, #050814 55%, #02040a 100%);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 7px 14px;
  background: rgba(6, 11, 24, 0.94);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  z-index: 20;
}

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

.brand-orb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, var(--cyan) 38%, var(--violet) 78%, transparent 100%);
  box-shadow: 0 0 14px rgba(56, 242, 255, 0.8), 0 0 26px rgba(167, 139, 250, 0.45);
  flex-shrink: 0;
}

.brand-title {
  font-size: 14.5px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  background: linear-gradient(90deg, #ffffff 0%, var(--cyan) 50%, var(--gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.1;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.chamber-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}

.tab-btn {
  appearance: none;
  border: 1px solid var(--border-soft);
  background: rgba(15, 25, 50, 0.72);
  color: #b7c9e6;
  font-family: var(--sans);
  font-size: 10.8px;
  font-weight: 600;
  padding: 4.5px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  border-color: rgba(56, 242, 255, 0.55);
  color: #ffffff;
  background: rgba(24, 42, 82, 0.85);
}

.tab-btn.active {
  background: linear-gradient(135deg, rgba(56, 242, 255, 0.22), rgba(167, 139, 250, 0.24));
  border-color: var(--cyan);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(56, 242, 255, 0.32), inset 0 0 8px rgba(56, 242, 255, 0.14);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(15, 26, 51, 0.8);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  padding: 4.5px 9px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.pill-btn:hover {
  border-color: var(--cyan);
  background: rgba(56, 242, 255, 0.16);
  color: #fff;
}

.pill-btn.active-sound {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(255, 209, 102, 0.14);
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.28);
}

.pill-btn.sibling-link {
  border-color: rgba(255, 209, 102, 0.4);
  color: #ffe39c;
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.stage-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  background: radial-gradient(circle at 50% 45%, #0a1329 0%, #040711 76%);
  overflow: hidden;
}

#waveCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.stage-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  background: rgba(6, 11, 24, 0.78);
  border: 1px solid rgba(56, 242, 255, 0.22);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  color: #c2d4f0;
  pointer-events: none;
  backdrop-filter: blur(6px);
  max-width: calc(100% - 24px);
}

.stage-hint strong {
  color: var(--cyan);
}

/* Right Control Sidebar */
.sidebar {
  width: 318px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  padding: 9px 11px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  backdrop-filter: blur(10px);
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(56, 242, 255, 0.25);
  border-radius: 4px;
}

.chamber-header {
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 7px;
}

.chamber-title {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  margin: 0 0 3px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.chamber-desc {
  font-size: 11.2px;
  line-height: 1.42;
  color: var(--muted);
  margin: 0;
}

.card {
  background: rgba(15, 25, 49, 0.65);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  padding: 7.5px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--cyan);
}

.btn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.btn-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.btn-grid.cols-3 .ctrl-btn {
  padding: 5px 4px;
  font-size: 10.4px;
}

.btn-grid.cols-1 {
  grid-template-columns: 1fr;
}

.ctrl-btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(10, 18, 36, 0.82);
  color: #cfe0fa;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  padding: 5.5px 7px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s ease;
  text-align: center;
}

.ctrl-btn:hover {
  border-color: rgba(56, 242, 255, 0.55);
  color: #ffffff;
  background: rgba(24, 42, 82, 0.85);
}

.ctrl-btn.active {
  border-color: var(--cyan);
  background: rgba(56, 242, 255, 0.18);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(56, 242, 255, 0.24);
}

.ctrl-btn.accent-gold {
  border-color: rgba(255, 209, 102, 0.55);
  color: #ffe39c;
  background: rgba(255, 209, 102, 0.11);
}

.ctrl-btn.accent-gold:hover,
.ctrl-btn.accent-gold.active {
  border-color: var(--gold);
  background: rgba(255, 209, 102, 0.24);
  color: #fff;
}

.ctrl-btn.accent-magenta {
  border-color: rgba(255, 77, 148, 0.55);
  color: #ffb0cf;
  background: rgba(255, 77, 148, 0.12);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.slider-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #c7d9f5;
}

.slider-val {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gold);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
  cursor: pointer;
  margin: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.2px;
  color: #cde0fb;
  cursor: pointer;
  user-select: none;
}

.toggle-row input[type="checkbox"] {
  accent-color: var(--cyan);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* Telemetry Readouts */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.stat-box {
  background: rgba(5, 10, 22, 0.78);
  border: 1px solid rgba(56, 242, 255, 0.14);
  border-radius: 6px;
  padding: 5px 7px;
}

.stat-box.wide {
  grid-column: span 2;
}

.stat-k {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat-v {
  font-family: var(--mono);
  font-size: 11.8px;
  font-weight: 700;
  color: #ffffff;
}

.stat-v.cyan { color: var(--cyan); }
.stat-v.gold { color: var(--gold); }
.stat-v.magenta { color: var(--magenta); }
.stat-v.emerald { color: var(--emerald); }

.badge-sharp {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 209, 102, 0.22);
  border: 1px solid var(--gold);
  color: var(--gold);
  margin-left: 5px;
  box-shadow: 0 0 8px rgba(255, 209, 102, 0.35);
}

.badge-strict {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(56, 242, 255, 0.14);
  border: 1px solid rgba(56, 242, 255, 0.45);
  color: var(--cyan);
  margin-left: 5px;
}

.energy-bar-wrap {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-top: 3px;
}

.energy-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.12s linear;
}

.theorem-box {
  background: linear-gradient(135deg, rgba(18, 30, 62, 0.72), rgba(28, 18, 52, 0.62));
  border: 1px solid rgba(167, 139, 250, 0.32);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.46;
  color: #d6e4fb;
}

.theorem-box strong {
  color: var(--gold);
}

.theorem-box code {
  font-family: var(--mono);
  font-size: 10.4px;
  color: var(--cyan);
  background: rgba(5, 10, 22, 0.55);
  padding: 1px 4px;
  border-radius: 3px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 5, 14, 0.78);
  backdrop-filter: blur(7px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: min(820px, 95vw);
  max-height: 88vh;
  overflow-y: auto;
  background: #0a1226;
  border: 1px solid var(--cyan);
  border-radius: 14px;
  padding: 18px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 32px rgba(56, 242, 255, 0.18);
}

.modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.modal-top h2 {
  margin: 0;
  font-size: 16px;
  color: #ffffff;
}

.modal-body h3 {
  margin: 12px 0 4px 0;
  font-size: 13px;
  color: var(--gold);
}

.modal-body p {
  margin: 0 0 7px 0;
  font-size: 12px;
  line-height: 1.5;
  color: #cbd9f2;
}

.cert-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11px;
}

.cert-table th, .cert-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.cert-table th {
  color: var(--cyan);
  font-weight: 700;
}

.cert-pass {
  color: var(--emerald);
  font-weight: 700;
}

.verify-cmd {
  margin-top: 10px;
  background: #040814;
  border: 1px solid rgba(56, 242, 255, 0.25);
  border-radius: 7px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--cyan);
  overflow-x: auto;
}

@media (max-width: 980px) {
  .topbar { padding: 6px 10px; }
  .chamber-tabs { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .sidebar { width: 292px; }
}

@media (max-width: 1180px) {
  .chamber-tabs {
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
  }
}

/* Golden home-star pill linking back to The Neon Decet — Grand Constellation Atlas */
.atlas-home-pill {
  color: #ffd666 !important;
  border-color: rgba(255, 214, 102, 0.58) !important;
  background: rgba(255, 214, 102, 0.12) !important;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 0 10px rgba(255, 214, 102, 0.18);
}
.atlas-home-pill:hover {
  color: #fff3c4 !important;
  border-color: rgba(255, 214, 102, 0.92) !important;
  background: rgba(255, 214, 102, 0.24) !important;
  box-shadow: 0 0 14px rgba(255, 214, 102, 0.38);
}
