:root {
  --bg: #080a10;
  --panel: #11151f;
  --panel2: #161b28;
  --line: #232a3a;
  --ink: #e8ecf6;
  --muted: #8a93a8;
  --pos: #ff8a3d;
  --neg: #4c9dff;
  --accent: #ffb35c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 22px 60px;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.sub a { color: inherit; text-decoration: none; border-bottom: 1px solid currentColor; }
.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.tools { display: flex; gap: 8px; }

.lang {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 13px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.lang:hover { border-color: var(--accent); }

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 12px;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 14px 9px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button:disabled { opacity: 0.45; cursor: default; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.stage {
  position: relative;
  background: #0b0e14;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  min-height: 420px;
  aspect-ratio: 4 / 3;
}

.canvasHost, .canvasHost canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* a finger on the canvas must orbit the figure, not zoom the page */
.canvasHost canvas {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(0, 0, 0, 0.35) 100%);
}

.badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(10, 13, 20, 0.72);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  z-index: 2;
}

.readout {
  position: absolute;
  top: 12px;
  /* the camera button sits in the same corner */
  right: 58px;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(10, 13, 20, 0.72);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  z-index: 2;
}
.readout:empty { display: none; }

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  z-index: 2;
}
.legend .bar {
  width: 130px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #2e8cff, #0d1119 50%, #ff9433);
  border: 1px solid var(--line);
}

/* caption burned into the picture */
.caption {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(10, 13, 20, 0.66);
  border: 1px solid var(--line);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  text-align: right;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  z-index: 2;
}
.caption b { color: var(--ink); font-weight: 600; }
.caption:empty { display: none; }

/* local extrema markers */
.peaks { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.peak { position: absolute; width: 0; height: 0; pointer-events: none; }
.peak .dot {
  position: absolute;
  left: -5.5px;
  top: -5.5px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 179, 92, 0.95);
  background: rgba(255, 179, 92, 0.18);
  transition: transform 0.12s ease, background 0.12s ease;
}
.peak.neg .dot { border-color: rgba(76, 157, 255, 0.95); background: rgba(76, 157, 255, 0.18); }
.peak.neg span { border-color: rgba(76, 157, 255, 0.85); }
.peak:hover .dot { transform: scale(1.45); background: rgba(255, 179, 92, 0.75); }
.peak.neg:hover .dot { background: rgba(76, 157, 255, 0.75); }
.peak span {
  position: absolute;
  left: 9px;
  top: -10px;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(8, 10, 16, 0.9);
  border: 1px solid rgba(255, 179, 92, 0.85);
  color: var(--ink);
  font-size: 11px;
  white-space: nowrap;
}

/* height readout that follows the cursor in 3D */
.slice {
  position: absolute;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(8, 10, 16, 0.86);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
  display: none;
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #14100a;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

/* version toast */
.reload {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #14100a;
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  z-index: 50;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 14px;
}

.group h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.seg {
  display: flex;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 8px;
}
.seg button {
  flex: 1;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 6px 4px;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
}
.seg button.on {
  background: var(--accent);
  color: #14100a;
  font-weight: 600;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-size: 13px;
  color: var(--muted);
}
.row > span { flex: 0 0 74px; }
.row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.row output { flex: 0 0 48px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.row input[type=number] {
  flex: 0 0 64px;
  background: var(--panel2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px 6px;
  font: inherit;
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.row input[type=number]:focus { outline: 1px solid var(--accent); }
.row select {
  flex: 1;
  background: var(--panel2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
}
.row.check { gap: 8px; }
.row.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.row.check span { flex: 1; color: var(--muted); }

.timeRow { gap: 10px; }
.timeRow input { flex: 1; }

button.icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}
button.icon.on { background: var(--accent); color: #14100a; border-color: var(--accent); }

.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.buttons + .buttons { margin-top: 8px; }
.buttons button {
  flex: 1;
  min-width: 70px;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.buttons button:hover { border-color: var(--accent); }
.buttons button.primary { background: var(--accent); color: #14100a; border-color: var(--accent); font-weight: 600; }
.recRow { display: flex; gap: 8px; }
.recDock {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.recIcon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.recIcon:hover { border-color: var(--accent); }
.recIcon.on { background: #d63b3b; border-color: #d63b3b; color: #fff; }
.recPanel {
  width: 218px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
  text-align: left;
}
.recPanel button {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.recPanel button:hover { border-color: var(--accent); }
.recPanel .recStart {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #14100a;
  font-weight: 600;
}
.recLive { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.recLive button { flex: 0 0 auto; }
.recDot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e14b4b;
  animation: recPulse 1s infinite;
}
@keyframes recPulse { 50% { opacity: 0.25; } }
.recDone { font-size: 12px; color: var(--muted); }
.recActions { display: flex; gap: 6px; }
.recActions button { flex: 1; }

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 13px;
}
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.stats.mono dd { font-family: "Cascadia Mono", "Consolas", monospace; font-size: 12px; }

#fockChart { width: 100%; height: 64px; display: block; margin-top: 10px; }

.hint {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.advanced { margin: 8px 0 2px; font-size: 12px; }
.advanced summary { cursor: pointer; color: var(--muted); }
.advanced p { margin: 6px 0 0; }

.about {
  margin-top: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 22px;
}
.about h2 { margin: 0 0 8px; font-size: 17px; }
.about p { color: var(--muted); font-size: 14px; max-width: 900px; }
.about a { color: var(--accent); }

table.parity {
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
table.parity th, table.parity td {
  text-align: left;
  padding: 7px 16px 7px 0;
  border-bottom: 1px solid var(--line);
}
table.parity th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.parity td.ok { color: #6fdc8c; }

.note { font-size: 12.5px; color: var(--muted); max-width: 900px; }
.muted { color: var(--muted); }
.rev { opacity: 0.75; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- light theme */
body.light {
  --bg: #eef2f8;
  --panel: #ffffff;
  --panel2: #f3f6fb;
  --line: #d3dbe8;
  --ink: #101722;
  --muted: #5a6578;
  --pos: #d9741c;
  --neg: #2f74d0;
  --accent: #c46a14;
}
body.light .stage { background: #dce4f0; }
body.light .stage::after {
  background: radial-gradient(ellipse at 50% 45%, transparent 50%, rgba(255, 255, 255, 0.5) 100%);
}
body.light .badge,
body.light .readout,
body.light .caption,
body.light .peak span,
body.light .slice { background: rgba(255, 255, 255, 0.86); }
body.light .legend .bar { background: linear-gradient(90deg, #1a5cc4, #f7f9fc 50%, #dd6a12); }
body.light .peak .dot { border-color: rgba(196, 106, 20, 0.95); background: rgba(196, 106, 20, 0.12); }
body.light .peak.neg .dot { border-color: rgba(47, 116, 208, 0.95); background: rgba(47, 116, 208, 0.12); }
body.light .seg button.on,
body.light .buttons button.primary,
body.light .toast,
body.light .reload { color: #fff; }

@media (max-width: 900px) {
  .wrap { padding: 14px 12px 40px; }
  main { grid-template-columns: 1fr; }
  .stage { aspect-ratio: 1 / 1; }
  h1 { font-size: 21px; }
  .panel { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .group { padding: 10px 12px 12px; }
}
@media (max-width: 560px) {
  .panel { grid-template-columns: 1fr; }
  .stage { aspect-ratio: 4 / 5; }
  /* the caption would sit on top of the legend on a narrow screen */
  .caption { bottom: 44px; font-size: 10.5px; padding: 6px 8px; }
}

.formats {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 10.5px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
}
