:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5b6470;
  --line: #d9dee5;
  --accent: #1f5fbf;
  --accent-soft: #e4edfb;
  --danger: #a8321f;
  --danger-soft: #fbe9e5;
  --ok: #1e7a46;
  --radius: 10px;
  --touch: 44px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
bdi, [dir="ltr"] { unicode-bidi: isolate; }

.skip {
  position: absolute; inset-block-start: -100px; inset-inline-start: 8px;
  background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 6px; z-index: 20;
}
.skip:focus { inset-block-start: 8px; }

.header { padding: 8px 16px; background: var(--surface); border-block-end: 1px solid var(--line); }
.header .top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.header h1 { font-size: 1.2rem; margin: 0; }
.header .stage-note { margin: 4px 0 2px; color: var(--muted); font-size: 0.95rem; }
.header .tag {
  display: inline-block; background: #fff4d6; border: 1px solid #e3c36a; border-radius: 999px;
  padding: 4px 12px; font-weight: 600; margin-block: 4px;
}
.header .meta { margin: 4px 0; }
.header details { margin-block-start: 6px; }
.header summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; }
.narrow-only { display: none; }

.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 0; min-height: 0;
}
.stage { position: relative; min-height: 0; background: #e9edf2; overflow: hidden; }
.viewer { position: absolute; inset: 0; outline: none; touch-action: none; }
.viewer:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); }
.viewer canvas { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(246, 247, 249, 0.85); padding: 16px; z-index: 5;
}
.overlay[hidden] { display: none; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; max-width: 520px; width: 100%; box-shadow: 0 6px 24px rgba(0,0,0,0.08);
}
.card.error { border-color: #e7b4aa; background: var(--danger-soft); }
.card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 12px; }

