:root {
  color-scheme: dark;
  --bg: #07131a;
  --panel: #0b1b24;
  --panel-2: #0e222c;
  --line: rgba(151, 190, 196, .14);
  --line-strong: rgba(151, 190, 196, .25);
  --text: #e9f4f3;
  --muted: #8ca4a8;
  --muted-2: #627c82;
  --accent: #6ce5d1;
  --accent-dim: rgba(108, 229, 209, .12);
  --accent-glow: rgba(108, 229, 209, .32);
  --radius: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
body.embed-mode { height: 100vh; height: 100dvh; overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
#app {
  width: 100%; height: 100vh; height: 100dvh; min-height: 0;
  display: grid; grid-template-rows: 72px minmax(280px, 1fr) 250px;
  overflow: hidden; background: radial-gradient(ellipse at 50% -30%, rgba(41, 107, 107, .17), transparent 55%), var(--bg);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 10px 24px; border-bottom: 1px solid var(--line); background: rgba(7, 19, 26, .94); z-index: 2;
}
.heading { min-width: 0; }
.eyebrow, .section-kicker, .caption-kicker { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .16em; line-height: 1.4; }
.eyebrow { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.eyebrow-dot, .live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent-glow); display: inline-block; }
h1 { font-size: 19px; line-height: 1.1; letter-spacing: -.035em; margin: 0; font-weight: 720; }
.subtitle { color: var(--muted); font-size: 11px; margin: 3px 0 0; }
.toolbar { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.tool-btn {
  height: 34px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: #0b1b24; color: #c2d5d5;
  font-size: 11px; font-weight: 700; cursor: pointer; transition: background .18s ease, border-color .18s ease, transform .18s ease, color .18s ease;
}
.tool-btn:hover, .preset-btn:hover { border-color: rgba(108, 229, 209, .6); background: #102832; color: var(--text); }
.tool-btn:active, .preset-btn:active { transform: translateY(1px); }
.tool-btn:focus-visible, .preset-btn:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.tool-btn.primary { color: #061c1b; border-color: var(--accent); background: var(--accent); }
.tool-btn.primary:hover { background: #91f2e4; border-color: #91f2e4; }
.quality-btn { min-width: 50px; color: var(--accent); letter-spacing: .08em; font-size: 9px; }
.stage { position: relative; min-height: 0; overflow: hidden; background: radial-gradient(ellipse at 50% 42%, rgba(31, 92, 96, .13), transparent 58%), #081820; }
#scene { display: block; width: 100%; height: 100%; }
.stage-topline { position: absolute; top: 16px; left: 24px; right: 24px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.stage-chip, .status-badge { display: inline-flex; align-items: center; gap: 8px; border: 1px solid rgba(155, 203, 204, .15); border-radius: 100px; padding: 7px 10px; background: rgba(6, 20, 27, .72); backdrop-filter: blur(8px); color: #b8cdcc; font-size: 9px; font-weight: 800; letter-spacing: .11em; }
.chip-sep { color: #47646b; }
.status-badge { color: var(--accent); border-color: rgba(108, 229, 209, .28); letter-spacing: .09em; }
.status-badge[data-state="clear"] { color: #d1e7e5; border-color: rgba(108, 229, 209, .16); }
.status-badge[data-state="quiet"] { color: var(--muted); }
.stage-caption { position: absolute; left: 24px; top: 60px; width: min(400px, calc(100% - 48px)); padding: 10px 13px; border-left: 2px solid var(--accent); background: linear-gradient(90deg, rgba(7, 19, 26, .75), rgba(7, 19, 26, 0)); pointer-events: none; }
.caption-kicker { font-size: 8px; color: var(--accent); }
.stage-caption p { color: #d3e2e1; font-size: 11px; line-height: 1.45; margin: 4px 0 0; max-width: 390px; text-wrap: pretty; }
.stage-legend { position: absolute; right: 24px; bottom: 14px; display: flex; gap: 14px; align-items: center; color: #789197; font-size: 9px; pointer-events: none; }
.stage-legend span { display: flex; align-items: center; gap: 6px; }
.legend-line { width: 14px; height: 2px; display: inline-block; background: var(--accent); border-radius: 2px; }
.legend-line.neighbour { opacity: .45; border-top: 1px dashed var(--accent); background: transparent; }
.legend-wave { width: 14px; height: 6px; display: inline-block; border-top: 1px solid var(--accent); border-radius: 50%; transform: translateY(2px); }
.dock { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(380px, 1fr); gap: 20px; padding: 14px 24px 12px; min-height: 0; overflow: hidden; border-top: 1px solid var(--line); background: #091820; }
.control-column, .readout-column { min-width: 0; min-height: 0; }
.section-heading { height: 34px; display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 9px; }
.section-kicker { font-size: 8px; letter-spacing: .14em; }
h2 { margin: 2px 0 0; font-size: 13px; letter-spacing: -.01em; font-weight: 700; }
.presets { display: flex; gap: 5px; }
.preset-btn { height: 26px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: transparent; color: var(--muted); font-size: 9px; font-weight: 700; cursor: pointer; transition: all .18s ease; }
.preset-btn.active { color: var(--accent); border-color: rgba(108, 229, 209, .35); background: var(--accent-dim); }
.slider-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.slider-card { min-width: 0; min-height: 76px; padding: 9px 10px 7px; border: 1px solid var(--line); border-radius: 9px; background: rgba(15, 36, 45, .68); transition: border-color .2s ease, background .2s ease; }
.slider-card:hover { border-color: var(--line-strong); background: rgba(18, 42, 51, .8); }
.slider-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.slider-top label { overflow: hidden; color: #c6d8d7; font-size: 10px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.slider-top output { flex-shrink: 0; color: var(--accent); font-size: 11px; font-weight: 750; font-variant-numeric: tabular-nums; }
input[type="range"] { display: block; width: 100%; height: 15px; margin: 7px 0 2px; appearance: none; background: transparent; cursor: pointer; touch-action: pan-y; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(90deg, rgba(108,229,209,.72), rgba(108,229,209,.16)); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: linear-gradient(90deg, rgba(108,229,209,.72), rgba(108,229,209,.16)); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4.5px; border-radius: 50%; border: 2px solid #06201e; background: var(--accent); box-shadow: 0 0 0 2px rgba(108,229,209,.18), 0 0 10px var(--accent-glow); }
input[type="range"]::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; border: 2px solid #06201e; background: var(--accent); box-shadow: 0 0 0 2px rgba(108,229,209,.18), 0 0 10px var(--accent-glow); }
.slider-bottom { display: flex; justify-content: space-between; align-items: center; gap: 3px; color: var(--muted-2); font-size: 8px; }
.number-tag { display: inline-flex; align-items: center; padding: 2px 4px; border-radius: 3px; font-size: 7px; font-weight: 850; letter-spacing: .07em; white-space: nowrap; }
.number-tag.illustrative { color: #a7c7c2; background: rgba(108, 229, 209, .08); }
.number-tag.scaled { color: #8faeb1; background: rgba(143, 174, 177, .09); }
.number-tag.textbook { color: var(--accent); background: rgba(108, 229, 209, .13); }
.readout-heading { margin-bottom: 9px; }
.elapsed-label { color: var(--muted-2); font-size: 8px; font-weight: 800; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.metric-card { min-width: 0; height: 67px; padding: 8px 9px 6px; border: 1px solid var(--line); border-radius: 9px; background: rgba(15, 36, 45, .68); }
.metric-label { color: var(--muted); font-size: 7px; letter-spacing: .1em; font-weight: 850; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-value { margin-top: 5px; color: var(--text); font-size: 19px; font-weight: 720; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.metric-value small { color: var(--muted); font-size: 10px; font-weight: 650; letter-spacing: 0; }
.metric-foot { display: flex; align-items: center; gap: 5px; margin-top: 6px; color: var(--muted-2); font-size: 7px; white-space: nowrap; overflow: hidden; }
.metric-foot .number-tag { font-size: 6px; }
.check-row { display: flex; align-items: center; gap: 9px; margin-top: 8px; min-height: 34px; padding: 6px 9px; border: 1px solid rgba(108, 229, 209, .16); border-radius: 8px; background: rgba(108, 229, 209, .045); }
.check-icon { width: 18px; height: 18px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: rgba(108, 229, 209, .15); color: var(--accent); font-size: 11px; font-weight: 900; }
.check-copy { min-width: 0; }
.check-title { color: #c9dddb; font-size: 9px; font-weight: 750; display: flex; align-items: center; gap: 6px; }
.check-value { margin-top: 2px; color: var(--muted); font-size: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.science-panel { margin-top: 7px; border-top: 1px solid var(--line); padding-top: 6px; }
.science-panel summary { display: flex; align-items: center; gap: 9px; color: #c9dddb; font-size: 9px; font-weight: 750; cursor: pointer; list-style: none; outline-offset: 3px; }
.science-panel summary::-webkit-details-marker { display: none; }
.science-panel summary::before { content: "+"; display: grid; place-items: center; width: 14px; height: 14px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--accent); font-size: 11px; }
.science-panel[open] summary::before { content: "−"; }
.details-hint { color: var(--muted-2); font-size: 8px; font-weight: 500; }
.science-content { max-height: 220px; overflow-y: auto; padding: 8px 4px 8px 23px; color: #9db2b3; font-size: 9px; line-height: 1.5; }
.science-content h3 { margin: 8px 0 3px; color: #d9e8e6; font-size: 10px; }
.science-content p { margin: 4px 0 7px; }
.science-content code { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 9px; }
.reference-line { color: #7f9a9e; }
.disclaimer { color: #c0d4d1; font-style: italic; }
@media (min-width: 1500px) {
  #app { grid-template-rows: 80px minmax(320px, 1fr) 270px; }
  .dock { padding-left: 32px; padding-right: 32px; }
}
@media (max-width: 900px) {
  #app { grid-template-rows: 68px minmax(270px, 1fr) 276px; }
  .topbar { padding: 8px 16px; gap: 10px; }
  .dock { grid-template-columns: minmax(0, 1.2fr) minmax(330px, 1fr); gap: 12px; padding: 12px 16px; }
  .slider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-card { height: 58px; }
  .metric-value { font-size: 17px; margin-top: 3px; }
  .metric-foot { margin-top: 4px; }
  .stage-topline { left: 16px; right: 16px; }
  .stage-caption { left: 16px; top: 56px; }
  .stage-legend { right: 16px; }
}
@media (max-width: 640px) {
  body { overflow: hidden; }
  #app { grid-template-rows: 66px minmax(260px, 39vh) minmax(0, 1fr); }
  .topbar { padding: 7px 12px; gap: 8px; }
  .eyebrow { font-size: 7px; margin-bottom: 2px; }
  h1 { font-size: 15px; }
  .subtitle { font-size: 9px; }
  .toolbar { gap: 4px; }
  .tool-btn { width: 30px; height: 30px; padding: 0; border-radius: 7px; font-size: 13px; }
  .tool-btn .btn-label { display: none; }
  .quality-btn { width: 38px; min-width: 38px; font-size: 8px; }
  .stage-topline { top: 10px; left: 12px; right: 12px; }
  .stage-chip, .status-badge { padding: 6px 8px; font-size: 7px; gap: 6px; }
  .stage-caption { top: 48px; left: 12px; width: calc(100% - 24px); padding: 7px 9px; }
  .stage-caption p { font-size: 9px; line-height: 1.35; margin-top: 3px; max-width: 300px; }
  .caption-kicker { font-size: 7px; }
  .stage-legend { left: 12px; right: auto; bottom: 8px; gap: 9px; font-size: 7px; }
  .dock { display: block; overflow-y: auto; overscroll-behavior: contain; padding: 12px 12px 24px; }
  .control-column, .readout-column { overflow: visible; }
  .section-heading { height: auto; min-height: 32px; margin-bottom: 8px; }
  .slider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .slider-card { min-height: 72px; padding: 8px 8px 6px; }
  .slider-top label { font-size: 9px; }
  .slider-top output { font-size: 10px; }
  .slider-bottom { font-size: 7px; }
  .number-tag { font-size: 6px; }
  .presets { gap: 4px; }
  .preset-btn { height: 24px; padding: 0 7px; font-size: 8px; }
  .readout-column { margin-top: 16px; }
  .readout-heading { margin-bottom: 8px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .metric-card { height: 64px; padding: 8px 9px; }
  .metric-label { font-size: 7px; }
  .metric-value { font-size: 18px; margin-top: 5px; }
  .metric-foot { margin-top: 5px; font-size: 7px; }
  .check-row { margin-top: 8px; }
  .science-panel { margin-top: 10px; }
  .science-content { max-height: none; padding-bottom: 12px; }
  .elapsed-label { font-size: 7px; }
}
@media (max-width: 370px) {
  .heading { max-width: 165px; }
  h1 { font-size: 14px; }
  .stage-chip { gap: 4px; font-size: 6px; }
  .status-badge { font-size: 6px; }
  .slider-grid { grid-template-columns: 1fr; }
  .slider-card { min-height: 66px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
/* Keep the field key clear of the live envelope trace. */
.stage-legend { top: 56px; bottom: auto; }
@media (max-width: 640px) { .stage-legend { display: none; } }
