:root {
  --bg: #eceef1;
  --panel: #ffffff;
  --panel-2: #f4f6f8;
  --line: #e1e5ea;
  --line-2: #cdd3db;
  --ink: #171b21;
  --ink-dim: #4b5563;
  --ink-faint: #616a78; /* darkened from #7b8492 (3.78:1) to meet WCAG AA (>=4.5:1) on the light panels; carries the honesty caveats */
  --accent: #0d7ab0;      /* deep dove-blue (brand); AA on white as text and as a button fill */
  --accent-ink: #ffffff;
  --danger: #cf1d47;
  --ok: #0f8a4f;
  --stage: #dde1e6;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

/* App-style splash / loader shown while the pose model loads */
.splash {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  transition: opacity 0.45s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-inner { display: flex; flex-direction: column; align-items: center; text-align: center; }
.splash-logo {
  border-radius: 20px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.25);
  animation: splashPulse 1.7s ease-in-out infinite;
}
.splash-word { margin-top: 16px; font-weight: 700; font-size: 24px; letter-spacing: 0.01em; color: var(--ink); }
.splash-sub { margin-top: 3px; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-faint); }
.splash-spinner {
  width: 22px; height: 22px; margin-top: 22px;
  border: 3px solid var(--line-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.splash-status { margin-top: 10px; font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
@keyframes splashPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) {
  .splash-logo, .splash-spinner { animation: none; }
}

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand {
  display: flex; align-items: baseline; gap: 10px;
  background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit;
  cursor: pointer; text-align: left;
}
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }
.brand:hover .mark { color: var(--accent); }
.expand { font-size: 13px; font-weight: 500; color: var(--ink-dim); }
.mark { font-weight: 700; letter-spacing: 0.02em; font-size: 16px; }
.sub {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}
.model-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  padding: 4px 9px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  background: var(--panel-2);
}
.model-state .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); }
.model-state[data-state="loading"] .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.model-state[data-state="ready"] .dot { background: var(--ok); }
.model-state[data-state="running"] .dot { background: var(--accent); animation: pulse 0.7s ease-in-out infinite; }
.model-state[data-state="error"] .dot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* scope strip */
.scopebar {
  padding: 7px 16px;
  font-size: 12px;
  color: var(--ink-dim);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}

/* workspace: rail + stage */
/* three regions: rail | stage (hero) | kinematics panel. The kin column is 0
   until a video is processed; open = fixed width, collapsed = a thin strip. */
.workspace {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr) var(--kin-col, 0px);
  grid-template-areas: "rail stage kin";
  min-height: 0;
}
body[data-kin="open"] { --kin-col: 344px; }
body[data-kin="collapsed"] { --kin-col: 44px; }

/* control rail. min-height:0 lets this grid item shrink below its content so
   overflow-y actually engages and it scrolls (instead of spilling / letting the
   canvas paint over it). */
