/* v16 — интерактивное эссе. Общие токены, типографика, ручка, «почему».
   Вёрстки: v16-m.css (телефон, html[data-layout=m]) и v16-d.css (компьютер). */

:root {
  --paper: #f5f1e8;
  --paper-2: #ece6d9;
  --ink: #1d1b17;
  --ink-2: #5b554b;
  --line: #d6cdbb;
  --ember: #c4501c;
  --ember-soft: #f3d9c8;
  --ok: #2c7a4b;
  --ok-soft: #d7ecdf;
  --no: #b3261e;
  --no-soft: #f6d9d5;
  --card: #fffdf8;
  --stage-dark: radial-gradient(120% 90% at 50% 20%, #3a3631 0%, #1c1a17 70%);
  --stage-light: radial-gradient(120% 90% at 50% 20%, #fbf8f2 0%, #e4ddd0 75%);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14130f;
    --paper-2: #1e1c18;
    --ink: #f1ece2;
    --ink-2: #b3ab9d;
    --line: #3a362f;
    --ember: #f08a4b;
    --ember-soft: #43291b;
    --ok: #6cc893;
    --ok-soft: #1b3326;
    --no: #ff8a7f;
    --no-soft: #3d1d1a;
    --card: #1b1916;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.55 var(--sans);
  overflow-x: hidden;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
img { max-width: 100%; }

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 50;
  background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: 8px;
}
.skip:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--ember); outline-offset: 2px; }

/* ---------------------------------------------------------------- шапка */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font: 700 19px/1 var(--serif); text-decoration: none; letter-spacing: -0.01em; }
.top-tag { color: var(--ink-2); font-size: 13px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.lang { font-size: 14px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; white-space: nowrap; }

/* ---------------------------------------------------------------- кинетика */
.kin { font-family: var(--serif); font-weight: 600; letter-spacing: -0.015em; text-wrap: balance; }
/* маска слова с запасом под выносы глифов; после въезда маска снимается совсем */
.kin .w { display: inline-block; overflow: hidden; vertical-align: top;
  padding: 0.14em 0.16em 0.22em; margin: -0.14em -0.16em -0.22em; }
.kin.done .w { overflow: visible; }
.kin .wi { display: inline-block; transform: translateY(105%); transition: transform .7s cubic-bezier(.2,.7,.1,1); transition-delay: calc(var(--i) * 55ms); }
.kin.in .wi { transform: none; }

.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; color: var(--ember); font-weight: 700; margin: 0 0 10px; }
.lead { color: var(--ink-2); font-size: 18px; margin: 0 0 18px; max-width: 34em; }

/* ---------------------------------------------------------------- загрузка */
.boot { padding: 48px 16px; max-width: 720px; margin: 0 auto; }
.boot h1 { font: 600 40px/1.08 var(--serif); margin: 0 0 14px; }
.boot-stage {
  height: 46vh; border-radius: var(--r);
  background: linear-gradient(100deg, var(--paper-2) 30%, var(--paper) 50%, var(--paper-2) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -100% 0; } }
.fatal { color: var(--no); font-weight: 600; }

/* ---------------------------------------------------------------- герой */
.hero h1 { margin: 0 0 16px; }
.hero-qs { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.hero-qs a {
  display: flex; gap: 12px; align-items: baseline; text-decoration: none;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  font-family: var(--serif); font-size: 18px; line-height: 1.3;
}
.hero-qs a:hover { border-color: var(--ember); }
.hero-n { font: 700 13px/1 var(--sans); color: var(--ember); min-width: 1.2em; }
.hero-touch { color: var(--ink-2); font-size: 14px; margin: 0; }

/* ---------------------------------------------------------------- глава */
.ch { scroll-margin-top: 64px; }
.ch-n { margin: 0 0 6px; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--ember); font-weight: 700; }
.ch-head h2 { margin: 0 0 18px; }
.kick { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-2); font-weight: 700; }

