/* chair-sim.css - interactive wheelchair model widget.
   Themes from the site tokens (--bg --surface --text --muted --line --accent); fallbacks below. */
.chair-sim {
  --cs-bg: var(--bg, #FAFAF7);
  --cs-surface: var(--surface, #FFFFFF);
  --cs-text: var(--text, #15171C);
  --cs-muted: var(--muted, #5A616E);
  --cs-line: var(--line, #E3E3DC);
  --cs-accent: var(--accent, #2774AE);
  --cs-mono: var(--mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  --cs-radius: var(--radius, 12px);
  container-type: inline-size;
  box-sizing: border-box;
  margin: 0;
  padding: 14px;
  color: var(--cs-text);
  background: var(--cs-surface);
  border: 1px solid var(--cs-line);
  border-radius: calc(var(--cs-radius) + 6px);
  font-size: 15px;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chair-sim {
    --cs-bg: var(--bg, #0D0F12); --cs-surface: var(--surface, #15191E); --cs-text: var(--text, #E7E9EC);
    --cs-muted: var(--muted, #9BA3AE); --cs-line: var(--line, #272D35); --cs-accent: var(--accent, #6CB4EE);
  }
}
:root[data-theme="dark"] .chair-sim {
  --cs-bg: var(--bg, #0D0F12); --cs-surface: var(--surface, #15191E); --cs-text: var(--text, #E7E9EC);
  --cs-muted: var(--muted, #9BA3AE); --cs-line: var(--line, #272D35); --cs-accent: var(--accent, #6CB4EE);
}
.chair-sim *, .chair-sim *::before, .chair-sim *::after { box-sizing: border-box; }

.cs-main { display: grid; grid-template-columns: minmax(0, 1fr) 188px; gap: 14px; align-items: stretch; }

/* top-down view */
.cs-stage {
  position: relative; min-width: 0; height: 360px;
  border-radius: var(--cs-radius); overflow: hidden;
  background-color: var(--cs-bg); border: 1px solid var(--cs-line);
  /* static 1 m-ish grid shown until the script draws the canvas over it */
  background-image: linear-gradient(var(--cs-line) 1px, transparent 1px), linear-gradient(90deg, var(--cs-line) 1px, transparent 1px);
  background-size: 96px 96px; background-position: center;
  outline: none; cursor: crosshair;
}
.cs-stage:focus-visible { box-shadow: 0 0 0 3px var(--cs-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cs-accent) 45%, transparent); }
.cs-view { display: block; width: 100%; height: 100%; }
.cs-badge {
  position: absolute; top: 10px; left: 10px;
  font: 500 11px/1 var(--cs-mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 5px 7px; border-radius: 6px; background: rgba(0, 0, 0, .72); color: #fff;
}
.cs-hud {
  position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; pointer-events: none;
}
.cs-read {
  display: flex; flex-direction: column; align-items: flex-end; min-width: 84px;
  padding: 7px 10px 6px; border-radius: 10px;
  background: var(--cs-surface);
  background: color-mix(in srgb, var(--cs-surface) 82%, transparent);
  border: 1px solid var(--cs-line);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.cs-num {
  font: 600 24px/1.05 var(--cs-mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
.cs-unit { font: 500 10.5px/1.3 var(--cs-mono); color: var(--cs-muted); letter-spacing: .03em; }
.cs-status {
  position: absolute; left: 10px; bottom: 10px;
  font: 500 11.5px/1 var(--cs-mono); white-space: nowrap; pointer-events: none;
  padding: 6px 10px; border-radius: 999px; color: var(--cs-muted);
  background: var(--cs-surface);
  background: color-mix(in srgb, var(--cs-surface) 82%, transparent); border: 1px solid var(--cs-line);
}
.chair-sim.is-scripted .cs-status { color: var(--cs-accent); }

/* controls */
.cs-controls { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-width: 0; }
.cs-joy {
  position: relative; width: 164px; height: 164px; flex: none; border-radius: 50%;
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
  background:
    linear-gradient(var(--cs-line), var(--cs-line)) center / 1px 72% no-repeat,
    linear-gradient(90deg, var(--cs-line), var(--cs-line)) center / 72% 1px no-repeat,
    radial-gradient(circle at 50% 50%, var(--cs-surface) 0 34%, var(--cs-bg) 35% 100%);
  border: 1px solid var(--cs-line);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, .06);
}
.cs-joy.is-active { cursor: grabbing; }
.cs-joy::after {
  content: ""; position: absolute; inset: 22%; border-radius: 50%;
  border: 1px dashed var(--cs-line); pointer-events: none;
}
.cs-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: var(--cs-accent); pointer-events: none; z-index: 1;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--cs-accent) 40%, transparent), inset 0 -3px 0 rgba(0, 0, 0, .15);
  will-change: transform;
}
.cs-knob::after {
  content: ""; position: absolute; inset: 30%; border-radius: 50%;
  background: color-mix(in srgb, #fff 35%, transparent);
}
.cs-joy-labels { position: absolute; inset: 0; pointer-events: none; font: 500 10px/1 var(--cs-mono); color: var(--cs-muted); }
.cs-joy-labels span { position: absolute; }
.cs-joy-labels .f { top: 8px; left: 50%; transform: translateX(-50%); }
.cs-joy-labels .b { bottom: 8px; left: 50%; transform: translateX(-50%); }
.cs-joy-labels .l { left: 9px; top: 50%; transform: translateY(-50%); }
.cs-joy-labels .r { right: 9px; top: 50%; transform: translateY(-50%); }
.cs-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.cs-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; font-size: 13px; font-weight: 500; line-height: 1; padding: 9px 12px; border-radius: 999px; cursor: pointer;
  color: var(--cs-text); background: var(--cs-surface); border: 1px solid var(--cs-line);
  transition: border-color .15s, background-color .15s;
}
.cs-btn:hover { border-color: var(--cs-accent); }
.cs-btn:focus-visible { outline: 2px solid var(--cs-accent); outline-offset: 2px; }
.cs-btn--primary { background: var(--cs-accent); border-color: var(--cs-accent); color: var(--cs-surface); }
.cs-btn--primary:hover { background: color-mix(in srgb, var(--cs-accent) 88%, var(--cs-text)); }
.cs-btn svg { width: 12px; height: 12px; fill: currentColor; flex: none; }

/* model vs measured */
.cs-chart-wrap { margin-top: 14px; }
.cs-chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 4px; }
.cs-chart-title { font-weight: 600; font-size: 14px; }
.cs-legend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font: 500 11.5px/1.3 var(--cs-mono); color: var(--cs-muted); }
.cs-legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.cs-sw { display: inline-block; width: 16px; height: 0; border-top: 2px solid; }
.cs-sw--meas { border-color: var(--cs-text); opacity: .8; }
.cs-sw--model { border-color: var(--cs-accent); border-top-width: 3px; }
.cs-sw--cmd { height: 10px; border: 0; background: var(--cs-accent); opacity: .18; border-radius: 2px; }
.cs-chart-box { position: relative; }
.cs-chart { display: block; width: 100%; height: 132px; }
/* static copy of the chart (same replay data) until the script has drawn it; inset = the canvas plot area */
.cs-fallback-box { position: absolute; left: 22px; right: 6px; top: 6px; bottom: 18px; pointer-events: none; }
.chair-sim.is-ready .cs-fallback-box { display: none; }
.cs-fallback { display: block; width: 100%; height: 100%; overflow: visible; }
.cs-fallback * { vector-effect: non-scaling-stroke; fill: none; }
.cs-fallback .cs-fb-band { fill: var(--cs-accent); opacity: .09; }
.cs-fallback .cs-fb-grid { stroke: var(--cs-line); stroke-width: 1; }
.cs-fallback .cs-fb-meas { stroke: var(--cs-text); stroke-width: 1.6; opacity: .8; stroke-linejoin: round; }
.cs-fallback .cs-fb-model { stroke: var(--cs-accent); stroke-width: 2.4; stroke-linejoin: round; }
.cs-note { margin: 10px 0 0; font-size: 12px; line-height: 1.45; color: var(--cs-muted); }

/* narrow: controls go under the canvas */
@container (max-width: 600px) {
  .cs-main { grid-template-columns: minmax(0, 1fr); }
  .cs-stage { height: 300px; }
  .cs-controls { flex-direction: row; justify-content: center; gap: 16px; }
  .cs-joy { width: 148px; height: 148px; }
  .cs-buttons { flex-direction: column; align-items: stretch; }
  .cs-num { font-size: 20px; }
  .cs-read { min-width: 72px; padding: 6px 8px 5px; }
}
@container (max-width: 380px) {
  .cs-stage { height: 280px; }
  .cs-joy { width: 136px; height: 136px; }
}
@supports not (container-type: inline-size) {
  @media (max-width: 640px) {
    .cs-main { grid-template-columns: minmax(0, 1fr); }
    .cs-stage { height: 300px; }
    .cs-controls { flex-direction: row; }
    .cs-buttons { flex-direction: column; align-items: stretch; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .cs-btn { transition: none; }
}
