:root {
  --bg: #05070f;
  --text: #e8eefc;
  --text-dim: #93a1bd;
  --cyan: #38bdf8;
  --violet: #a78bfa;
  --green: #34d399;
  --amber: #facc15;
  --panel: rgba(10, 16, 32, 0.78);
  --panel-border: rgba(148, 184, 255, 0.14);
  --radius: 14px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

.aurora-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(50% 36% at 8% 0%, rgba(56, 189, 248, 0.12), transparent 62%),
    radial-gradient(44% 34% at 94% 4%, rgba(167, 139, 250, 0.11), transparent 62%),
    radial-gradient(58% 40% at 50% 108%, rgba(244, 114, 182, 0.07), transparent 62%),
    var(--bg);
}

/* ---------- Top bar ---------- */
.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(5, 7, 15, 0.82);
  backdrop-filter: blur(16px);
  position: relative;
  z-index: 60;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: all 0.25s;
  white-space: nowrap;
}

.back-btn:hover { color: var(--cyan); border-color: rgba(56, 189, 248, 0.35); background: rgba(56, 189, 248, 0.07); }

.topbar-title { text-align: center; }

.topbar-title h1 {
  font-size: 16px;
  letter-spacing: 2px;
  font-weight: 800;
  background: linear-gradient(90deg, #7dd3fc, #c4b5fd);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.topbar-sub { font-size: 11px; color: var(--text-dim); letter-spacing: 1.5px; }

.topbar-right { min-width: 92px; display: flex; justify-content: flex-end; }

.live-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  padding: 5px 13px;
  border-radius: 999px;
  color: #9fe8cd;
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse 1.8s infinite; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  height: calc(100vh - 54px);
  position: relative;
}

.stage3d {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#webglHolder { position: absolute; inset: 0; }

#webglHolder canvas { display: block; outline: none; }

#labelLayer {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  overflow: hidden;
}

.lbl {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  will-change: transform, opacity;
  transition: transform 0.12s ease-out, opacity 0.3s ease;
  animation: lblIn 0.4s ease both;
}

@keyframes lblIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lbl-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lc, #fff);
  box-shadow: 0 0 10px var(--lc, #fff);
  margin: -3.5px 0 0 -3.5px;
  flex-shrink: 0;
}

.lbl-line {
  width: 13px;
  height: 1px;
  margin: 0 1px;
  flex-shrink: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.08));
}

.lbl.flip { flex-direction: row-reverse; }

.lbl.flip .lbl-line {
  background: linear-gradient(270deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.08));
}

.lbl-pill {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(20, 24, 36, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
}

.lbl-t {
  font-size: 11.5px;
  letter-spacing: 0.2px;
  color: #eef2f9;
  white-space: nowrap;
}

.lbl-f {
  font-size: 10.5px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  color: var(--lc, #fff);
  white-space: nowrap;
  letter-spacing: 0.1px;
}

.lbl.first .lbl-t { font-weight: 600; }

/* ---------- Legend panel ---------- */
#legendLayer {
  position: absolute;
  left: 22px;
  bottom: 72px;
  z-index: 8;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 13px;
  border-radius: 12px;
  background: rgba(8, 13, 27, 0.68);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.lg-title {
  font-size: 9.5px;
  letter-spacing: 2.5px;
  color: #8fa3c2;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.lg-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: #dbe4f5;
  padding: 3px 0;
  white-space: nowrap;
}

.lg-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

@media (max-width: 640px) {
  #legendLayer { display: none; }
}

.stage-overlay {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.o-top-left { top: 18px; left: 22px; flex-direction: column; align-items: flex-start; gap: 4px; }
.o-top-right { top: 18px; right: 22px; }
.o-bottom-left { bottom: 18px; left: 220px; }
.o-bottom-right { bottom: 18px; right: 22px; }

.part-indicator {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(5, 10, 22, 0.72);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
}

.part-indicator b { color: var(--cyan); font-size: 13px; }

.part-name-big {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 6px 14px;
  border-radius: 12px;
  background: rgba(5, 10, 22, 0.72);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
}

.status-pill, .hint-pill {
  font-size: 11.5px;
  letter-spacing: 1px;
  color: #9fd8ff;
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(5, 10, 22, 0.72);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
}

.hint-pill { color: var(--text-dim); }

.side-toggle {
  display: none;
  position: absolute;
  top: 18px;
  right: 22px;
  z-index: 40;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.4);
  background: rgba(8, 14, 30, 0.85);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  backdrop-filter: blur(10px);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 372px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 18px;
  border-left: 1px solid var(--panel-border);
  background: rgba(8, 13, 27, 0.86);
  backdrop-filter: blur(18px);
  z-index: 50;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(148, 184, 255, 0.2); border-radius: 3px; }

.side-sec { margin-bottom: 20px; }

.side-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #9fd8ff;
  margin-bottom: 11px;
}

.side-tag { font-size: 10.5px; font-weight: 500; color: var(--text-dim); letter-spacing: 1px; }

/* steps */
.step-list { display: flex; flex-direction: column; gap: 8px; }

.step-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  transition: all 0.25s;
}

