/* App shell layout. The design's canonical column is 390px; on desktop we
   centre it and let it grow to ~520px (handoff §Responsive). Everything else
   comes from the Industry styles.css tokens. */

html, body { height: 100%; }

/* launch splash — a big FORMÉ cover: the runner fills the screen with the wordmark above.
   Tap anywhere to enter (web/splash.js fades it out). #splash-stripes overlays #splash-hero
   pixel-aligned and pulses for an electric effect. */
#splash { position: fixed; inset: 0; z-index: 100; }
#splash.hide { opacity: 0; pointer-events: none; transition: opacity 0.5s ease; }
#splash-cover {
  position: absolute; inset: 0; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 34%, #17262b 0%, #0b0b0d 66%), #0b0b0d;
}
/* Runner big + fully visible (head included). Same box for the stripe overlay so they align. */
#splash-hero, #splash-stripes {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; object-position: center 52%; pointer-events: none;
}
#splash-hero { filter: drop-shadow(0 0 48px rgba(12, 192, 223, 0.16)); }
#splash-stripes { mix-blend-mode: screen; animation: splash-electric 1.9s ease-in-out infinite; }
@keyframes splash-electric {
  0%, 100% { opacity: 0.55; filter: brightness(0.9); }
  35%      { opacity: 1;    filter: brightness(1.55); }
  55%      { opacity: 0.7;  filter: brightness(1.1); }
  72%      { opacity: 1;    filter: brightness(1.35); }
}
@media (prefers-reduced-motion: reduce) { #splash-stripes { animation: none; opacity: 0.9; } }
#splash-brand { position: absolute; left: 0; right: 0; top: 9%; text-align: center; }
.splash-title {
  font-family: var(--font-heading); font-weight: var(--font-heading-weight);
  font-size: calc(74px * var(--font-scale)); letter-spacing: 0.04em; line-height: 1;
  color: #f4f5f7;   /* white wordmark (no brand gradient on the splash) */
}
.splash-sub {
  font-size: calc(16px * var(--font-scale)); color: var(--color-neutral-600);
  margin-top: 8px; letter-spacing: 0.06em;
}
.splash-tap {
  margin-top: 26px; font-size: calc(12px * var(--font-scale));
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--color-neutral-500);
  animation: splash-tap-pulse 1.6s ease-in-out infinite; transition: opacity 0.3s ease;
}
.splash-tap.gone { opacity: 0; animation: none; }
@keyframes splash-tap-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.95; } }
/* Brand gradient text (deck signature yellow→green→cyan) — wordmark + brand headings. */
.brand-gradient-text {
  background: var(--brand-gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  overflow: hidden;
}

.frame {
  width: 100%;
  max-width: 520px;
  min-width: 320px;
  height: 100vh;
  height: 100dvh; /* mobile: track the *visible* viewport so the tab bar + lower
                     playback controls (speed etc.) aren't clipped under the URL bar */
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--color-divider);
  border-right: 1px solid var(--color-divider);
  background: var(--color-bg);
}

/* 11px status strip — clock left, brand mark centred, battery right.
   The 3-column grid keeps the logo optically centred regardless of the
   side text widths. Shared chrome, so the mark shows on every screen. */
.status-strip {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 20px 4px;
  font-size: calc(11px * var(--font-scale));
  letter-spacing: 0.06em;
  color: var(--color-neutral-600);
}
.status-strip #status-right { text-align: right; }
/* small app mark, top-centre of every page. logo-forme.png (the FORMÉ runner-circle) is
   already a disc with transparent corners, so no clipping/border-radius is needed. */
.brand-mark {
  width: calc(22px * var(--font-scale));
  height: calc(22px * var(--font-scale));
  display: block;
  margin: 0 auto;
}

/* the current screen fills the space between strip and tab bar */
#screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.screen-header {
  flex: none;
  padding: 8px 20px 12px;
  border-bottom: 1px solid var(--color-divider);
}
.screen-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

