:root {
  --bg: #05060f;
  --bg-deep: #02030a;
  --panel: rgba(9, 13, 24, 0.78);
  --panel-line: rgba(0, 229, 255, 0.18);
  --panel-line-soft: rgba(0, 229, 255, 0.09);
  --cyan: #00e5ff;
  --cyan-soft: #7ce8f7;
  --violet: #8b5cf6;
  --magenta: #ff2d95;
  --amber: #ffb020;
  --text: #e8f2ff;
  --text-dim: #93aec6;
  --text-faint: #5f7891;
  --radius: 14px;
  --shadow: 0 18px 48px -18px rgba(0, 0, 0, 0.9);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { position: relative; }

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#stage:active { cursor: grabbing; }

.stage-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(0, 229, 255, 0.07), transparent 58%),
    radial-gradient(90% 70% at 50% 108%, rgba(139, 92, 246, 0.09), transparent 62%);
  mix-blend-mode: screen;
}

/* ── 顶栏 ── */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 78px;
  padding: 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  pointer-events: none;
  z-index: 20;
}
.topbar::after {
  content: "";
  position: absolute;
  left: 26px; right: 26px; bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--panel-line) 18%, var(--panel-line) 82%, transparent);
}

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

.brand-pulse {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgba(0, 229, 255, 0.13), 0 0 16px var(--cyan);
  flex: none;
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.78); }
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: #fff;
  white-space: nowrap;
}
.brand-text h1 em { font-style: normal; color: var(--cyan); opacity: 0.7; margin: 0 2px; }
.brand-text p {
  margin: 3px 0 0;
  font-size: 11.5px;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  text-transform: uppercase;
  white-space: nowrap;
}

/* ── 模式切换 ── */
.mode-switch {
  position: relative;
  display: flex;
  padding: 4px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(6, 9, 18, 0.82);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}
.mode-switch button {
  position: relative;
  z-index: 2;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.08em;
  padding: 9px 22px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.28s ease;
  white-space: nowrap;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.is-active { color: #04121a; font-weight: 600; }
.mode-switch button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}
.mode-glider {
  position: absolute;
  z-index: 1;
  top: 4px; left: 4px;
  height: calc(100% - 8px);
  width: calc(50% - 4px);
  border-radius: 999px;
  background: linear-gradient(100deg, var(--cyan), #6ee7ff 60%, #a5f3fc);
  box-shadow: 0 0 22px rgba(0, 229, 255, 0.45);
  transition: transform 0.42s cubic-bezier(0.5, 1.4, 0.4, 1);
}
.mode-switch[data-active="spectrometer"] .mode-glider { transform: translateX(100%); }

/* ── 面板 ── */
.panel {
  position: absolute;
  z-index: 15;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.15);
  padding: 17px 18px 18px;
}
.panel[hidden] { display: none; }

.panel-left { top: 96px; left: 26px; width: 292px; }
.panel-right { top: 96px; right: 26px; width: 274px; }

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 13px; height: 13px;
  border: 1px solid var(--cyan);
  opacity: 0.55;
  pointer-events: none;
}
.panel::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-radius: 14px 0 0 0; }
.panel::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-radius: 0 0 14px 0; }

.panel-head { display: flex; align-items: baseline; gap: 9px; margin-bottom: 16px; }
.panel-tag {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.2em;
  color: var(--cyan);
  opacity: 0.72;
  border: 1px solid var(--panel-line-soft);
  border-radius: 4px;
  padding: 3px 6px;
}
.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--text-dim);
}

/* ── 表单 ── */
.field { margin-bottom: 17px; }
.field > label,
.field-row label {
  display: block;
  font-size: 12.5px;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.field-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.field-row label { margin-bottom: 8px; }
.field label i { font-style: italic; color: var(--cyan-soft); font-family: var(--mono); }
.field output {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--cyan);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

select {
  width: 100%;
  appearance: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: rgba(0, 229, 255, 0.05)
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2300e5ff' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E")
    no-repeat right 11px center;
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  padding: 10px 32px 10px 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
select:hover { border-color: rgba(0, 229, 255, 0.36); }
select:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
select option { background: #0b1220; color: var(--text); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  display: block;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(0, 229, 255, 0.55), rgba(139, 92, 246, 0.35));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  margin-top: -6px;
  border-radius: 50%;
  background: #041019;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.7);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.16); }
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.24);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.95);
}
input[type="range"]::-moz-range-track {
  height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, rgba(0, 229, 255, 0.55), rgba(139, 92, 246, 0.35));
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #041019;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.7);
}
input[type="range"]:focus-visible { outline: 2px solid var(--cyan); outline-offset: 4px; border-radius: 4px; }