.stage {
  position: relative; overflow: hidden; border-radius: var(--r);
  background: var(--stage-dark);
  isolation: isolate;
}
.stage.on-light { background: var(--stage-light); }
.stage-canvas, .stage .snap, .stage .poster {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
}
.stage .snap { object-fit: contain; }
.stage .poster { object-fit: cover; }
/* до первой модели движка — превью пресета (настоящая картинка изделия), потом 3D;
   глава без холста держит снимок своего последнего кадра */
.stage .poster { z-index: 1; pointer-events: none; }
.stage.has-glb .poster, .stage .snap { display: none; }
.stage.has-glb:not(.has-canvas) .snap { display: block; }
.stage::after {             /* полоса «работаю» поверх низа сцены */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--ember), transparent) 0 0 / 50% 100% no-repeat;
  opacity: 0; transition: opacity .2s;
}
.stage.is-busy::after { opacity: 1; animation: busy 1.1s linear infinite; }
@keyframes busy { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.no-webgl .stage .poster { display: block !important; }

/* пилюля статуса — единственное, что лежит поверх 3D */
.pill {
  position: absolute; left: 10px; top: 10px; z-index: 2; margin: 0;
  padding: 5px 10px 5px 24px; border-radius: 999px; font-size: 13px; font-weight: 600; line-height: 1.25;
  background: rgba(20, 18, 15, .72); color: #fff; backdrop-filter: blur(6px);
  max-width: calc(100% - 20px);
}
.pill::before {
  content: ""; position: absolute; left: 10px; top: 50%; width: 8px; height: 8px; margin-top: -4px;
  border-radius: 50%; background: #c9c1b3;
}
.pill:empty { display: none; }
.pill[data-state=ok]::before { background: #59d48c; }
.pill[data-state=no]::before, .pill[data-state=beyond]::before { background: #ff6b5e; }
.pill[data-state=building]::before, .pill[data-state=busy]::before { background: #f5b04b; animation: blink 1s infinite; }
.pill[data-state=off]::before { background: #9a9388; }
@keyframes blink { 50% { opacity: .3; } }

/* ---------------------------------------------------------------- ручка */
.knob { position: relative; margin: 14px 0 4px; }
.knob-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.knob-head label { font-weight: 600; }
.knob-val { font: 700 20px/1 var(--serif); color: var(--ember); font-variant-numeric: tabular-nums; }
.knob.is-bad .knob-val { color: var(--no); }
.knob-track { position: relative; height: 44px; display: flex; align-items: center; }
.knob-track::before {      /* дорожка: заштрихованные края «за межею», полоса «можна» */
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 10px; margin-top: -5px; border-radius: 6px;
  background:
    linear-gradient(90deg, transparent var(--lo), var(--ember-soft) var(--lo), var(--ember-soft) var(--hi), transparent var(--hi)),
    repeating-linear-gradient(135deg, var(--line) 0 4px, transparent 4px 8px);
  border: 1px solid var(--line);
}
.knob input[type=range] {
  position: relative; width: 100%; margin: 0; height: 44px; background: transparent;
  -webkit-appearance: none; appearance: none; touch-action: pan-y;
}
.knob input[type=range]::-webkit-slider-runnable-track { height: 44px; background: transparent; }
.knob input[type=range]::-moz-range-track { height: 44px; background: transparent; }
.knob input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 30px; height: 30px; margin-top: 7px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--ember); box-shadow: 0 2px 8px rgba(0,0,0,.25); cursor: grab;
}
.knob input[type=range]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; background: var(--card); border: 3px solid var(--ember); cursor: grab;
}
.knob.is-bad input[type=range]::-webkit-slider-thumb { border-color: var(--no); }
.knob.is-bad input[type=range]::-moz-range-thumb { border-color: var(--no); }
.knob-scale { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.knob-allowed { color: var(--ink); font-weight: 600; text-align: center; }
.knob-flag { display: block; min-height: 1.3em; font-size: 13px; color: var(--no); font-weight: 700; }

.text-row { display: grid; gap: 4px; margin: 4px 0 6px; }
.text-row label { font-weight: 600; }
.text-row input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  font: 600 18px/1.2 var(--serif); letter-spacing: .04em; min-width: 0; width: 100%;
}
.hint { font-size: 13px; color: var(--ink-2); margin: 2px 0 0; }
.attr { font-size: 11px; color: var(--ink-2); margin: 6px 0 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- текст главы */
.prose p { margin: 0 0 12px; font-family: var(--serif); font-size: 19px; line-height: 1.55; }
.live {
  font-family: var(--sans); font-weight: 700; font-size: .9em; color: var(--ember);
  border-bottom: 2px dotted currentColor; font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ---------------------------------------------------------------- «почему» */
.why {
  margin: 18px 0 0; padding: 14px 14px 12px; border-radius: var(--r);
  background: var(--card); border: 1px solid var(--line);
  border-left: 5px solid var(--line);
}
.why[data-mode=ok] { border-left-color: var(--ok); }
.why[data-mode=no] { border-left-color: var(--no); }
.why-h { margin: 0 0 8px; font: 700 15px/1.2 var(--sans); text-transform: uppercase; letter-spacing: .08em; }
.why[data-mode=ok] .why-h { color: var(--ok); }
.why[data-mode=no] .why-h { color: var(--no); }
.why-pic svg { display: block; width: 100%; height: auto; overflow: visible; }
.why-nums { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0; font-size: 15px; }
.why-nums dt { color: var(--ink-2); }
.why-nums dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.why-nums dd.is-bad { color: var(--no); }
.why-says-h { margin: 10px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-2); font-weight: 700; }
.why blockquote { margin: 0 0 6px; padding: 8px 10px; border-radius: 8px; background: var(--no-soft); font-weight: 600; }
.why ul { margin: 0; padding-left: 18px; }
.why li { margin: 0 0 3px; }
.why-tips li { color: var(--ink-2); }
.why[data-mode=off] p { margin: 0; color: var(--ink-2); }

/* SVG-сценки */
.w-track { stroke: var(--line); stroke-width: 6; stroke-linecap: round; }
.w-band { fill: var(--ok); opacity: .35; }
.w-ruler.is-bad .w-band { fill: var(--ink-2); opacity: .25; }
.w-tick { font: 600 11px var(--sans); fill: var(--ink-2); }
.w-num { font: 700 13px var(--sans); fill: var(--ink); }
.w-mark { transform: translateX(var(--to)); }
.why.play .w-mark { animation: markIn .8s cubic-bezier(.2,.8,.2,1) both; }
@keyframes markIn { from { transform: translateX(var(--from)); } to { transform: translateX(var(--to)); } }
.w-mark-head { fill: var(--ember); transform: translateY(18px); }
.w-mark-line { stroke: var(--ember); stroke-width: 2; transform: translateY(18px); }
.w-ruler.is-bad .w-mark-head { fill: var(--no); }
.w-ruler.is-bad .w-mark-line { stroke: var(--no); }
.w-ruler.is-bad .w-mark { animation-name: markIn, nudge; animation-duration: .8s, .35s; animation-delay: 0s, .8s; animation-iteration-count: 1, 2; }
@keyframes nudge { 50% { transform: translateX(calc(var(--to) + 4px)); } }

.w-scene { margin-top: 6px; }
.w-ground { stroke: var(--ink-2); stroke-width: 2; }
.w-limit { stroke: var(--ok); stroke-width: 1.5; stroke-dasharray: 5 4; }
.w-dim { stroke: var(--ember); stroke-width: 2; }
.w-body { fill: var(--ember-soft); stroke: var(--ember); stroke-width: 2; }
.w-scene.is-bad .w-body, .w-scene.is-bad .w-wax, .w-scene.is-bad .w-plaster { stroke: var(--no); }
.w-grow { transform-origin: 150px 154px; }
.why.play .w-grow { animation: grow .9s cubic-bezier(.2,.8,.2,1) both; }
@keyframes grow { from { transform: scaleY(.6); opacity: .4; } }

.w-plaster { fill: var(--paper-2); stroke: var(--ink-2); stroke-width: 1.5; }
.w-core-r { fill: var(--line); opacity: .7; }
.w-arrow { fill: none; stroke: var(--ember); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.why.play .w-core { animation: corePull 2.4s ease-in-out .3s both; }
@keyframes corePull { 0% { transform: none; } 45%, 70% { transform: translateY(-34px); } 100% { transform: none; } }
.w-crack { fill: none; stroke: var(--no); stroke-width: 2.5; stroke-linecap: round; }
.why.play .w-crack { stroke-dasharray: 60; animation: draw .6s ease-out 1s both; }
.why.play .w-d2 { animation-delay: 1.25s; }
@keyframes draw { from { stroke-dashoffset: 60; } to { stroke-dashoffset: 0; } }

.w-mold { fill: var(--line); stroke: var(--ink-2); stroke-width: 1.5; }
.w-wax { fill: var(--ember-soft); stroke: var(--ember); stroke-width: 2; }
.w-edge { fill: none; stroke: var(--ember); stroke-width: 2; opacity: .8; }
.why.play[data-mode=ok] .w-unscrew { animation: unscrew 2.6s ease-in-out .3s both; }
@keyframes unscrew { 0% { transform: none; } 45%, 60% { transform: translateY(-38px); } 100% { transform: none; } }
.why.play[data-mode=ok] .w-edge { animation: edgeRun 2.6s ease-in-out .3s both; }
@keyframes edgeRun { 45%, 60% { transform: translateX(10px); } }
.why.play[data-mode=no] .w-unscrew { animation: jam .5s ease-in-out .3s 3 both; }
@keyframes jam { 50% { transform: translateY(-5px); } }
.w-spin { transform-origin: 216px 70px; }
.why.play .w-spin { animation: spin 2.6s ease-in-out .3s both; }
@keyframes spin { 50% { transform: rotate(-30deg); } }

.w-mold-c { fill: var(--line); stroke: var(--ink-2); stroke-width: 1.5; }
.w-wax-c { fill: var(--ember-soft); stroke: var(--ember); stroke-width: 2; }
.w-letters { font-family: var(--sans); font-weight: 800; fill: var(--ink); }
.w-mir { fill: var(--ink-2); }
.w-scene.is-bad .w-letters { fill: var(--no); }
.w-box { fill: none; stroke: var(--ok); stroke-width: 1.5; stroke-dasharray: 4 3; }
.why.play .w-cast-top { animation: flipIn .9s cubic-bezier(.2,.8,.2,1) .5s both; transform-origin: 218px 84px; }
@keyframes flipIn { from { transform: scaleX(-1); opacity: .2; } }
.why.play .w-flow { animation: flow 1.2s ease-in-out .2s both; }
@keyframes flow { from { opacity: 0; transform: translateX(-10px); } }

/* ---------------------------------------------------------------- финал */
.build-body .label { margin: 0 0 8px; font-weight: 700; }
.pick { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
.pick-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); cursor: pointer; text-align: left;
}
.pick-chip[aria-checked=true] { border-color: var(--ember); box-shadow: inset 0 0 0 1px var(--ember); }
.pick-n { font-weight: 700; color: var(--ember); }
.pick-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.pick-chip[data-st=ok] .dot { background: var(--ok); }
.pick-chip[data-st=no] .dot { background: var(--no); }
.build-sum { font: 600 18px/1.4 var(--serif); margin: 0 0 12px; }
.build-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.build-note { min-height: 1.4em; margin: 0 0 6px; color: var(--ink-2); }
.build-price { margin: 0 0 12px; font-weight: 600; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 12px 22px;
  border-radius: 999px; border: 1px solid transparent; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--ember); color: #fff; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { border-color: var(--ink); }
.link { color: var(--ember); font-weight: 600; }

/* ---------------------------------------------------------------- оглавление */
.toc a { text-decoration: none; }
.toc a.is-on .toc-n { background: var(--ember); color: #fff; border-color: var(--ember); }
.toc-n {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); font-weight: 700; font-size: 13px; flex: none;
}

.foot { display: flex; gap: 16px; justify-content: space-between; flex-wrap: wrap; padding: 24px 16px 32px; color: var(--ink-2); font-size: 13px; border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------- без движения */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .kin .wi { transform: none; transition: none; }
  .boot-stage, .stage.is-busy::after, .pill::before { animation: none !important; }
  .why *, .why.play * { animation: none !important; transition: none !important; }
  .why.play .w-crack { stroke-dashoffset: 0; }
}