/* bottom tab bar */
.tabbar {
  flex: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border-top: 1px solid var(--color-divider);
}
.tabbar button {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 11px 0;
  font-family: var(--font-body);
  font-size: calc(10px * var(--font-scale));
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-neutral-600);
  cursor: pointer;
}
.tabbar button.active {
  color: var(--color-text);
  background: var(--color-accent-200); /* clearer selected tint (matches the sub-menu) */
  border-bottom-color: var(--color-accent);
}
.tabbar button:hover { color: var(--color-accent); }

/* contextual sub-menu row (tier 2), sits just above the group bar. Collapsed to
   0 height and slides open (max-height transition) when a group with children is active. */
.subnav {
  flex: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  max-height: 0;
  overflow: hidden;
  background: var(--color-neutral-100);
  transition: max-height 0.22s ease;
}
.subnav.open {
  max-height: 64px;
  border-top: 1px solid var(--color-divider);
}
.subnav button {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 11px 0; /* match the group bar's button height */
  font-family: var(--font-body);
  font-size: calc(10px * var(--font-scale));
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-neutral-600);
  cursor: pointer;
  transition: background 0.15s ease;
}
.subnav button.active {
  color: var(--color-text);
  background: var(--color-accent-200); /* selected tint (clearer) */
  border-bottom-color: var(--color-accent);
}
.subnav button:hover { color: var(--color-accent); }
/* Level-3 leaf row: a hair smaller + a subtle accent-tinted surface so the three tiers
   read distinctly when stacked (leaf row on top, then sub-menu, then the group bar). */
/* Level-3 leaf row: now a TOP strip (under the header), so it borders BELOW itself. */
.subnav2 { background: color-mix(in srgb, var(--color-accent) 8%, var(--color-neutral-100)); }
.subnav2 button { font-size: calc(9.5px * var(--font-scale)); padding: 9px 0; }
.subnav2.open { max-height: 56px; border-top: 0; border-bottom: 1px solid var(--color-divider); }

/* meta labels reused across screens */
.kicker {
  font-size: calc(10px * var(--font-scale));
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-neutral-600);
}
.tabular { font-variant-numeric: tabular-nums; }

/* the accent-900 scope field */
.scope {
  position: relative;
  background: var(--color-accent-900);
}
.scope .corner { color: rgba(148, 188, 227, 0.65); }
.scope-meta {
  display: flex;
  justify-content: space-between;
  padding: 8px 11px;
  font-size: calc(10px * var(--font-scale));
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(214, 235, 255, 0.6);
}
.scope-meta.top { border-bottom: 1px solid rgba(214, 235, 255, 0.14); }
.scope-meta.bottom {
  border-top: 1px solid rgba(214, 235, 255, 0.14);
  letter-spacing: 0.08em;
}
.scope-plot {
  position: relative;
  /* Responsive so the playback control stack (transport + speed buttons + hr)
     stays in view on shorter / DPI-scaled windows instead of being pushed below
     the fold. Fullscreen overrides this to fill the space (see body.fs rules). */
  height: clamp(96px, 17vh, 150px);
  /* The graticule is drawn on the canvas by drawEcgGrid() at the current clinical
     scale (see scope.js). A second, fixed-pitch CSS background grid used to sit
     behind the transparent canvas and showed through every cleared frame — two
     mismatched grids overlaid. Canvas is now the sole grid, so major/minor toggles
     take full effect and live/replay no longer double up. */
}
.scope-plot canvas { display: block; width: 100%; height: 100%; }

/* scope controls: window length · sweep/scroll · trail */
.scope-ctrls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.sc-group { display: flex; border: 1px solid var(--color-divider); }
.sc-group button,
.sc-toggle {
  appearance: none;
  background: transparent;
  border: 0;
  font-family: var(--font-body);
  font-size: calc(11px * var(--font-scale));
  letter-spacing: 0.04em;
  padding: 6px 11px;
  cursor: pointer;
  color: var(--color-neutral-600);
}
.sc-group button + button { border-left: 1px solid var(--color-divider); }
.sc-toggle { border: 1px solid var(--color-divider); }
.sc-group button:hover,
.sc-toggle:hover { color: var(--color-accent); }
.sc-group button.on,
.sc-toggle.on {
  background: var(--color-accent);
  color: var(--color-bg);
}
.sc-toggle.disabled { opacity: 0.4; pointer-events: none; }