.rail {
  grid-area: rail;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 6px 0;
}
.group { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.group-head {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  margin-bottom: 12px;
}
details.advanced summary {
  cursor: pointer;
  list-style: none;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::before { content: "+"; font-family: var(--mono); color: var(--ink-faint); }
details.advanced[open] summary::before { content: "-"; }
details.advanced[open] summary { margin-bottom: 12px; }

/* mode buttons */
.modes { display: flex; gap: 6px; margin-bottom: 12px; }
.mode-btn {
  flex: 1;
  font: inherit;
  font-size: 12.5px;
  padding: 7px 4px;
  background: var(--panel-2);
  color: var(--ink-dim);
  border: 1px solid var(--line-2);
  border-radius: 2px;
  cursor: pointer;
}
.mode-btn.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.mode-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.mode-panel[hidden] { display: none; }

/* file picker */
.file { display: flex; align-items: center; gap: 10px; }
.file input[type="file"] { display: none; }
.file-btn {
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  background: var(--panel-2);
  cursor: pointer;
  white-space: nowrap;
}
.file-btn:hover { border-color: var(--accent); }
.sample-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.sample-btn:hover { text-decoration: none; }
.sample-btn:disabled { color: var(--ink-faint); cursor: default; text-decoration: none; }
.file-name {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* action buttons (camera) */
.cam-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.btn {
  font: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* fields */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
  margin-bottom: 7px;
}
.field-label output { color: var(--ink); font-weight: 600; }

/* segmented control */
.segmented { display: flex; border: 1px solid var(--line-2); border-radius: 2px; overflow: hidden; }
.segmented button {
  flex: 1;
  font: inherit;
  font-size: 12px;
  padding: 6px 0;
  background: var(--panel-2);
  color: var(--ink-dim);
  border: none;
  border-right: 1px solid var(--line-2);
  cursor: pointer;
}
.segmented button:last-child { border-right: none; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* stepper */
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: 2px; }
.stepper button { font: inherit; width: 30px; background: var(--panel-2); color: var(--ink); border: none; cursor: pointer; }
.stepper button:hover { color: var(--accent); }
.stepper output {
  min-width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  border-left: 1px solid var(--line-2);
  border-right: 1px solid var(--line-2);
}

/* range sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--line-2);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--panel);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--panel);
}

/* video replay controls */
.replay { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.replay-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.btn.rp { padding: 5px 12px; font-size: 12px; }
.replay-row .check.small { margin-left: auto; }
#rp-scrub { width: 100%; }
.timeline { accent-color: var(--accent); cursor: pointer; height: 18px; }
.replay-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 6px;
}
#rp-time { color: var(--ink); font-weight: 600; }
.rp-steps { margin-left: auto; display: flex; gap: 4px; }
/* frame-stepping is secondary - keep it but de-emphasize */
.btn.step {
  padding: 3px 7px;
  font-size: 11px;
  color: var(--ink-dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.btn.step:hover { color: var(--ink); border-color: var(--line-2); }

/* overlay export (video / gif) */
.replay-export { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.replay-export .field-label { margin-bottom: 7px; }
.replay-export-btns { display: flex; gap: 8px; }
.replay-export-btns .btn { flex: 1; }
.btn.small { padding: 6px 10px; font-size: 12px; }
#export-note { margin-top: 7px; }

/* disabled controls while a video is processing */
.segmented button:disabled, .stepper button:disabled,
input[type="range"]:disabled { opacity: 0.45; cursor: not-allowed; }

/* selectors + inline rows */
.row-inline { display: flex; align-items: center; gap: 8px; }
.select {
  font: inherit; font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  background: var(--panel-2);
  color: var(--ink);
}
.cam-select { width: 100%; margin-bottom: 10px; padding: 7px 8px; }

/* kinematics */
/* kinematics right-side panel */
.kinpanel {
  grid-area: kin;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}
.kinpanel[hidden] { display: none; }
.kinpanel-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.kinpanel-title {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-faint);
}
.kinpanel-toggle {
  font: inherit; font-size: 11px; padding: 4px 9px;
  border: 1px solid var(--line-2); border-radius: 2px;
  background: var(--panel-2); color: var(--ink); cursor: pointer;
}
.kinpanel-toggle:hover { border-color: var(--accent); }
/* the body scrolls independently; min-height:0 so overflow engages */
.kinpanel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 14px; }

/* collapsed: thin vertical strip with just the toggle */
body[data-kin="collapsed"] .kinpanel-body { display: none; }
body[data-kin="collapsed"] .kinpanel-title { display: none; }
body[data-kin="collapsed"] .kinpanel-head { flex-direction: column; padding: 12px 4px; }
body[data-kin="collapsed"] .kinpanel-toggle { writing-mode: vertical-rl; }

/* small-multiples plot list */
.kin-plots-list { display: flex; flex-direction: column; gap: 10px; }
.kin-plot-item { }
.kin-plot-name { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); margin-bottom: 3px; }
.kin-plot-name .kin-sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; vertical-align: middle; }
.kin-plot-scroll { overflow-x: auto; overflow-y: hidden; }
.kin-plot-item canvas { display: block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 2px; }
.kin-zoom-lbl { display: inline-flex; margin-left: 8px; font-weight: 400; }

.kin-joints { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }
.kin-metrics { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); margin: 8px 0; }
.kin-metrics .kin-row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.kin-metrics .kin-sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; vertical-align: middle; }
.kin-asym-val { font-family: var(--mono); font-weight: 600; color: var(--ink); }

/* joint angles: name | range bar (with current-position dot) | current | range */
.kin-angles { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.kin-arow { display: grid; grid-template-columns: 56px 1fr 40px 58px; align-items: center; gap: 8px; font-size: 12px; }
.kin-aname { color: var(--ink-dim); }
.kin-abar { position: relative; height: 4px; background: var(--line-2); border-radius: 2px; }
.kin-abar[data-empty] { opacity: 0.4; }
.kin-abar i { position: absolute; top: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); transform: translateX(-50%); }
.kin-abar[data-empty] i { display: none; }
.kin-aval { font-family: var(--mono); text-align: right; color: var(--ink); }
.kin-arange { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); text-align: right; }

