:root {
  color-scheme: dark;
  --bg: #050608;
  --fg: #f4efe6;
  --muted: #a69d8e;
  --faint: #756d61;
  --brass: #d9b67c;
  --brass-bright: #f2d59f;
  --border: rgba(232, 206, 166, 0.18);
  --border-active: rgba(236, 204, 152, 0.62);
  --panel: rgba(12, 13, 16, 0.78);
  --panel-hover: rgba(34, 30, 24, 0.90);
  --wave-color: #7ef54c;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--fg);
  background: var(--bg);
}

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

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  user-select: none;
  -webkit-user-select: none;
}

button, input, select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.mono {
  font-family: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

#scene, #overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#scene {
  touch-action: none;
  cursor: default;
}

#scene.hover-item {
  cursor: grab;
}

#scene.hover-rotate {
  cursor: ew-resize;
}

#scene.dragging {
  cursor: grabbing;
}

#scene.panning {
  cursor: move;
}

#overlay {
  pointer-events: none;
  z-index: 2;
}

/* Outer-Perimeter 3D Rendered Optical-Glass Formula Plates */
.holo-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.holo-card {
  --card-accent: #e5c185;
  --card-glow: rgba(229, 193, 133, 0.14);
  position: fixed;
  width: 288px;
  padding: 11px 14px 11px 15px;
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(255, 248, 234, 0.075) 0%, rgba(255, 255, 255, 0.015) 36%, transparent 38%),
    linear-gradient(155deg, rgba(20, 23, 31, 0.72) 0%, rgba(9, 11, 16, 0.52) 58%, rgba(16, 20, 28, 0.68) 100%);
  backdrop-filter: blur(22px) saturate(165%) brightness(1.10);
  -webkit-backdrop-filter: blur(22px) saturate(165%) brightness(1.10);
  border: 1px solid rgba(238, 214, 174, 0.24);
  box-shadow:
    0 16px 46px rgba(0, 0, 0, 0.64),
    0 0 30px var(--card-glow),
    inset 0 1px 0 rgba(255, 248, 232, 0.24),
    inset 0 -1px 0 rgba(255, 255, 255, 0.05);
  transition: opacity 0.25s ease, border-color 0.25s ease;
}

.holo-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 8px;
  padding: 1px;
  background: linear-gradient(135deg, var(--card-accent) 0%, transparent 24%, transparent 76%, var(--card-accent) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.65;
  pointer-events: none;
}

.holo-card::after {
  content: "";
  position: absolute;
  top: 16%;
  bottom: 16%;
  width: 1.5px;
  background: linear-gradient(180deg, transparent 0%, var(--card-accent) 50%, transparent 100%);
  box-shadow: 0 0 12px var(--card-accent);
  opacity: 0.85;
  pointer-events: none;
}

.holo-card.wing-left::after { right: -1px; }
.holo-card.wing-right::after { left: -1px; }

.holo-card[data-accent="ice"] {
  --card-accent: #90d5ff;
  --card-glow: rgba(130, 205, 255, 0.14);
}

.holo-card[data-accent="spectral"] {
  --card-accent: var(--wave-color);
  --card-glow: rgba(140, 235, 160, 0.13);
}

.holo-card.wing-left {
  left: clamp(14px, 2.0vw, 30px);
  width: 278px;
  transform-origin: left center;
  transform: perspective(1050px) rotateY(6deg);
}

.holo-card.wing-right {
  right: clamp(14px, 2.2vw, 34px);
  width: 294px;
  transform-origin: right center;
  transform: perspective(1050px) rotateY(-6deg);
}

.holo-pin {
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #fffdf7;
  border: 2px solid var(--card-accent);
  box-shadow: 0 0 12px var(--card-accent), 0 0 4px #ffffff;
}

.holo-pin.pin-right { right: -5px; }
.holo-pin.pin-left { left: -5px; }

.holo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 7px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(236, 214, 176, 0.12);
}

.holo-id {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.11em;
  white-space: nowrap;
  color: var(--card-accent);
  text-shadow: 0 0 12px var(--card-glow);
}

.holo-badge {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  padding: 1.5px 6px;
  border-radius: 3px;
  color: #efe7d8;
  background: rgba(255, 245, 224, 0.08);
  border: 1px solid rgba(255, 240, 210, 0.16);
}