/* the 3-cell numbers row */
.numbers {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  border: 1px solid var(--color-divider);
}
.numbers > div { padding: 9px 12px; }
.numbers > div + div { border-left: 1px solid var(--color-divider); }
.stat-value { font-family: var(--font-heading); font-weight: var(--font-heading-weight); }

.bordered { border: 1px solid var(--color-divider); }
.rec-dot { width: 9px; height: 9px; background: var(--color-accent); display: block; }

/* tags card */
.tags-card { padding: 9px 11px; display: flex; flex-direction: column; gap: 7px; }
/* delete affordance on a chip — a generous tap target (the tiny glyph was hard
   to hit on touch). Padding + min size grow the hittable box; negative margins
   pull it back so the chip barely grows. data-remove stays on THIS element so
   the removal handlers (which read e.target) still fire. */
.tag-x {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; min-height: 22px; padding: 3px 5px;
  margin: -2px -5px -2px 1px; border-radius: var(--radius-md);
  color: var(--color-accent-600); cursor: pointer;
  font-size: calc(15px * var(--font-scale)); line-height: 1;
}
.tag-x:hover { color: var(--color-accent-800); background: color-mix(in srgb, var(--color-accent) 15%, transparent); }
.tag-x:active { background: color-mix(in srgb, var(--color-accent) 26%, transparent); }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag.tag-outline { cursor: pointer; }

/* Collapsible filter bar: one outer .filter-pane holding the Subject/Name/Tags/Timing
   .filter-section sub-panes. */
.filter-pane { border: 1px solid var(--color-divider); padding: 8px 10px; }
.filter-section { border: 1px solid var(--color-divider); padding: 7px 10px; }
.filter-section + .filter-section { border-top: 0; }
.filter-pane > summary,
.filter-section > summary {
  cursor: pointer; list-style: none;
  font-size: calc(11px * var(--font-scale)); letter-spacing: 0.04em;
  color: var(--color-accent-700);
}
.filter-pane > summary { font-size: calc(12px * var(--font-scale)); }
.filter-pane > summary::-webkit-details-marker,
.filter-section > summary::-webkit-details-marker { display: none; }
.filter-pane > summary::before,
.filter-section > summary::before { content: "▸ "; color: var(--color-neutral-600); }
.filter-pane[open] > summary::before,
.filter-section[open] > summary::before { content: "▾ "; }

/* Dual-handle range slider (two overlaid native range inputs). */
.dual { position: relative; height: 34px; }
.dual-track {
  position: absolute; left: 2px; right: 2px; top: 8px; height: 4px;
  border-radius: 2px; background: var(--color-neutral-300);
}
.dual-fill { position: absolute; top: 0; bottom: 0; background: var(--color-accent); border-radius: 2px; }
.dual input[type="range"] {
  position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 20px;
  margin: 0; background: none; -webkit-appearance: none; appearance: none;
  pointer-events: none;
}
.dual input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; pointer-events: auto;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--color-accent); border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-accent-700), var(--shadow-sm); cursor: grab;
}
.dual input[type="range"]::-moz-range-thumb {
  pointer-events: auto; width: 16px; height: 16px; border-radius: 50%;
  background: var(--color-accent); border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-accent-700); cursor: grab;
}
.dual input[type="range"]::-moz-range-track { background: none; }
.dual input[type="range"]:disabled::-webkit-slider-thumb { opacity: 0.4; cursor: default; }
.dual-labels {
  position: absolute; left: 0; right: 0; top: 19px; display: flex;
  justify-content: space-between; font-size: calc(11px * var(--font-scale));
  color: var(--color-neutral-600);
}