/* settings action buttons */
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }

/* checkbox */
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; margin: 6px 0; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.check.small { font-size: 12px; color: var(--ink-dim); margin: 4px 0; }
.check.master { font-weight: 600; margin-bottom: 10px; }

/* radios */
.radios { display: flex; flex-direction: column; gap: 6px; }
.radio { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.radio input { accent-color: var(--accent); cursor: pointer; }

/* advanced subsections + filters */
.subhead {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin: 16px 0 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.filter-group { margin-bottom: 8px; }
.filter-mains {
  margin: 2px 0 0 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 10px;
}
#interactions.disabled { opacity: 0.45; pointer-events: none; }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 12px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
}
.legend-item i { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }

/* notes */
.note {
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-dim);
  margin: 10px 0 0;
  padding-left: 10px;
  border-left: 2px solid var(--line-2);
}
.note.dim { border-left-color: transparent; padding-left: 0; margin: 8px 0 0; color: var(--ink-faint); }
.note.warn { color: var(--accent); border-left-color: var(--accent); }

/* stage / canvas hero */
.stage {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(0,0,0,0.03) 23px, rgba(0,0,0,0.03) 24px),
    repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(0,0,0,0.03) 23px, rgba(0,0,0,0.03) 24px),
    var(--stage);
  padding: 20px;
  overflow: hidden;
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  touch-action: none;
}
video { display: none; }

/* floating stage controls */
.stage-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  cursor: pointer;
}
.stage-btn:hover { border-color: var(--accent); }
/* retry-after-model-failure button, centered on the stage */
.stage-retry {
  position: absolute; left: 50%; top: 58%;
  transform: translate(-50%, -50%); z-index: 6;
}

/* visible keyboard focus for all interactive controls */
button:focus-visible,
[role="radio"]:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
.mode-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
.file input:focus-visible + .file-btn { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Save PNG sits top-right; nudge Reset view left of it so they never overlap
   (both can be visible at once in zoomed image/video views). */
.stage-btn-tr { top: 12px; right: 12px; }
#resetview { right: 92px; }
.stage-btn-tl { top: 12px; left: 12px; right: auto; }

/* expanded ("big view"): the stage fills the whole viewport. CSS-based so it
   works everywhere, including iOS Safari (which blocks the Fullscreen API on
   non-video elements). */
body.stage-expanded { overflow: hidden; }
body.stage-expanded .stage {
  position: fixed; inset: 0; z-index: 1000;
  min-height: 0; padding: 12px;
}

/* drag & drop affordance */
.stage.dragover {
  outline: 2px dashed var(--accent);
  outline-offset: -10px;
}
.stage.dragover::after {
  content: "Drop image or video";
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(18,184,134,0.06);
  pointer-events: none;
}

.tooltip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  max-width: 240px;
  padding: 6px 9px;
  border-radius: 4px;
  background: rgba(20,23,28,0.92);
  color: #f2f4f7;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.tooltip .cav { color: #aab2bd; }
.placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  pointer-events: none;
}
.stage.has-image .placeholder { display: none; }
/* loading spinner: shown while busy with nothing yet rendered */
.stage.busy:not(.has-image) .placeholder { flex-direction: column; }
.stage.busy:not(.has-image) .placeholder::before {
  content: "";
  display: block;
  width: 26px; height: 26px;
  margin: 0 auto 12px;
  border: 3px solid var(--line-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .stage.busy:not(.has-image) .placeholder::before { animation: none; border-top-color: var(--line-2); }
}
.stage:not(.has-image) #output { display: none; }

/* status bar */
.statusbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
}
.status-item { color: var(--ink); }
.status-item.ro { color: var(--ink-faint); }
.status-item.grow { flex: 1; color: var(--accent); }
#status.error { color: var(--danger); }
#status.ready { color: var(--ok); }
.status-item.links { display: inline-flex; gap: 6px; align-items: center; }
.linkbtn {
  font: inherit; font-size: 11px; letter-spacing: 0.03em;
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--ink-faint); text-decoration: none;
}
.linkbtn:hover { color: var(--accent); text-decoration: underline; }

