/* «Сказки 1902»: буквы, обведённые со скана «Сказок русского народа» (М.: Ступин, 1902).
   Чего в книге нет (латиница, цифры), берётся из Old Standard TT — шрифта того же рисунка. */
@font-face { font-family: "Skazki 1902"; font-weight: 400; font-style: normal; font-display: swap; src: url(/fonts/skazki-1902.woff2) format("woff2"); }
@font-face { font-family: "Fairy Tales 1870"; font-weight: 400; font-style: normal; font-display: swap; src: url(/fonts/fairy-tales-1870.woff2) format("woff2"); }
:root { --serif: "Skazki 1902", "Fairy Tales 1870", "Old Standard TT", Georgia, serif; }
html[lang="en"] { --serif: "Fairy Tales 1870", "Skazki 1902", "Old Standard TT", Georgia, serif; }
@font-face { font-family: "Old Standard TT"; size-adjust: 90%; font-weight: 400; font-style: normal; font-display: swap; src: url(/fonts/old-standard-tt-cyrillic-400-normal.woff2) format("woff2"); unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }
@font-face { font-family: "Old Standard TT"; size-adjust: 90%; font-weight: 400; font-style: normal; font-display: swap; src: url(/fonts/old-standard-tt-latin-400-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+20AC,U+2122,U+2212; }
@font-face { font-family: "Old Standard TT"; size-adjust: 90%; font-weight: 400; font-style: italic; font-display: swap; src: url(/fonts/old-standard-tt-cyrillic-400-italic.woff2) format("woff2"); unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }
@font-face { font-family: "Old Standard TT"; size-adjust: 90%; font-weight: 400; font-style: italic; font-display: swap; src: url(/fonts/old-standard-tt-latin-400-italic.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+20AC,U+2122,U+2212; }

:root {
  --paper: #f2ead8;
  --ink: #2b231e;
  --red: #d23f27;
  --blue: #2c4aa0;
  --yellow: #f2c33d;
  /* ширина всего театра; на телефоне театр увеличен так, чтобы сцена заняла экран */
  --tw: calc(100vw - 16px);
  --sw: calc(var(--tw) * .38);   /* сторона квадрата со спиралью */
  --door: 12%;
}
@media (min-width: 820px) {
  :root { --tw: min(1100px, 94vw, calc((100svh - 150px) * 1.141)); --door: 10.5%; }
  .theatre { transform: translateX(-50%); }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
/* тёмно-синий бархат */
html { background: #0d1636; }
body {
  min-height: 100svh;
  background: #0d1636 url(/img/velvet.jpg) center top / cover no-repeat;
  color: var(--ink); font-synthesis: style;
  font-family: var(--serif); -webkit-font-smoothing: antialiased;
}
.sheet { padding: 18px 0 28px; overflow-x: hidden; }

.masthead { text-align: center; padding: 0 14px; }
.title {
  margin: 0; font-family: var(--serif); font-weight: 400;
  text-transform: uppercase; letter-spacing: .07em;
  font-size: clamp(20px, 5.4vw, 32px); line-height: 1;
  /* тиснение по бархату: в примятом месте ворс ложится и блестит, поэтому буквы светлее ткани,
     а край вдавленности сверху темнее */
  color: rgba(128,148,214,.62);
  text-shadow: 0 -1px 0 rgba(0,0,0,.55), 0 1px 1px rgba(170,190,250,.15);
}
.subtitle { margin: 8px 0 14px; font-size: 15px; color: #efe5cf; }

/* ---------- театр ---------- */
.view { position: relative; overflow: hidden; }
.theatre {
  position: relative; width: var(--tw); left: 50%;
  transform: translateX(-47%);       /* на телефоне центр сцены — по центру экрана */
}
.theatre-img { display: block; width: 100%; height: auto; filter: drop-shadow(0 6px 14px rgba(0,0,0,.55)); }
/* сцена: проём между кулисами, всё, что за краем, — за кулисами */
.spiral {
  position: absolute; left: 24%; top: 29.6%; width: 53.5%; height: 50.4%;
  overflow: hidden;
}
.status { margin: 14px 16px 0; text-align: center; font-size: 15px; color: #efe5cf; }
.status:empty { display: none; }
body.closed .status { visibility: hidden; }
.intro-line { margin: 6px 16px 0; text-align: center; }
.intro-link {
  border: 0; padding: 2px 0; background: none; cursor: pointer;
  font: 15px var(--serif); color: #f2c76a;
  text-decoration: underline; text-underline-offset: 3px;
}
.credits { margin: 14px 16px 0; font-size: 12px; line-height: 1.5; color: rgba(239,229,207,.55); text-align: center; }

/* ---------- окошки: фигурки на ниточках из-за кулис ---------- */
.door {
  --fw: calc(var(--tw) * .062 * var(--k, 1));
  position: absolute; top: 0; width: var(--fw);
  transform: translateX(-50%) rotate(0deg); transform-origin: 50% 0;
  display: flex; flex-direction: column; align-items: center;
  border: 0; padding: 0; background: none; cursor: pointer; pointer-events: none;
  -webkit-tap-highlight-color: transparent;
  animation: hang var(--dur, 4s) ease-in-out var(--delay, 0s) infinite;
}
/* витой красный шнур — кусок настоящей фотографии, повторяется по длине */
.door .thread {
  width: calc(var(--tw) * .0016); height: calc(var(--tw) * var(--len, .1)); flex: none;
  margin-bottom: -2px;
  background: url(/img/rope.webp) center top / 100% auto repeat-y;
  filter: drop-shadow(.5px 1px .6px rgba(30,20,10,.4));
}
.door img {
  display: block; width: 100%; height: auto; pointer-events: auto;
  transform: rotate(var(--r, 0deg));
  filter: drop-shadow(1px 2px 1.5px rgba(30,20,10,.45));
  transition: filter .3s, transform .3s; user-select: none; -webkit-user-select: none;
}
/* фигурка и привязанная к ней бирочка с номером дня (настоящий старый ярлык с бечёвкой) */
.door .fig { position: relative; display: block; width: 100%; }
.door .fig img { position: relative; z-index: 1; }
.door .tag {
  position: absolute; z-index: 0; top: 60%; left: calc(50% + var(--tx, 0%));
  width: 28%; aspect-ratio: 169 / 400;
  background: url(/img/tag.webp) 0 0 / 100% 100% no-repeat;
  transform: translateX(-67%) rotate(var(--tr, 0deg)); transform-origin: 67% 0;   /* висит на петле */
  filter: sepia(.45) saturate(1.3) brightness(.8) drop-shadow(.5px 1px .8px rgba(30,20,10,.5));   /* бумага потемнее, чтобы не сливалась с полом */
  pointer-events: auto; transition: opacity .6s;
}
.door .tag b {
  position: absolute; left: 2%; right: 12%; top: 56%;
  font: 400 calc(var(--tw) * .0095 * var(--k, 1)) / 1 var(--serif); color: #1e1712; text-align: center;
}
/* прочитанное окошко — ярлык снят */
.door.seen .tag { opacity: 0; pointer-events: none; }
@keyframes hang {
  0%, 100% { transform: translateX(-50%) rotate(-1.2deg); }
  50% { transform: translateX(-50%) rotate(1.2deg); }
}
.door:hover img, .door:focus-visible img { transform: rotate(var(--r, 0deg)) translateY(-3px); filter: drop-shadow(1px 3px 2px rgba(30,20,10,.5)) brightness(1.08); }
.door:focus-visible { outline: none; }
.door:focus-visible img { outline: 2px solid var(--yellow); outline-offset: 2px; }
.door.locked, .door.offact { display: none; }
/* смена действия: фигурки уезжают за ближнюю кулису */
.door.exit { animation: exit .95s cubic-bezier(.5,0,.75,.4) both; }
@keyframes exit {
  0% { transform: translateX(-50%) rotate(0deg); }
  100% { transform: translateX(calc(-50% + var(--tw) * var(--from))) rotate(calc(var(--from) * 30deg)); }
}
/* прочитанные отходят вглубь сцены: меньше и в тени */
.door .fig { transition: transform 1s ease, filter 1s ease; transform-origin: 50% 0; }
.door.seen .fig { transform: scale(.82); filter: brightness(.72) saturate(.85); }
/* действия под театром: I · II · III · IV */
.acts { display: flex; justify-content: center; gap: 4px; margin: 10px 0 0; }
.acts[hidden] { display: none; }
.acts button {
  font: 16px var(--serif); letter-spacing: .08em; color: rgba(239,229,207,.8);
  background: none; border: 0; padding: 4px 12px; cursor: pointer;
  border-bottom: 1px solid transparent;
}
.acts button.on { color: #f2c76a; border-bottom-color: currentColor; }
.acts button:disabled { color: rgba(239,229,207,.25); cursor: default; }
.acts button + button::before { content: "·"; position: relative; left: -10px; color: rgba(239,229,207,.35); }
/* не открытые ещё — чуть светятся */
.door.ready img { filter: drop-shadow(0 0 1.5px rgba(255,230,160,.9)) drop-shadow(1px 2px 1.5px rgba(30,20,10,.45)); }
/* сегодняшняя — качается сильнее */
.door.today { animation: hang-today 2.6s ease-in-out infinite; }
@keyframes hang-today {
  0%, 100% { transform: translateX(-50%) rotate(-4deg); }
  50% { transform: translateX(-50%) rotate(4deg); }
}
/* выход из-за кулисы: едет по колосникам и раскачивается, останавливаясь */
.door.enter { animation: enter 2.6s cubic-bezier(.3,.6,.25,1) var(--ed, .7s) both; }
@keyframes enter {
  0% { transform: translateX(calc(-50% + var(--tw) * var(--from))) rotate(0deg); }
  70% { transform: translateX(-50%) rotate(calc(var(--from) * -40deg)); }
  85% { transform: translateX(-50%) rotate(calc(var(--from) * 18deg)); }
  100% { transform: translateX(-50%) rotate(0deg); }
}
.door.flip { animation: jiggle .8s ease-out; }
@keyframes jiggle {
  0% { transform: translateX(-50%) rotate(0); }
  25% { transform: translateX(-50%) rotate(7deg); }
  55% { transform: translateX(-50%) rotate(-4deg); }
  80% { transform: translateX(-50%) rotate(2deg); }
  100% { transform: translateX(-50%) rotate(0); }
}

/* ---------- поле для кода внизу письма ---------- */
.gate { display: none; margin-top: 22px; padding-top: 16px; border-top: 1.5px solid rgba(44,74,160,.55); text-align: center; }
.letter.gate-mode .gate { display: block; animation: gatein .7s ease-out 2.3s both; }
@keyframes gatein { from { opacity: 0; transform: translateY(8px); } }
.ticket-text { margin: 0 0 10px; font-size: 15px; line-height: 1.45; }
.gate input {
  display: block; width: min(100%, 320px); margin: 0 auto; padding: 9px 12px;
  font: 17px var(--serif); text-align: center;
  color: var(--ink); background: #fffaf0; border: 1px solid rgba(43,35,30,.45); border-radius: 0;
}
.gate input:focus { outline: 2px solid var(--yellow); outline-offset: 1px; }
.gate button {
  display: block; width: min(100%, 320px); margin: 8px auto 0; padding: 10px; cursor: pointer;
  font: 400 16px var(--serif); text-transform: uppercase; letter-spacing: .1em;
  color: #fff8ea; background: var(--red); border: 0; border-radius: 0;
}
.gate button:disabled { opacity: .6; cursor: wait; }
.gate .buy {
  display: block; width: min(100%, 320px); margin: 0 auto; padding: 12px 10px; box-sizing: border-box;
  font: 400 17px var(--serif); text-transform: uppercase; letter-spacing: .1em; text-decoration: none;
  color: #fff8ea; background: var(--red); cursor: pointer;
}
.gate .buy:hover, .gate .buy:focus-visible { filter: brightness(1.08); }
.buy-note { margin: 8px auto 0; max-width: 320px; font-size: 13px; line-height: 1.4; color: rgba(43,35,30,.7); }
.gate .has-code {
  width: auto; margin: 12px auto 0; padding: 2px 0; background: none; color: var(--blue, #2c4aa0);
  text-transform: none; letter-spacing: 0; font-size: 15px;
  border-bottom: 1px solid currentColor;
}
.gate .has-code[hidden], .codebox[hidden] { display: none; }
.codebox { margin-top: 14px; }
.ticket-error { min-height: 1.2em; margin: 6px 0 0; font-size: 13px; color: var(--red); }

/* ---------- конверт и письмо ---------- */
.veil { position: fixed; inset: 0; z-index: 20; background: rgba(28,22,18,0); transition: background .5s; overflow: hidden; }
.veil[hidden] { display: none; }
.veil.on { background: rgba(28,22,18,.72); }
.envelope {
  position: absolute; left: 50%; bottom: 6svh; z-index: 2;
  width: min(88vw, 520px); height: auto;
  transform: translate(-50%, 130%) rotate(-2deg);
  transition: transform .65s cubic-bezier(.2,.8,.25,1);
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.35));
  pointer-events: none;
}
.veil.up .envelope { transform: translate(-50%, 0) rotate(-2deg); }
.veil.away .envelope { transform: translate(-50%, 160%) rotate(4deg); transition: transform .8s cubic-bezier(.5,0,.75,0) 1.5s; }
.letter {
  position: absolute; left: 50%; z-index: 1;
  /* лист целиком, в своих пропорциях 2 : 3 */
  width: min(90vw, 560px, 58svh); aspect-ratio: 2 / 3;
  top: var(--letter-top, 100svh);
  transform: translateX(-50%) rotate(-1deg);
  color: var(--ink);
  background: #efe6d2 url(/img/letter.jpg) center / 100% 100% no-repeat;
  box-shadow: 2px 3px 0 rgba(10,12,20,.4);
  clip-path: inset(0 0 calc(100% - var(--vis, 100%)) 0);
  transition: top 1.6s cubic-bezier(.3,.6,.25,1), transform .8s, clip-path 1.6s cubic-bezier(.3,.6,.25,1);
}
/* текст живёт внутри рамки из веточек и прокручивается там же */
.letter-inner {
  position: absolute; top: 10.5%; bottom: 9.5%; left: 13%; right: 13%;
  overflow-y: auto; overscroll-behavior: contain; padding-right: 2px;
  scrollbar-width: thin; scrollbar-color: rgba(44,74,160,.35) transparent;
}
.veil.away .letter { transform: translateX(-50%) rotate(0); }
.letter.free { transition: top 1.6s cubic-bezier(.3,.6,.25,1), transform .8s, clip-path .8s cubic-bezier(.5,0,.75,0); }
.letter:focus { outline: none; }
.close {
  position: absolute; z-index: 2; top: 1.2%; right: 1.5%; width: 32px; height: 32px; border: 0; cursor: pointer;
  font: 26px/30px var(--serif); color: var(--ink); background: none;
}
.kicker {
  margin: 0; font-family: var(--serif); text-transform: uppercase;
  letter-spacing: .12em; font-size: 12px; color: rgba(43,35,30,.6);
}
.letter h2 {
  margin: 4px 0 12px; padding-bottom: 10px; border-bottom: 1.5px solid rgba(44,74,160,.55);
  font-family: var(--serif); font-weight: 400; text-transform: uppercase;
  letter-spacing: .03em; font-size: clamp(19px, 5.2vw, 26px); line-height: 1.1; color: var(--red);
}
.body p { margin: 0 0 .75em; font-size: clamp(14px, 3.9vw, 16px); line-height: 1.5; text-align: justify; -webkit-hyphens: auto; hyphens: auto; }
.body p:last-child { margin-bottom: 0; }
.body a { color: var(--blue); text-underline-offset: 3px; }
.body .empty { color: rgba(43,35,30,.65); text-align: left; }
.media:empty { display: none; }
.media { margin: 0 0 18px; }
.media figure { margin: 0; }
.media img { display: block; width: 100%; height: auto; }
.media figcaption { margin-top: 6px; font-size: 12px; color: rgba(43,35,30,.6); }
.media audio, .media video { width: 100%; }
.media .frame { position: relative; aspect-ratio: 16 / 9; }
.media .frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.media > * + * { margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 30;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  padding: 9px 16px; font-size: 15px; width: max-content; max-width: 88vw; text-align: center;
  color: var(--ink); background: var(--paper); box-shadow: 2px 2px 0 rgba(10,12,20,.5);
  transition: opacity .3s, transform .3s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .door, .door.today, .door.flip, .door.enter, .door.exit { animation: none !important; }
}

/* ---------- телефон: весь театр, по нажатию сцена приближается ---------- */
.zoom-back, .zoom-hint { display: none; }
@media (max-width: 819px) {
  .theatre {
    transform: translateX(-50%);
    transform-origin: 47% 51.2%;            /* центр сцены */
    /* мягкий, медленный наезд, как камера: плавно трогается и долго тормозит */
    transition: transform 1.8s cubic-bezier(.37,0,.18,1);
    will-change: transform;            /* масштабирование на видеокарте — без рывков */
  }
  body.near .theatre { transform: translateX(-50%) scale(1.92); }
  body:not(.near) .door img { pointer-events: none; }   /* издалека нажимается вся сцена */
  body:not(.near) .theatre { cursor: zoom-in; }
  .zoom-hint {
    display: block; margin: 10px 16px 0; text-align: center; font-size: 15px;
    color: rgba(239,229,207,.8); transition: opacity .8s;
  }
  body.near .zoom-hint { opacity: 0; }
  .zoom-back {
    display: block; position: absolute; z-index: 6; top: 8px; left: 8px;
    padding: 7px 12px; border: 0; cursor: pointer;
    font: 15px var(--serif); color: var(--ink);
    background: var(--paper); box-shadow: 1px 2px 0 rgba(10,12,20,.45);
    opacity: 0; pointer-events: none; transform: translateY(-6px);
    transition: opacity .6s 1.2s, transform .6s 1.2s;
  }
  body.near .zoom-back { opacity: 1; pointer-events: auto; transform: none; }
}