/* Analytics dashboard tab-strip (named boards): a scrollable row of tabs + add. */
.dash-tabbar { display: flex; align-items: center; gap: 6px; overflow-x: auto; }
.dash-tab {
  appearance: none; flex: none; cursor: pointer; white-space: nowrap;
  background: transparent; border: 1px solid var(--color-divider);
  color: var(--color-neutral-600); font-family: var(--font-body);
  font-size: calc(12px * var(--font-scale)); padding: 6px 12px;
}
.dash-tab.on { background: var(--color-accent); color: var(--color-bg); border-color: var(--color-accent); }
.dash-tab-add { flex: none; padding: 6px 11px; }

/* quality diagnostics line */
.quality {
  display: flex;
  justify-content: space-between;
  font-size: calc(11px * var(--font-scale));
  color: var(--color-neutral-600);
  font-variant-numeric: tabular-nums;
}
.quality b { font-weight: 400; color: var(--color-text); }
.quality .ok { color: var(--color-accent-700); }

/* full-screen recording view: scope + heart rate + session avg only */
body.fs .frame { max-width: none; border-left: 0; border-right: 0; }
body.fs .status-strip,
body.fs .tabbar,
body.fs .subnav,
body.fs [data-fs="hide"] { display: none !important; }
body.fs .screen-header { padding: 8px 20px 10px; }
body.fs .screen-header h2 { font-size: calc(20px * var(--font-scale)); }
body.fs .screen-body { gap: 14px; justify-content: flex-start; }
body.fs .scope { flex: 1; display: flex; flex-direction: column; }  /* scope fills the space */
body.fs .scope-plot { flex: 1; min-height: 40vh; height: auto; }
body.fs .numbers > div { padding: 14px 16px; }
body.fs #hr { font-size: calc(64px * var(--font-scale)) !important; }     /* beat the inline sizes */
body.fs #hr-avg, body.fs #hr-range { font-size: calc(40px * var(--font-scale)) !important; }
body.fs #fs-btn { background: var(--color-accent); color: var(--color-bg); border-color: var(--color-accent); }

/* warm-streaming toggle + live signal LEDs */
.warm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: calc(12px * var(--font-scale));
  cursor: pointer;
}
.warm-row input { accent-color: var(--color-accent); }
.signals {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-top: 8px;
  font-size: calc(11px * var(--font-scale));
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-neutral-600);
}
/* the three per-stream lights stack vertically on the RIGHT; the status sits left */
.sig-stack { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.signals .sig { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.signals .sig-top { display: flex; align-items: center; gap: 6px; }
.sig-timer { min-width: 44px; text-align: right; font-size: calc(10px * var(--font-scale)); letter-spacing: 0.02em; color: var(--color-neutral-600); font-variant-numeric: tabular-nums; }
.sig-timer.done { color: var(--color-accent-700); }
.signals .ready { flex: 1 1 auto; min-width: 0; text-wrap: pretty; }
/* while warming, the connect-time hint reads as a sentence, not a label */
.signals .ready.hint { text-transform: none; letter-spacing: normal; }
.led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-neutral-400);
  box-shadow: none;
}
.led.on {
  background: #37b24d; /* green */
  box-shadow: 0 0 6px rgba(55, 178, 77, 0.8);
}
.led.warn {
  background: #f59f00; /* amber — connecting / warming */
  box-shadow: 0 0 6px rgba(245, 159, 0, 0.7);
  animation: led-pulse 1s ease-in-out infinite;
}
@keyframes led-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Connect screen: unified device list rows (strap + feet), expand-on-tap */
.dev-row { border: 1px solid var(--color-divider); border-radius: 2px; background: var(--color-surface, transparent); overflow: hidden; }
.dev-row-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.dev-thumb { width: calc(38px * var(--font-scale)); height: calc(38px * var(--font-scale)); object-fit: contain; flex: 0 0 auto; }
.dev-row-main { flex: 1; min-width: 0; }
.dev-row-main .card-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-chev { color: var(--color-neutral-600); transition: transform 0.15s ease; flex: 0 0 auto; }
.dev-chev.open { transform: rotate(90deg); }
.dev-row-detail { padding: 4px 12px 12px; border-top: 1px solid var(--color-divider); }
.dev-row.unstored { opacity: 0.62; }

