/* Bilingual font scheme — Inter for Latin, PingFang SC / Microsoft YaHei for CJK,
   JetBrains Mono for code, Georgia / STIX Two Math for symbols (e.g. κ, δ).
   Conventions follow the scientific-python-web skill: EN/ZH locale codes,
   weights 400/500/600/700, font: inherit on form controls. */

/* Product variables alias the shared tokens (platform/shared-web/shared-tokens.css,
   loaded before this file). Values identical to the shared palette resolve
   through var(); BON-specific values stay as literal overrides. */
:root {
  --velo-cyan: #23b9d7; /* BON accent differs from the shared cyan (#1ea7a1) */
  --ink: var(--velo-ink);
  --muted: var(--velo-muted);
  --line: var(--velo-line);
  --bg: #f4f8fc;
  --blue: var(--velo-blue);
  --cyan: var(--velo-cyan);
  --negative: #c52aa6;
  --panel: var(--velo-panel);

  --font-sans: var(--velo-font-sans);
  --font-mono: var(--velo-font-mono);
  --font-serif: var(--velo-font-serif);
}

* { box-sizing: border-box; }

html { font-size: 14px; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 400 14px/1.55 var(--font-sans);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Form controls inherit body stack so numbers stay consistent with body text. */
input, select, button, textarea {
  font: inherit;
  color: inherit;
}

/* Mono used for numeric / code-like readouts. */
.mono, code, kbd, samp, pre { font-family: var(--font-mono); }
.mono, code, .hover-info { font-variant-numeric: tabular-nums; }

.tick { font: 11px var(--font-sans); fill: #68768a; }

.topbar {
  height: 58px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #102a4b;
  color: #fff;
}

.brand,
.topbar a {
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand { display: inline-flex; align-items: center; font-size: 18px; }
.brand .logo { font-weight: 700; letter-spacing: .14em; }
.brand .logo b { color: var(--cyan); }
.brand .sub { display: inline-flex; flex-direction: column; gap: 1px; margin-left: 9px; font-size: 10.5px; line-height: 1.1; letter-spacing: .04em; color: #b8c8db; font-weight: 500; }
.brand .brand-purpose { color: #8aa0b8; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 13px;
}
.node-status {
  color: #b8c8db;
  font-size: 12px;
}
/* Dark-topbar override of the shared .hbtn (shared-controls.css); font-size
   pins the historical 14px against the shared 12px default. */
.hbtn {
  border: 1px solid #5b7597;
  border-radius: 7px;
  background: transparent;
  color: #fff;
  padding: 5px 9px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
}
.hbtn:hover { background: rgba(255, 255, 255, 0.08); }
.hbtn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.help-menu-wrap {
  position: relative;
  flex: 0 0 auto;
}
.help-menu-trigger[aria-expanded="true"] {
  border-color: var(--cyan);
  color: var(--cyan);
}
.help-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  display: none;
  min-width: 138px;
  padding: 5px;
  border: 1px solid #5b7597;
  border-radius: 7px;
  background: #102a4b;
  box-shadow: 0 10px 24px #07152559;
}
.help-menu.on {
  display: grid;
  gap: 2px;
}
.help-menu .hbtn {
  display: block;
  width: 100%;
  border-color: transparent;
  text-align: left;
  white-space: nowrap;
}

.studio {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  /* Two columns: a widened input column (~1/3 wider than before) and the
     combined middle column that now also holds the diagnostics + actions
     previously split into a separate right-hand results column. */
  grid-template-columns: minmax(300px, 373px) minmax(450px, 1fr);
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 4px 18px #16355a0d;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.visual h1 {
  font-size: 24px;
  line-height: 1.15;
  margin: 6px 0;
  letter-spacing: -0.025em;
  font-weight: 700;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 18px;
  line-height: 1.55;
}

.field {
  display: block;
  margin: 12px 0;
}
.controls [hidden] { display: none; }
.field span {
  display: block;
  font-weight: 600;
  margin-bottom: 5px;
}
.field select,
.field input {
  width: 100%;
  padding: 8px;
  border: 1px solid #bcc9d6;
  border-radius: 8px;
  background: #fff;
}

.io-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 15px 0;
}
.io-row button,
.export-button {
  border: 1px solid #b9c6d5;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  cursor: pointer;
}

.run-button {
  border: 0;
  border-radius: 9px;
  background: var(--blue);
  color: #fff;
  width: 100%;
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
}
.run-button:hover { background: #1a59c0; }
.run-button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.run-button:disabled,
.export-button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.message {
  min-height: 0;
  color: #b42318;
  font-size: 12px;
}

/* Diagnostic tiles live directly under the plot — the old 运行诊断 heading
   and its divider are gone; a modest gap follows the hover bar. */
.visual .metrics {
  margin-top: 14px;
}

.visual-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
}
.visual h2 {
  margin: 4px 0;
  font-size: 20px;
  font-weight: 600;
}
.badge {
  border-radius: 999px;
  background: #edf3ff;
  color: var(--blue);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--muted);
  font-size: 12px;
  margin: 9px 0;
}
.legend span:not(.negative):not(.complex) { margin-left: -9px; }
.legend .negative,
.legend .complex {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  display: inline-block;
}
.negative {
  background: #c52aa63b;
  border: 1px solid var(--negative);
}
.complex { background: linear-gradient(90deg, #2166ac, #f7d03c, #b2182b); }

.plot-shell {
  height: 580px;
  border: 1px solid var(--line);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  background: #fff;
}
.plot-shell svg { width: 100%; height: 100%; display: block; }

.hover-info {
  min-height: 22px;
  margin-top: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.metrics.metrics-3 {
  grid-template-columns: repeat(3, 1fr);
}
.metrics article {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.metrics strong { font-size: 17px; }

.export-button {
  width: 100%;
  color: var(--blue);
  font-weight: 700;
}
.export-button:not(:disabled):hover { background: #f0f6ff; }

/* Full-width report action sits directly under the run button. The empty
   error line collapses to zero height, so this margin is the whole gap —
   kept tight (about half the previous run→report spacing). */
.export-button.report-button {
  margin-top: 16px;
}

/* The editable multi-fluid v2 controls share the main panel. The three fixed
   radial reference cases hide this block and run through stable v1 contracts. */
.v2-controls {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

/* Custom research mode (v2) — collapsible, never fixture-equivalent. */
.custom-controls {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.custom-controls summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--blue);
  font-size: 13px;
  padding: 4px 0;
  list-style: none;
}
.custom-controls summary::-webkit-details-marker { display: none; }
.custom-controls summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.15s;
  color: var(--muted);
}
.custom-controls[open] summary::before { transform: rotate(90deg); }
.custom-controls[open] summary { margin-bottom: 8px; }
.custom-note {
  color: var(--muted);
  font-size: 11px;
  margin: 0 0 10px;
  line-height: 1.45;
}
.scan-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.params {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
}
.params .field { margin: 8px 0; }
.params .field span { font-size: 11px; }
.params .field input:disabled {
  opacity: 0.5;
  background: #f4f6f9;
  cursor: not-allowed;
}
/* Species profile and model span the full parameter row; scalar params pair
   up two-per-row (扫描变量 | 模型, 温度 | 密度, 磁场 | 平行折射率, 频率 | 扫描点数). */
.params .field.wide {
  grid-column: 1 / -1;
}
/* The scanned variable is set per-scan; mark its label with a dotted underline
   so the title-tooltip (hover) is discoverable without a redundant hint line. */
.field .tip-label {
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: help;
}
.run-button.secondary {
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--blue);
  margin-top: 6px;
}
.run-button.secondary:hover { background: #f0f6ff; }
.run-button.secondary:disabled { opacity: 0.5; cursor: wait; }
.species-editor { min-width: 0; margin: 10px 0 14px; }
.species-editor-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.species-editor-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.species-editor-chevron { flex: 0 0 auto; margin-left: 8px; color: var(--muted); transition: transform 0.15s; }
.species-editor-toggle[aria-expanded="true"] .species-editor-chevron { transform: rotate(90deg); }
.species-editor-panel { min-width: 0; padding-top: 6px; }
.species-editor-actions { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.species-editor-actions button,
.species-remove { width: 28px; height: 28px; border: 1px solid #b9c6d5; border-radius: 6px; background: #fff; cursor: pointer; }
.species-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; align-items: end; padding: 9px 0; border-top: 1px solid var(--line); }
.species-row label { min-width: 0; }
.species-row label span { display: block; min-height: 26px; color: var(--muted); font-size: 9px; line-height: 1.3; }
.species-row input { box-sizing: border-box; width: 100%; min-width: 0; padding: 6px; border: 1px solid #bcc9d6; border-radius: 6px; }
.species-row .species-remove { grid-column: 2; justify-self: end; }
#v2Error { margin-top: 6px; }

#tour { display: none; }
.tour-dim {
  position: fixed;
  inset: 0;
  background: #071525a6;
  z-index: 20;
}
.tour-card {
  position: fixed;
  z-index: 21;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100% - 32px));
  padding: 20px;
  background: #fff;
  border-radius: 13px;
  box-shadow: 0 12px 48px #0007;
}
.tour-card h2 { margin: 4px 0; font-size: 18px; }
.tour-card p { color: var(--muted); }
.tour-card div {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}
.tour-card button {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  background: #fff;
  cursor: pointer;
}
.tour-card #tourNext {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 600;
}

/* 数据说明 subpage: research mode, numerical contract, interpretation boundary.
   Uses the same .panel surface as the studio. */
.notes {
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 18px 48px;
}
.notes h1 {
  font-size: 26px;
  margin: 4px 0;
  letter-spacing: -0.025em;
  font-weight: 700;
}
.notes-section { margin-top: 16px; }
.notes-section h2 {
  font-size: 16px;
  margin: 0 0 10px;
  font-weight: 600;
  color: var(--ink);
}
.notes-dl { margin: 0; }
.notes-dl div {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid #eef2f6;
}
.notes-dl dt { color: var(--muted); font-weight: 600; }
.notes-dl dd { margin: 0; font-size: 12px; word-break: break-word; }
.notes-warn {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.notes-warn li {
  padding: 8px 0;
  border-top: 1px solid #eef2f6;
  overflow-wrap: anywhere;
}
.notes-warn li code {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--blue);
}
.notes-warn li span { color: var(--muted); font-size: 12px; line-height: 1.5; }

/* CJK body text is denser — bump heading weight in ZH so it doesn't read lighter. */
html[lang="zh"] .visual h1,
html[lang="zh"] .notes h1 {
  font-weight: 800;
}

/* Keep the same font stack under @media print so PDFs match the live UI. */
@media print {
  body { font: 12px/1.5 var(--font-sans); }
  .topbar, .io-row, .run-button, .export-button, .custom-controls, #tour, #historyPanel { display: none; }
}

/* Mobile / narrow viewports. */
@media (max-width: 1050px) {
  .studio { grid-template-columns: 1fr; }
  .plot-shell { height: 480px; }
  .actions { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .topbar {
    height: auto;
    min-height: 58px;
    padding: 10px 14px;
    align-items: flex-start;
  }
  .brand { min-width: 0; }
  .brand .sub { min-width: 0; }
  .topbar-right { min-width: 0; justify-content: flex-end; flex-wrap: wrap; }
  .node-status,
  .topbar-right > a { display: none; }
  .help-menu { max-width: calc(100vw - 28px); }
  .studio { display: block; padding: 10px; }
  .panel { margin-bottom: 10px; }
  .plot-shell { height: 390px; }
  .metrics.metrics-3 { grid-template-columns: repeat(2, 1fr); }
  .species-row { grid-template-columns: minmax(0, 1fr); }
  .species-row .species-remove { grid-column: 1; }
  .metrics article { padding: 7px; }
  .metrics strong { font-size: 14px; }
}

/* ---- dark theme (toggle folded into the Help menu) ----
   The topbar/help-menu stay dark-navy in both themes, so only the main
   content surface is themed. Scientific plot colours (branch mapColor,
   evanescent magenta, the RdBu legend gradient) are theme-independent;
   draw() picks the axis/grid/tick/hover colours from data-theme. */
[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8eef7;
  --muted: #94a3b8;
  --line: #2a3a55;
  --bg: #121a29;
  --blue: #5b9bff;
  --panel: #1e2940;
  --surface-2: #243250;
}
[data-theme="dark"] body { background: var(--bg); }
[data-theme="dark"] .panel { background: var(--panel); box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35); }
[data-theme="dark"] .field select,
[data-theme="dark"] .field input,
[data-theme="dark"] .io-row button,
[data-theme="dark"] .species-editor-toggle,
[data-theme="dark"] .species-editor-actions button,
[data-theme="dark"] .species-remove,
[data-theme="dark"] .export-button,
[data-theme="dark"] .run-button.secondary,
[data-theme="dark"] .tour-card,
[data-theme="dark"] .tour-card button {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
}
[data-theme="dark"] .params .field input:disabled { background: #172031; }
[data-theme="dark"] .plot-shell { background: var(--surface-2); }
[data-theme="dark"] .tick { fill: #8a98ad; }
[data-theme="dark"] .badge { background: #1e2f4d; color: var(--blue); }
[data-theme="dark"] .run-button { background: var(--blue); color: #0b1220; }
[data-theme="dark"] .run-button:hover { background: #7ab0ff; }
[data-theme="dark"] .run-button.secondary:hover,
[data-theme="dark"] .export-button:not(:disabled):hover { background: #2f4366; }
[data-theme="dark"] .message { color: #ff6b6b; }
[data-theme="dark"] .tour-card #tourNext { background: var(--blue); border-color: var(--blue); color: #0b1220; }
[data-theme="dark"] .notes-dl div { border-bottom-color: var(--line); }
[data-theme="dark"] .notes-warn li { border-top-color: var(--line); }

/* ── Account dropdown menu ── */
.toolbar-menu-wrap { position: relative; flex: 0 0 auto; }
.toolbar-menu-trigger {
  display: inline-flex; align-items: center; gap: 5px;
  font: 12px/1.2 var(--font-sans); letter-spacing: inherit;
  color: rgba(255,255,255,.75); background: transparent;
  border: 1px solid transparent; border-radius: 6px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
.toolbar-menu-trigger:hover { color: var(--blue); background: rgba(255,255,255,.08); }
.toolbar-menu-trigger[aria-expanded="true"] { color: var(--blue); background: rgba(255,255,255,.08); }
.toolbar-menu-trigger .menu-caret { font-size: 9px; opacity: .7; }
.toolbar-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 80;
  display: none; min-width: 156px; padding: 5px;
  background: #0e1625; border: 1px solid #2a3a55; border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0,0,0,.4);
}
.toolbar-menu.on { display: grid; gap: 2px; }
.toolbar-menu button {
  width: 100%; border: 0; border-radius: 6px;
  background: transparent; color: #94a3b8; cursor: pointer;
  text-align: left; font: 11px/1.35 var(--font-sans); padding: 7px 8px;
}
.toolbar-menu button:hover { background: rgba(91,155,255,.12); color: #e8eef7; }
.toolbar-menu button.danger:hover { color: #ff6b6b; }
.toolbar-menu .menu-aff {
  padding: 5px 8px 7px; border-bottom: 1px solid #2a3a55;
  font-size: 10px; color: #64748b; line-height: 1.35; overflow-wrap: anywhere;
}
.toolbar-menu .unverified { color: #ff7b7b; font-weight: 700; }
.toolbar-menu .unverified:hover { color: #ff7b7b; }
.userbox {
  display: inline-flex; position: relative; margin-left: 6px;
  font-size: 13px;
}
.userbox .uname { color: rgba(255,255,255,.85); font-weight: 600; }
.userbox.guest .uname { color: var(--blue); }
.userbox.guest .menu-caret { display: none; }
.userbox.guest #userMenu { display: none !important; }