@font-face {
  font-family: "Caveat";
  font-weight: 700;
  font-display: swap;
  src: url("fonts/caveat-cyrillic-700-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Caveat";
  font-weight: 700;
  font-display: swap;
  src: url("fonts/caveat-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #e9dfcb;
  --bg-lift: #f3ecdb;
  --paper: #f6f1e4;
  --ink: #2b3a2e;
  --green: #2f5d44;
  --cover: #2f5d44;
  --cover-edge: #234a36;
  --brass: #8a5f2a;
  --gold: #b88a45;
  --line: #c9bda2;
  --hand: "Caveat", "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 90% at 50% 30%, var(--bg-lift) 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 22px;
  line-height: 1.35;
  padding: max(14px, env(safe-area-inset-top)) 16px max(40px, env(safe-area-inset-bottom));
  overflow-x: hidden;
}

.grain { position: fixed; inset: 0; pointer-events: none; opacity: .09; mix-blend-mode: multiply; z-index: 3; }
.doodles { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.doodle {
  position: absolute;
  fill: none;
  stroke: var(--green);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .32;
  transform: rotate(var(--rot));
  animation: drift var(--dur) ease-in-out var(--delay) infinite alternate;
}
.doodle:nth-child(3n) { stroke: var(--brass); }
@keyframes drift {
  from { transform: translateY(-5px) rotate(calc(var(--rot) - 3deg)); }
  to { transform: translateY(6px) rotate(calc(var(--rot) + 3deg)); }
}

.masthead { position: relative; z-index: 1; text-align: center; height: 62px; }
.wordmark { margin: 0; font-size: 46px; line-height: 62px; font-weight: 700; color: var(--green); letter-spacing: .01em; }
.wordmark span { color: var(--brass); font-size: .6em; margin-left: 6px; vertical-align: .35em; }
.back { position: absolute; left: 0; top: 0; min-height: 44px; display: grid; place-items: center; color: var(--brass); text-decoration: none; font-size: 22px; }
.sound { position: fixed; top: max(10px, env(safe-area-inset-top)); right: 10px; z-index: 10; width: 48px; height: 48px; display: grid; place-items: center; background: transparent; border: 0; color: var(--green); cursor: pointer; }
.sound .wave { transition: opacity .2s ease; }
.sound.off .wave { opacity: 0; }
.sound:focus-visible { outline: 2px solid var(--green); outline-offset: -4px; border-radius: 50%; }

main { position: relative; z-index: 1; width: 100%; max-width: 680px; margin: 0 auto; }
.scene { text-align: center; padding-top: 6px; }

.hint { font-size: 22px; color: var(--brass); margin: 14px 0 18px; min-height: 1.3em; }
.ask { font-size: 34px; color: var(--green); margin: 30px 0 18px; }
.pageinfo { font-size: 22px; color: var(--brass); margin: 4px 0 16px; min-height: 1.3em; }

.buttons { display: grid; gap: 12px; justify-items: center; margin-top: 6px; }
.buttons.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 14px; }
button, .btn { font: inherit; color: var(--ink); cursor: pointer; }
.btn {
  --tilt: -.6deg;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  min-width: 52px;
  padding: 4px 22px 6px;
  font-size: 26px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 255px 14px 225px 14px / 14px 225px 14px 255px;
  transform: rotate(var(--tilt));
  transition: transform .12s ease, color .12s ease, background .12s ease;
}
.btn:nth-child(even) { --tilt: .7deg; border-radius: 14px 255px 14px 225px / 225px 14px 255px 14px; }
.btn.big { min-width: min(78vw, 300px); font-size: 30px; color: var(--green); }
.btn:hover, .btn:focus-visible { transform: rotate(var(--tilt)) translateY(-2px); background: #fffaf0; outline: none; }
.btn:focus-visible { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--green); }
.btn:active { transform: rotate(var(--tilt)) translateY(1px); }
.btn:disabled { color: var(--brass); border-style: dashed; cursor: default; background: transparent; }
.link { background: none; border: 0; font-size: 24px; color: var(--brass); text-decoration: underline wavy; text-underline-offset: 6px; min-height: 44px; padding: 0 10px; }
.link:hover, .link:focus-visible { color: var(--green); outline: none; }

.transport { display: flex; gap: 12px; justify-content: center; width: min(94vw, 520px); margin: 4px auto 0; }
.transport .btn.big { min-width: 0; flex: 1 1 auto; }
.speeds { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin: 14px 0 6px; }
.speeds button { background: none; border: 0; font-size: 23px; color: var(--brass); min-height: 44px; padding: 0 4px; }
.speeds button[aria-pressed="true"] { color: var(--green); text-decoration: underline wavy var(--green); text-underline-offset: 8px; }
.scrub { margin: 10px auto 0; width: min(94vw, 620px); padding: 0 6px; position: relative; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 44px;
  background:
    linear-gradient(var(--brass), var(--brass)) center / 100% 2px no-repeat,
    repeating-linear-gradient(90deg, var(--brass) 0 2px, transparent 2px calc(100% / 18)) center bottom / 100% 10px no-repeat;
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--brass); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: 8px;
  border-radius: 52% 48% 55% 45%;
  background: #f1d7a5;
  border: 2.5px solid var(--green);
}
input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: #f1d7a5; border: 2.5px solid var(--green); }
input[type="range"]:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---- Блокнот ---- */
.book {
  position: relative;
  width: min(94vw, 640px);
  aspect-ratio: 2.54;
  margin: 6px auto 0;
  container-type: inline-size;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.cover { position: absolute; inset: 0; background: var(--cover); border-radius: 1.4cqw; box-shadow: 0 1.6cqw 2.6cqw rgba(43, 58, 46, .28), inset 0 0 0 .5cqw var(--cover-edge); }
.leftpage { position: absolute; left: 3.4%; top: 7%; width: 46.3%; height: 86%; background: var(--paper); border-radius: 1cqw 0 0 1cqw; box-shadow: inset -1cqw 0 1.4cqw rgba(43, 58, 46, .08); }
.left-frame { position: absolute; inset: 6% 7% 7% 7%; border: .3cqw dashed rgba(43, 58, 46, .35); border-radius: 2cqw; pointer-events: none; }
.left-note { position: absolute; left: 14%; top: 24%; margin: 0; font-size: 3.4cqw; line-height: 1; color: var(--green); transform: rotate(-3deg); }
.left-arrow { position: absolute; left: 14%; top: 36%; width: 26%; fill: none; stroke: var(--green); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.left-small { position: absolute; right: 14%; bottom: 14%; margin: 0; font-size: 2.6cqw; line-height: 1; color: var(--brass); }

.pages { position: absolute; left: 50.8%; top: 2.5%; width: 45.6%; height: 95%; perspective: 150cqw; perspective-origin: 0 50%; }
.base { position: absolute; inset: 0; background: var(--paper); border-radius: 0 1cqw 1cqw 0; }
.page { position: absolute; inset: 0; transform-origin: left center; transform-style: preserve-3d; will-change: transform, opacity; }
.face, .back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--paper); border-radius: 0 1cqw 1cqw 0; box-shadow: inset 0 0 0 1px rgba(43, 58, 46, .12); }
.back { transform: rotateY(180deg); }
.back canvas { position: absolute; left: 5%; top: 5.5%; width: 90%; height: 82%; opacity: .22; transform: scaleX(-1); border-radius: 2.2cqw; }
.shot { position: absolute; left: 5%; top: 5.5%; width: 90%; height: 82%; border-radius: 2.2cqw; overflow: hidden; background: #e8e0cd; box-shadow: inset 0 0 0 .35cqw rgba(43, 58, 46, .35); }
.shot canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.shot::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 55%, rgba(246, 241, 228, .6) 100%); pointer-events: none; }
.stamp { position: absolute; right: 4%; bottom: 5%; z-index: 2; font-family: var(--mono); font-weight: 700; font-size: 2.1cqw; line-height: 1; color: #e0822c; text-shadow: 0 0 .5cqw rgba(224, 130, 44, .55); }
.ticks { position: absolute; left: 5%; right: 15%; top: 90.5%; height: 3.2%; background: repeating-linear-gradient(90deg, rgba(43, 58, 46, .5) 0 1px, transparent 1px 4.2%); }
.badge { position: absolute; right: 5%; bottom: 2.6%; width: 4.2cqw; height: 4.2cqw; display: grid; place-items: center; font-size: 2.6cqw; line-height: 1; color: var(--green); border: .3cqw solid var(--green); border-radius: 52% 46% 54% 48%; }
.shade { position: absolute; inset: 0; background: var(--ink); opacity: 0; pointer-events: none; border-radius: inherit; }

.ring { position: absolute; left: 50%; width: 4.6cqw; height: 3.4cqw; transform: translate(-50%, -50%); border: .6cqw solid var(--gold); border-radius: 50%; background: radial-gradient(ellipse at center, #4b3c25 0 45%, #7a6540 100%); box-shadow: 0 .3cqw .6cqw rgba(0, 0, 0, .3), inset 0 0 .3cqw rgba(255, 255, 255, .5); z-index: 100; pointer-events: none; }
.ring::before { content: ""; position: absolute; right: 100%; top: 50%; width: 2.6cqw; height: 1px; background: rgba(120, 90, 40, .55); }

/* ---- Камера ---- */
.camwindow { position: relative; width: min(94vw, 520px); aspect-ratio: 4 / 3; margin: 6px auto 0; background: var(--ink); border: 3px solid var(--ink); border-radius: 22px 18px 24px 16px / 18px 24px 16px 22px; overflow: hidden; }
.camwindow video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.camwindow video.mirror { transform: scaleX(-1); }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 150px; line-height: 1; color: var(--paper); text-shadow: 0 3px 0 var(--ink); pointer-events: none; }
.recbadge { position: absolute; left: 14px; top: 12px; display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-weight: 700; font-size: 15px; color: #fff; }
.recbadge i { width: 12px; height: 12px; border-radius: 50%; background: #d4412f; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.framecount { position: absolute; right: 14px; top: 12px; font-family: var(--mono); font-weight: 700; font-size: 15px; color: #fff; }
.flash { position: absolute; inset: 0; background: var(--paper); opacity: 0; pointer-events: none; }
.flash.on { animation: flash .18s ease-out; }
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }
.camerror { position: absolute; inset: 0; padding: 24px; display: grid; place-items: center; font-size: 24px; color: var(--paper); background: var(--ink); }
.shots { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; min-height: 40px; margin: 12px auto 0; max-width: 520px; }
.shots canvas { width: 36px; height: 27px; border: 2px solid var(--ink); border-radius: 4px; }

/* ---- Видео ---- */
.strip { position: relative; width: min(94vw, 520px); height: 60px; margin: 6px auto 0; border: 3px solid var(--ink); border-radius: 12px 16px 12px 18px; overflow: hidden; touch-action: none; cursor: ew-resize; }
.stripshots { display: flex; height: 100%; }
.stripshots canvas { flex: 1 1 0; min-width: 0; height: 100%; object-fit: cover; opacity: .75; }
.striphandle { position: absolute; top: 0; bottom: 0; border: 3px solid var(--green); background: rgba(47, 93, 68, .22); border-radius: 6px; pointer-events: none; }
.striphandle span { position: absolute; left: 50%; top: 50%; width: 4px; height: 24px; margin: -12px 0 0 -2px; border-radius: 2px; background: var(--green); }
.strip:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.paces { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin: 12px 0 16px; }
.paces button { background: none; border: 0; font-size: 26px; color: var(--brass); min-height: 44px; padding: 0 6px; }
.paces button[aria-pressed="true"] { color: var(--green); text-decoration: underline wavy var(--green); text-underline-offset: 8px; }

/* ---- Сборка ---- */
.stitch-doodle { width: 130px; height: 130px; margin: 60px auto 10px; display: block; fill: none; stroke: var(--green); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 260; animation: draw 1.6s ease-in-out infinite alternate; }
@keyframes draw { from { stroke-dashoffset: 260; } to { stroke-dashoffset: 0; } }
.stitch-text { font-size: 32px; color: var(--green); margin: 0 0 18px; }
.dots i { font-style: normal; animation: dots 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes dots { 0%, 60%, 100% { opacity: .2; } 30% { opacity: 1; } }
.stitch-bar { width: min(80vw, 320px); height: 14px; margin: 0 auto; border: 2.5px solid var(--ink); border-radius: 10px 6px 12px 7px; overflow: hidden; }
.stitch-bar div { height: 100%; width: 0; background: var(--green); transition: width .15s linear; }

.busy { position: fixed; inset: 0; background: rgba(233, 223, 203, .93); display: grid; place-items: center; text-align: center; font-size: 30px; color: var(--green); z-index: 5000; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 480px) {
  .wordmark { font-size: 40px; }
  .btn.big { font-size: 28px; }
  .countdown { font-size: 110px; }
}
@media (prefers-reduced-motion: reduce) {
  .doodle, .stitch-doodle, .recbadge i, .dots i { animation: none; }
  .btn, .sound .wave { transition: none; }
  .flash.on { animation: none; }
}
