/* v5 «Рисовані історії»: бумага, тушь, кисть. Мобильная раскладка — основная (stories-first),
   десктоп (≥ 900px) — сетка историй и большая сцена. Бумажная текстура — --paper из v5.js. */

:root {
  --bg: #f7efe2;
  --card: #fffaf1;
  --ink: #2b211a;
  --muted: #6b5d50;
  --accent: #a94f26;
  --accent-ink: #8f421f;
  --rose: #e8506a;
  --gold: #c99a3a;
  --line: rgb(43 33 26 / 18%);
  --hand: "Segoe Print", "Bradley Hand", "Marker Felt", "Comic Sans MS", "Chalkboard SE", cursive;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: 16px;
  --radius: 22px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1915;
    --card: #26211c;
    --ink: #f1e8dc;
    --muted: #b9ab9b;
    --accent: #e08a5c;
    --accent-ink: #f0a47c;
    --line: rgb(241 232 220 / 18%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg) var(--paper, none) repeat;
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  overflow-x: hidden;
  padding-bottom: calc(76px + var(--safe-b));
}
html.st-open body { overflow: hidden; }
img, canvas, svg { display: block; }
a { color: var(--accent-ink); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--hand); font-weight: 700; line-height: 1.15; margin: 0 0 .4em; letter-spacing: -.01em; }
h2 { font-size: clamp(1.6rem, 6vw, 2.4rem); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; z-index: 50; }
.skip:focus { top: 8px; }
.defs { position: absolute; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

/* контур «от руки»: рамка в псевдоэлементе с SVG-фильтром — текст не дрожит */
.sketch { position: relative; }
.sketch::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  border: 2.5px solid var(--ink); border-radius: var(--radius);
  filter: url(#rough); opacity: .85;
}

/* лист бумаги под рисунком: в тёмной теме остаётся светлым — токены переопределены локально */
.stage, .cut-view {
  --ink: #2b211a; --card: #fffaf1; --muted: #6b5d50; --accent-ink: #8f421f; --bg: #f7efe2;
  color: var(--ink); background: #fffaf1 var(--paper-sheet, none) !important;
}

/* кнопки */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 22px; border: 0; border-radius: 999px; cursor: pointer;
  text-decoration: none; font-weight: 700; white-space: nowrap; transition: transform .2s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; border: 2.5px solid var(--ink);
  filter: url(#rough); pointer-events: none;
}
.btn:active { transform: scale(.97); }
.btn-ink { background: var(--ink); color: var(--bg); }
.btn-ghost { background: transparent; color: var(--ink); }
@media (hover: hover) { .btn:hover { transform: translateY(-2px) rotate(-.6deg); } }
.link-arrow { display: inline-block; margin-top: 14px; font-weight: 700; text-underline-offset: 4px; text-decoration-thickness: 2px; }
.link-arrow::after { content: " →"; }
.chip-btn {
  min-height: 36px; padding: 4px 14px; border-radius: 999px; border: 2px solid var(--ink);
  background: var(--card); cursor: pointer; font-weight: 700; font-size: .9rem;
}
.chip-btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* ------------------------------------------------------------------ шапка */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.logo { display: inline-flex; flex-direction: column; color: var(--ink); text-decoration: none; margin-right: auto; }
.logo-w { font-family: var(--hand); font-weight: 700; font-size: 1.45rem; line-height: 1; }
.logo-u { width: 100%; height: 8px; margin-top: 2px; }
.logo-u path { fill: none; stroke: var(--rose); stroke-width: 3; stroke-linecap: round; }
.nav { display: none; gap: 22px; }
.nav a { color: var(--ink); text-decoration: none; font-weight: 600; }
.nav a:hover { text-decoration: underline wavy var(--rose); text-underline-offset: 6px; }
.lang { min-width: 44px; min-height: 44px; border: 2px solid var(--ink); border-radius: 50%; background: transparent; font-weight: 800; cursor: pointer; font-size: .8rem; }
.top-make { display: none; }

/* ------------------------------------------------------------------ кольца историй (телефон) */
.rings-wrap { padding: 4px 0 6px; }
.rings {
  display: flex; gap: 14px; overflow-x: auto; padding: 6px var(--gutter) 10px;
  scroll-snap-type: x mandatory; scrollbar-width: none;
}
.rings::-webkit-scrollbar { display: none; }
.ring {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: 78px; border: 0; padding: 0; background: none; cursor: pointer; scroll-snap-align: start;
}
.ring-pic {
  width: 74px; height: 74px; border-radius: 50%; padding: 3px;
  background: conic-gradient(from 200deg, var(--st-accent), var(--rose), var(--gold), var(--st-accent));
}
.ring.seen .ring-pic { background: var(--line); }
.ring-pic canvas {
  width: 100%; height: 100%; border-radius: 50%; background: var(--st-bg);
  border: 3px solid var(--bg); object-fit: cover;
}
.ring-t { font-size: .74rem; font-weight: 600; line-height: 1.2; text-align: center; color: var(--ink); }

/* ------------------------------------------------------------------ герой */
.hero { display: flex; flex-direction: column; gap: 18px; padding: 8px var(--gutter) 24px; }
.hero-copy { order: 2; }
.stage { order: 1; }
.eyebrow { margin: 0 0 6px; font-weight: 700; color: var(--accent-ink); text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; }
.hero h1 { font-size: clamp(2rem, 8.6vw, 3.6rem); margin: 0; }
.ink-line { width: min(280px, 70%); height: 16px; margin: 4px 0 10px; }
.ink-line path { fill: none; stroke: var(--rose); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 360; stroke-dashoffset: 360; animation: draw 1.4s .4s var(--ease) forwards; filter: url(#rough); }
@keyframes draw { to { stroke-dashoffset: 0; } }
.lead { font-size: 1.06rem; color: var(--muted); margin: 0 0 18px; max-width: 34em; }
.hero-btns { display: flex; flex-wrap: wrap; gap: 10px; }

.stage {
  margin: 0; aspect-ratio: 4 / 5; border-radius: var(--radius);
  background: var(--card) var(--paper-card, none);
}
.stage canvas.hero-sketch { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity .6s var(--ease); }
.stage .hero-3d { position: absolute; opacity: 0; pointer-events: none; transition: opacity .7s var(--ease); touch-action: pan-y; cursor: grab; }
.stage.live .hero-3d { opacity: 1; pointer-events: auto; }
.stage.live .hero-sketch { opacity: .1; }
/* подложка под 3D по яркости изделия (stageContrast): круг за моделью */
.stage .hero-3d { border-radius: 50%; }
.stage.on-dark .hero-3d { background: radial-gradient(closest-side, #4a3a2e, #3a2d24 62%, rgb(58 45 36 / 0%)); }
.stage.on-light .hero-3d { background: radial-gradient(closest-side, #fff8ec, #f3e7d4 62%, rgb(243 231 212 / 0%)); }
.hero-hint { position: absolute; top: 12px; left: 0; right: 0; margin: 0; text-align: center; font-family: var(--hand); color: var(--muted); font-size: .9rem; opacity: 0; transition: opacity .4s; pointer-events: none; }
.stage.live .hero-hint { opacity: 1; }
.stage figcaption {
  position: absolute; left: 14px; right: 14px; bottom: 56px; text-align: center;
  font-family: var(--hand); font-size: 1.02rem; line-height: 1.3;
}
.stage-link { white-space: nowrap; font-weight: 700; }
.stage-link::after { content: " →"; }
.stage-ctl { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 8px; }
.hero-dots { display: flex; gap: 2px; margin-right: auto; }
.hero-dots button { width: 36px; height: 36px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; padding: 0; }
.hero-dots i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); transition: background .3s, transform .3s; }
.hero-dots [aria-current="true"] i { background: var(--rose); border-color: var(--rose); transform: scale(1.2); }

/* ------------------------------------------------------------------ секции */
.sec { padding: 34px var(--gutter); }
.sec-lead { color: var(--muted); margin: 0 0 18px; max-width: 38em; }

/* истории: на телефоне — карусель, на десктопе — сетка */
.story-grid {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
  margin: 0 calc(-1 * var(--gutter)); padding: 4px var(--gutter) 14px; scrollbar-width: none;
}
.story-grid::-webkit-scrollbar { display: none; }
.scard {
  position: relative; flex: 0 0 58%; aspect-ratio: 9 / 16; border: 0; padding: 0; cursor: pointer;
  border-radius: 18px; overflow: hidden; background: var(--st-bg); color: #2b211a; text-align: left;
  scroll-snap-align: start; box-shadow: 0 2px 4px rgb(60 40 20 / 10%), 0 18px 34px -18px rgb(60 40 20 / 45%);
  transition: transform .3s var(--ease);
}
.scard.dark { color: #fdf6e8; }
.scard canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.scard-bars { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 4px; }
.scard-bars i { flex: 1; height: 3px; border-radius: 3px; background: currentColor; opacity: .3; }
.scard.seen .scard-bars i { opacity: .7; }
.scard-t { position: absolute; top: 22px; left: 12px; font-family: var(--hand); font-weight: 700; font-size: 1.05rem; }
.scard-c { position: absolute; left: 12px; right: 12px; bottom: 14px; font-family: var(--hand); font-size: .95rem; line-height: 1.25; }
@media (hover: hover) { .scard:hover { transform: translateY(-4px) rotate(-.8deg); } }

/* открытка */
.card-sec { display: flex; flex-direction: column; gap: 22px; }
.card-form { padding: 22px 18px; border-radius: var(--radius); background: var(--card) var(--paper-card, none); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-weight: 700; font-size: .92rem; flex: 1; min-width: 0; }
.field input, .field select {
  min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--ink);
  background: var(--bg); font-weight: 500; font-size: 1.05rem; width: 100%;
}
.field input { font-family: var(--hand); font-size: 1.2rem; }
.field-row { display: flex; gap: 12px; }
.card-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.card-view canvas {
  width: 100%; height: auto; aspect-ratio: 4 / 5; border-radius: 14px;
  box-shadow: 0 2px 6px rgb(60 40 20 / 12%), 0 26px 50px -24px rgb(60 40 20 / 50%);
  transform: rotate(-1.2deg);
}

/* вырубки */
.cut-sec { display: flex; flex-direction: column; gap: 18px; }
.cut-view { aspect-ratio: 1; border-radius: var(--radius); background: var(--card) var(--paper-card, none); }
.cut-view canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
/* телефон: одна полоса из нескольких силуэтов, листается пальцем */
.cut-chips {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)) 14px; padding: 6px var(--gutter) 8px; scroll-padding: 0 var(--gutter);
}
.cut-chips::-webkit-scrollbar { display: none; }
.cut-chips .chip { flex: 0 0 auto; scroll-snap-align: start; }
.cut-more { display: inline-block; margin-top: 10px; color: var(--muted); font-weight: 600; text-underline-offset: 4px; }
.cut-order { display: block; }
.chip {
  width: 52px; height: 52px; border-radius: 16px; border: 2px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer; padding: 8px; transition: transform .2s var(--ease), border-color .2s;
}
.chip svg { width: 100%; height: 100%; }
.chip use, .chip svg { fill: var(--ink); }
.chip .o-det { fill: var(--card); }
.chip[aria-pressed="true"] { border-color: var(--rose); background: color-mix(in srgb, var(--rose) 14%, var(--card)); transform: rotate(-4deg) scale(1.06); }
.chip[aria-pressed="true"] svg { fill: var(--rose); }

/* шаги */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; counter-reset: s; }
.steps li { position: relative; padding: 16px 16px 16px 64px; border-radius: 18px; background: var(--card) var(--paper-card, none); counter-increment: s; }
.steps li::before {
  content: counter(s); position: absolute; left: 14px; top: 14px; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--hand); font-weight: 700; font-size: 1.2rem;
  border: 2.5px solid var(--rose); color: var(--rose); filter: url(#rough);
}
.steps b { display: block; font-family: var(--hand); font-size: 1.15rem; }
.steps span { color: var(--muted); }

.foot { padding: 30px var(--gutter) 20px; color: var(--muted); font-size: .9rem; text-align: center; }
.foot p { margin: 4px 0; }

/* нижняя панель телефона */
.mbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; gap: 10px;
  padding: 10px var(--gutter) calc(10px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.mbar .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s var(--ease);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------------ сторис */
.story {
  padding: 0; border: 0; margin: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none;
  background: #000; color: #2b211a;
}
.story::backdrop { background: rgb(20 14 10 / 82%); backdrop-filter: blur(6px); }
.st-frame {
  position: relative; width: 100%; height: 100%; overflow: hidden; background: var(--st-bg, #fde6df);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.st-frame.dark { color: #fdf6e8; }
.st-frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.st-bars { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); left: 10px; right: 10px; display: flex; gap: 4px; z-index: 2; }
.st-bars span { flex: 1; height: 3px; border-radius: 3px; background: rgb(0 0 0 / 15%); overflow: hidden; }
.st-frame.dark .st-bars span { background: rgb(255 255 255 / 25%); }
.st-bars i { display: block; height: 100%; background: currentColor; transform-origin: left; transform: scaleX(0); }
.st-head { position: absolute; top: calc(22px + env(safe-area-inset-top, 0px)); left: 12px; right: 6px; display: flex; align-items: center; gap: 8px; z-index: 2; }
.st-dot { width: 30px; height: 30px; border-radius: 50%; background: var(--st-accent); border: 2px solid currentColor; }
.st-title { font-family: var(--hand); font-weight: 700; font-size: 1.05rem; margin-right: auto; }
.st-close { width: 44px; height: 44px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; color: inherit; }
.st-close svg, .st-prev svg, .st-next svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.st-text {
  position: absolute; left: 22px; right: 22px; top: 62%; margin: 0; z-index: 2;
  font-family: var(--hand); font-weight: 700; font-size: clamp(1.45rem, 7vw, 2rem); line-height: 1.22; text-align: center;
}
.st-text.in { animation: rise .6s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) rotate(-1deg); } }
.st-end { position: absolute; left: 22px; right: 22px; bottom: calc(26px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 3; }
.st-cta { width: 100%; max-width: 360px; min-height: 54px; font-size: 1.05rem; background: var(--st-accent); color: #fff; animation: pop .5s .2s var(--ease) both; }
.st-cta::before { border-color: rgb(0 0 0 / 35%); }
.st-hint { margin: 0; font-size: .85rem; opacity: .8; text-align: center; }
@keyframes pop { from { opacity: 0; transform: scale(.9); } }
.st-prev, .st-next {
  position: absolute; top: 50%; z-index: 3; width: 44px; height: 44px; margin-top: -22px; border-radius: 50%;
  border: 0; background: rgb(255 255 255 / 65%); color: #2b211a; cursor: pointer; display: grid; place-items: center;
  opacity: 0; transition: opacity .2s;
}
.st-prev { left: 8px; }
.st-next { right: 8px; }
.st-prev:focus-visible, .st-next:focus-visible { opacity: 1; }
@media (hover: hover) and (pointer: fine) { .st-frame:hover .st-prev, .st-frame:hover .st-next { opacity: 1; } }
/* на тач-экране невидимые стрелки не должны глотать свайп: касание уходит кадру (края листают) */
@media (hover: none), (pointer: coarse) { .st-prev, .st-next { pointer-events: none; } }

/* ------------------------------------------------------------------ планшет и десктоп */
@media (min-width: 900px) {
  :root { --gutter: 32px; }
  body { padding-bottom: 0; }
  .mbar, .rings-wrap { display: none; }
  .nav { display: flex; margin-right: 8px; }
  .top-make { display: inline-flex; }
  .top { padding: 14px var(--gutter); }
  .top .logo { margin-right: auto; }
  main, .foot { max-width: 1240px; margin: 0 auto; }
  .hero { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); align-items: center; gap: 40px; padding-top: 28px; }
  .hero-copy { order: 0; }
  .stage { aspect-ratio: 4 / 3.4; }
  .stage figcaption { font-size: 1.2rem; }
  .story-grid { display: grid; grid-template-columns: repeat(5, 1fr); overflow: visible; margin: 0; padding: 4px 0 0; gap: 18px; }
  .scard { flex: none; }
  .scard:nth-child(odd) { transform: rotate(-1deg); }
  .scard:nth-child(even) { transform: rotate(.8deg) translateY(10px); }
  @media (hover: hover) { .scard:hover { transform: translateY(-6px) rotate(0); } }
  .card-sec { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 48px; }
  .card-form { padding: 32px; }
  .card-view { max-width: 480px; justify-self: center; width: 100%; }
  .cut-sec { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); align-items: center; gap: 48px; }
  .cut-view { aspect-ratio: 5 / 4; }
  .cut-chips { flex-wrap: wrap; overflow: visible; margin: 0 0 16px; padding: 0; }
  .steps { grid-template-columns: repeat(3, 1fr); }
  .toast { bottom: 28px; }
  .story { background: transparent; width: 100vw; height: 100vh; place-items: center; }
  .story[open] { display: grid; }
  .st-frame { height: min(88vh, 880px); width: auto; aspect-ratio: 9 / 16; border-radius: 20px; box-shadow: 0 30px 80px -20px rgb(0 0 0 / 60%); }
  .st-prev { left: 10px; }
  .st-next { right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .ink-line path { stroke-dashoffset: 0; }
}