/* Connect screen: per-foot board row (name + status + connect button) */
.foot-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.foot-row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: 0 0 auto; }
.foot-status { display: inline-flex; align-items: center; gap: 6px; }
.btn.mini { padding: 4px 12px; font-size: calc(11px * var(--font-scale)); flex: 0 0 auto; }
/* Rename (✎) affordance next to a device name */
.rename-btn {
  background: none; border: none; cursor: pointer; padding: 0 2px; line-height: 1;
  color: var(--color-neutral-600); font-size: calc(12px * var(--font-scale));
}
.rename-btn:hover { color: var(--color-accent-700); }
/* Connect screen: debug sub-tab (per-device/stream packet stats) */
#connect-debug-view { flex-direction: column; gap: 12px; }
.dbg-card { padding: 10px 12px; }
.dbg-title { font-size: calc(13px * var(--font-scale)); font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.dbg-state { font-size: calc(10px * var(--font-scale)); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-accent-700); white-space: nowrap; }
.dbg-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 3px 10px; margin-top: 8px; align-items: baseline; }
.dbg-k { font-size: calc(10px * var(--font-scale)); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-neutral-600); white-space: nowrap; }
.dbg-v { font-size: calc(12px * var(--font-scale)); font-variant-numeric: tabular-nums; }
.dbg-svc { margin-top: 8px; font-size: calc(10px * var(--font-scale)); color: var(--color-neutral-600); word-break: break-all; }
.dbg-err { margin-top: 6px; font-size: calc(11px * var(--font-scale)); color: #e03131; }
.signals .ready { color: var(--color-accent-700); }

/* Cockpit: fuzzy-logic estimation tucked behind a tap-to-open symbol */
.fuzzy-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; padding: 2px 0; cursor: pointer;
  color: var(--color-text); text-align: left;
}
.fuzzy-toggle .fuzzy-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  width: calc(26px * var(--font-scale)); height: calc(26px * var(--font-scale));
  border: 1px solid var(--color-accent-700); border-radius: 50%;
  color: var(--color-accent-700); font-size: calc(15px * var(--font-scale)); line-height: 1;
  flex: 0 0 auto;
}
.fuzzy-toggle .fuzzy-label {
  flex: 1; font-size: calc(10px * var(--font-scale)); letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--color-neutral-600);
}
.fuzzy-toggle .fuzzy-chev { color: var(--color-neutral-600); transition: transform 0.15s ease; }
.fuzzy-toggle.open .fuzzy-chev { transform: rotate(90deg); }

/* Activity screen: fuzzy classification bars + the metrics behind the decision */
.act-probs { display: flex; flex-direction: column; gap: 7px; margin-top: 8px; }
.act-prob { display: grid; grid-template-columns: 78px 1fr 40px; align-items: center; gap: 8px; }
.act-prob .lbl { font-size: calc(10px * var(--font-scale)); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-neutral-600); white-space: nowrap; }
.act-prob .track { height: 9px; background: var(--color-divider); position: relative; overflow: hidden; }
.act-prob .fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--color-accent); transition: width 0.2s ease; }
.act-prob.win .lbl { color: var(--color-text); }
.act-prob.win .fill { background: var(--color-accent-700); }
.act-prob .pct { text-align: right; font-size: calc(10px * var(--font-scale)); font-variant-numeric: tabular-nums; color: var(--color-neutral-600); }
.act-metrics { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--color-divider); }
.act-metrics > div { padding: 8px 9px; }
.act-metrics > div + div { border-left: 1px solid var(--color-divider); }
.act-metrics .stat-value { font-size: calc(19px * var(--font-scale)); }

/* device screen bits */
.dev-lbl {
  font-size: calc(9px * var(--font-scale));
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-neutral-600);
}
.combo-chev {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: calc(9px * var(--font-scale));
  color: var(--color-neutral-600);
  pointer-events: none;
}
.nearby-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-top: 1px solid var(--color-divider);
  cursor: pointer;
}
.nearby-row:last-child { border-bottom: 1px solid var(--color-divider); }
.nearby-row.unusable { opacity: 0.45; cursor: default; }
.nearby-row:hover:not(.unusable) { background: color-mix(in srgb, var(--color-text) 4%, transparent); }
.nearby-row.selected { background: color-mix(in srgb, var(--color-accent) 12%, transparent); }
.nearby-row .sel-mark { color: var(--color-accent-700); font-size: calc(11px * var(--font-scale)); }