/* ── 按钮 ── */
.panel-actions { display: flex; gap: 9px; margin: 4px 0 2px; }
.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 12.5px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.22s ease;
}
.btn svg { width: 14px; height: 14px; fill: currentColor; flex: none; }
.btn:hover { color: var(--text); border-color: rgba(0, 229, 255, 0.4); background: rgba(0, 229, 255, 0.07); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn-primary {
  color: #04121a;
  background: linear-gradient(100deg, var(--cyan), #7dd3fc);
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 6px 20px -8px rgba(0, 229, 255, 0.9);
}
.btn-primary:hover {
  color: #04121a;
  background: linear-gradient(100deg, #5cf0ff, #a5e9ff);
  box-shadow: 0 8px 26px -8px rgba(0, 229, 255, 1);
}

.panel-divider {
  position: relative;
  margin: 20px 0 14px;
  height: 1px;
  background: var(--panel-line-soft);
}
.panel-divider span {
  position: absolute;
  top: -7px; left: 0;
  padding-right: 9px;
  font-size: 10px;
  letter-spacing: 0.24em;
  color: var(--text-faint);
  background: #080c16;
  text-transform: uppercase;
}

.toggles { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  appearance: none;
  font-family: inherit;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: all 0.22s ease;
  white-space: nowrap;
}
.chip:hover { color: var(--text-dim); border-color: rgba(0, 229, 255, 0.28); }
.chip.is-on {
  color: #04121a;
  background: var(--cyan-soft);
  border-color: transparent;
  box-shadow: 0 0 16px -4px rgba(0, 229, 255, 0.8);
  font-weight: 600;
}
.chip:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ── 读数 ── */
.readout[hidden] { display: none; }
.ro-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
}
.ro-row:last-child { border-bottom: 0; }
.ro-row span {
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.ro-row b {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  text-align: right;
}
.ro-row b sub { font-size: 0.7em; }
.ro-sep { height: 12px; }
.ro-head b { font-size: 11px; color: var(--text-faint); letter-spacing: 0.12em; }
.ro-head span { color: var(--text-faint); }

.ro-spec {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
}
.ro-spec .swatch {
  width: 7px; height: 7px;
  border-radius: 2px;
  flex: none;
}
.ro-spec .name {
  font-size: 12px;
  color: var(--text-dim);
  flex: 1;
  font-family: var(--mono);
}
.ro-spec .val {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.panel-note {
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-line-soft);
}
.formula {
  margin: 0;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--cyan-soft);
  display: flex;
  align-items: center;
  gap: 4px;
  letter-spacing: 0.02em;
}
.formula .frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  font-size: 12px;
  line-height: 1.15;
}
.formula .frac i { font-style: italic; padding: 0 3px; }
.formula .frac > span {
  border-top: 1px solid rgba(124, 232, 247, 0.55);
  padding: 0 3px;
  font-style: italic;
}
.formula-sub {
  margin: 9px 0 0;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

/* ── 底部提示 ── */
.bottom-hint {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--panel-line-soft);
  background: rgba(6, 9, 18, 0.72);
  backdrop-filter: blur(12px);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  white-space: nowrap;
  pointer-events: none;
}
.bottom-hint .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

/* ── 加载 / 兜底 ── */
.loading {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg-deep);
  transition: opacity 0.6s ease, visibility 0.6s;
}
.loading.is-done { opacity: 0; visibility: hidden; }
.loading span {
  font-size: 11.5px;
  letter-spacing: 0.28em;
  color: var(--text-faint);
  text-transform: uppercase;
}
.loading-bar {
  width: 190px;
  height: 1px;
  background: rgba(0, 229, 255, 0.14);
  overflow: hidden;
}
.loading-bar i {
  display: block;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  animation: sweep 1.2s ease-in-out infinite;
}
@keyframes sweep {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(360%); }
}

.fallback {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 30px;
  text-align: center;
  background: var(--bg-deep);
}
.fallback[hidden] { display: none; }
.fallback h2 { margin: 0; font-size: 17px; font-weight: 500; letter-spacing: 0.08em; }
.fallback p { margin: 0; max-width: 420px; font-size: 13px; line-height: 1.7; color: var(--text-dim); }

/* ── 响应式 ── */
@media (max-width: 1180px) {
  .panel-left { width: 264px; }
  .panel-right { width: 248px; }
  .brand-text h1 { font-size: 15px; }
}

@media (max-width: 900px) {
  .topbar {
    height: auto;
    padding: 14px 16px 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .topbar::after { left: 16px; right: 16px; }
  .brand-text p { display: none; }
  .mode-switch { align-self: stretch; }
  .mode-switch button { flex: 1; padding: 9px 10px; font-size: 12.5px; }

  .panel {
    left: 12px; right: 12px;
    width: auto;
    border-radius: 16px 16px 0 0;
    backdrop-filter: blur(20px);
  }
  .panel-left {
    top: auto; bottom: 0; left: 0; right: 0;
    max-height: 47vh;
    overflow-y: auto;
    padding: 14px 16px 18px;
  }
  .panel-right {
    top: auto; bottom: 0; left: 0; right: 0;
    width: auto;
    max-height: 30vh;
    overflow-y: auto;
    display: none;
  }
  .panel::before, .panel::after { display: none; }
  .field { margin-bottom: 13px; }
  .field > label, .field-row label { font-size: 12px; margin-bottom: 6px; }
  .toggles { gap: 6px; }
  .chip { padding: 6px 11px; font-size: 11px; }

  .bottom-hint {
    bottom: auto;
    top: 50%;
    font-size: 10.5px;
    padding: 6px 13px;
    display: none;
  }
  .panel-note { display: none; }
  .readout .ro-row { padding: 5px 0; }
}

@media (max-height: 620px) and (min-width: 901px) {
  .panel-left, .panel-right { top: 88px; }
  .field { margin-bottom: 12px; }
  .panel-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