.step-btn:hover { border-color: rgba(56, 189, 248, 0.4); }

.step-btn.active {
  border-color: rgba(56, 189, 248, 0.55);
  background: linear-gradient(120deg, rgba(56, 189, 248, 0.14), rgba(139, 92, 246, 0.1));
}

.step-num {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-family: "SF Mono", Menlo, monospace;
  flex-shrink: 0;
}

.step-btn.active .step-num { color: var(--cyan); }

.step-txt { display: flex; flex-direction: column; gap: 2px; }

.step-txt b { font-size: 14px; font-weight: 700; }

.step-txt i { font-size: 11.5px; color: var(--text-dim); font-style: normal; }

.step-btn.active .step-txt i { color: #9fd8ff; }

/* seg control */
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  width: 100%;
}

.seg-btn {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.25s;
}

.seg-btn.active {
  color: #fff;
  background: linear-gradient(120deg, #0ea5e9, #8b5cf6);
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.35);
}

.seg-small { width: auto; }
.seg-small .seg-btn { padding: 8px 18px; }

.ctrl-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.ctl-btn {
  padding: 8px 17px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.25s;
}

.ctl-btn:hover { border-color: rgba(56, 189, 248, 0.5); background: rgba(56, 189, 248, 0.08); }

.ctl-btn.disabled { opacity: 0.35; pointer-events: none; }

/* fx chips */
.fx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }

.fx-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
}

.fx-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(148, 184, 255, 0.3);
  flex-shrink: 0;
  transition: all 0.2s;
}

.fx-chip.on {
  border-color: rgba(52, 211, 153, 0.45);
  background: rgba(52, 211, 153, 0.08);
  color: #a7f3d0;
}

.fx-chip.on .fx-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }

.fx-chip.off-for-part { opacity: 0.42; }

.fx-all { display: flex; gap: 8px; }

.fx-all-btn {
  flex: 1;
  padding: 7px 0;
  border-radius: 9px;
  border: 1px dashed rgba(148, 184, 255, 0.3);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
}

.fx-all-btn:hover { color: var(--cyan); border-color: rgba(56, 189, 248, 0.5); }

/* phenomena & principle */
.phenomena { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.phenomena li {
  display: flex;
  gap: 9px;
  font-size: 12.5px;
  line-height: 1.8;
  color: #c6d3ea;
}

.phenomena li::before {
  content: "";
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  margin-top: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  transform: rotate(45deg);
}

.phenomena b { color: #eef4ff; font-weight: 600; }

.eq-box { display: flex; flex-direction: column; gap: 8px; }

.eq-line {
  font-size: 12.5px;
  line-height: 1.8;
  color: #c6d3ea;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.05);
  border-left: 2.5px solid rgba(56, 189, 248, 0.6);
}

.eq-line .eq-formula { font-family: "SF Mono", Menlo, Consolas, monospace; color: #7dd3fc; font-weight: 600; }

.eq-line .eq-formula.eq-green { color: #6ee7b7; }
.eq-line .eq-formula.eq-amber { color: #fcd34d; }
.eq-line .eq-formula.eq-orange { color: #fdba74; }
.eq-line .eq-formula.eq-gray { color: #94a3b8; }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 7px 13px; }

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #c6d3ea;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

/* fallback */
.webgl-fallback {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 14px;
}

/* responsive */
@media (max-width: 1080px) {
  .sidebar {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    transform: translateX(102%);
    transition: transform 0.35s ease;
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5);
    width: min(372px, 88vw);
  }

  .sidebar.open { transform: translateX(0); }

  .side-toggle { display: block; }

  .stage3d { margin-right: 0; }
}

@media (max-width: 640px) {
  .topbar-sub { display: none; }
  .part-name-big { font-size: 17px; }
  .o-bottom-left { display: none; }
}
