:root {
  --bg: #e9eff6;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --ink: #1b2533;
  --ink-soft: #5b6b80;
  --line: #d3dce8;
  --accent: #0072b2;
  --accent-2: #e69f00;
  --danger: #c0392b;
  --ok: #1e8f5a;
  --radius: 10px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, "Arial Hebrew", "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

#app { display: grid; grid-template-columns: 1fr 460px; height: 100vh; }

/* ---------- 3D viewport ---------- */
#viewport-wrap { position: relative; overflow: hidden; min-width: 0; }
#viewport, #labels-layer { position: absolute; inset: 0; }
#labels-layer { pointer-events: none; z-index: 1; }
.ui-panel, #camera-bar { z-index: 3; }
#toast { z-index: 6; }
#viewport canvas { display: block; }
.hidden { display: none !important; }

.glass {
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(27, 37, 51, 0.08);
}

/* панель камер: один компактный ряд */
#camera-bar { position: absolute; top: 10px; left: 10px; display: flex; align-items: center; gap: 5px; padding: 5px 6px; flex-wrap: wrap; max-width: calc(100% - 270px); }
#camera-bar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }
#camera-buttons { display: flex; gap: 3px; flex-wrap: wrap; }
.cam-btn { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 4px 7px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.cam-btn kbd { font-family: ui-monospace, Menlo, monospace; font-size: 10.5px; background: #eef3f9; border-radius: 4px; padding: 0 4px; margin-right: 4px; color: var(--accent); }
.cam-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.cam-btn.active kbd { background: rgba(255,255,255,0.25); color: #fff; }
button.accent { background: var(--accent-2); color: #fff; border: 0; border-radius: 7px; padding: 5px 9px; font-size: 12px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.tool { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 4px 8px; font-size: 12px; cursor: pointer; color: var(--ink); white-space: nowrap; }
.tool:hover { border-color: #9fb4cc; }
.tool.icon { width: 26px; padding: 4px 0; text-align: center; font-weight: 700; }
.tool.on { background: #e8f1f9; border-color: var(--accent); color: var(--accent); }
.tool.restore { position: absolute; top: 10px; left: 10px; z-index: 4; box-shadow: 0 4px 14px rgba(0,0,0,0.12); }

#help-pop { position: absolute; top: 52px; left: 10px; z-index: 7; padding: 10px 12px; font-size: 12px; line-height: 1.7; min-width: 280px; }
#help-pop kbd { font-family: ui-monospace, Menlo, monospace; font-size: 11px; background: #eef3f9; border: 1px solid #d6e0ec; border-radius: 4px; padding: 0 5px; color: var(--accent); }
#help-close { display: none; }
#help-pop .muted { color: var(--ink-soft); font-size: 11px; line-height: 1.4; margin-top: 4px; }

/* показания: сворачиваются до Vm + рефрактерность */
#hud { position: absolute; top: 10px; right: 10px; width: 240px; padding: 8px 10px; font-size: 11.5px; }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.hud-label { color: var(--ink-soft); font-size: 10.5px; }
.hud-vm-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; margin-bottom: 4px; }
.hud-vm-value small { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.hud-row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-top: 1px dashed #e3e9f1; }
.hud-row b { font-weight: 600; text-align: right; }
.hud-row.small { font-size: 10.5px; color: var(--ink-soft); }
#hud.collapsed .hud-more { display: none; }
#hud.collapsed { width: 200px; }
.gate-bars { margin: 5px 0; display: grid; gap: 3px; }
.gate { display: grid; grid-template-columns: 58px 1fr 38px; align-items: center; gap: 6px; }
.gate i { display: block; height: 7px; background: #e6ecf3; border-radius: 4px; overflow: hidden; }
.gate em { display: block; height: 100%; width: 0; background: #0072b2; border-radius: 4px; transition: width 60ms linear; }
#bar-m { background: #e74c3c; }
#bar-h { background: #e69f00; }
#bar-kv { background: #1d6fa5; }
#bar-hcn { background: #8e44ad; }
.gate b { text-align: right; font-variant-numeric: tabular-nums; }

#badges { position: absolute; left: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.badge { background: rgba(27, 37, 51, 0.8); color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 6px; }
.badge.ok { background: rgba(30, 143, 90, 0.88); }
.badge.fail { background: rgba(192, 57, 43, 0.92); }
.badge.chip { cursor: help; }
#badge-time { background: rgba(0, 114, 178, 0.88); }

/* пояснение к ракурсу: появляется при смене камеры и само исчезает */
#camera-note { position: absolute; right: 10px; bottom: 10px; max-width: 340px; padding: 7px 8px 7px 10px; font-size: 11.5px; color: var(--ink-soft); display: flex; gap: 6px; align-items: flex-start; transition: opacity 0.4s; }
#camera-note.faded { opacity: 0; pointer-events: none; }
#viewport-wrap.lesson-on #camera-note { right: auto; left: 10px; bottom: 82px; }
#camera-note .tool.icon { flex: none; width: 20px; height: 20px; padding: 0; font-size: 10px; line-height: 18px; }
#toast { position: absolute; left: 50%; top: calc(var(--bar-bottom, 48px) + 50px); transform: translateX(-50%); padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; color: #fff; background: rgba(27,37,51,0.88); opacity: 0; transition: opacity 0.25s; pointer-events: none; max-width: 60%; text-align: center; }
#toast.show { opacity: 1; }
#toast.bad { background: rgba(192, 57, 43, 0.94); }
#toast.good { background: rgba(30, 143, 90, 0.94); }

/* режим «чистая сцена» (H) */
#viewport-wrap.ui-hidden .ui-panel, #viewport-wrap.ui-hidden #camera-bar, #viewport-wrap.ui-hidden #help-pop { display: none !important; }

/* 3D callouts (CSS2DRenderer) */
.callout { font-size: 11px; line-height: 1.25; padding: 3px 7px; background: rgba(255,255,255,0.9); border: 1px solid var(--line); border-left: 3px solid var(--c, #0072b2); border-radius: 5px; color: var(--ink); white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,0.08); transform: translateY(-14px); transition: opacity 0.18s; }
.callout b { font-weight: 700; }
.callout.small { font-size: 10px; padding: 2px 5px; }
.callout.warn { border-left-color: #c0392b; color: #8e1e12; }
.callout.flux { font-size: 10.5px; padding: 2px 6px; font-weight: 600; transform: none; }
.callout.occluded { opacity: 0; pointer-events: none; }
.callout.lead { transform: none; }
.labels-off .callout { display: none; }
.labels-main .callout.small, .labels-main .callout.zone { display: none; }
.overview .callout.small { display: none; }
#labels-layer:not(.overview) .callout.overview-only { display: none; }
#labels-layer.phone-labels .callout { white-space: normal; max-width: 70vw; }
#labels-layer.phone-labels .callout.occluded { visibility: hidden; }
#labels-layer.phone-labels .callout.overview-only,
#labels-layer.phone-labels .callout.small.zone { display: none; }
#labels-layer.phone-labels .callout.zone .zone-detail { display: none; }
#labels-layer.phone-labels .callout.zone[data-zone] { pointer-events: auto; cursor: pointer; }

/* ---------- Dock ---------- */
#dock { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: #f4f7fb; min-height: 0; }
.panel { padding: 10px 12px; }
#scope-panel { border-bottom: 1px solid var(--line); background: var(--panel-solid); flex: none; }
#scope-panel header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
#scope-panel h2 { font-size: 14px; margin: 0; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #e8f1f9; color: var(--accent); font-weight: 600; }
.pill.scenario { background: #fdf2e0; color: #a35f00; }
.pill.step { background: #efe6fa; color: #6b2fa6; }
.pill.scrub { background: #fde8e6; color: #a32e22; }
#scope { width: 100%; height: clamp(140px, 25vh, 225px); display: block; cursor: ew-resize; border-radius: 6px 6px 0 0; background: #0f1724; }
#scope-gates { width: 100%; height: clamp(70px, 10vh, 96px); display: block; cursor: ew-resize; border-radius: 0 0 6px 6px; background: #121c2b; border-top: 1px solid #24324a; }
.axis-label { font-size: 11px; color: var(--ink-soft); margin-top: 4px; }
#scope-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11px; color: var(--ink-soft); margin-top: 3px; }
.lg { display: inline-block; width: 14px; height: 8px; margin-right: 4px; vertical-align: middle; border-radius: 2px; }
.lg.trace { background: #4fc3f7; height: 3px; }
.lg.ref { border-top: 2px dashed #f0e442; height: 0; }
.lg.csv { background: #fff; width: 7px; height: 7px; border-radius: 50%; border: 2px solid #e69f00; }
.lg.abs { background: rgba(231, 76, 60, 0.45); }
.lg.norm { background: rgba(200, 210, 222, 0.85); height: 3px; }
.lg.pin { background: #d48df0; height: 3px; }
.scope-tools { display: flex; gap: 4px; align-items: center; }
.scope-tools .tool { font-size: 11px; padding: 3px 7px; }
.lg.rel { background: rgba(241, 196, 15, 0.4); }

#controls { overflow-y: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.group { background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 10px; }
.group h3 { font-size: 12.5px; margin: 0 0 7px; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.group h3 small { font-weight: 500; color: var(--ink-soft); font-size: 11px; }
.note { font-size: 11px; color: var(--ink-soft); margin: 6px 0 0; line-height: 1.35; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; }
.opt { border: 1px solid var(--line); background: #f8fafc; border-radius: 7px; padding: 5px 8px; font-size: 12px; cursor: pointer; text-align: start; line-height: 1.25; }
.opt:hover { border-color: #9fb4cc; }
.opt.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.opt.drug { border-left: 4px solid var(--c, #999); }
.opt.drug.active { background: #1b2533; border-color: #1b2533; border-left-color: var(--c); }
.opt:disabled { opacity: 0.45; cursor: not-allowed; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row + .row { margin-top: 6px; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 6px 10px; font-size: 12px; cursor: pointer; }
.btn.primary { background: var(--danger); color: #fff; border-color: var(--danger); font-weight: 700; }
.btn.primary:active { transform: translateY(1px); }
.btn.secondary { background: #1b2533; color: #fff; border-color: #1b2533; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
input[type=range] { flex: 1; accent-color: var(--accent); }
.val { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 54px; text-align: right; font-size: 12px; }
.checks { display: grid; gap: 4px; font-size: 12px; }
.checks label { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }
.step-info { font-size: 11.5px; background: #f6f1fd; border: 1px solid #e3d5f5; border-radius: 7px; padding: 6px 8px; margin-top: 6px; line-height: 1.35; }
.callout-box { font-size: 11.5px; border-radius: 7px; padding: 6px 8px; margin-top: 6px; line-height: 1.35; background: #fff8eb; border: 1px solid #f3dcae; }

/* ---------- Loading ---------- */
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); z-index: 50; gap: 14px; text-align: center; padding: 20px; }
#loading.gone { display: none; }
#loading.error p { color: var(--danger); max-width: 640px; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid #cfdbe8; border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 58vh 42vh; }
  #dock { border-left: 0; border-top: 1px solid var(--line); flex-direction: row; }
  #scope-panel { width: 50%; border-bottom: 0; border-right: 1px solid var(--line); overflow-y: auto; }
  #hud { width: 220px; }
}

/* ---------- Урок ---------- */
.lesson-btn { background: #6b2fa6; color: #fff; border: 0; border-radius: 7px; padding: 6px 11px; font-size: 12px; font-weight: 700; cursor: pointer; }
#lesson-card { position: absolute; right: 10px; bottom: 10px; width: min(380px, calc(100% - 20px)); padding: 8px 11px 9px; font-size: 12px; line-height: 1.42; border-left: 4px solid #6b2fa6; z-index: 5; }
#lesson-card .lesson-head { cursor: grab; user-select: none; }
#lesson-card.dragging .lesson-head { cursor: grabbing; }
#lesson-card .lesson-text { max-height: 34vh; overflow-y: auto; }
#lesson-card.folded h3 { margin-bottom: 4px; }
#lesson-card .lesson-head { display: flex; justify-content: space-between; align-items: center; }
#lesson-card .lesson-step { font-size: 11px; color: #6b2fa6; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
#lesson-card .lesson-tools button { border: 0; background: transparent; cursor: pointer; font-size: 13px; color: var(--ink-soft); padding: 0 4px; }
#lesson-card h3 { margin: 2px 0 5px; font-size: 14px; }
#lesson-card .lesson-hint { margin-top: 6px; font-size: 11.5px; color: #6b2fa6; background: #f6f1fd; border-radius: 6px; padding: 4px 7px; }
#lesson-card .lesson-hint:empty { display: none; }
#lesson-card .lesson-dots { display: flex; gap: 4px; margin: 8px 0 6px; }
#lesson-card .lesson-dots i { width: 18px; height: 4px; border-radius: 2px; background: #dfe5ee; }
#lesson-card .lesson-dots i.done { background: #b99ad8; }
#lesson-card .lesson-dots i.on { background: #6b2fa6; }
#lesson-card .lesson-nav { display: flex; gap: 6px; justify-content: flex-end; }
#lesson-card.folded .lesson-nav { margin-top: 2px; }
#lesson-card .lesson-nav .primary { background: #6b2fa6; border-color: #6b2fa6; }
#lesson-card.folded .lesson-body { display: none; }
.lesson-group { border-color: #d9c8ef; background: #fbf8ff; }
.lesson-group .lesson-start { background: #6b2fa6; border-color: #6b2fa6; }
.lesson-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 6px; }
.lesson-list .opt { font-size: 11.5px; }
.lesson-list .opt.active { background: #6b2fa6; border-color: #6b2fa6; }

/* сворачиваемые блоки панели управления */
.group h3.collapsible { cursor: pointer; user-select: none; }
.group h3.collapsible::before { content: '▾'; display: inline-block; width: 12px; color: var(--ink-soft); font-size: 10px; transition: transform 0.15s; }
.group.collapsed h3.collapsible::before { transform: rotate(-90deg); }
.group.collapsed > :not(h3) { display: none !important; }
.group.collapsed h3 { margin-bottom: 0; }
.group h3.collapsible { justify-content: flex-start; }
.group h3.collapsible small { margin-left: auto; }

/* подпись текущей фазы */
#phase-caption { position: absolute; left: 10px; top: calc(var(--bar-bottom, 48px) + 6px); max-width: min(620px, calc(100% - 290px)); padding: 6px 12px; font-size: 12.5px; font-weight: 600; display: flex; gap: 8px; align-items: center; transition: opacity 0.4s; pointer-events: none; }
#phase-caption.faded { opacity: 0; }
#phase-caption .dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: #9aa5b1; }
#phase-caption.ap .dot { background: #e74c3c; box-shadow: 0 0 0 3px rgba(231,76,60,0.2); }
#phase-caption.block .dot { background: #7b2cbf; }
#phase-caption.info .dot { background: #e69f00; }

/* справочная карточка объекта */
#info-card { position: absolute; z-index: 8; width: 330px; padding: 9px 11px; font-size: 12px; line-height: 1.42; }
#info-card .info-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; margin-bottom: 4px; }
#info-card .info-head b { font-size: 13.5px; }
#info-card #info-live { margin-top: 6px; padding: 5px 7px; background: #eef5fb; border-radius: 6px; color: #0b4f7a; font-size: 11.5px; font-variant-numeric: tabular-nums; }
#info-card #info-live:empty { display: none; }
#info-card .info-actions { margin-top: 6px; display: flex; justify-content: flex-end; }
#info-card .info-actions .hidden { display: none; }
#viewport canvas { cursor: default; }

/* ---------- иврит: раскладка окна не зеркалится (панель управления справа, как принято в RTL),
   справа налево идёт текст внутри панелей; графики осциллографа остаются слева направо ---------- */
html.lang-he #dock, html.lang-he #hud, html.lang-he #lesson-card, html.lang-he #info-card,
html.lang-he #camera-note, html.lang-he #phase-caption, html.lang-he #toast, html.lang-he #help-pop,
html.lang-he #loading, html.lang-he #camera-bar, html.lang-he #badges, html.lang-he .callout { direction: rtl; }
html.lang-he .callout { border-left: 1px solid var(--line); border-right: 3px solid var(--c, #0072b2); }
html.lang-he #lesson-card { border-left: 1px solid var(--line); border-right: 4px solid #6b2fa6; }
html.lang-he #badges { align-items: flex-start; }
html.lang-he .callout.flux { direction: rtl; }
html.lang-he .group h3.collapsible small { margin-left: 0; margin-right: auto; }
html.lang-he #lesson-card .lesson-nav { justify-content: flex-start; }
html.lang-he .val { text-align: left; }
html.lang-he #hud-vm, html.lang-he #hud-particles, html.lang-he #hud-point, html.lang-he #hud-pump,
html.lang-he .gate b, html.lang-he .val { direction: ltr; unicode-bidi: isolate; }
html.lang-he #hud-rest { unicode-bidi: plaintext; }
html.lang-he .hud-vm-value { direction: ltr; text-align: right; }
.formula { unicode-bidi: isolate; }

/* ---------- телефон: узкий экран или малая высота — одна колонка без выхода за края ----------
   Порядок сверху вниз: сцена → панель камер → показания → бейджи → осциллограф → блоки управления.
   Карточка объекта, урок и подсказка всплывают снизу, не заходя в левый нижний угол 140×56
   (там сайт ставит свою кнопку «На сайт»). На компьютере эти правила не действуют. */
@media (max-width: 760px), (max-height: 520px) and (max-width: 1100px) {
  html, body { height: auto; overflow-x: hidden; overflow-y: auto; }
  #app, #loading { --scene-h: max(300px, 56svh); }
  #app { display: block; height: auto; width: 100%; max-width: 100vw; overflow-x: hidden; }
  #app *, #loading * { font-size: 16px !important; line-height: 1.4; }
  #app h2, #app h3 { font-size: 17px !important; }

  /* сцена и наложенные на неё элементы */
  #viewport-wrap { display: flex; flex-direction: column; overflow: hidden; }
  #viewport { position: relative; inset: auto; height: var(--scene-h); flex: none; order: 0; }
  #labels-layer { inset: auto; top: 0; left: 0; right: 0; height: var(--scene-h); }
  #phase-caption { top: 8px !important; left: 8px; right: 8px; max-width: none; padding: 6px 10px; }
  #toast { top: calc(var(--scene-h) / 3); max-width: calc(100% - 24px); }
  #camera-note, #viewport-wrap.lesson-on #camera-note { left: 8px; right: 8px; bottom: calc(100% - var(--scene-h) + 8px); max-width: none; max-height: calc(var(--scene-h) - 70px); overflow-y: auto; align-items: center; }
  #btn-ui-restore { top: 8px; left: 8px; }
  #viewport-wrap.ui-hidden #camera-note { display: none !important; }

  /* под сценой, по очереди */
  #camera-bar { position: static; order: 1; max-width: none; margin: 8px; gap: 6px; }
  #camera-bar .sep { display: none; }
  #camera-buttons { gap: 6px; }
  #hud { position: static; order: 2; width: auto !important; margin: 0 8px 8px; padding: 6px 10px; }
  #app .hud-vm-value, #app .hud-vm-value > span { font-size: 28px !important; }
  #app .hud-vm-value small { font-size: 16px !important; }
  .gate { grid-template-columns: 92px 1fr 64px; }
  .gate i { height: 10px; }
  #badges { position: static; order: 3; margin: 0 8px 8px; flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .badge { padding: 4px 9px; max-width: 100%; }

  /* в уроке вольтметр нужен на виду: компактная плашка в правом верхнем углу сцены (как пишет урок) */
  #viewport-wrap.lesson-on #hud { position: absolute; top: 8px; right: 8px; left: auto; margin: 0; padding: 4px 6px 4px 10px; z-index: 4; }
  #viewport-wrap.lesson-on #hud.collapsed .hud-label, #viewport-wrap.lesson-on #hud.collapsed > .hud-row { display: none; }
  #viewport-wrap.lesson-on #hud .hud-top { align-items: center; gap: 10px; }
  #viewport-wrap.lesson-on #hud .hud-vm-value { margin: 0; }
  #viewport-wrap.lesson-on #phase-caption { top: 78px !important; }

  /* всплывающие окна: снизу, выше левого нижнего угла с кнопкой сайта */
  #info-card, #lesson-card {
    position: fixed; z-index: 30;
    left: 8px !important; right: 8px !important; top: auto !important; bottom: 72px !important;
    width: auto; max-height: calc(100svh - 88px); overflow-y: auto;
  }
  #lesson-card { max-height: min(48svh, calc(100svh - 88px)); display: flex; flex-direction: column; }
  #lesson-card .lesson-body { overflow-y: auto; min-height: 0; }
  #lesson-card .lesson-text { max-height: none; overflow: visible; }
  #lesson-card .lesson-head { cursor: default; }
  #lesson-card .lesson-tools { display: flex; gap: 6px; }
  #lesson-card .lesson-tools button { width: 48px; height: 48px; padding: 0; font-size: 18px !important; }
  #lesson-card .lesson-nav { flex-wrap: wrap; }
  #lesson-card .lesson-dots i { flex: 1; max-width: 22px; }
  #help-close { display: inline-block; float: inline-end; margin: -4px -6px 4px 8px; }
  #help-pop { position: fixed; z-index: 30; left: 8px; right: 8px; top: 8px; min-width: 0; max-height: calc(100svh - 88px); overflow-y: auto; }

  /* кнопки и поля не меньше 48 px */
  #app button, #app .opt, #app select { min-height: 48px; min-width: 48px; }
  .cam-btn, .tool, .btn, .opt, .lesson-btn, button.accent { padding: 8px 12px; }
  .tool.icon { width: 48px; padding: 0; }
  #camera-note .tool.icon { width: 48px; height: 48px; line-height: 1; }
  .checks label { min-height: 48px; align-items: center; }
  .checks input[type=checkbox] { width: 22px; height: 22px; flex: none; }
  input[type=range] { height: 48px; min-width: 0; }
  .val { min-width: 70px; }
  .group h3.collapsible { min-height: 48px; align-items: center; margin-bottom: 0; }
  .group:not(.collapsed) h3.collapsible { margin-bottom: 6px; }
  .group h3.collapsible::before { width: 20px; font-size: 16px; }
  .group h3 small { min-width: 0; overflow-wrap: anywhere; }
  .segmented, .lesson-list { grid-template-columns: 1fr; }
  .row { gap: 8px; }

  /* осциллограф и панели — под сценой, в общий поток страницы */
  #dock { display: block; border-left: 0; border-top: 1px solid var(--line); padding-bottom: 72px; }
  #scope-panel { width: auto; border-right: 0; overflow: visible; }
  #scope-panel header { flex-wrap: wrap; gap: 6px; }
  .scope-tools { flex-wrap: wrap; gap: 6px; }
  .scope-tools .tool { padding: 8px 12px; }
  #scope { height: 250px; }
  #scope-gates { height: 130px; }
  #scope-legend { gap: 6px 14px; }
  #controls { overflow: visible; flex: none; }
  .panel { padding: 10px 8px; }

  /* сцена: длинные подписи переносятся, а не уходят за край */
  .callout { white-space: normal; max-width: 70vw; }
}
/* лёжа: высоты мало — сцена занимает почти весь экран, под ней остаётся полоса для прокрутки */
@media (max-height: 520px) and (max-width: 1100px) {
  #app, #loading { --scene-h: max(240px, 80svh); }
  #info-card, #lesson-card, #help-pop { left: auto !important; width: min(460px, calc(100vw - 16px)); bottom: 8px !important; top: 8px !important; max-height: none; }
  /* урок — слева (вольтметр остаётся справа вверху), низ карточки выше угла с кнопкой сайта */
  #lesson-card { left: 8px !important; right: auto !important; top: 8px !important; bottom: 64px !important; width: min(460px, calc(50vw - 12px)); max-height: none; }
  #viewport-wrap.lesson-on #phase-caption { left: calc(min(460px, 50vw - 12px) + 16px); }
  #info-card { top: auto !important; max-height: calc(100svh - 16px); }
  #scope { height: 220px; }
}