/* library rows */
.lib-row {
  border-top: 1px solid var(--color-divider);
  padding: 11px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lib-row:last-child { border-bottom: 1px solid var(--color-divider); }
.lib-row.selected { background: color-mix(in srgb, var(--color-accent) 12%, transparent); }
.lib-empty { padding: 24px 0; text-align: center; color: var(--color-neutral-600); font-size: calc(12px * var(--font-scale)); }
/* Library sort dropdown — themed native select. */
.lib-sort {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-body);
  font-size: calc(12px * var(--font-scale));
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-divider);
  border-radius: 0;
  padding: 5px 26px 5px 9px;
  cursor: pointer;
  /* caret drawn as an inline SVG so no external asset is needed */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.lib-sort:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
/* selection checkbox shown in multi-select mode */
.sel-box { width: 15px; height: 15px; flex: none; display: block; border: 1px solid var(--color-neutral-500); }
.sel-box.on {
  border-color: var(--color-accent);
  background: var(--color-accent);
  box-shadow: inset 0 0 0 3px var(--color-bg);
}
button.btn:disabled { opacity: 0.4; cursor: default; }
.lib-menu-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--color-divider);
  color: var(--color-neutral-600);
  font-size: calc(15px * var(--font-scale));
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
}
.lib-menu-btn:hover { border-color: var(--color-accent); color: var(--color-accent); }

/* right-click / ⋯ context menu */
.ctx-menu {
  position: fixed;
  z-index: 50;
  min-width: 168px;
  background: var(--color-bg);
  border: 1px solid var(--color-divider);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
}
.ctx-menu button {
  appearance: none;
  background: transparent;
  border: 0;
  text-align: left;
  font-family: var(--font-body);
  font-size: calc(13px * var(--font-scale));
  padding: 9px 14px;
  cursor: pointer;
  color: var(--color-text);
}
.ctx-menu button:hover { background: color-mix(in srgb, var(--color-accent) 12%, transparent); }
.ctx-menu button.danger { color: #c0392b; }
.ctx-menu .ctx-name {
  padding: 8px 14px 6px;
  font-size: calc(11px * var(--font-scale));
  color: var(--color-neutral-600);
  border-bottom: 1px solid var(--color-divider);
  cursor: default;
}

/* export / convert screen */
.fmt-row {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  width: 100%;
  padding: 11px 0;
  border-top: 1px solid var(--color-divider);
  cursor: pointer;
}
.fmt-row:last-child { border-bottom: 1px solid var(--color-divider); }
/* a format the current host can't produce (e.g. Parquet on Android) — greyed
   + inert, mirroring .inc-cell.disabled */
.fmt-row.disabled { color: var(--color-neutral-600); opacity: 0.4; pointer-events: none; }
.fmt-row .dot { margin-top: 2px; flex: none; }
.fmt-row .dot.on {
  border-color: var(--color-accent);
  background: var(--color-accent);
  box-shadow: inset 0 0 0 4px var(--color-bg);
}
.fmt-size { font-size: calc(11px * var(--font-scale)); font-variant-numeric: tabular-nums; color: var(--color-neutral-600); }
.inc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-size: calc(13px * var(--font-scale));
}
.inc-cell { display: flex; gap: 9px; align-items: center; cursor: pointer; }
.inc-cell.disabled { cursor: default; color: var(--color-neutral-600); }
.inc-box { width: 13px; height: 13px; flex: none; display: block; }
.inc-box.on { background: var(--color-accent); }
.inc-box.off { border: 1px solid var(--color-neutral-500); }

