/*
 * Experiment canvas (/experiments/canvas). Colours, type, spacing and radii come from the design
 * files in docs/ (desktop.html ≥ 1200px, tablet.html 768–1199px, mobile.html < 768px).
 * Every rule is scoped to .cv / .cv-body, because Propshaft links every stylesheet on every page.
 */
.cv-body {
  margin: 0;
  background: #E9EDF3;
  color: #14213D;
  font-family: 'Atkinson Hyperlegible', ui-sans-serif, system-ui, sans-serif;
  overflow: hidden;
}

.cv {
  --accent: #2F5BEA;
  --accent-dark: #1E3FB0;
  --ink: #14213D;
  --muted: #4A5568;
  --line: #DCE2EA;
  --control: #D5DCE6;
  --hover: #F1F4F9;
  --soft-line: #E6EAF0;
  --bench: #F3F6FA;
  --danger: #B42318;
  --select: #E8772E;
  --ib: 40px;
  --btn-h: 40px;
  --btn-fs: 14px;
  --r: 10px;
  --chip-h: 34px;
  --chip-r: 999px;
  --chip-fs: 13px;
  --tile-h: 80px;
  --inp-h: 40px;
  --inp-fs: 14px;
  --range-h: 28px;

  height: 100vh;
  height: 100dvh;
  display: grid;
  background: #E9EDF3;
  color: var(--ink);
  font-family: 'Atkinson Hyperlegible', ui-sans-serif, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.cv a { color: var(--accent); }
.cv a:hover { color: var(--accent-dark); }
.cv .disp { font-family: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif; }
.cv .mono { font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace; }
.cv .cv-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cv [hidden] { display: none !important; }

/* ---- Controls --------------------------------------------------------------------------- */
.cv .ib {
  width: var(--ib); height: var(--ib); flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--control); background: #fff; border-radius: var(--r); color: var(--ink); cursor: pointer; padding: 0;
  text-decoration: none;
}
.cv .ib:hover { background: var(--hover); color: var(--ink); }
.cv .ib.on, .cv .ib[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.cv .ib:disabled { opacity: .4; cursor: default; background: #fff; }
.cv .ib.quiet { border-color: transparent; }
.cv .ib.quiet[aria-pressed="true"] { border-color: var(--ink); }
.cv .ib.danger { color: var(--danger); }

.cv .btn {
  height: var(--btn-h); padding: 0 16px; border-radius: var(--r); border: 1px solid var(--control); background: #fff; color: var(--ink);
  font: inherit; font-weight: 700; font-size: var(--btn-fs); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.cv .btn:hover { background: var(--hover); }
.cv .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.cv .btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.cv .btn.outline-accent { border-color: var(--accent); color: var(--accent); }

.cv .chip {
  height: var(--chip-h); padding: 0 12px; border-radius: var(--chip-r); border: 1px solid var(--control); background: #fff; color: var(--ink);
  font: inherit; font-size: var(--chip-fs); font-weight: 700; cursor: pointer;
}
.cv .chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

.cv .tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: var(--tile-h);
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font: inherit; font-size: 12px; line-height: 1.2;
  cursor: grab; padding: 4px; text-align: center; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.cv .tile:hover { border-color: var(--accent); background: #F4F7FF; }
.cv .tile:disabled { cursor: default; color: #8A94A6; background: #fff; border-color: var(--line); border-style: dashed; }
.cv .tile small { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }

.cv .el:focus-visible, .cv .tile:focus-visible, .cv .ib:focus-visible, .cv .btn:focus-visible, .cv .chip:focus-visible,
.cv .rail:focus-visible, .cv .seg:focus-visible, .cv .inp:focus-visible, .cv input:focus-visible, .cv select:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

.cv input[type=range] { width: 100%; margin: 0; height: var(--range-h); accent-color: var(--accent); }
.cv .lbl { font-size: 13px; color: var(--muted); font-weight: 700; }
.cv .inp {
  height: var(--inp-h); border: 1px solid var(--control); border-radius: var(--r); padding: 0 10px; font: inherit; font-size: var(--inp-fs);
  color: var(--ink); background: #fff; box-sizing: border-box; width: 100%; min-width: 0;
}
.cv .sec { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 0; }
.cv .check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; cursor: pointer; }
.cv .check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* Controls the designs draw smaller than 44px keep their look but get a 44px touch area. */
.cv .chip, .cv .seg, .cv .cv-strip-actions .btn { position: relative; }
.cv .chip::after, .cv .seg::after, .cv .cv-strip-actions .btn::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }

/* ---- Top bar ---------------------------------------------------------------------------- */
.cv-top {
  grid-area: top; min-height: 64px; display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 10px 16px; box-sizing: border-box;
  background: #fff; border-bottom: 1px solid var(--line); position: relative; z-index: 6;
}
.cv-brand { display: flex; align-items: center; gap: 10px; color: var(--ink) !important; text-decoration: none; }
.cv-logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); display: flex; align-items: center; justify-content: center; color: #fff; }
.cv-brand .disp { font-weight: 700; font-size: 18px; }
.cv-divider { width: 1px; height: 28px; background: var(--line); }
.cv-heading { display: flex; flex-direction: column; min-width: 0; flex: 1 1 260px; }
.cv-crumbs { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-heading h1 { margin: 0; font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-group { display: flex; gap: 8px; align-items: center; position: relative; }
.cv-run { min-width: 112px; }
.cv .btn.cv-guided-btn { color: var(--accent-dark); border-color: #B9CBFB; background: #F5F8FF; }
.cv .btn.cv-guided-btn:hover { background: #EAF0FF; }
.cv-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(20,33,61,.14); padding: 6px; display: flex; flex-direction: column; z-index: 20;
  max-width: min(340px, calc(100vw - 24px)); max-height: calc(100dvh - 90px); overflow-y: auto; box-sizing: border-box;
}
.cv-menu button, .cv-menu a {
  min-height: 44px; border: 0; background: transparent; border-radius: 8px; text-align: left; padding: 0 12px; font: inherit; font-size: 14px;
  font-weight: 700; color: var(--ink); cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.cv-menu button:hover, .cv-menu button:focus-visible, .cv-menu a:hover, .cv-menu a:focus-visible { background: var(--hover); outline: none; color: var(--ink); }
.cv-menu a { text-decoration: none; }
.cv-menu a[aria-current="page"] { color: var(--accent-dark); }
.cv-menu-check { width: 18px; flex: none; display: inline-flex; }
.cv-menu-label { display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 10px 12px 4px; border-top: 1px solid var(--soft-line); margin-top: 6px; }
#cv-experiments-menu > .cv-menu-label:first-child { border-top: 0; margin-top: 0; }
.cv-menu .cv-guided { color: var(--accent-dark); }
.cv-menu { max-width: min(380px, calc(100vw - 24px)); }

/* The experiment picker: subject tabs, a search, and the experiments as cards grouped by topic. */
.cv { --physics: #2F5BEA; --chemistry: #7C3AED; --biology: #15803D; --environment: #0D9488; --technology: #0891B2; --math: #C2410C; }
.cv [data-subject="physics"] { --subject: var(--physics); }
.cv [data-subject="chemistry"] { --subject: var(--chemistry); }
.cv [data-subject="biology"] { --subject: var(--biology); }
.cv [data-subject="environment"] { --subject: var(--environment); }
.cv [data-subject="technology"] { --subject: var(--technology); }
.cv [data-subject="math"] { --subject: var(--math); }
.cv .cv-picker {
  width: min(760px, calc(100vw - 24px)); max-width: none; height: min(640px, calc(100dvh - 90px)); padding: 0; gap: 0; overflow: hidden;
}
.cv-picker-head { display: flex; flex-direction: column; gap: 12px; padding: 16px 16px 12px; border-bottom: 1px solid var(--soft-line); flex: none; }
.cv-picker-title { display: flex; align-items: center; gap: 12px; }
.cv-picker-title h2 { margin: 0; font-size: 20px; flex: 1; }
.cv .cv-picker-title .cv-guided { min-height: 36px; font-size: 13px; padding: 0 10px; }
.cv .cv-picker .cv-picker-close { width: 36px; height: 36px; border: 0; padding: 0; justify-content: center; }
.cv-picker-tabs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.cv .cv-picker .cv-picker-tab {
  flex: none; min-height: 38px; padding: 0 12px; border: 1px solid var(--control); border-radius: 999px; background: #fff; font-size: 14px; gap: 8px;
}
.cv .cv-picker .cv-picker-tab:hover { background: var(--hover); }
.cv .cv-picker .cv-picker-tab[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.cv .cv-picker .cv-picker-tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.cv-picker.is-searching .cv-picker-tab { opacity: .6; }
.cv-subject-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--subject, var(--muted)); flex: none; box-shadow: 0 0 0 2px #fff; }
.cv-picker-count { font-size: 12px; font-weight: 700; min-width: 22px; height: 20px; padding: 0 6px; box-sizing: border-box; border-radius: 999px; background: var(--hover); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.cv-picker-tab[aria-pressed="true"] .cv-picker-count { background: rgba(255,255,255,.18); color: #fff; }
.cv-picker-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
.cv-picker-subject { display: flex; flex-direction: column; gap: 4px; }
.cv-picker-subject-name { display: none; align-items: center; gap: 8px; margin: 12px 0 0; font-size: 15px; }
.cv-picker.is-searching .cv-picker-subject-name { display: flex; }
.cv-picker-topic-name { margin: 16px 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.cv-picker-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.cv .cv-picker a.cv-exp {
  height: 100%; box-sizing: border-box; min-height: 68px; padding: 10px 12px 10px 14px; border: 1px solid var(--line); border-left: 4px solid var(--subject, var(--accent));
  border-radius: 10px; background: #fff; flex-direction: column; align-items: stretch; justify-content: space-between; gap: 6px; font-weight: 400;
}
.cv .cv-picker a.cv-exp:hover, .cv .cv-picker a.cv-exp:focus-visible { background: var(--hover); border-color: var(--control); border-left-color: var(--subject, var(--accent)); box-shadow: 0 2px 8px rgba(20,33,61,.08); }
.cv .cv-picker a.cv-exp:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.cv .cv-picker a.cv-exp[aria-current="page"] { background: #EAF0FF; border-color: #B9CBFB; border-left-color: var(--subject, var(--accent)); }
.cv-exp-title { font-weight: 700; font-size: 14px; line-height: 1.3; color: var(--ink); }
.cv-exp-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.cv-exp-topic { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv .cv-search input:focus-visible { outline: none; }
.cv-exp-lock { flex: none; margin-left: auto; display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 999px; background: #FEF3C7; color: #92400E; font-weight: 700; }
.cv .cv-picker a.cv-exp.is-locked .cv-exp-title { color: var(--muted); }
.cv-exp-now { flex: none; margin-left: auto; display: inline-flex; align-items: center; gap: 4px; color: var(--accent-dark); font-weight: 700; }
.cv-picker-empty { margin: 0; padding: 32px 0; text-align: center; font-size: 14px; color: var(--muted); }

/* ---- The guided lab's canvas scene (lab/scenes/canvas.js): a fixed picture of the bench ------ */
.cv.cv-embed { display: block; height: 480px; background: var(--bench); border-radius: inherit; }
.cv.cv-embed .cv-bench { position: relative; height: 100%; overflow: hidden; }
/* Handles drawn over the apparatus (registry handles): only the handles take the pointer. */
.cv .cv-handles { position: absolute; overflow: visible; pointer-events: none; z-index: 2; }
.cv .cv-handles [data-drag], .cv .cv-handles [data-tap], .cv .cv-handles [data-handle] { pointer-events: all; cursor: pointer; }
.cv .cv-handles [data-drag], .cv .cv-handles [data-kind="drag"] { cursor: grab; touch-action: none; }
.cv .cv-handles .is-dragging { cursor: grabbing; }
.cv .cv-handles [data-drag]:focus-visible, .cv .cv-handles [data-tap]:focus-visible, .cv .cv-handles [data-handle]:focus-visible { outline: none; }
.cv .cv-handles :is([data-drag], [data-tap], [data-handle]):focus-visible > :first-child { stroke: var(--accent); stroke-width: 3; }
/* The previous picture, fading out over the new one (lab/scenes/canvas.js). */
.cv .cv-fade { position: absolute; inset: 0; pointer-events: none; opacity: 1; transition: opacity .24s ease-out; }
.cv .cv-fade .cv-optic-tag { display: none; }
/* Item ids (GT1) belong to the bench, not to a guided picture. */
.cv.cv-embed .cv-optic-tag { display: none; }
@media (max-width: 767px) { .cv.cv-embed { height: 320px; } }

/* ---- A locked bench (canvas/locked.html.erb) ------------------------------------------------ */
.cv.cv-locked-page { display: flex; flex-direction: column; overflow-y: auto; }
.cv-locked { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 24px; padding: 48px 16px; box-sizing: border-box; }
.cv-locked-card {
  width: min(520px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-sizing: border-box;
  box-shadow: 0 10px 30px rgba(20,33,61,.08); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.cv-locked-icon { width: 56px; height: 56px; border-radius: 16px; background: #FEF3C7; color: #B45309; display: inline-flex; align-items: center; justify-content: center; }
.cv-locked-card h2 { margin: 4px 0 0; font-size: 22px; }
.cv-locked-card p { margin: 0; font-size: 15px; line-height: 1.5; color: var(--muted); }
.cv-locked-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
.cv .cv-locked-note { font-size: 14px; }
.cv-locked-free { width: min(520px, 100%); }
.cv-locked-free ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.cv-locked-free a {
  display: block; padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; background: #fff;
  font-weight: 700; font-size: 14px; color: var(--ink); text-decoration: none;
}
.cv-locked-free a:hover { background: var(--hover); color: var(--ink); }

/* ---- Experiment view (data-focus) and Free build ------------------------------------------
 * Experiments with a guided version open with only their own apparatus and the tools a learner needs;
 * Free build (the switch at the top of the toolbox, or the menu) brings back the whole lab. */
.cv-view-switch { display: flex; gap: 4px; padding: 4px; background: #EEF1F6; border-radius: 12px; flex: none; }
.cv .cv-view-btn {
  flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.cv .cv-view-btn[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(20,33,61,.15); }
.cv .cv-view-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.cv .cv-link { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--accent-dark); text-decoration: underline; cursor: pointer; }
.cv-focus-note { margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); padding-top: 12px; border-top: 1px solid var(--soft-line); }
.cv .cv-focus-only { display: none; }
.cv[data-focus] .cv-focus-only { display: block; }
.cv[data-focus] .cv-free-only, .cv[data-focus] .cv-arrange { display: none !important; }
.cv[data-focus] .cv-tools-head .cv-hint, .cv[data-focus] .cv-tools .cv-search, .cv[data-focus] .cv-chips { display: none; }
.cv[data-focus] .cv-toolbar [data-action="grid"] { display: none; }
.cv[data-focus][data-no-wires] .cv-toolbar [data-tool="wire"] { display: none; }
.cv[data-focus] .cv-obs-head .cv-record { background: var(--accent); border-color: var(--accent); color: #fff; min-height: 44px; padding: 0 20px; font-size: 15px; }
.cv[data-focus] .cv-obs-head .cv-record:hover { background: var(--accent-dark); }
.cv[data-focus] .cv-strip-actions [data-action="record"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.cv-menu .cv-switch-item { min-height: 56px; align-items: center; }
.cv-menu .cv-switch-item small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.cv-switch { width: 34px; height: 20px; flex: none; border-radius: 999px; background: var(--control); position: relative; transition: background .15s; }
.cv-switch::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
[aria-checked="true"] > .cv-switch { background: var(--accent); }
[aria-checked="true"] > .cv-switch::after { transform: translateX(14px); }

/* First-visit tips (canvas/views/tips.js). */
.cv-tip-ring {
  position: fixed; z-index: 60; border-radius: 14px; box-shadow: 0 0 0 3px var(--accent), 0 0 0 9999px rgba(20,33,61,.35); pointer-events: none;
  transition: left .2s, top .2s, width .2s, height .2s;
}
.cv-tip {
  position: fixed; z-index: 61; background: #fff; border-radius: 14px; padding: 14px 16px; box-sizing: border-box; box-shadow: 0 16px 40px rgba(20,33,61,.3);
  display: flex; flex-direction: column; gap: 8px;
}
.cv-tip-count { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-dark); }
.cv-tip-text { margin: 0; font-size: 15px; line-height: 1.45; color: var(--ink); }
.cv-tip-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 4px; }
@media (prefers-reduced-motion: reduce) { .cv-tip-ring, .cv-switch, .cv-switch::after { transition: none; } }

/* ---- Subject rail (tablet) and apparatus toolbox ----------------------------------------- */
.cv-rail {
  grid-area: rail; width: 80px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 12px 0; box-sizing: border-box;
}
.cv .rail {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 64px; padding: 8px 0; border-radius: 12px; border: 0;
  background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}
.cv .rail[aria-pressed="true"] { background: #EAF0FF; color: var(--accent-dark); }

.cv-tools {
  grid-area: tools; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; padding: 16px;
  box-sizing: border-box; overflow-y: auto; min-height: 0;
}
.cv-tools-head { display: flex; flex-direction: column; gap: 4px; }
.cv-tools-head h2 { margin: 0; font-size: 18px; }
.cv-hint { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.4; }
.cv-search {
  display: flex; align-items: center; gap: 8px; height: 40px; border: 1px solid var(--control); border-radius: 10px; padding: 0 10px;
  color: var(--muted); flex: none;
}
.cv-search input { border: 0; outline: 0; flex: 1; min-width: 0; font: inherit; font-size: 14px; color: var(--ink); background: transparent; }
.cv-search:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.cv-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cv-groups { display: flex; flex-direction: column; gap: 16px; }
.cv-group-list { display: flex; flex-direction: column; gap: 10px; }
.cv-tiles-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cv-empty { font-size: 13px; color: var(--muted); margin: 0; }

/* ---- Bench ------------------------------------------------------------------------------ */
.cv-bench {
  --gs: 22px; --gx: 0px; --gy: 0px;
  grid-area: bench; position: relative; overflow: hidden; min-height: 0; min-width: 0; touch-action: none; user-select: none; -webkit-user-select: none;
  background: var(--bench); outline: none;
}
.cv-bench.grid-on { background: radial-gradient(circle, #C2CBD8 1.1px, transparent 1.5px) var(--gx) var(--gy) / var(--gs) var(--gs), var(--bench); }
.cv-bench[data-tool="pan"] .cv-viewport { cursor: grab; }
.cv-bench.panning .cv-viewport { cursor: grabbing; }
.cv-viewport { position: absolute; inset: 0; }
.cv-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.cv-stage svg { position: absolute; left: 0; top: 0; overflow: visible; }
.cv-wires, .cv-terminals { pointer-events: none; }

.cv-toolbar {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 4px;
  background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 4px 14px rgba(20,33,61,.08); z-index: 3;
}
.cv-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.cv-zoom { font-size: 13px; width: 48px; text-align: center; }
.cv-status {
  position: absolute; left: 16px; bottom: 16px; display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); font-size: 13px; font-weight: 700; z-index: 2; max-width: calc(100% - 32px); box-sizing: border-box;
}
.cv-status span:last-of-type { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-status-action {
  display: inline-flex; align-items: center; gap: 4px; border: 0; background: #EAF0FF; color: var(--accent-dark); font: inherit; font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 2px 8px; margin-right: -6px; cursor: pointer; white-space: nowrap; position: relative;
}
.cv-status-action::after { content: ""; position: absolute; inset: -10px -4px; }

/* The bench mission (canvas/views/mission.js): the guided experiment's steps as a checklist. */
.cv-mission {
  position: absolute; left: 16px; top: 76px; width: 300px; max-width: calc(100% - 32px); max-height: calc(100% - 136px); z-index: 3;
  display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 8px 24px rgba(20,33,61,.12); box-sizing: border-box; overflow: hidden;
}
.cv-mission-head {
  display: grid; grid-template-columns: auto 1fr auto auto; grid-template-rows: auto auto; align-items: center; column-gap: 8px; row-gap: 6px;
  width: 100%; min-height: 48px; padding: 10px 12px; border: 0; background: transparent; font: inherit; color: var(--ink); cursor: pointer; text-align: left;
}
.cv-mission-head:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; border-radius: 14px; }
.cv-mission-icon { color: var(--accent); display: inline-flex; }
.cv-mission-title { font-weight: 700; font-size: 15px; }
.cv-mission-count { font-size: 12px; font-weight: 700; color: var(--muted); }
.cv-mission-chevron { display: inline-flex; color: var(--muted); transition: transform .15s; }
.cv-mission.is-open .cv-mission-chevron { transform: rotate(180deg); }
.cv-mission-bar { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--hover); overflow: hidden; }
.cv-mission-bar span { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.cv-mission.is-complete .cv-mission-bar span { background: #15803D; }
.cv-mission-body { display: none; flex-direction: column; gap: 10px; padding: 2px 12px 12px; overflow-y: auto; }
.cv-mission.is-open .cv-mission-body { display: flex; }
.cv-mission-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cv-mission-step { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.35; color: var(--muted); padding: 6px; border-radius: 10px; }
.cv-mission-step.is-current { background: #EAF0FF; color: var(--ink); font-weight: 700; }
.cv-mission-step.is-done { color: var(--muted); }
.cv-mission-step.is-done > span:last-child { text-decoration: line-through; text-decoration-color: rgba(74,85,104,.4); }
.cv-mission-tick {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--control); box-sizing: border-box; display: inline-flex;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--muted); background: #fff;
}
.cv-mission-step.is-current .cv-mission-tick { border-color: var(--accent); color: var(--accent); }
.cv-mission-step.is-done .cv-mission-tick { background: #15803D; border-color: #15803D; color: #fff; }
.cv-mission-note { display: block; margin-top: 4px; font-size: 12px; font-weight: 400; color: var(--accent-dark); }
.cv-mission-prediction { margin: 0; font-size: 13px; padding: 8px 10px; border-radius: 10px; background: #FFF7E6; color: #7A4B00; }
.cv-mission-prediction span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 2px; }
.cv-mission-hint { margin: 0; display: flex; gap: 8px; font-size: 13px; line-height: 1.4; padding: 8px 10px; border-radius: 10px; background: #F0FDF4; color: #14532D; }
.cv-mission-hint svg { flex: none; color: #15803D; }
.cv-mission-warn { margin: 0; font-size: 13px; padding: 8px 10px; border-radius: 10px; background: #FEF3F2; color: var(--danger); }
.cv-mission-done { margin: 0; font-size: 14px; font-weight: 700; color: #15803D; }
.cv .cv-mission-link { font-size: 13px; font-weight: 700; color: var(--accent-dark); }
.cv-mission-reward { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 13px; }
.cv-mission-reward strong { padding: 3px 10px; border-radius: 999px; background: #FEF3C7; color: #92400E; font-size: 14px; }
.cv-mission-badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--ink); }
.cv-mission-saved { margin: 0; font-size: 13px; color: var(--muted); }
.cv-dot { width: 8px; height: 8px; border-radius: 50%; background: #8A94A6; flex: none; }
.cv-wire-hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); margin: 0; font-size: 12px; font-weight: 700; color: #fff;
  background: var(--ink); padding: 6px 10px; border-radius: 8px; white-space: nowrap; z-index: 2; pointer-events: none;
}

/* Bench items, drawn as in the designs. */
.cv .el {
  position: absolute; background: #fff; border: 1.5px solid #C5CFDC; border-radius: 14px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; cursor: grab; font: inherit; color: var(--ink); padding: 6px; box-sizing: border-box; overflow: visible;
  box-shadow: 0 1px 2px rgba(20,33,61,.08), 0 6px 16px rgba(20,33,61,.07); touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.cv .el.is-locked { cursor: default; }
.cv .el.is-dragging { box-shadow: 0 14px 30px rgba(20,33,61,.18); z-index: 2; }
.cv .el.is-short { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(180,35,24,.15); }
.cv .el.is-flipped > svg { transform: scaleX(-1); }
.cv-tag { font-size: 12px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.cv-val { font-size: 14px; font-weight: 700; white-space: nowrap; }
.cv .el.is-round .cv-val { font-size: 17px; }
.cv-unit { font-size: 12px; color: var(--muted); }
.cv-name { font-size: 13px; font-weight: 700; white-space: nowrap; }
.cv-glow {
  position: absolute; left: 50%; top: 34%; width: 150px; height: 150px; margin: -75px 0 0 -75px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255,196,61,.9) 0%, rgba(255,196,61,0) 68%);
}
.cv-lock { position: absolute; right: 4px; top: 4px; color: var(--muted); }
.cv .ring { position: absolute; inset: -9px; border: 2px dashed var(--select); border-radius: 18px; pointer-events: none; }
.cv .el.is-round .ring { border-radius: 56px; }
.cv .hd { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid var(--select); border-radius: 3px; box-sizing: border-box; }

/* Light apparatus draws its own shape; the light layer sits above it. */
.cv .el.is-optic { background: transparent; border: 0; box-shadow: none; padding: 0; }
.cv .el.is-optic:focus-visible { outline-offset: 6px; }
.cv-optic-tag {
  position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--muted);
  white-space: nowrap; pointer-events: none;
}
.cv .cv-tag-above { top: auto; bottom: 100%; margin: 0 0 4px; }
.cv-optic-label { position: absolute; font-size: 12px; font-weight: 700; color: #fff; pointer-events: none; }
.cv-light { pointer-events: none; }
.cv-ray { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.cv-light-text { font: 700 12px 'Atkinson Hyperlegible', ui-sans-serif, system-ui, sans-serif; fill: #1E3FB0; paint-order: stroke; stroke: #F3F6FA; stroke-width: 4px; stroke-linejoin: round; }

/* Glassware: drawn by the guided lab's ContainerView (lab/glassware.js), with its animations. */
.cv .el.is-glass { cursor: grab; }
.cv-glass { position: absolute; inset: 0; display: flex; align-items: flex-end; pointer-events: none; }
.cv-glass svg { width: 100%; height: 100%; display: block; overflow: visible; }
.cv .cv-glass-tag { display: flex; flex-direction: column; align-items: center; text-align: center; white-space: normal; width: max-content; max-width: calc(100% + 34px); line-height: 1.25; }
.cv .cv-glass-tag small { font-size: 11px; font-weight: 700; color: #1E3FB0; }
@keyframes cv-lab-bubble { 0% { transform: translateY(0); opacity: 0.95; } 100% { transform: translateY(-30px); opacity: 0; } }
@keyframes cv-lab-foam { from { transform: scale(0.85); } to { transform: scale(1.1); } }
@keyframes cv-lab-steam { 0% { transform: translateY(6px); opacity: 0; } 30% { opacity: 0.8; } 100% { transform: translateY(-14px); opacity: 0; } }
@keyframes cv-lab-rain { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(70px); opacity: 0.6; } }
.cv .lab-bubbles circle { animation: cv-lab-bubble 1.1s ease-in infinite; transform-box: fill-box; }
.cv .lab-bubbles g circle { animation: cv-lab-foam 1.6s ease-in-out infinite alternate; }
.cv .lab-steam path { animation: cv-lab-steam 2.4s ease-out infinite; transform-box: fill-box; }
.cv .lab-rain ellipse { animation: cv-lab-rain 1.4s ease-in infinite; transform-box: fill-box; }
@media (prefers-reduced-motion: reduce) {
  .cv .lab-bubbles circle, .cv .lab-bubbles g circle, .cv .lab-steam path, .cv .lab-rain ellipse { animation: none; }
}
.cv-reagent { padding: 4px 2px; }
.cv-reagent-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 11px; }
.cv-contents { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.cv-contents li { display: flex; justify-content: space-between; gap: 8px; }
.cv-contents .cv-empty-row, .cv-contents .cv-residue span:first-child { color: var(--muted); }
.cv-chem-note { margin: 0; font-size: 14px; line-height: 1.45; background: #FFF7ED; border: 1px solid #FED7AA; border-radius: 10px; padding: 8px 10px; }
.cv-assumptions { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); line-height: 1.45; display: flex; flex-direction: column; gap: 4px; }
.cv-notes { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.cv-notes ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; font-size: 14px; line-height: 1.4; }
.cv-notes li { border-left: 3px solid var(--line); padding-left: 10px; }
.cv-notes li:first-child { border-left-color: var(--accent); }
.cv-notes li.warn { border-left-color: var(--select); color: #7A2E0E; }
.cv-notes .mono { font-size: 12px; color: var(--muted); }

/* Wires and terminals. */
.cv-wire { fill: none; stroke: #33415C; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.cv-wire.is-selected { stroke: var(--select); }
.cv-wire.is-string { stroke: #14213D; stroke-width: 1.5; }
.cv-wire-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.cv-flow { fill: none; stroke: #F2A93B; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 6 16; animation: cv-flow .9s linear infinite; pointer-events: none; }
@keyframes cv-flow { to { stroke-dashoffset: -22; } }
@media (prefers-reduced-motion: reduce) { .cv-flow { animation: none; } }
/* A motor's coil turning about its upright axle (the face sets the duration and direction). */
@keyframes cv-coil-turn { 0% { transform: scaleX(1); } 25% { transform: scaleX(0.04); } 50% { transform: scaleX(-1); } 75% { transform: scaleX(0.04); } 100% { transform: scaleX(1); } }
.cv .cv-coil { transform-box: fill-box; transform-origin: center; }
.cv .cv-coil.is-turning { animation: cv-coil-turn 1s linear infinite; }
@media (prefers-reduced-motion: reduce) { .cv .cv-coil.is-turning { animation: none; } }
/* Sound and waves: a pulse or wavefronts running along (the face sets --shift and the duration),
   and a string vibrating. */
@keyframes cv-run { from { transform: translateX(0); } to { transform: translateX(var(--shift)); } }
@keyframes cv-vibrate { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(-1); } }
.cv .cv-run { animation: cv-run 1s linear infinite; }
.cv .cv-vibrate { animation: cv-vibrate 0.12s linear infinite; }
@media (prefers-reduced-motion: reduce) { .cv .cv-run, .cv .cv-vibrate { animation: none; } }
/* Class 6: a heart beating at the pulse and lungs filling at the breathing rate (the face sets the duration). */
@keyframes cv-beat { 0%, 60%, 100% { transform: scale(1); } 20% { transform: scale(1.25); } }
@keyframes cv-breathe { 0%, 100% { transform: scale(0.85); } 50% { transform: scale(1.1); } }
.cv .cv-beat, .cv .cv-breathe { transform-box: fill-box; transform-origin: center; }
.cv .cv-beat { animation: cv-beat 1s ease-in-out infinite; }
.cv .cv-breathe { animation: cv-breathe 4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .cv .cv-beat, .cv .cv-breathe { animation: none; } }
/* A pendulum swinging to and fro (the face sets --swing and the duration: one swing each way). */
@keyframes cv-swing { 0%, 100% { transform: rotate(var(--swing)); } 50% { transform: rotate(calc(-1 * var(--swing))); } }
.cv .cv-swing { transform-box: view-box; animation: cv-swing 2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .cv .cv-swing { animation: none; } }
/* A candle flame flickering. */
@keyframes cv-flicker { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(0.92, 1.08); } }
.cv .cv-flame { transform-box: fill-box; transform-origin: 50% 100%; animation: cv-flicker 0.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .cv .cv-flame { animation: none; } }
.cv-rubber { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 5; }
.cv-term { fill: #fff; stroke: #33415C; stroke-width: 2; }
.cv-term-hit { fill: transparent; pointer-events: all; cursor: crosshair; }
.cv-bench[data-tool="wire"] .cv-term { stroke: var(--accent); }
.cv-term.is-start { fill: var(--accent); stroke: var(--accent); }
.cv-term.is-target { fill: #EAF0FF; stroke: var(--accent); stroke-width: 3; }

/* The apparatus being dragged in from the toolbox. */
.cv-ghost { position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cv-ghost-disc {
  width: 92px; height: 92px; border-radius: 46px; border: 2px dashed var(--accent); background: rgba(255,255,255,.85); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; transform: rotate(-4deg); box-shadow: 0 14px 30px rgba(20,33,61,.18); position: relative;
  color: var(--accent);
}
.cv-ghost-disc span { font-size: 12px; font-weight: 700; color: var(--accent-dark); }
.cv-ghost-cursor { position: absolute; right: -10px; bottom: -12px; }
.cv-ghost-tip { font-size: 12px; font-weight: 700; color: #fff; background: var(--ink); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }

/* ---- Properties ------------------------------------------------------------------------- */
.cv-props {
  grid-area: props; background: #fff; border-left: 1px solid var(--line); padding: 16px; box-sizing: border-box; display: flex; flex-direction: column;
  gap: 20px; overflow-y: auto; min-height: 0;
}
.cv-props-sel { display: flex; flex-direction: column; gap: 10px; }
.cv-props-head { display: flex; align-items: center; gap: 8px; }
.cv-props-titles { flex: 1; min-width: 0; display: flex; flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 10px; }
.cv-props-titles h2 { margin: 0; font-size: 20px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cv-kind { font-size: 12px; font-weight: 700; color: #B5531A; background: #FDEEE3; padding: 4px 8px; border-radius: 6px; white-space: nowrap; }
.cv-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cv-section { display: flex; flex-direction: column; gap: 14px; padding-top: 16px; border-top: 1px solid var(--soft-line); }
.cv-field { display: flex; flex-direction: column; gap: 6px; }
.cv-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cv-row .mono { font-weight: 700; }
.cv-minmax { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.cv-seg-group { display: flex; flex-wrap: wrap; min-width: 0; margin-left: auto; border: 1px solid var(--control); border-radius: 10px; padding: 3px; gap: 3px; }
/* Many choices (six lengths, six frequencies) move under their label, and wrap if they must, rather
   than widen the panel. */
.cv-row:has(> .cv-seg-group) { flex-wrap: wrap; row-gap: 6px; }
.cv-seg-group .chip { white-space: nowrap; }
.cv-seg-group .chip:not([aria-pressed="true"]) { border-color: transparent; }
.cv-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.cv-unit-input { display: flex; align-items: center; gap: 8px; }
.cv-unit-input span { font-size: 14px; color: var(--muted); min-width: 1.5em; }
.cv-warning { margin: 0; font-size: 13px; color: var(--danger); font-weight: 700; }
.cv-pos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cv-pos label, .cv-label-field { display: flex; flex-direction: column; gap: 4px; }
.cv-conn { display: flex; flex-direction: column; gap: 8px; }
.cv-conn ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.cv-conn li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.cv-conn li .ib { width: 44px; height: 44px; }
.cv-props-empty { display: flex; flex-direction: column; gap: 8px; }
.cv-props-empty h2 { margin: 0; font-size: 20px; }
.cv-props-empty p { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.45; }
.cv-mini { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cv-mini div { background: var(--bench); border-radius: 12px; padding: 10px 12px; display: flex; justify-content: space-between; align-items: baseline; }
.cv-mini .mono { font-size: 17px; font-weight: 700; }

/* ---- Observations ----------------------------------------------------------------------- */
.cv-obs { grid-area: obs; background: #fff; border-top: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cv-obs-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cv-obs-head h2 { margin: 0; font-size: 18px; flex: 1 1 auto; }
.cv-obs-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 16px; }
.cv-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-content: start; }
.cv-tile { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cv-tile .mono { font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-table-wrap { border: 1px solid var(--line); border-radius: 12px; overflow: auto; max-height: 172px; align-self: start; }
.cv-table-wrap table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cv-table-wrap thead tr { background: var(--bench); text-align: left; }
.cv-table-wrap th { padding: 8px 12px; position: sticky; top: 0; background: var(--bench); }
.cv-table-wrap td { padding: 8px 12px; border-top: 1px solid var(--soft-line); }
.cv-table-wrap td:first-child { color: var(--muted); }
.cv-table-wrap .cv-none td { color: var(--muted); font-size: 13px; }
.cv-graph { margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cv-graph-row { display: flex; gap: 8px; align-items: stretch; }
.cv-graph-y { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 11px; color: var(--muted); text-align: center; }
.cv-plot {
  position: relative; flex: 1; height: 128px; border-left: 2px solid #33415C; border-bottom: 2px solid #33415C;
  background: repeating-linear-gradient(0deg, transparent 0 31px, var(--soft-line) 31px 32px);
}
.cv-point {
  position: absolute; width: 10px; height: 10px; margin: 0 0 -5px -5px; border-radius: 50%; background: var(--accent); border: 2px solid #fff;
  box-sizing: border-box; padding: 0; cursor: default;
}
.cv-point::after { content: ""; position: absolute; inset: -8px; }
.cv-point-tip {
  position: absolute; transform: translate(-50%, calc(-100% - 10px)); background: var(--ink); color: #fff; font-size: 12px; font-weight: 700;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; z-index: 2;
}
.cv-axis-max { position: absolute; font-size: 10px; color: var(--muted); }
.cv-graph-x { font-size: 11px; color: var(--muted); text-align: right; }

.cv-strip { grid-area: strip; display: none; }
.cv-tabs { grid-area: tabs; display: none; }

/* ---- Notices ---------------------------------------------------------------------------- */
.cv-toast {
  position: fixed; left: 50%; top: 140px; transform: translateX(-50%); z-index: 50; max-width: min(520px, calc(100vw - 32px));
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 700; padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(20,33,61,.25); box-sizing: border-box;
}
.cv-toast.warn { background: #7A2E0E; }
.cv-toast:empty { display: none; }

/* ---- Desktop ≥ 1200px ------------------------------------------------------------------- */
@media (min-width: 1200px) {
  .cv {
    grid-template-columns: 280px minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top top top" "tools bench props" "tools obs props";
  }
  .cv .cv-not-d, .cv .cv-only-t, .cv .cv-only-m, .cv-rail { display: none !important; }
}

/* Touch screens get 44px targets even at desktop widths. */
@media (pointer: coarse) {
  .cv { --ib: 44px; --btn-h: 44px; --inp-h: 44px; --chip-h: 44px; }
  .cv .cv-view-btn { min-height: 44px; }
}

/* ---- Tablet 768–1199px ------------------------------------------------------------------ */
@media (min-width: 768px) and (max-width: 1199px) {
  .cv .cv-picker { position: fixed; top: 76px; left: 50%; right: auto !important; transform: translateX(-50%); width: min(720px, calc(100vw - 32px)); height: calc(100dvh - 100px); }
  .cv {
    --ib: 44px; --btn-h: 44px; --btn-fs: 15px; --r: 12px; --chip-h: 36px; --tile-h: 84px; --inp-h: 44px; --inp-fs: 15px; --range-h: 32px;
    grid-template-columns: 80px 220px minmax(0, 1fr);
    grid-template-rows: 68px minmax(0, 1fr) 112px;
    grid-template-areas: "top top top" "rail tools bench" "rail tools strip";
  }
  .cv[data-focus] { grid-template-columns: 240px minmax(0, 1fr); grid-template-areas: "top top" "tools bench" "tools strip"; }
  .cv[data-focus] .cv-rail { display: none !important; }
  .cv[data-focus] .cv-tools-head h2 { display: block; }
  .cv .cv-only-d, .cv .cv-only-m { display: none !important; }
  .cv-top { height: 68px; flex-wrap: nowrap; gap: 12px; padding: 0 16px; }
  .cv-heading { flex: 1 1 auto; }
  .cv-heading h1 { font-size: 18px; }
  .cv-run { min-width: 116px; }
  .cv-tools { padding: 16px 14px; gap: 14px; }
  .cv-tools .tile { font-size: 13px; }
  .cv-tiles-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cv-tools .cv-search, .cv-chips { display: none; }

  .cv-toolbar { top: auto; bottom: 16px; left: 24px; transform: none; border-radius: 16px; box-shadow: 0 4px 14px rgba(20,33,61,.1); }
  .cv-zoom { width: 44px; }
  .cv-status { top: 16px; left: 24px; bottom: auto; max-width: calc(100% - 340px); }
  .cv-mission { top: 60px; left: 24px; max-height: calc(100% - 150px); }
  .cv .hd { width: 12px; height: 12px; }

  /* Properties float over the bench while something is selected. */
  .cv-props {
    grid-area: bench; justify-self: end; align-self: stretch; width: 270px; margin: 16px; border: 1px solid var(--line); border-radius: 18px;
    box-shadow: 0 10px 30px rgba(20,33,61,.12); gap: 16px; z-index: 4;
  }
  .cv:not([data-has-selection]) .cv-props { display: none; }
  .cv-props-titles { flex-direction: column-reverse; align-items: flex-start; gap: 2px; }
  .cv-props-titles h2 { flex: none; }
  .cv-kind { background: none; padding: 0; }
  .cv-props .cv-actions { order: 99; margin-top: auto; }
  .cv-props .cv-actions .danger { margin-left: auto; }
  .cv-minmax { display: none; }

  /* Readings strip, with the table and graph opening over the bench. */
  .cv-strip {
    display: flex; background: #fff; border-top: 1px solid var(--line); padding: 14px 16px; box-sizing: border-box; align-items: center; gap: 10px;
  }
  .cv-strip .cv-tiles { flex: 1; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cv-strip-actions { display: flex; flex-direction: column; gap: 8px; }
  .cv-strip-actions .btn { height: 40px; }
  .cv-obs {
    grid-area: bench; margin: 16px; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 10px 30px rgba(20,33,61,.16); z-index: 5;
    overflow: auto; align-self: start; max-height: calc(100% - 32px); box-sizing: border-box;
  }
  .cv:not([data-obs-open]) .cv-obs { display: none; }
  .cv-obs .cv-tiles { display: none; }
}

/* ---- Phone < 768px ---------------------------------------------------------------------- */
@media (max-width: 767px) {
  .cv .cv-picker { position: fixed; inset: 0; width: auto; height: auto; max-height: none; border-radius: 0; border: 0; }
  .cv-picker-grid { grid-template-columns: 1fr; }
  .cv {
    --ib: 44px; --btn-h: 44px; --btn-fs: 15px; --r: 12px; --chip-h: 44px; --chip-r: 12px; --chip-fs: 14px; --inp-h: 44px; --inp-fs: 15px; --range-h: 36px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 64px minmax(300px, 1fr) auto auto;
    grid-template-areas: "top" "bench" "tabs" "sheet";
  }
  .cv .cv-only-d, .cv .cv-only-t, .cv .cv-not-m, .cv-rail { display: none !important; }
  .cv-top { height: 64px; flex-wrap: nowrap; gap: 8px; padding: 0 12px; }
  .cv-heading { flex: 1 1 auto; }
  .cv-run { min-width: 96px; padding: 0 14px; }
  .cv .btn { padding: 0 14px; }

  .cv-toolbar { top: 10px; gap: 2px; border-radius: 16px; box-shadow: 0 4px 14px rgba(20,33,61,.1); }
  .cv-status { left: 10px; bottom: 10px; font-size: 12px; height: 28px; }
  .cv-mission { top: 64px; left: 10px; width: auto; right: 10px; max-width: none; max-height: calc(100% - 110px); }
  .cv-mission:not(.is-open) { right: auto; }
  .cv-mission:not(.is-open) .cv-mission-bar { width: 120px; }
  .cv .hd { width: 12px; height: 12px; }
  .cv-wire-hint { bottom: 46px; }

  .cv-tabs {
    display: flex; flex-direction: column; gap: 12px; background: #fff; border-radius: 24px 24px 0 0; box-shadow: 0 -8px 24px rgba(20,33,61,.12);
    padding: 8px 16px 0; position: relative; z-index: 3;
  }
  .cv-tabs::before { content: ""; width: 40px; height: 5px; border-radius: 3px; background: #C5CFDC; align-self: center; }
  .cv-tablist { display: flex; gap: 4px; padding: 4px; background: #EEF1F6; border-radius: 12px; }
  .cv .seg { flex: 1; height: 40px; border: 0; border-radius: 10px; font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; background: transparent; color: var(--muted); }
  .cv .seg[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(20,33,61,.15); }

  .cv-tools, .cv-props, .cv-obs {
    grid-area: sheet; border: 0; max-height: 36dvh; overflow-y: auto; padding: 12px 16px 16px; gap: 14px; background: #fff; z-index: 3;
  }
  .cv:not([data-panel="add"]) .cv-tools, .cv:not([data-panel="props"]) .cv-props, .cv:not([data-panel="read"]) .cv-obs { display: none; }
  .cv-tools-head h2, .cv-tools .cv-search, .cv-chips, .cv-tools .sec { display: none; }
  .cv-groups { gap: 8px; }
  .cv-tiles-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  .cv-props-titles { flex-direction: column-reverse; align-items: flex-start; gap: 0; }
  .cv-props-titles h2 { flex: none; }
  .cv-kind { background: none; padding: 0; }
  .cv-props .cv-props-sel > .sec { display: none; }
  .cv-props-sel { flex-direction: row; align-items: center; gap: 8px; }
  .cv-props-head { flex: 1; min-width: 0; }
  .cv-props .cv-actions { flex-wrap: nowrap; }
  .cv-minmax { display: none; }
  .cv-seg-group { border: 0; padding: 0; gap: 8px; flex: 1; }
  .cv-seg-group .chip { flex: 1; }
  .cv-seg-group .chip:not([aria-pressed="true"]) { border-color: var(--control); }

  .cv-obs { gap: 10px; }
  .cv-obs-head { order: 2; }
  .cv-obs-head h2 { display: none; }
  .cv-obs-head .cv-record { flex: 1; background: var(--accent); border-color: var(--accent); color: #fff; }
  .cv-obs-body { gap: 10px; }
  .cv-obs .cv-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cv-obs .cv-tile:nth-child(n + 4) { display: none; }
  .cv-tile { padding: 8px 10px; }
  .cv-tile .mono { font-size: 16px; }
  .cv-table-wrap { max-height: 112px; }
  .cv-table-wrap th, .cv-table-wrap td { padding: 6px 10px; }
  .cv-toast { top: 136px; }
}