.math-eq {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin: 4px 0 7px;
  font: 400 13px / 1.25 "Cambria Math", "Times New Roman", Georgia, serif;
  color: #fbf7ef;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.65);
}

.eq-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.math-eq i { font-style: italic; }
.math-eq sub, .math-eq sup { font-size: 0.72em; line-height: 0; }
.eq-sep { color: rgba(229, 193, 133, 0.55); margin: 0 2px; }

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  font-size: 0.86em;
  line-height: 1.1;
  padding: 0 2px;
}

.frac .num { padding: 0 3px 2px; border-bottom: 1px solid rgba(248, 238, 220, 0.68); }
.frac .den { padding: 2px 3px 0; }

.sum-wrap {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
  margin: 0 1px;
}
.sum-wrap small { font-size: 8.5px; color: #d8cebe; }
.sum-sym { font-size: 15px; line-height: 1; }

.holo-metrics {
  font-size: 10.5px;
  color: #efd199;
  line-height: 1.4;
}

.wave-strip {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid rgba(236, 214, 176, 0.11);
}

#waveScope {
  width: 100%;
  height: 18px;
  display: block;
}

/* Brand Header */
.brand {
  position: fixed;
  top: clamp(14px, 2.6vh, 30px);
  left: clamp(16px, 2.6vw, 38px);
  pointer-events: none;
  z-index: 4;
}

.brand h1 {
  margin: 0;
  font: 500 clamp(22px, 2.8vw, 40px) / 1.06 "Songti SC", "STSong", "Noto Serif SC", "SimSun", serif;
  letter-spacing: 0.10em;
  color: var(--fg);
  text-shadow: 0 4px 28px rgba(0, 0, 0, 0.78);
}

.brand .subtitle {
  margin: 4px 0 0;
  font: italic clamp(11.5px, 1.15vw, 15.5px) / 1.2 Georgia, "Times New Roman", serif;
  color: #cbbba3;
  letter-spacing: 0.03em;
}

/* Minimalist Top-Right Darkroom Toolbar */
.toolbar {
  position: fixed;
  top: clamp(14px, 2.6vh, 30px);
  right: clamp(16px, 2.6vw, 38px);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  z-index: 6;
  max-width: calc(100vw - 240px);
}

button, .toolbar-select {
  color: var(--fg);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 11px;
  font-size: 12px;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.toolbar-select {
  padding-right: 22px;
  color: var(--brass-bright);
  border-color: rgba(217, 182, 124, 0.34);
  background-color: rgba(20, 18, 15, 0.85);
}

.toolbar-select option {
  background: #101216;
  color: var(--fg);
}

button:hover, .toolbar-select:hover {
  border-color: var(--border-active);
  background: var(--panel-hover);
}

button[aria-pressed="true"], button[aria-expanded="true"] {
  border-color: var(--brass);
  background: rgba(58, 46, 29, 0.88);
  color: var(--brass-bright);
  box-shadow: 0 0 16px rgba(217, 182, 124, 0.18);
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* Collapsible Add-Element & Share Popovers */
.popover-anchor {
  position: relative;
}

.popover-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 288px;
  padding: 12px;
  z-index: 12;
  background: rgba(11, 13, 17, 0.94);
  border: 1px solid rgba(232, 206, 166, 0.30);
}

.share-pop {
  width: 186px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pop-group + .pop-group {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(232, 206, 166, 0.12);
}

.pop-title {
  font-size: 10.5px;
  letter-spacing: 0.10em;
  color: var(--brass);
  margin-bottom: 6px;
}

.pop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.pop-btn {
  padding: 5px 8px;
  font-size: 11.5px;
  text-align: center;
  background: rgba(26, 28, 34, 0.72);
}

.pop-btn.full {
  width: 100%;
  text-align: left;
  padding: 6px 10px;
}

.pop-btn.danger {
  color: #f39a8e;
  border-color: rgba(243, 154, 142, 0.26);
}

.pop-btn.danger:hover {
  border-color: rgba(243, 154, 142, 0.7);
  background: rgba(84, 28, 24, 0.55);
}

/* Shared Glass Instrument Cards */
.glass-card {
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 42px rgba(0, 0, 0, 0.58);
  z-index: 5;
}

/* Bottom-Left Contextual Inspector & Spectral Probe */
#inspectorPanel {
  position: fixed;
  left: clamp(16px, 2.6vw, 38px);
  bottom: clamp(14px, 2.6vh, 30px);
  width: min(420px, calc(100vw - 290px));
  padding: 11px 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.mat-tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--fg);
  min-width: 0;
}