/* Privacy / Terms modal */
.legal-dialog {
  width: min(640px, 92vw);
  max-height: 82vh;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.legal-dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.legal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel);
}
.legal-title { margin: 0; font-size: 16px; font-weight: 700; }
.legal-close {
  font: inherit; font-size: 18px; line-height: 1;
  background: none; border: 0; cursor: pointer; color: var(--ink-dim);
  padding: 4px 6px; border-radius: 4px;
}
.legal-close:hover { color: var(--ink); background: var(--panel-2); }
.legal-body { padding: 8px 20px 22px; overflow-y: auto; max-height: calc(82vh - 56px); font-size: 13.5px; line-height: 1.55; }
.legal-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); margin: 20px 0 6px; }
.legal-body p { margin: 8px 0; color: var(--ink-dim); }
.legal-body ul { margin: 8px 0; padding-left: 20px; color: var(--ink-dim); }
.legal-body li { margin: 4px 0; }
.legal-body strong { color: var(--ink); }
.legal-body code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); padding: 1px 5px; border-radius: 3px; }
.legal-body a { color: var(--accent); }
.legal-updated { font-family: var(--mono); font-size: 11px; color: var(--ink-faint) !important; }
.legal-foot { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--line); }

/* medium: kinematics panel stacks BELOW the canvas (never squeezes it) */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 296px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "rail stage" "kin kin";
  }
  .kinpanel {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 42vh;
  }
  body[data-kin="collapsed"] .kinpanel { max-height: none; }
  body[data-kin="collapsed"] .kinpanel-head { flex-direction: row; padding: 10px 14px; }
  body[data-kin="collapsed"] .kinpanel-title { display: inline; }
  body[data-kin="collapsed"] .kinpanel-toggle { writing-mode: horizontal-tb; }
}

/* narrow: everything stacks. Stage (the result) goes FIRST so it is visible
   without scrolling past the whole control rail; the Input controls are the
   first rail section, so they sit right below the stage. */
@media (max-width: 720px) {
  .app { height: auto; min-height: 100vh; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas: "stage" "rail" "kin";
  }
  .rail { border-right: none; border-top: 1px solid var(--line); }
  .stage { min-height: 62vh; }
  /* keep the processed frame in view while its kinematics render below it */
  .kinpanel { border-top: 1px solid var(--line); }
}

/* (i) info affordance + tap/hover popover (rendered fixed, above the rail scroll) */
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; padding: 0; margin-left: 5px;
  border: 1px solid var(--line-2); border-radius: 50%;
  background: var(--panel-2); color: var(--ink-dim);
  font-family: var(--mono); font-style: italic; font-weight: 700; font-size: 10px;
  line-height: 1; cursor: pointer; vertical-align: middle; flex: none;
}
.info:hover { border-color: var(--accent); color: var(--accent); }
.info:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.info[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.infopop {
  position: fixed; z-index: 1000; max-width: 300px;
  padding: 9px 11px; border-radius: 6px;
  background: #14181d; color: #fff;               /* fixed dark surface (theme-independent) so it stays legible in dark mode too */
  font-size: 12px; line-height: 1.45;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

/* always-visible honesty summary: use the darker --ink-dim (7.5:1), never grey out */
.note.kin-caveat { color: var(--ink-dim); }

/* ---- Dark theme (follows the OS setting) ------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161b22;
    --panel-2: #1c2129;
    --line: #262c35;
    --line-2: #39414c;
    --ink: #e6e9ee;
    --ink-dim: #b4bcc8;      /* ~9:1 on the panels */
    --ink-faint: #8a94a2;    /* ~5.3:1 on the panels, still AA */
    --danger: #ef5a79;
    --ok: #35c07a;
    --stage: #0b0e12;
    --accent: #1391cc;      /* brighter dove-blue for legibility on the dark panels */
  }
  /* stage grid: faint light hairlines instead of dark-on-dark */
  .stage {
    background:
      repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(255,255,255,0.04) 23px, rgba(255,255,255,0.04) 24px),
      repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(255,255,255,0.04) 23px, rgba(255,255,255,0.04) 24px),
      var(--stage);
  }
  /* floating stage buttons were white-on-dark-text; flip to a dark surface */
  .stage-btn { background: rgba(28,33,41,0.92); color: var(--ink); border-color: var(--line-2); }
  /* themed native checkboxes / sliders */
  input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }
}
