/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-page, #02010a);
  color: var(--text, #E8F4FF);
  overflow: hidden;
  line-height: 1.5;
}

/* === Topbar === */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(2, 1, 10, 0.85), rgba(2, 1, 10, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 18px; font-weight: 600;
  color: var(--brand-color, #98e8ff);
}
.brand-glyph {
  font-size: 22px;
  color: var(--brand-glyph-color, #98e8ff);
  text-shadow: var(--brand-glyph-shadow, 0 0 10px #98e8ff);
  transform: rotate(45deg);
  display: inline-block;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border-soft, rgba(152, 232, 255, 0.3));
  color: var(--text-muted, rgba(200, 210, 230, 0.75));
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  display: flex; gap: 8px; align-items: center;
}
.theme-toggle:hover { border-color: var(--brand-glyph-color, #98e8ff); }
.theme-current { color: var(--brand-glyph-color, #98e8ff); font-weight: 600; }
.meta-readout {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted, rgba(200, 210, 230, 0.6));
}

/* === Stage === */
.stage {
  position: fixed; inset: 0;
  z-index: 1;
}
.graph-container { position: absolute; inset: 0; }
.graph-container canvas { display: block; }

.cmb-layer {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
  background:
    radial-gradient(circle at 20% 30%, rgba(230, 191, 82, 0.04), transparent 30%),
    radial-gradient(circle at 80% 70%, rgba(230, 191, 82, 0.04), transparent 30%),
    radial-gradient(circle at 50% 50%, rgba(152, 232, 255, 0.02), transparent 50%);
  transition: opacity 0.3s ease;
}
.cmb-layer.active { animation: cmb-flicker 0.4s steps(3) infinite; }
@keyframes cmb-flicker {
  0% { transform: translate(0, 0); }
  33% { transform: translate(2px, -1px); }
  66% { transform: translate(-1px, 1px); }
}

.tooltip {
  position: absolute; z-index: 25;
  padding: 8px 12px; border-radius: 7px;
  background: rgba(2, 1, 10, 0.92);
  border: 1px solid var(--border-tooltip, rgba(152, 232, 255, 0.5));
  color: var(--text, #E8F4FF);
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  max-width: 240px;
}
.tooltip.visible { opacity: 1; }
.tooltip .ttitle { color: var(--brand-glyph-color, #98e8ff); font-weight: 600; }
.tooltip .tmeta { color: var(--text-muted, rgba(200, 210, 230, 0.7)); font-family: 'JetBrains Mono', monospace; font-size: 10px; margin-top: 2px; }

.status-bar {
  position: absolute; bottom: 18px; left: 22px; z-index: 25;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted, rgba(200, 210, 230, 0.55));
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* === Modal === */
.modal {
  position: fixed; top: 64px; right: 0; bottom: 80px; width: 360px;
  z-index: 20;
  background: rgba(2, 1, 10, 0.92);
  border-left: 1px solid var(--border-soft, rgba(152, 232, 255, 0.18));
  padding: 24px 22px;
  transform: translateX(110%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  box-shadow: var(--shadow-modal, -8px 0 32px rgba(2, 1, 10, 0.6));
}
.modal.open { transform: translateX(0); }
.modal-close {
  position: absolute; top: 10px; right: 14px;
  background: transparent; border: none;
  color: var(--text-muted, rgba(200, 210, 230, 0.6));
  font-size: 24px; cursor: pointer;
  line-height: 1;
}
.modal-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px; font-weight: 600;
  color: var(--brand-glyph-color, #98e8ff);
  margin-bottom: 6px;
  margin-right: 24px;
}
.modal-subtitle {
  font-style: italic;
  color: var(--text-muted, rgba(200, 210, 230, 0.85));
  margin-bottom: 14px;
}
.modal-essence {
  margin-bottom: 18px;
  font-size: 14px;
}
.modal-neighbours { margin-bottom: 12px; }
.modal-section-label {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted, rgba(200, 210, 230, 0.5));
  margin-bottom: 6px;
}
.neighbour-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.neighbour-pills button {
  background: transparent;
  border: 1px solid var(--border-soft, rgba(152, 232, 255, 0.3));
  color: var(--text, #E8F4FF);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.neighbour-pills button:hover {
  border-color: var(--brand-glyph-color, #98e8ff);
  color: var(--brand-glyph-color, #98e8ff);
}
.modal-hint {
  font-size: 11px;
  color: var(--text-muted, rgba(200, 210, 230, 0.4));
  font-style: italic;
}

/* === Control Panel (slider) === */
.control-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 18px 24px;
  background: linear-gradient(0deg, rgba(2, 1, 10, 0.95), rgba(2, 1, 10, 0));
}
.ctrl-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--brand-glyph-color, #98e8ff);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  min-width: 130px;
}
.ctrl-glyph { color: var(--gold, #E6BF52); }
.gold-slider {
  flex: 1;
  -webkit-appearance: none; appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg,
    rgba(152, 232, 255, 0.3) 0%,
    rgba(201, 162, 58, 0.6) 50%,
    rgba(230, 191, 82, 1) 100%);
  outline: none;
  cursor: pointer;
}
.gold-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle, #E6BF52, #C9A23A);
  border: 2px solid white;
  box-shadow: 0 0 12px rgba(230, 191, 82, 0.8);
  cursor: grab;
}
.gold-slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle, #E6BF52, #C9A23A);
  border: 2px solid white;
  box-shadow: 0 0 12px rgba(230, 191, 82, 0.8);
  cursor: grab;
}
.ctrl-value {
  color: var(--gold, #E6BF52);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  min-width: 50px;
  text-align: right;
  text-shadow: 0 0 8px rgba(230, 191, 82, 0.5);
}

/* === Mobile === */
@media (max-width: 768px) {
  .modal {
    top: auto; right: 0; bottom: 80px; left: 0;
    width: 100%; height: 38vh;
    border-left: none;
    border-top: 1px solid var(--border-soft, rgba(152, 232, 255, 0.18));
    transform: translateY(110%);
  }
  .modal.open { transform: translateY(0); }
  .meta-readout { display: none; }
  .ctrl-label { min-width: 80px; font-size: 10px; }
}

/* === Accessibility === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01s !important;
    transition-duration: 0.01s !important;
  }
}