.panel {
  background: var(--surface); border-inline-start: 1px solid var(--line); overflow: auto; padding: 12px 16px 24px;
}
.panel h2 { font-size: 1.05rem; margin: 12px 0 6px; }
.panel .hint { color: var(--muted); margin: 0 0 8px; }
.btn {
  min-height: var(--touch); min-width: var(--touch); padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.btn:hover { background: var(--accent-soft); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #184c9a; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn .key { color: var(--muted); font-size: 0.9em; margin-inline-start: 6px; }

.selected { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--bg); margin-block: 8px; }
.selected .name { font-weight: 700; font-size: 1.05rem; }
.selected dl { margin: 6px 0 0; display: grid; grid-template-columns: 1fr; gap: 2px; }
.selected dt { color: var(--muted); font-size: 0.9em; margin-block-start: 6px; }
.selected dd { margin: 0; overflow-wrap: anywhere; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 0.9em; border: 1px solid var(--line); background: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.note { color: var(--muted); font-size: 0.95em; margin: 6px 0; }

.fallback { position: absolute; inset: 0; overflow: auto; padding: 24px 16px; background: var(--bg); display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.fallback[hidden] { display: none; }
.status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.statusbar { padding: 8px 12px; border-radius: 8px; background: var(--accent-soft); margin: 8px 0; }
.statusbar.error { background: var(--danger-soft); }

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: 52dvh minmax(0, 1fr); }
  .panel { border-inline-start: 0; border-block-start: 1px solid var(--line); border-start-start-radius: 16px; border-start-end-radius: 16px; }
  .header h1 { font-size: 1.1rem; }
  .header { padding: 8px 12px; }
  .header .wide { display: none; }
  .narrow-only { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- section & cycle ---- */
#cycle { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-block: 8px; background: #fbfcfe; }
#cycle .readouts { display: grid; grid-template-columns: 1fr; gap: 2px; margin: 8px 0; }
#cycle .readouts dt { margin-block-start: 6px; font-size: 0.9em; }
#cycle .readouts dt { color: var(--muted); }
#cycle .readouts dd { margin: 0; font-weight: 600; }
#cycle .phase-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); border: 1px solid var(--accent); }
#cycle .valve { display: inline-block; padding: 1px 8px; border-radius: 6px; border: 1px solid var(--line); margin-inline-end: 6px; }
#cycle .valve[data-open="true"] { background: #e8f5ec; border-color: #1e7a46; }
#cycle .valve[data-open="false"] { background: #f6f7f9; }
.cycle-bar .bar-valves { display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: 0.86rem; }
.cycle-bar .valve-slot, .cycle-bar .phase-pill, .cycle-bar .bar-angle { display: inline-block; white-space: nowrap; }
.cycle-bar .valve { white-space: nowrap; }
.cycle-bar .valve-slot > .valve { display: block; text-align: center; }
.cycle-bar .valve { display: inline-block; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); background: #f6f7f9; }
.cycle-bar .valve[data-open="true"] { background: #e8f5ec; border-color: #1e7a46; }
#cycle .valve[data-state="at_start"], #cycle .valve[data-state="opening"], #cycle .valve[data-state="closing"],
.cycle-bar .valve[data-state="at_start"], .cycle-bar .valve[data-state="opening"], .cycle-bar .valve[data-state="closing"] { background: #fff6dd; border-color: #c99a1d; }
#cycle .speed { font-weight: 600; margin: 6px 0; }
#cycle .insert-parts { margin: 6px 0; padding-inline-start: 18px; }
#cycle svg { width: 100%; height: auto; display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.section-banner {
  position: absolute; inset-inline-start: 12px; inset-block-start: 10px; max-inline-size: min(62%, 560px); z-index: 6; padding: 6px 12px;
  border-radius: 8px; background: rgba(255, 244, 214, 0.95); border: 1px solid #e3c36a; font-weight: 600; font-size: 0.9rem; line-height: 1.3;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.section-banner[hidden] { display: none; }
.badge.schematic { border-color: #c9ced6; background: #f1f3f6; }
.badge.derived { border-color: #9fc3f0; background: #eaf3fe; }
.badge.catalogue { border-color: #9fd3b0; background: #e8f5ec; }

/* ---- floating cycle bar ---- */
.cycle-bar {
  position: absolute; inset-inline: 12px; inset-block-end: 10px; z-index: 6; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: space-between;
  padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,0.94); border: 1px solid var(--line); box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.cycle-bar[hidden] { display: none; }
.cycle-bar .bar-row { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.cycle-bar .bar-angle { font-weight: 600; min-width: 3.2em; text-align: center; }
.cycle-bar .btn.view { background: #f3f5f8; }
.cycle-bar .btn.view[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
@media (max-width: 760px) {
  .cycle-bar { inset-block-end: 6px; inset-inline: 6px; padding: 4px 6px; gap: 4px 8px; }
  .section-banner { inset-inline: 6px; inset-block-start: 6px; max-inline-size: none; font-size: 0.82rem; padding: 4px 8px; }
}

/* ---- stage call to action while the section is closed ---- */
.open-fab {
  position: absolute; inset-block-end: 14px; inset-inline-start: 50%; transform: translateX(50%); z-index: 6;
  box-shadow: 0 4px 16px rgba(31, 95, 191, 0.3); font-weight: 600; padding-inline: 18px;
}
[dir="ltr"] .open-fab { transform: translateX(-50%); }
.open-fab[hidden] { display: none; }
.open-fab .key { color: rgba(255,255,255,0.8); }

/* ---- narrow windows: a taller stage and a more compact floating bar ---- */
@media (max-width: 760px) {
  .layout { grid-template-rows: 60dvh minmax(0, 1fr); }
  .header .tag { font-size: 0.85rem; padding: 2px 10px; margin-block: 2px; }
  .cycle-bar .key { display: none; }
  .cycle-bar .btn { padding: 6px 10px; }
  .cycle-bar .bar-row { gap: 4px 6px; }
}
/* сайт (SV-019): путь назад на описание работы на сайте */
.site-back { flex: none; display: flex; padding: 4px 16px; background: var(--surface); border-block-end: 1px solid var(--line); }
.site-back a { display: inline-flex; align-items: center; min-height: 48px; padding: 0 14px; font-size: 18px; border: 1px solid var(--line); border-radius: 8px;
  color: var(--accent); font-weight: 600; text-decoration: none; white-space: nowrap; }
.site-back a:hover { background: var(--accent-soft); }
.site-back a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* /сайт (SV-019) */
