/* Шарашка: the deck looks like a design-bureau drawing sheet — tracing-paper
   grid, a sheet frame with a wide binding margin, and a title block in the
   corner. Dark theme is a blueprint (cyanotype). */

:root {
  --paper: #f3f1ea;
  --grid: rgba(37, 78, 160, 0.07);
  --grid-major: rgba(37, 78, 160, 0.13);
  --ink: #16213e;
  --ink-soft: #4b5877;
  --ink-faint: rgba(22, 33, 62, 0.28);
  --accent: #c23a2b;
  --accent-2: #1d5bb8;
  --card: rgba(255, 255, 255, 0.62);
  --veil: rgba(243, 241, 234, 0.94);
  --shadow: 0 1px 0 rgba(22, 33, 62, 0.06);

  --f-head: "IBM Plex Sans Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", Roboto, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;

  --gap-l: 30px; /* binding margin of the sheet frame */
  --gap: 12px;
  --top-h: 52px;
  --bottom-h: 58px;
  --ease: cubic-bezier(0.2, 0.75, 0.15, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e2a4c;
    --grid: rgba(170, 205, 255, 0.06);
    --grid-major: rgba(170, 205, 255, 0.12);
    --ink: #eaf1fb;
    --ink-soft: #a3b8d6;
    --ink-faint: rgba(234, 241, 251, 0.3);
    --accent: #ffb04a;
    --accent-2: #82c6ff;
    --card: rgba(8, 28, 56, 0.6);
    --veil: rgba(14, 42, 76, 0.95);
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0e2a4c;
  --grid: rgba(170, 205, 255, 0.06);
  --grid-major: rgba(170, 205, 255, 0.12);
  --ink: #eaf1fb;
  --ink-soft: #a3b8d6;
  --ink-faint: rgba(234, 241, 251, 0.3);
  --accent: #ffb04a;
  --accent-2: #82c6ff;
  --card: rgba(8, 28, 56, 0.6);
  --veil: rgba(14, 42, 76, 0.95);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  color: var(--ink);
  font: 400 17px/1.5 var(--f-body);
  transition: background-color 0.4s, color 0.4s;
}

a { color: var(--accent-2); text-underline-offset: 3px; }
a:hover { color: var(--accent); }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Sheet chrome ---------- */

.frame {
  position: fixed;
  inset: var(--gap) var(--gap) var(--gap) var(--gap-l);
  border: 1.5px solid var(--ink);
  pointer-events: none;
  z-index: 5;
}

.topbar {
  position: fixed;
  top: var(--gap);
  left: var(--gap-l);
  right: var(--gap);
  height: var(--top-h);
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--ink);
  z-index: 6;
}

.rail {
  flex: 1;
  display: flex;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }

.rail__chapter {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  column-gap: 8px;
  align-items: center;
  padding: 6px 14px 7px;
  border-right: 1px solid var(--ink-faint);
  text-align: left;
  white-space: nowrap;
  color: var(--ink-soft);
  transition: color 0.3s, background-color 0.3s;
}
.rail__chapter:hover { color: var(--ink); }
.rail__chapter.is-current { color: var(--ink); background: var(--card); }
.rail__num {
  font: 500 11px/1 var(--f-mono);
  color: var(--accent);
}
.rail__name {
  font: 600 14px/1 var(--f-head);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.rail__ticks {
  grid-column: 1 / -1;
  display: flex;
  gap: 3px;
  margin-top: 5px;
}
.rail__ticks i {
  display: block;
  width: 10px;
  height: 3px;
  background: var(--ink-faint);
  transition: background-color 0.4s;
}
.rail__ticks i.is-done { background: var(--accent); }

.btn-toc {
  flex: none;
  padding: 0 16px;
  border-left: 1px solid var(--ink);
  font: 500 12px/1 var(--f-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.btn-toc:hover { background: var(--card); }
/* Both labels share one grid cell, so the button is as wide as the longer
   one and does not change size when the label swaps. */
.btn-toc { display: grid; place-items: center; }
.btn-toc > span { grid-area: 1 / 1; }
.btn-toc__close, .toc-open .btn-toc__open { visibility: hidden; }
.toc-open .btn-toc__close { visibility: visible; }
/* The top bar stays above the contents overlay; the chapter rail hides so
   that only the toggle is live there. */
.toc-open .topbar { z-index: 21; }
.toc-open .rail { visibility: hidden; }

.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.7s var(--ease);
}

.bottombar {
  position: fixed;
  left: var(--gap-l);
  right: var(--gap);
  bottom: var(--gap);
  height: var(--bottom-h);
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--ink);
  z-index: 6;
}

.hint {
  flex: 1;
  align-self: center;
  padding: 0 16px;
  font: 400 12px/1.3 var(--f-mono);
  color: var(--ink-soft);
  min-width: 0;
}

.btn-theme {
  flex: none;
  width: 48px;
  border-left: 1px solid var(--ink);
  font-size: 18px;
}
.btn-theme:hover { background: var(--card); }

/* Title block (основная надпись): organisation, product, sheet, sheets. */
.stamp {
  flex: none;
  display: grid;
  grid-template-columns: auto minmax(120px, auto) 64px 64px auto;
  border-left: 1px solid var(--ink);
  background: var(--card);
}
.stamp__cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 0 12px;
  border-right: 1px solid var(--ink);
  min-width: 0;
}
.stamp__cell small {
  font: 400 10px/1 var(--f-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.stamp__cell b {
  font: 600 15px/1.1 var(--f-head);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stamp__org b { font-size: 17px; letter-spacing: 0.12em; }
.stamp__nav { display: flex; }
.stamp__nav button {
  width: 52px;
  font: 500 20px/1 var(--f-mono);
}
.stamp__nav button + button { border-left: 1px solid var(--ink); }
.stamp__nav button:hover { background: var(--paper); color: var(--accent); }

.wipe {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), -60px 0 80px -20px var(--accent);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}
.wipe.is-on { animation: wipe 0.9s var(--ease); }
@keyframes wipe {
  0% { transform: translateX(var(--gap-l)); opacity: 0.9; }
  100% { transform: translateX(100vw); opacity: 0; }
}

/* ---------- Slides ---------- */

.deck {
  position: fixed;
  top: calc(var(--gap) + var(--top-h));
  bottom: calc(var(--gap) + var(--bottom-h));
  left: var(--gap-l);
  right: var(--gap);
  overflow: hidden;
}

/* Without JS the sheets stack into one long page. */
html:not(.js) .deck { position: static; overflow: visible; padding: 80px 0; }
html:not(.js) .topbar, html:not(.js) .bottombar, html:not(.js) .frame { display: none; }

.js .slide {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  visibility: hidden;
}

.js.is-ready .slide {
  transition:
    transform 0.8s var(--ease),
    opacity 0.55s ease,
    visibility 0s linear 0.8s;
}

.js .slide[data-place="right"] { transform: translate3d(16%, 0, 0); }
.js .slide[data-place="left"] { transform: translate3d(-16%, 0, 0); }
.js .slide[data-place="below"] { transform: translate3d(0, 12%, 0); }
.js .slide[data-place="above"] { transform: translate3d(0, -12%, 0); }
.js .slide[data-place="current"] {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.js.is-ready .slide[data-place="current"] {
  transition-delay: 0.1s, 0.1s, 0s;
}

.sheet {
  min-height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(24px, 4.5vh, 56px) clamp(20px, 4vw, 64px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

/* ---------- Typography ---------- */

h1, h2, h3 {
  margin: 0;
  font-family: var(--f-head);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: 0.01em;
}
h1 { font-size: clamp(2.6rem, 8vw, 7rem); text-transform: uppercase; letter-spacing: 0.05em; }
h2 { font-size: clamp(1.9rem, 4.4vw, 3.5rem); }
h3 { font-size: clamp(1.15rem, 1.9vw, 1.45rem); font-weight: 600; }
p { margin: 0; }

.kicker {
  font: 500 12px/1.3 var(--f-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.kicker::before { content: "— "; }

.lead {
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
  line-height: 1.5;
  max-width: 62ch;
  color: var(--ink);
}
.muted { color: var(--ink-soft); }
.small { font-size: 0.88em; }
em { font-style: normal; color: var(--accent); }

ul.list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}
ul.list li {
  position: relative;
  padding-left: 22px;
}
ul.list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 12px;
  height: 1px;
  background: var(--accent);
}

/* ---------- Building blocks ---------- */

.cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  gap: 14px;
}
.cols--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }

.cell {
  position: relative;
  border: 1px solid var(--ink);
  background: var(--card);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
}
.cell__h {
  display: block;
  margin: -14px -16px 12px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--ink);
  font: 500 11px/1.3 var(--f-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.cell h3 { margin-bottom: 6px; }
.cell p { color: var(--ink-soft); font-size: 0.95em; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(20px, 3.5vw, 48px);
  align-items: center;
}
.split > div { display: grid; gap: 16px; align-content: center; }

.spec {
  display: grid;
  grid-template-columns: max-content 1fr;
  margin: 0;
  border-top: 1px solid var(--ink);
}
.spec dt, .spec dd {
  margin: 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--ink-faint);
}
.spec dt {
  padding-right: 18px;
  font: 500 12px/1.6 var(--f-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 0;
  border: 1px solid var(--ink);
  background: var(--card);
}
.stat {
  padding: 16px 18px;
  border-right: 1px solid var(--ink-faint);
}
.stat:last-child { border-right: 0; }
.stat__n {
  display: block;
  font: 700 clamp(2rem, 4.2vw, 3.3rem)/1 var(--f-head);
  letter-spacing: 0.01em;
}
.stat__l {
  display: block;
  margin-top: 6px;
  font: 400 12px/1.35 var(--f-mono);
  color: var(--ink-soft);
}

.fig { margin: 0; display: grid; gap: 8px; justify-items: center; }
.fig img {
  display: block;
  max-width: 100%;
  height: auto;
}
.fig--shot img {
  border: 1px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink-faint);
}
.fig figcaption, .caption {
  font: 400 12px/1.4 var(--f-mono);
  color: var(--ink-soft);
  justify-self: start;
}
.fig figcaption b { color: var(--ink); font-weight: 500; }

.row-figs {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(8px, 2vw, 28px);
  flex-wrap: wrap;
}
.row-figs img { max-height: min(34vh, 300px); width: auto; max-width: 100%; }
.row-figs .fig { flex: 1 1 0; min-width: 0; }
.row-figs .fig img { margin: 0 auto; }
.diagram-wrap { overflow-x: auto; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  padding: 3px 9px;
  border: 1px solid var(--ink-faint);
  font: 400 12px/1.4 var(--f-mono);
  color: var(--ink-soft);
  background: var(--card);
}

.status {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font: 500 10px/1.5 var(--f-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  vertical-align: 2px;
  border: 1px solid currentColor;
}
.status--yes { color: var(--accent-2); }
.status--plan { color: var(--ink-soft); border-style: dashed; }

.note {
  border-left: 2px solid var(--accent);
  padding: 4px 0 4px 14px;
  color: var(--ink-soft);
  max-width: 70ch;
}

/* Dimension line: |<—— label ——>| */
.dim {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  font: 400 12px/1 var(--f-mono);
  letter-spacing: 0.06em;
  color: var(--accent);
}
.dim::before, .dim::after {
  content: "";
  flex: 1;
  height: 1px;
  background: currentColor;
}
.dim > span { white-space: nowrap; }
.dim--ends { border-left: 1px solid currentColor; border-right: 1px solid currentColor; padding: 6px 0; }

/* ---------- Title and chapter covers ---------- */

.slide--title .sheet { gap: 22px; }
.mark {
  font-size: clamp(3.2rem, 13vw, 10.5rem);
  letter-spacing: 0.08em;
  line-height: 0.92;
}
.title-aside {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 18px;
  font-size: 0.95em;
  color: var(--ink-soft);
}

.cover .sheet { gap: 14px; }
.cover__num {
  font: 700 clamp(6rem, 22vw, 15rem)/0.85 var(--f-head);
  color: transparent;
  -webkit-text-stroke: 2px var(--accent);
  letter-spacing: 0.02em;
}
.cover__label {
  font: 500 13px/1.3 var(--f-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.cover h2 { font-size: clamp(2.6rem, 7vw, 5.6rem); text-transform: uppercase; letter-spacing: 0.04em; }
.cover .split { align-items: end; }

/* ---------- Diagram ---------- */

.diagram { width: 100%; height: auto; max-height: 58vh; }
.diagram text { fill: var(--ink); font: 500 13px var(--f-mono); }
.diagram .dg-sub { fill: var(--ink-soft); font: 400 11px var(--f-mono); }
.diagram .dg-node { fill: var(--paper); stroke: var(--ink); stroke-width: 1.2; }
.diagram .dg-hub { fill: var(--paper); stroke: var(--accent); stroke-width: 2; }
.diagram .dg-link { stroke: var(--ink); stroke-width: 1.2; fill: none; }
.diagram .dg-mesh { stroke: var(--accent-2); stroke-width: 1.2; stroke-dasharray: 5 5; fill: none; }
.diagram .dg-zone { fill: none; stroke: var(--ink-faint); stroke-dasharray: 2 4; }
.diagram .dg-zone-label { fill: var(--ink-soft); font: 500 11px var(--f-mono); letter-spacing: 0.1em; }

/* ---------- Contents overlay ---------- */

.toc {
  position: fixed;
  /* Starts under the top bar: the toggle there stays visible and the list
     never scrolls beneath it. */
  inset: calc(var(--gap) + var(--top-h)) 0 0 0;
  z-index: 20;
  background: var(--veil);
  backdrop-filter: blur(3px);
  overflow-y: auto;
  padding: 20px 16px 28px;
}
.toc[hidden] { display: none; }
.toc__panel { max-width: 1100px; margin: 0 auto; }
.toc__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1.5px solid var(--ink);
  padding-bottom: 12px;
  margin-bottom: 20px;
}
.toc__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 22px 28px;
}
.toc__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--ink-faint);
  padding-bottom: 6px;
}
.toc__num { font: 500 11px var(--f-mono); color: var(--accent); }
.toc__slides { margin: 8px 0 0; padding: 0 0 0 22px; color: var(--ink-soft); font: 400 12px var(--f-mono); }
.toc__link {
  text-align: left;
  padding: 3px 0;
  font: 400 15px/1.35 var(--f-body);
  color: var(--ink-soft);
}
.toc__link:hover { color: var(--ink); }
.toc__link.is-current { color: var(--accent); }

/* ---------- Narrow screens ---------- */

@media (max-width: 860px) {
  :root { --gap-l: 16px; --gap: 8px; --top-h: 46px; --bottom-h: 48px; }
  body { font-size: 16px; }
  .hint { display: none; }
  .bottombar { justify-content: flex-end; }
  .btn-theme { border-left: 0; margin-right: auto; border-right: 1px solid var(--ink); }
  .stamp { grid-template-columns: minmax(0, 1fr) auto auto; flex: 1; }
  .stamp__org, .stamp__total { display: none !important; }
  .stamp__cell b { font-size: 13px; }
  .stamp__nav button { width: 48px; }
  .rail__chapter { padding: 6px 10px 7px; }
  .rail__chapter:not(.is-current) .rail__name { display: none; }
  .split { grid-template-columns: 1fr; }
  .sheet { justify-content: flex-start; padding-top: 22px; padding-bottom: 28px; }
  .cover .sheet, .slide--title .sheet { justify-content: center; }
  .spec { grid-template-columns: 1fr; }
  .diagram { min-width: 640px; max-height: none; }
  .spec dt { padding-bottom: 0; border-bottom: 0; }
  .stat { border-right: 0; border-bottom: 1px solid var(--ink-faint); }
  .stat:last-child { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .js.is-ready .slide, .progress i { transition-duration: 0.01s !important; transition-delay: 0s !important; }
  .js .slide[data-place] { transform: none; }
  .wipe { display: none; }
}
