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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(ellipse at 35% 40%, #1a2848 0%, #0F172A 65%);
  color: #F8FAFC;
}

#three-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Labels ── */
#labels-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.node-label {
  position: fixed;
  pointer-events: none;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 5px 10px;
  background: rgba(10, 17, 36, 0.82);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.11);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  transition: opacity 0.2s;
}
.node-label .lbl-title {
  font-size: 12px;
  font-weight: 600;
  display: block;
}
.node-label .lbl-chakra {
  font-size: 10px;
  color: #94A3B8;
  display: block;
  margin-top: 1px;
}

.face-label {
  position: fixed;
  pointer-events: none;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 3px 9px;
  background: rgba(10, 17, 36, 0.70);
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.09);
  backdrop-filter: blur(4px);
  white-space: nowrap;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: opacity 0.2s;
}

/* ── Tooltip ── */
#tooltip {
  position: fixed;
  background: rgba(30, 41, 59, 0.97);
  color: #F8FAFC;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  border: 1px solid rgba(255,255,255,0.12);
  z-index: 150;
  max-width: 240px;
}
#tooltip.show { opacity: 1; }

/* ── Side Panel ── */
#panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background: rgba(11, 18, 35, 0.97);
  border-left: 1px solid rgba(255,255,255,0.09);
  backdrop-filter: blur(14px);
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  z-index: 300;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#panel.open { transform: translateX(0); }

@media (max-width: 768px) {
  #panel {
    width: 100vw;
    height: 62vh;
    top: auto;
    bottom: 0;
    right: 0;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.1);
    transform: translateY(110%);
    border-radius: 16px 16px 0 0;
  }
  #panel.open { transform: translateY(0); }
}

.panel-color-bar { height: 4px; width: 100%; flex-shrink: 0; }

.panel-header {
  padding: 18px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  position: relative;
}

.close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.14);
  color: #94A3B8;
  cursor: pointer;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
  line-height: 1;
  padding: 0;
}
.close-btn:hover { color: #F8FAFC; background: rgba(255,255,255,0.13); }

.panel-type-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
  margin-bottom: 6px;
}

[contenteditable="true"] {
  outline: none;
  border-radius: 4px;
  transition: background 0.18s;
  padding: 2px 4px;
  margin: -2px -4px;
  cursor: text;
}
[contenteditable="true"]:hover { background: rgba(255,255,255,0.05); }
[contenteditable="true"]:focus { background: rgba(255,255,255,0.07); }

.panel-title {
  font-size: 21px;
  font-weight: 700;
  color: #F8FAFC;
  display: block;
  margin-bottom: 4px;
  min-width: 10px;
}

.panel-subtitle {
  font-size: 13px;
  color: #64748B;
  margin-top: 2px;
}

.panel-body { padding: 18px 20px 28px; }

.field-group { margin-bottom: 18px; }

.field-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
  margin-bottom: 7px;
  display: block;
}

.field-textarea {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: #CBD5E1;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s, background 0.2s;
}
.field-textarea:focus {
  outline: none;
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
}

.badge-grid { display: flex; flex-wrap: wrap; gap: 7px; }

.node-badge {
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.18s, transform 0.14s;
  color: #F8FAFC;
  border: 1px solid transparent;
}
.node-badge:hover { filter: brightness(1.3); transform: translateY(-1px); }

.circle-badge {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.11);
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  color: #CBD5E1;
  transition: all 0.18s;
}
.circle-badge:hover { background: rgba(255,255,255,0.13); color: #F8FAFC; }

.axis-display {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 13px;
  color: #CBD5E1;
  display: flex;
  align-items: center;
  gap: 9px;
}
.ax-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.heart-note {
  background: rgba(34, 197, 94, 0.07);
  border: 1px solid rgba(34, 197, 94, 0.24);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 12px;
  color: #86EFAC;
  line-height: 1.55;
  margin-top: 18px;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 7px;
}
.type-pill.crown-type {
  background: rgba(139, 92, 246, 0.14);
  border: 1px solid rgba(139, 92, 246, 0.28);
  color: #C4B5FD;
}
.type-pill.root-type {
  background: rgba(239, 68, 68, 0.11);
  border: 1px solid rgba(239, 68, 68, 0.28);
  color: #FCA5A5;
}

/* ── Controls Bar ── */
#controls-bar {
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 200;
}

.ctrl-btn {
  background: rgba(20, 30, 52, 0.88);
  border: 1px solid rgba(255,255,255,0.11);
  color: #94A3B8;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.18s;
  backdrop-filter: blur(6px);
  white-space: nowrap;
  text-align: left;
}
.ctrl-btn:hover {
  background: rgba(40, 55, 85, 0.92);
  color: #E2E8F0;
  border-color: rgba(255,255,255,0.18);
}
.ctrl-btn.active {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(99, 102, 241, 0.42);
  color: #A5B4FC;
}

/* ── Axis Indicator ── */
#axis-indicator {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11, 18, 35, 0.92);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 30px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  color: #F8FAFC;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 400;
  text-align: center;
  white-space: nowrap;
}
#axis-indicator.show { opacity: 1; }

/* ── Legend ── */
#legend {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: rgba(11, 18, 35, 0.9);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 11px;
  padding: 12px 16px;
  z-index: 200;
  backdrop-filter: blur(8px);
  transition: opacity 0.28s, transform 0.28s;
  min-width: 160px;
}
#legend.hidden {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}
.legend-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
  margin-bottom: 9px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 7px;
  font-size: 12px;
  color: #94A3B8;
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 3px;
  transition: color 0.18s;
}
.legend-row:last-child { margin-bottom: 0; }
.legend-row:hover { color: #E2E8F0; }
.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 5px currentColor;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

/* ── Interactive hint ── */
#octa-hint {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.32);
  color: #A5B4FC;
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
  z-index: 200;
  transition: opacity 1s;
  white-space: nowrap;
}
#octa-hint.faded { opacity: 0; }

/* ── Node panel rich display ── */
.panel-desc {
  font-size: 13px;
  color: #CBD5E1;
  line-height: 1.65;
  margin: 0 0 12px;
}
.panel-quote {
  font-size: 12px;
  color: #94A3B8;
  font-style: italic;
  border-left: 2px solid rgba(255,255,255,0.15);
  padding-left: 10px;
  margin: 10px 0 0;
  line-height: 1.55;
  display: block;
}