.accent-val {
  color: var(--brass-bright);
  font-size: 11px;
  font-weight: 400;
}

.mode-pills {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.mini-btn {
  padding: 3px 8px;
  font-size: 11px;
}

.mini-btn.danger {
  color: #f39a8e;
  border-color: rgba(243, 154, 142, 0.25);
}

.dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--wave-color);
  box-shadow: 0 0 10px var(--wave-color);
}

.inspector-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 8px;
}

.inspector-body:empty {
  display: none;
  margin-bottom: 0;
}

.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: #dfd5c5;
}

.ctrl-label {
  color: var(--muted);
  white-space: nowrap;
  min-width: 58px;
  font-size: 11px;
}

.ctrl-range {
  flex: 1;
  accent-color: var(--brass);
  height: 4px;
  cursor: pointer;
}

.ctrl-val {
  min-width: 52px;
  text-align: right;
  font-size: 11px;
  color: var(--brass-bright);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.pill-row .mini-btn {
  flex: 1 1 auto;
  text-align: center;
  padding: 3px 6px;
}

.slider-block {
  padding-top: 2px;
}

.slider-wrap {
  position: relative;
  height: 18px;
  display: flex;
  align-items: center;
}

.spectrum-bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    #6312a8 0%,
    #5c3df7 14%,
    #2176fa 26%,
    #19c9fc 38%,
    #35eba9 48%,
    #7ef54c 56%,
    #f5ea51 67%,
    #ff9f36 78%,
    #fa3b2b 90%,
    #9e0822 100%
  );
  pointer-events: none;
}

#waveSlider {
  position: relative;
  width: 100%;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  height: 18px;
}

#waveSlider::-webkit-slider-runnable-track { height: 5px; background: transparent; }
#waveSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -4px;
  border-radius: 50%;
  background: #fdfaf3;
  border: 2px solid var(--wave-color);
  box-shadow: 0 0 10px var(--wave-color), 0 1px 4px rgba(0, 0, 0, 0.85);
}

.readout {
  margin: 5px 0 0;
  font-size: 10.5px;
  line-height: 1.38;
  color: var(--muted);
}

/* Bottom-Right Hardware Telemetry & Per-Pass Profiler */
#telemetry {
  position: fixed;
  right: clamp(16px, 2.6vw, 38px);
  bottom: clamp(14px, 2.6vh, 30px);
  width: 244px;
  padding: 10px 12px;
}

#telemetry .stats {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
}

.fps-val { font-weight: 600; color: var(--fg); }
.ms-val { font-size: 11.5px; color: var(--brass-bright); }

#perfGraph {
  width: 100%;
  height: 30px;
  display: block;
  margin: 4px 0;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
}

.pass-breakdown {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(232, 206, 166, 0.12);
}

.pass-bars {
  display: flex;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 4px;
}

.pbar { height: 100%; transition: width 0.18s ease; }
.pbar-mc { background: #f2b85c; width: 30%; }
.pbar-vol { background: #5cd6a6; width: 15%; }
.pbar-rt { background: #64b5ff; width: 40%; }
.pbar-fx { background: #c58aff; width: 15%; }

.pass-text {
  font-size: 9.5px;
  color: #c8beae;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bench-banner {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(232, 206, 166, 0.16);
  font-size: 10px;
  line-height: 1.45;
  color: var(--brass-bright);
}

/* Toast Notification */
.toast {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 5px;
  font-size: 11.5px;
  color: var(--brass-bright);
  background: rgba(14, 16, 22, 0.92);
  border: 1px solid rgba(232, 206, 166, 0.36);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
  z-index: 20;
}

/* Startup / Error Modal */
.status-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, 86vw);
  padding: 20px 24px;
  text-align: center;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--fg);
  background: rgba(12, 13, 16, 0.94);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.78);
  z-index: 25;
}

.spinner {
  width: 22px;
  height: 22px;
  margin: 0 auto 12px;
  border: 2px solid rgba(217, 182, 124, 0.22);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
  .holo-layer { display: none; }
}

@media (max-width: 720px) {
  #inspectorPanel {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
  }
  #telemetry {
    top: 66px;
    bottom: auto;
    right: 12px;
    width: 190px;
  }
  .toolbar {
    right: 12px;
    max-width: calc(100vw - 24px);
  }
}