/* playback scrubber: a big, grabbable, draggable knob (touch + mouse) */
#pb-track { touch-action: none; }
.pb-knob {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-accent-700), var(--shadow-sm);
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  z-index: 2;
}
.pb-knob:active { cursor: grabbing; }
/* generous hit area so the knob is easy to grab on touch */
.pb-knob::before { content: ""; position: absolute; inset: -10px; }
/* Section range markers as book-ends: tall accent bars with an inner bracket lip,
   deliberately unlike the round playhead dot so the two never read as the same. */
.pb-bookend { width: 10px; height: 24px; border-radius: 3px; }
.pb-bookend::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--color-bg);
  opacity: 0.85;
}
.pb-bookend-a::after { left: 2px; }   /* lip on the span side (opens right) */
.pb-bookend-b::after { right: 2px; }  /* lip on the span side (opens left) */

/* heart rate at the playhead: big condensed number next to the strip controls */
.pb-hr-now { margin-left: auto; display: flex; align-items: baseline; gap: 5px; }
.pb-hr-now .stat-value { font-size: calc(27px * var(--font-scale)); line-height: 1; color: var(--color-accent-700); }

/* setup screen */
.seg-opt.sel { background: var(--color-accent); color: var(--color-bg); }
/* playback speed: taller, higher-contrast so it reads clearly below the transport row */
.seg.pb-speed { border-color: var(--color-accent-700); }
.seg.pb-speed .seg-opt { padding-block: 10px; font-size: calc(14px * var(--font-scale)); font-weight: 600; }
.seg.pb-speed .seg-opt.sel { font-weight: 700; }
.behav { border-bottom: 1px solid var(--color-divider); }
.behav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--color-divider);
}
.toggle {
  flex: none;
  width: 38px;
  height: 18px;
  border: 1px solid var(--color-neutral-500);
  display: flex;
  padding: 2px;
  cursor: pointer;
}
.toggle .knob { width: 14px; height: 12px; background: var(--color-neutral-400); display: block; }
.toggle.on { border-color: var(--color-accent); background: var(--color-accent); justify-content: flex-end; }
.toggle.on .knob { background: var(--color-bg); }
/* Greyed + inert switch/segment (e.g. the disabled RR-label controls). */
.toggle.disabled, .sc-group.disabled { opacity: 0.4; pointer-events: none; cursor: default; }
.kv { display: flex; justify-content: space-between; font-size: calc(11px * var(--font-scale)); color: var(--color-neutral-600); }
.kv .v { color: var(--color-text); }
.kv.clickable { cursor: pointer; }
.kv.clickable .v { color: var(--color-accent-700); }

/* collapsible setup sections — the summary is the tappable header, default
   collapsed; the ▸ chevron rotates when open. */
.setup-sec { border-bottom: 1px solid var(--color-divider); }
.setup-sec > .sec-head {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 2px;
}
.setup-sec > .sec-head::-webkit-details-marker { display: none; }
.setup-sec > .sec-head::after {
  content: "\203A"; margin-left: auto; line-height: 1;
  font-size: calc(16px * var(--font-scale)); color: var(--color-neutral-500);
  transition: transform 0.15s ease;
}
.setup-sec[open] > .sec-head::after { transform: rotate(90deg); }
.setup-sec > .sec-head:hover .kicker { color: var(--color-accent); }
.setup-sec > .sec-head:hover::after { color: var(--color-accent); }
.setup-sec > .sec-body { padding: 0 2px 12px; }

/* placeholder screens (not yet built) */
.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--color-neutral-600);
  text-align: center;
}
.placeholder .big {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: calc(22px * var(--font-scale));
  color: var(--color-text);
}

/* Analytics/Dashboard table widgets: sortable headers + clickable rows */
th[data-w-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-w-sort]:hover { color: var(--color-accent); }
.table tbody tr[data-w-row] { cursor: pointer; }
#lib-table td:first-child, #dash-widgets td:first-child { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Trend chart tooltip (Library trend tab) */
.trend-tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--color-neutral-900);
  color: var(--color-bg);
  font-size: calc(11px * var(--font-scale));
  line-height: 1.35;
  padding: 5px 8px;
  border-radius: 3px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* Toast: transient, non-blocking status popups (e.g. export progress/result).
   Bottom-centre, stacking upward; square-cornered to match the blueprint frame. */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-4));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: var(--space-2);
  width: max-content;
  max-width: min(92vw, 460px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  padding: 10px 14px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-divider);
  border-left: 3px solid var(--color-neutral-600);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-body);
  font-size: calc(13px * var(--font-scale));
  line-height: 1.35;
  word-break: break-word;
  animation: toast-in 160ms ease-out;
}
.toast-success { border-left-color: var(--color-accent); }
.toast-error { border-left-color: #c0392b; }
.toast-msg { flex: 1; }
.toast-out { animation: toast-out 190ms ease-in forwards; }
.toast-spin {
  flex: none;
  width: 13px;
  height: 13px;
  border: 2px solid var(--color-divider);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: toast-spin 700ms linear infinite;
}
@keyframes toast-spin { to { transform: rotate(360deg); } }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(8px); }
}

/* Monitor guided editor (screen 06) */
.mon-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; padding: 0; flex: none;
  border: 1px solid var(--color-divider); border-radius: 50%;
  background: transparent; color: var(--color-neutral-600);
  font-family: var(--font-body); font-size: 10px; font-style: italic; font-weight: 700;
  line-height: 1; cursor: pointer; vertical-align: middle;
}
.mon-info:hover { border-color: var(--color-accent); color: var(--color-accent); }
.mon-section { border: 1px solid var(--color-divider); padding: 10px 12px; margin-top: 12px; }
.mon-sechead { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.mon-sectitle { font-family: var(--font-heading); font-weight: var(--font-heading-weight); font-size: calc(15px * var(--font-scale)); }
.mon-rule { border: 1px solid var(--color-divider); background: var(--color-surface); padding: 9px 10px; margin-top: 8px; }
.mon-rulehead { display: flex; gap: 8px; align-items: center; }
.mon-rulehead .input { flex: 1; }
.mon-cond { padding: 7px 9px; margin-top: 6px; }
.mon-condhead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mon-sel { width: auto; padding: 4px 8px; font-size: calc(12px * var(--font-scale)); }
.mon-x { margin-left: auto; padding: 2px 8px; }
.mon-condrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.mon-numwrap { display: inline-flex; align-items: center; gap: 4px; }
.mon-num { width: 78px; text-align: right; padding: 5px 7px; }
.mon-seg button { padding: 3px 9px; }
.mon-join { text-align: center; font-size: calc(10px * var(--font-scale)); letter-spacing: 0.14em; color: var(--color-neutral-600); margin: 6px 0; }
.mon-or { color: var(--color-accent); font-weight: 700; }
.mon-add { border-style: dashed; padding-block: 6px; margin-top: 8px; }
.mon-warn { color: #c0392b; padding: 6px 0; }
.mon-scalar { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: calc(12px * var(--font-scale)); padding: 5px 0; }
.mon-scalar > span { display: flex; align-items: center; gap: 5px; }
.mon-scalar input[type="number"] { width: 96px; text-align: right; }

/* Fullscreen chart modal. A fixed covering overlay (works in the Android WebView, unlike
   the native Fullscreen API which needs host WebChromeClient support). The chart's canvas is
   MOVED into .chart-fs-body and re-rendered at the overlay size, so axis text is drawn crisp
   rather than bitmap-stretched. The body is rotated 90° when the phone is portrait (forced
   landscape); the ✕ close stays in screen space at the top-right like a normal modal. */
.chart-fs-overlay { position: fixed; inset: 0; z-index: 10000; background: var(--color-bg); }
.chart-fs-overlay .chart-fs-body { position: absolute; inset: 0; box-sizing: border-box; padding: 10px; }
.chart-fs-overlay .chart-fs-body .chart-scroll { width: 100%; height: 100%; overflow: auto; }
.chart-fs-overlay canvas { width: 100% !important; height: 100% !important; transform: none !important; }
.chart-fs-close { position: absolute; top: 8px; right: 10px; z-index: 2; font-size: calc(18px * var(--font-scale)); line-height: 1; padding: 4px 10px; }
