@import url('../assets/fonts/fonts.css');

:root {
  /* Playfair Display — высококонтрастный шрифт с плакатов, для заголовков.
     PT Serif сделан под русский и держит мелкий текст. Оба лежат локально. */
  --display-font: "Playfair Display", Georgia, "Times New Roman", serif;
  --body-font: "PT Serif", Georgia, "Times New Roman", serif;

  --gold: #d8a441;
  --ink: #f3ead6;
  --muted: #a2937a;
  --primary: #5b4bd6;

  /* Киоск всегда работает в вертикальном 9:16. На вертикальном мониторе это
     весь экран, на обычном — полоса по центру. Так макет один и тот же везде,
     и то, что видно при отладке, совпадает с тем, что увидит посетитель. */
  --stage-h: min(100vh, calc(100vw * 16 / 9));
  --stage-w: calc(var(--stage-h) * 9 / 16);
  /* Единицы сцены — замена vw/vh внутри киоска. Считать от окна нельзя:
     на горизонтальном мониторе сцена уже него, и вёрстка вылезала за края. */
  --sw: calc(var(--stage-w) / 100);
  --sh: calc(var(--stage-h) / 100);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; overflow: hidden; }

body {
  background: #000;
  color: var(--ink);
  font-family: var(--body-font);
}

/* Общая рамка сцены: всё, что растянуто «на весь экран», живёт внутри неё. */
.scene, .scene__veil, .screen {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: var(--stage-w);
  height: var(--stage-h);
}

/* ---------- фон эпохи ---------- */

.scene {
  background-image: url('../assets/scene/bg-gold.png');
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity .9s ease, filter .9s ease;
}
.scene.is-on { opacity: 1; }
.scene__veil {
  background:
    radial-gradient(120% 80% at 50% 42%, rgba(0,0,0,0) 45%, rgba(0,0,0,.42) 100%),
    linear-gradient(180deg, rgba(0,0,0,.34) 0%, transparent 26%, transparent 62%, rgba(0,0,0,.62) 100%);
  pointer-events: none;
}

/* Полоса света: главный переход киоска. Проходит поверх зала при смене
   эпохи и не касается ни рамы зеркала, ни живого отражения в стекле. */
.sweep {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: var(--stage-w);
  height: var(--stage-h);
  pointer-events: none;
  z-index: 3;
  opacity: 0;
}
.sweep.is-on { animation: sweep .7s cubic-bezier(.22,.61,.36,1); }
.sweep.is-back { --dir: -1; }
@keyframes sweep {
  from { opacity: 0; background-position: calc(var(--dir, 1) * -130%) 0; }
  18%  { opacity: 1; }
  82%  { opacity: 1; }
  to   { opacity: 0; background-position: calc(var(--dir, 1) * 130%) 0; }
}
.sweep.is-on {
  background-image: linear-gradient(105deg,
    transparent 30%, rgba(255,238,205,.34) 46%, rgba(255,246,225,.5) 50%,
    rgba(255,238,205,.34) 54%, transparent 70%);
  background-size: 260% 100%;
  background-repeat: no-repeat;
}
@media (prefers-reduced-motion: reduce) { .sweep.is-on { animation: none; } }

/* Текст лежит поверх рисованного зала, где есть и чёрное, и светлая луна.
   Тень под буквами — не украшение, а условие читаемости. */
.kicker, .lead, .display, .screen__title, .confirm__text,
.epoch-hint, .book-about, .hold__caption, .attract__brand,
.result__title, .result__caption, .share__lead, .share__note,
.shot__hint, .stage__hint, .generate__title, .generate__status {
  text-shadow: 0 2px 10px rgba(6,4,2,.9), 0 0 30px rgba(6,4,2,.7);
}

/* ---------- экраны ---------- */

/* Скрытие — через display: оно срабатывает мгновенно и не может «застрять»,
   поэтому экраны никогда не накладываются друг на друга. Плавность даёт
   анимация появления, и она намеренно без fill-mode: если анимации почему-то
   не идут (окно свёрнуто, включён режим без движения), экран просто окажется
   сразу видимым. Отказ в худшую сторону — резкая смена, а не пустой экран. */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: calc(var(--sh) * 3) calc(var(--sw) * 4);
  text-align: center;
}
.screen.is-active {
  display: flex;
  animation: screen-in .45s ease;
}
@keyframes screen-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.994); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .screen.is-active { animation: none; }
}

.kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: .28em;
  font-size: clamp(11px, calc(var(--sw) * 1.5), 16px);
  color: var(--gold);
}
.display {
  margin: 10px 0 0;
  font-family: var(--display-font);
  font-size: clamp(30px, calc(var(--sw) * 6.4), 82px);
  font-weight: 600;
  letter-spacing: -.01em;
  text-shadow: 0 8px 40px rgba(0,0,0,.7);
}
.lead { margin: 14px 0 0; font-size: clamp(14px, calc(var(--sw) * 2), 24px); color: #e6dbc3; }
.screen__title {
  margin: 0;
  font-family: var(--display-font);
  font-size: clamp(20px, calc(var(--sw) * 3.4), 40px);
  font-weight: 600;
  text-shadow: 0 6px 24px rgba(0,0,0,.7);
}
/* Второе слово заголовка — акцентом эпохи: золото или серебро. */
.screen__title em { font-style: normal; color: var(--gold); }

/* ---------- приглашение ---------- */

.screen--attract { justify-content: flex-start; padding-top: calc(var(--sh) * 6); }
.attract {
  /* Позиционируем, чтобы текст лёг поверх фоновых слоёв: позиционированные
     элементы рисуются выше обычных, и без этого фон закрыл бы заголовок. */
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: calc(var(--sh) * 1);
  width: 100%; height: 100%;
}

/* Два зала на первом экране, сменяются перетеканием.
   Цикл: 30 с показа + 2.5 с перехода на слой, значит полный круг 65 с.
   Второй слой идёт с задержкой в половину круга — пока один гаснет,
   второй уже проявился, и чёрного провала между ними не бывает. */
.attract__bg {
  position: absolute; inset: 0;
  z-index: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  animation: attract-cycle 65s linear infinite;
}
.attract__bg--1 { background-image: url('../assets/scene/bg-attract-1.png'); }
.attract__bg--2 {
  background-image: url('../assets/scene/bg-attract-2.png');
  animation-delay: -32.5s;
}
@keyframes attract-cycle {
  0%      { opacity: 1; }
  46.15%  { opacity: 1; }   /* 30 с из 65 — держим кадр */
  50%     { opacity: 0; }   /* 2.5 с — перетекание */
  96.15%  { opacity: 0; }
  100%    { opacity: 1; }
}
/* Без движения показываем только первый зал: второй слой просто не проявляется. */
@media (prefers-reduced-motion: reduce) {
  .attract__bg { animation: none; }
  .attract__bg--2 { opacity: 0; }
}
.attract__brand {
  margin: 0; font-family: var(--display-font); line-height: 1.05;
  font-size: clamp(15px, calc(var(--sw) * 2.6), 28px);
  color: #e9dcbc;
}
.display em {
  font-style: normal;
  color: var(--gold);
}
.attract__foot {
  margin-top: auto;
  display: flex; flex-direction: column; align-items: center;
  gap: calc(var(--sh) * 1.4);
  padding-bottom: calc(var(--sh) * 2);
}
.attract__foot .hold__caption { margin: 0; }

/* Строка состояния под кнопкой: пока камера в порядке, она пустая,
   и место под ней не схлопывается — кнопка не прыгает при ошибке. */
.hold__caption {
  margin: 6px 0 0; min-height: 1.4em;
  color: #e2d6bb; font-size: clamp(13px, calc(var(--sw) * 1.7), 18px); letter-spacing: .04em;
}

/* ---------- выбор эпохи: плакат на фоне зала ---------- */

/* Свой фон: зал с бюстом Пушкина слева и ночным Петербургом справа — один
   на обе эпохи, потому что эпоха здесь ещё не выбрана. Лежит поверх общего
   фона сцены, поэтому остальные экраны своего света не теряют. */
.screen--epoch {
  justify-content: flex-start;
  gap: 0;
  /* По бокам полей нет: соседний плакат должен уходить за самый край экрана,
     как на референсе. Отступы держат на себе заголовок и нижняя панель. */
  padding: calc(var(--sh) * 4) 0 calc(var(--sh) * 2.5);
  background: url('../assets/scene/bg-epoch.png') center / cover no-repeat;
}
.screen--epoch .screen__title { margin-bottom: calc(var(--sh) * 1.5); }

/* Колода: карточки стоят в ряд, выбранная выведена в центр экрана.
   Соседняя выглядывает из-за края — видно, что эпоха не одна. */
.epoch-deck {
  --card-w: clamp(170px, calc(var(--sw) * 56), 560px);
  --card-gap: calc(var(--sw) * 6);
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.epoch-track {
  /* Сдвиг колоды в пикселях считает applyEpoch по реальной вёрстке: карточки
     живут в единицах сцены, а умножать их на число прямо в calc() браузер
     отказывается — получается ноль. */
  --shift: 0px;
  /* Растянут по колоде, карточки внутри centered: так у дорожки есть точная
     ширина, и сдвиг остаётся чистыми пикселями — без процентов, которые
     считаются от неё же. */
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  gap: var(--card-gap);
  transform: translateX(var(--shift));
  transition: transform .55s cubic-bezier(.22,.61,.36,1);
}

.epoch-card {
  position: relative;
  flex: none;
  width: var(--card-w);
  /* Пропорция до загрузки картинки; дальше renderEpochs ставит свою по файлу. */
  aspect-ratio: 3 / 4;
  padding: 0; border: 0; border-radius: 8px;
  background: none;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 26px 70px rgba(0,0,0,.7);
  transform: scale(.92);
  filter: brightness(.6) saturate(.85);
  transition: transform .55s cubic-bezier(.22,.61,.36,1), filter .55s ease, box-shadow .55s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.epoch-card img { width: 100%; height: 100%; display: block; border-radius: 8px; }
.epoch-card.is-active {
  transform: scale(1);
  filter: none;
  box-shadow: 0 34px 90px rgba(0,0,0,.78), 0 0 0 2px var(--gold);
}
.epoch-card:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

/* Стрелки сидят на краях выбранной карточки, как на референсе. */
.epoch-deck .arrow {
  position: absolute; top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}
.epoch-deck .arrow--prev { left: calc(50% - var(--card-w) / 2 - var(--sw) * 1.5); }
.epoch-deck .arrow--next { right: calc(50% - var(--card-w) / 2 - var(--sw) * 1.5); }

.epoch-bar {
  width: 100%;
  display: flex; flex-direction: column; align-items: center;
  gap: calc(var(--sh) * 1.2);
  padding: 0 calc(var(--sw) * 4);
  flex: none;
}
.epoch-hint {
  margin: 0; color: #d8cbae;
  font-size: clamp(12px, calc(var(--sw) * 1.6), 17px);
}

.confirm { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; justify-content: center; }
.confirm__text { margin: 0; font-size: clamp(13px, calc(var(--sw) * 1.7), 18px); color: #ddd0b4; line-height: 1.5; flex-basis: 100%; }
.confirm__text b { color: var(--gold); font-weight: 600; }
.btn--next { font-size: 18px; padding: 16px 44px; }
.btn--sm { font-size: 12.5px; padding: 8px 14px; border-radius: 9px; }

#s-writers { justify-content: flex-start; padding-bottom: 0; }

/* ---------- книги на полке ---------- */

/* Полка в три колонки: шесть писателей Золотого века встают двумя рядами,
   три писателя Серебряного — одним. Ширина карточки при этом одна и та же,
   поэтому эпохи выглядят как один каталог, а не как два разных экрана. */
.books {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: center; justify-items: center; align-items: center;
  gap: calc(var(--sh) * 2) calc(var(--sw) * 2);
  width: 100%;
  /* Полка занимает середину экрана: карточки — главный предмет выбора. */
  flex: 1 1 auto;
  min-height: 0;
  perspective: 1400px;
}

/* Корешок: потёртая ткань переплёта, тиснение, бинтовка. */
.book {
  position: relative;
  width: clamp(120px, calc(var(--sw) * 23), 300px);
  max-width: 100%;
  aspect-ratio: 3 / 4.6;
  border: 0;
  border-radius: 4px 10px 10px 4px;
  padding: calc(var(--sw) * 3) calc(var(--sw) * 2.4) calc(var(--sw) * 2.6) calc(var(--sw) * 5);
  font: inherit;
  color: inherit;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: calc(var(--sh) * 1);
  background:
    linear-gradient(100deg, #1e120a 0 5%, #3d2415 5% 8%, #5a3620 8%, #47291a 55%, #2e1a10 100%);
  box-shadow: 0 24px 60px rgba(0,0,0,.6), inset 0 0 0 1px rgba(216,164,65,.22);
  transform: rotateY(9deg) scale(.9);
  filter: brightness(.62) saturate(.85);
  transition: transform .38s cubic-bezier(.2,.8,.3,1.05), filter .38s ease, box-shadow .38s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* Обрез страниц по левому краю корешка. */
.book::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: calc(var(--sw) * 1.6);
  background: repeating-linear-gradient(180deg, #e8dcc0 0 2px, #c9b891 2px 4px);
  opacity: .5;
}
.book:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* Бинтовка — поперечные валики на корешке настоящей книги. */
.book__bands {
  position: absolute; left: calc(var(--sw) * 1.6); right: 0; top: 0; bottom: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, transparent 17%, rgba(216,164,65,.32) 17.4%, rgba(0,0,0,.3) 18.4%, transparent 18.8%),
    linear-gradient(180deg, transparent 79%, rgba(216,164,65,.32) 79.4%, rgba(0,0,0,.3) 80.4%, transparent 80.8%);
}

.book.is-active {
  transform: rotateY(0) translateY(calc(var(--sh) * -1.6)) scale(1.06);
  filter: none;
  box-shadow: 0 32px 80px rgba(0,0,0,.72), 0 0 0 2px var(--gold), inset 0 0 60px rgba(216,164,65,.14);
}

/* Медальон с портретом: то же, что человек увидит на себе. */
.book__medallion {
  width: 82%; aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(216,164,65,.55), 0 6px 18px rgba(0,0,0,.5);
  flex: none;
}
.book__portrait { width: 100%; height: 100%; display: block; }

.book__name {
  font-family: var(--display-font);
  font-size: clamp(12px, calc(var(--sw) * 1.9), 21px);
  line-height: 1.2;
  color: #f0dfb4;
  text-shadow: 0 1px 0 rgba(0,0,0,.6);
  margin-top: auto;
}
.book__years {
  font-size: clamp(10px, calc(var(--sw) * 1.2), 14px);
  letter-spacing: .1em;
  color: #c2a97c;
}

/* Блик по тиснению: золото ловит свет, когда книгу выбрали. */
.book__glint {
  position: absolute; inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 38%, rgba(255,231,170,.5) 50%, transparent 62%);
  opacity: 0;
}
.book.is-glinting .book__glint { animation: glint .75s ease-out; }
@keyframes glint {
  from { opacity: 0; transform: translateX(-60%); }
  35%  { opacity: 1; }
  to   { opacity: 0; transform: translateX(60%); }
}

.book-about {
  margin: 0; max-width: calc(var(--stage-w) * 0.86);
  font-family: var(--display-font);
  font-size: clamp(15px, calc(var(--sw) * 2.5), 26px);
  line-height: 1.4; color: #f0e4c8; min-height: 2.8em;
}

/* Готовый плакат: рамка, имя и годы уже нарисованы на картинке,
   поэтому вся отделка корешка здесь выключается. */
.book--poster {
  padding: 0;
  background: none;
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
  /* Пропорция до загрузки картинки; дальше renderBooks ставит свою по файлу,
     чтобы плакат не обрезался ни по рамке, ни по подписи внизу. */
  aspect-ratio: 2 / 3;
  width: 100%;
  height: auto;
  min-width: 0;
}
.book--poster::before { content: none; }
.book__poster { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 6px; }
/* В сетке карточка растёт на месте: разворот корешка тут ни к чему,
   а подъём вверх наезжал бы на соседний ряд. */
.book--poster { transform: scale(.94); }
.book--poster.is-active {
  transform: scale(1.04);
  z-index: 2;
  box-shadow: 0 32px 80px rgba(0,0,0,.72), 0 0 0 3px var(--gold);
}

/* Соседние карточки уходят за края: выбранная всегда в центре. */
.books { overflow: visible; }

/* Низ экрана писателей: панель с градиентом держит подпись и кнопки. */
.writers-bar {
  width: 100%;
  margin-top: auto;
  display: flex; flex-direction: column; align-items: center;
  gap: calc(var(--sh) * 2);
  padding: calc(var(--sh) * 6) calc(var(--sw) * 5) calc(var(--sh) * 5);
  background: linear-gradient(180deg, transparent, rgba(8,6,4,.85) 40%, rgba(8,6,4,.95));
}
.writers-bar .confirm { gap: calc(var(--sw) * 3); }

/* ---------- о писателе ---------- */

.screen--about { justify-content: center; gap: calc(var(--sh) * 3); }

.about {
  display: flex; flex-direction: column; align-items: center;
  gap: calc(var(--sh) * 1.2);
  max-width: calc(var(--stage-w) * 0.86);
  padding: calc(var(--sh) * 3) calc(var(--sw) * 5);
  border: 1px solid rgba(216,164,65,.28);
  border-radius: 16px;
  background: rgba(12,10,8,.72);
  backdrop-filter: blur(10px);
}
.about__name {
  margin: 0; font-family: var(--display-font); font-weight: 600;
  font-size: clamp(24px, calc(var(--sw) * 4.4), 46px);
}
.about__years {
  margin: 0; font-size: 14px; letter-spacing: .12em; color: var(--muted);
}
.about__story {
  margin: 0; line-height: 1.6; color: #e2d6bc;
  font-size: clamp(14px, calc(var(--sw) * 1.85), 19px);
}
.about__works { width: 100%; }
.about__label {
  margin: 0 0 6px; font-size: 11.5px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--gold);
}
.about__works ul {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-wrap: wrap; gap: 6px 10px; justify-content: center;
  font-size: clamp(12px, calc(var(--sw) * 1.5), 16px); color: #cbbea4;
}
.about__works li {
  padding: 4px 11px; border-radius: 999px;
  border: 1px solid rgba(216,164,65,.28);
}
.about__quote {
  margin: 0; font-family: var(--display-font); font-style: italic;
  font-size: clamp(14px, calc(var(--sw) * 2), 21px);
  color: #f0e4c8;
}

/* ---------- сцена съёмки ---------- */

.screen--stage,
.screen--editor { justify-content: center; gap: 0; padding: 0; }
/* Кадр во весь экран с небольшими полями. Экран и кадр оба 9:16, поэтому
   одинаковый процентный отступ со всех сторон сохраняет пропорцию: картинка
   ложится в окно один в один, без обрезки и без чёрных полей по бокам. */
.stage {
  position: relative;
  flex: none;
  height: calc(var(--sh) * 95);
  aspect-ratio: 9 / 16;
  max-width: calc(var(--sw) * 95);
  border-radius: 12px;
  overflow: hidden;
  background: #0a0806;
  box-shadow: 0 0 0 2px rgba(216,164,65,.4), 0 26px 70px rgba(0,0,0,.72);
}
#video { position: absolute; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
#canvas,
#editor-canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* Оснастка кадра: затвор, полка предметов и строка обработки. Лежит поверх
   низа кадра — иначе на 9:16 экране под неё пришлось бы ужимать сам кадр. */
.stage__deck {
  position: absolute; left: 0; right: 0; bottom: 0;
  z-index: 3;
  display: flex; flex-direction: column; align-items: center;
  gap: calc(var(--sh) * 1.2);
  padding: calc(var(--sh) * 8) calc(var(--sw) * 2.5) calc(var(--sh) * 2.2);
  background: linear-gradient(180deg, transparent, rgba(8,7,10,.55) 34%, rgba(8,7,10,.88));
  pointer-events: none;
}
.stage__deck > * { pointer-events: auto; }

/* Затвор над полкой значков: полка прижата к краю, кнопка стоит на этаж выше.
   Размер в единицах сцены — кнопка одинакова и в окне отладки, и на киоске. */
.shutter {
  position: relative;
  flex: none;
  z-index: 4;
  width: calc(var(--sw) * 12); height: calc(var(--sw) * 12);
  min-width: 56px; min-height: 56px;
  max-width: 132px; max-height: 132px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.45);
  background: rgba(21,19,31,.5);
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  cursor: pointer; z-index: 3;
  transition: background .16s ease, border-color .16s ease;
}
.shutter__icon { width: 46%; height: 46%; position: relative; z-index: 2; }
.shutter__icon path, .shutter__icon circle { fill: none; stroke: #fff; stroke-width: 2.1; stroke-linejoin: round; }
.shutter:hover,
.shutter:active { background: rgba(91,75,214,.85); border-color: #fff; }
.shutter:disabled { opacity: .4; cursor: default; }

/* Верхняя панель кадра: имя писателя и служебные кнопки. Лежит поверх кадра,
   а не под ним, — иначе сцена съёмки была бы ниже экрана снимка и картинка
   прыгала бы при переходе. */
.stage__top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 12px 14px 34px;
  background: linear-gradient(180deg, rgba(8,7,10,.72), transparent);
}
.stage__actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  padding: 7px 14px; border-radius: 999px;
  background: rgba(10,9,12,.6); backdrop-filter: blur(6px);
  border: 1px solid rgba(216,164,65,.35);
  font-size: 13px; color: #e6dbc3; white-space: nowrap;
}
/* Подсказка наверху: низ кадра занял затвор. */
.stage__hint {
  position: absolute; left: 50%; top: 68px; transform: translateX(-50%);
  margin: 0; padding: 8px 18px; border-radius: 16px;
  background: rgba(10,9,12,.6); backdrop-filter: blur(6px);
  font-size: clamp(12px, calc(var(--sw) * 1.5), 16px); color: #ddd0b4;
  /* Сцена узкая — подсказка переносится, а не вылезает за её край. */
  max-width: calc(100% - 24px); line-height: 1.5;
}
.stage__status {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(12,11,16,.88); font-size: 18px; padding: 30px; text-align: center;
}
.stage__status[hidden] { display: none; }
.stage__countdown {
  position: absolute; inset: 0; display: none; place-items: center;
  font: 600 min(calc(var(--sh) * 28), 220px)/1 Georgia, serif; color: #fff;
  text-shadow: 0 10px 50px rgba(0,0,0,.6);
}
.stage__countdown.is-on { display: grid; animation: pop .8s ease-out; }
@keyframes pop { from { transform: scale(1.5); opacity: 0 } 30% { opacity: 1 } to { transform: scale(1); opacity: .9 } }
.stage__flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.stage__flash.is-on { animation: flash .5s ease-out; }
@keyframes flash { from { opacity: .95 } to { opacity: 0 } }

/* ---------- результат ---------- */

/* Вертикальный экран: портрет сверху, панель действий снизу. */
.screen--result { flex-direction: column; gap: calc(var(--sh) * 1.6); padding: calc(var(--sh) * 3) calc(var(--sw) * 4); }
/* Flex, а не grid: у grid ряд авто-размера, и `max-height: 100%` у портрета
   считался бы от его же высоты — картинка не ужималась и лезла на панель. */
.portrait {
  flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
}
.portrait canvas,
.portrait__img {
  max-height: 100%; max-width: 100%;
  border-radius: 8px; box-shadow: 0 30px 80px rgba(0,0,0,.65);
}
/* Готовый портрет проступает, а не появляется щелчком. */
.portrait__img { transition: opacity .9s ease, transform .9s ease; }
.portrait__img.is-fading { opacity: 0; transform: scale(1.03); }
.result__title {
  margin: 0; font-family: var(--display-font); font-weight: 600;
  font-size: clamp(20px, calc(var(--sw) * 3.4), 40px);
}
.result__caption {
  margin: 0; max-width: calc(var(--stage-w) * 0.86);
  color: #d5c8ac; line-height: 1.5;
  font-size: clamp(13px, calc(var(--sw) * 1.8), 19px);
}

/* ---------- экран с QR ---------- */

/* Здесь посетитель достаёт телефон, поэтому на экране ровно одно действие:
   отсканировать. Код печати не дублируем — он есть на самой странице гостя. */
.screen--share { gap: calc(var(--sh) * 2); }
.share {
  background: #f3ead6;
  border-radius: 18px;
  padding: calc(var(--sw) * 3);
  box-shadow: 0 24px 60px rgba(0,0,0,.6), 0 0 0 2px rgba(216,164,65,.5);
}
/* QR должен читаться телефоном с расстояния вытянутой руки — отсюда размер. */
.share__qr {
  display: block;
  width: clamp(180px, calc(var(--sw) * 52), 520px);
  aspect-ratio: 1;
  image-rendering: pixelated;
}
.share__lead {
  margin: 0; max-width: calc(var(--stage-w) * 0.8);
  font-family: var(--display-font);
  font-size: clamp(15px, calc(var(--sw) * 2.4), 26px);
  line-height: 1.4; color: #f0e4c8;
}
.share__note {
  margin: 0; color: #bdae90;
  font-size: clamp(12px, calc(var(--sw) * 1.6), 17px);
}

/* ---------- наборная касса ---------- */

/* Лоток с гнёздами под кадром. Ячейки — обычные кнопки: палец по экрану
   и мышь попадают по ним точнее, чем распознавание кисти в воздухе. */
.case {
  /* Гнездо всегда одного размера, сколько бы предметов ни было у писателя:
     у кого-то их четыре, у кого-то пять, и растягивать ячейки под ширину
     экрана значит менять размер предмета от писателя к писателю.
     Лоток вместо этого сужается и остаётся по центру. */
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, calc(var(--sw) * 11.5));
  justify-content: center;
  gap: calc(var(--sw) * 1.6);
  max-width: 100%;
  padding: calc(var(--sw) * 2);
  border-radius: 14px;
  background: rgba(23,18,12,.82);
  border: 1px solid rgba(216,164,65,.3);
  flex: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 12%;
  border: 1px solid rgba(20,14,8,.75);
  border-radius: 8px;
  background: #e6dcc4;
  /* Гнездо утоплено в лоток: тень сверху, не рамка вокруг. */
  box-shadow: inset 0 3px 7px rgba(60,44,24,.32);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .16s ease, border-color .16s ease, transform .12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.cell:hover { border-color: var(--gold); }
.cell:active { transform: scale(.95); }
.cell:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* Предмет вынут из кассы и отпечатан: бумага по чернилам. */
.cell.is-worn {
  background: #241c12;
  border-color: var(--gold);
  box-shadow: inset 0 3px 8px rgba(0,0,0,.55), 0 0 0 1px rgba(216,164,65,.35);
}

.eng { width: 100%; height: 100%; display: block; overflow: visible; }
.eng path { fill: none; stroke: #241c12; stroke-linecap: round; stroke-linejoin: round; }
.eng .eng__out   { stroke-width: 5; }
.eng .eng__hatch { stroke-width: 2.5; opacity: .75; }
.cell.is-worn .eng path { stroke: #e6dcc4; }

/* Подпись показывается только на широких ячейках — иначе не читается. */
.cell__name {
  position: absolute; left: 50%; bottom: -2px;
  transform: translate(-50%, 100%);
  font-size: 11px; color: #cbbea4; white-space: nowrap;
  opacity: 0; transition: opacity .16s ease; pointer-events: none;
}
.cell:hover .cell__name { opacity: 1; }

.stage__bar {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; flex-wrap: wrap; flex: none;
}
.stage__bar .stage__hint {
  position: static; transform: none; margin: 0;
  background: none; backdrop-filter: none; padding: 0;
  font-size: clamp(12px, calc(var(--sw) * 1.6), 17px); color: #ccbfa3; max-width: none;
}

/* ---------- снимок готов ---------- */

/* Примерка идёт в той же рамке и того же размера, что и съёмка: переход
   со студии на этот экран не должен «дёргать» картинку. Поэтому у .screen--editor
   тот же .stage, а вся оснастка примерки лежит в общей .stage__deck. */

/* Панель выбранного предмета: минус, название, плюс. Кнопки крупные —
   по ним попадают пальцем, не глядя, пока вторая рука держит предмет. */
.tool {
  display: flex; align-items: center; justify-content: center;
  gap: calc(var(--sw) * 1.8);
  padding: calc(var(--sh) * .8) calc(var(--sw) * 2.4);
  border-radius: 999px;
  background: rgba(23,18,12,.86);
  border: 1px solid rgba(216,164,65,.42);
}
.tool[hidden] { display: none; }
.tool__btn {
  width: calc(var(--sw) * 9); height: calc(var(--sw) * 9);
  min-width: 40px; min-height: 40px;
  max-width: 78px; max-height: 78px;
  border-radius: 50%;
  border: 1px solid rgba(216,164,65,.5);
  background: #e6dcc4; color: #241c12;
  font: 600 clamp(20px, calc(var(--sw) * 4), 40px)/1 var(--body-font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tool__btn:active { transform: scale(.94); }
.tool__name {
  font-family: var(--display-font);
  font-size: clamp(13px, calc(var(--sw) * 2), 22px);
  color: #f0e4c8; min-width: 5.5em;
  padding: 0 calc(var(--sw) * .8);
}
/* Стрелки наклона рисуются шрифтом и без этого сидят выше середины кнопки. */
#btn-rot-left, #btn-rot-right { font-size: clamp(17px, calc(var(--sw) * 3.4), 34px); line-height: .9; }

/* ---------- экран генерации ---------- */

/* display НЕ задаём: .screen скрыт по умолчанию, показывает его .is-active.
   Любой display здесь перебил бы скрытие и экран висел бы поверх остальных. */
.generate {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  text-align: center; max-width: 440px;
}
.generate__title { margin: 0; font-family: var(--display-font); font-size: clamp(22px, calc(var(--sw) * 3.4), 38px); }
.generate__preview { display: flex; justify-content: center; min-height: 0; }
.generate__preview img {
  max-height: calc(var(--sh) * 46); max-width: 100%;
  border-radius: 10px; border: 2px solid rgba(216,164,65,.3);
  box-shadow: 0 20px 50px rgba(0,0,0,.55);
}

/* ---------- холст на мольберте ---------- */

/* Один и тот же кадр в двух слоях: нижний обесцвечен, верхний цветной и
   подрезан круглой маской. Радиус маски задаётся из js через --paint. */
.easel {
  --paint: 0;
  position: relative;
  /* Высота задаётся явно: оба слоя позиционированы абсолютно и своей высоты
     не дают, а от одного max-height холст схлопывался в несколько пикселей. */
  height: calc(var(--sh) * 46);
  max-width: 100%;
  flex: none;
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(216,164,65,.3);
  box-shadow: 0 20px 50px rgba(0,0,0,.55);
}
.easel canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
/* Загрунтованный холст: цвет ушёл, тон бумаги остался. */
.easel__primed {
  filter: grayscale(1) contrast(.9) brightness(1.08) sepia(.22);
}
/* Написанное: цвет проступает кругом из центра, край мягкий. */
.easel__painted {
  -webkit-mask-image: radial-gradient(circle at 50% 44%,
    #000 calc(var(--paint) * 1%),
    transparent calc((var(--paint) + 16) * 1%));
          mask-image: radial-gradient(circle at 50% 44%,
    #000 calc(var(--paint) * 1%),
    transparent calc((var(--paint) + 16) * 1%));
  transition: -webkit-mask-image .6s ease-out, mask-image .6s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .easel__painted { transition: none; }
}

/* Полоса: жёлоб с внутренней тенью, заливка с бликом и бегущим отсветом,
   чтобы ожидание читалось как работа, а не как зависший индикатор. */
.generate__progress {
  position: relative;
  width: 100%; height: 12px; border-radius: 999px;
  background: rgba(255,255,255,.09);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.5);
  overflow: hidden;
}
.generate__bar {
  position: relative;
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, #b8862c, var(--gold) 55%, #f4d98a);
  box-shadow: 0 0 14px rgba(216,164,65,.55);
  transition: width .5s cubic-bezier(.22,.61,.36,1);
}
/* Бегущий блик поверх заливки. */
.generate__bar::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  animation: sheen 1.7s ease-in-out infinite;
}
@keyframes sheen { from { transform: translateX(-100%) } to { transform: translateX(100%) } }

/* Надписи сменяют друг друга: уходящая тает вверх, приходящая всплывает. */
.generate__status {
  margin: 0; min-height: 1.5em;
  font-size: clamp(14px, calc(var(--sw) * 1.9), 19px);
  color: #d8cbb0;
  transition: opacity .35s ease, transform .35s ease;
}
.generate__status.is-swapping { opacity: 0; transform: translateY(-8px); }

/* ---------- латунная табличка ---------- */

/* Кнопка-табличка из референса. Собрана в css, а не картинкой: подписи
   в киоске меняются (эпоха, писатель, обработка), и вшитый в png текст
   пришлось бы перерисовывать на каждую новую строку. */
.plate {
  position: relative;
  font-family: var(--display-font);
  font-size: clamp(15px, calc(var(--sw) * 2.4), 27px);
  line-height: 1;
  color: #17120b;
  padding: calc(var(--sh) * 1.5) calc(var(--sw) * 6);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  /* Состаренная латунь: тёплый градиент с потёртостью к краям. */
  background:
    radial-gradient(120% 180% at 30% 20%, rgba(255,255,255,.5), transparent 60%),
    linear-gradient(180deg, #f3dda2 0%, #e8c880 45%, #d9b464 100%);
  box-shadow:
    0 0 0 3px #14100a,
    0 0 0 4px rgba(216,164,65,.85),
    0 10px 26px rgba(0,0,0,.55);
  transition: transform .12s ease, filter .16s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.plate:hover { filter: brightness(1.06); }
.plate:active { transform: translateY(1px) scale(.985); }
.plate:focus-visible { outline: 2px solid #fff; outline-offset: 5px; }
.plate__arrow { margin-left: .5em; font-weight: 700; }
.plate--lg { font-size: clamp(17px, calc(var(--sw) * 3), 32px); padding: calc(var(--sh) * 1.9) calc(var(--sw) * 8); }

/* Второстепенное действие: та же табличка, но тёмная. */
.plate--dark {
  color: #f0e2bd;
  background: linear-gradient(180deg, #1b1610 0%, #100c07 100%);
  box-shadow: 0 0 0 2px rgba(216,164,65,.75), 0 8px 20px rgba(0,0,0,.5);
}

/* Круглая стрелка — картинкой из набора. */
.arrow {
  width: clamp(44px, calc(var(--sw) * 11), 96px);
  aspect-ratio: 1;
  padding: 0; border: 0; background: none;
  cursor: pointer; border-radius: 50%;
  transition: transform .14s ease, filter .16s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex: none;
}
.arrow img { width: 100%; height: 100%; display: block; }
.arrow:hover { filter: brightness(1.15); }
.arrow:active { transform: scale(.93); }
.arrow:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
/* В колоде стрелка уже сдвинута по вертикали — нажатие не должно её сбрасывать. */
.epoch-deck .arrow:active { transform: translateY(-50%) scale(.93); }

/* ---------- кнопки и тост ---------- */

.btn {
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 13px 24px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(216,164,65,.4);
  background: rgba(20,17,22,.7); color: var(--ink);
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover { background: rgba(216,164,65,.18); border-color: var(--gold); }
.btn--primary { background: var(--primary); border-color: transparent; color: #fff; }
.btn--primary:hover { background: #6d5ee0; }
.btn--ghost { background: transparent; border-color: rgba(255,255,255,.18); color: #cbbea4; }

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #17151d; color: #f3ead6; padding: 14px 24px;
  border: 1px solid rgba(216,164,65,.35); border-radius: 12px; z-index: 20;
}
.toast[hidden] { display: none; }

/* Product usability: focus, truthful waiting state, reduced motion and print. */
[hidden] { display: none !important; }
button:focus-visible, a:focus-visible { outline: 3px solid #ffe0a0; outline-offset: 5px; }
.privacy-note { max-width: 48ch; margin: 18px auto 0; font: 400 clamp(12px, 1.5vh, 18px)/1.5 system-ui,sans-serif; color: #eee1cb; }
.result-tools { display:flex; justify-content:center; gap:12px; margin:8px 0; }
.generate__progress.is-working .generate__bar { width:35% !important; animation: waiting 2s ease-in-out infinite alternate; }
@keyframes waiting { from { transform:translateX(0); } to { transform:translateX(185%); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration:.01ms !important; transition-duration:.01ms !important; } }
@media print {
  @page { size:100mm 150mm; margin:0; }
  html, body { width:100mm; height:150mm; overflow:hidden; background:white; }
  body > * { display:none !important; }
  body > #s-result { display:block !important; position:static; transform:none; width:100mm; height:150mm; padding:0; }
  #s-result > * { display:none !important; }
  #s-result > #portrait-holder { display:block !important; width:100mm; height:150mm; margin:0; padding:0; }
  #portrait-holder canvas { display:block; width:100mm !important; height:150mm !important; max-height:none; max-width:none; box-shadow:none; border:0; }
}

/* Collage controls occupy their own space, never the canvas. */
#s-editor.is-active {display:grid;grid-template-columns:minmax(0,1fr) minmax(300px,360px);grid-template-rows:auto minmax(0,1fr) auto;gap:12px;padding:16px;height:100dvh;box-sizing:border-box}
.collage-header {grid-column:1/-1;display:flex;justify-content:space-between;align-items:center;gap:12px;min-width:0}
.collage-header .badge {position:static}
#collage-scene {margin:4px 0;color:#d8c7a6;font-size:15px}
.collage-workspace {grid-column:1;grid-row:2;min-height:0;min-width:0;display:flex;justify-content:center;align-items:center;background:#181512;border-radius:10px;overflow:hidden}
#editor-canvas {position:static;inset:auto;flex:none;object-fit:fill;touch-action:none;border-radius:6px}
.collage-controls {grid-column:2;grid-row:2;display:flex;flex-direction:column;gap:14px;overflow:auto;min-width:0;min-height:0;border:1px solid #705538;border-radius:10px;margin:0;padding:12px;background:rgba(22,18,14,.95)}
.collage-controls label {display:flex;flex-direction:column;gap:6px;font:15px/1.4 system-ui;color:#eee0c8}
.collage-controls button,.collage-controls select {min-height:42px;font:14px/1.3 system-ui;background:#32291e;color:#fff0d5;border:1px solid #8a7048;border-radius:6px;padding:8px;cursor:pointer;max-width:100%}
.collage-controls button.is-selected {background:#806038;border-color:#f0c878}
.collage-controls input[type=range] {width:100%;height:30px}
.collage-controls .tool {padding:5px 0;gap:5px;width:100%;margin:6px 0}
.collage-controls .tool__btn {width:42px;height:42px;flex:none}
.collage-controls .tool__name {font:13px system-ui;min-width:0;overflow:hidden;text-overflow:ellipsis}
.collage-row {display:flex;gap:6px;flex-wrap:wrap;margin:8px 0}
.collage-accessories h3 {font:600 15px system-ui;margin:0 0 8px}
.collage-controls .case {display:grid;grid-template-columns:repeat(auto-fill,minmax(86px,1fr));gap:6px;width:100%;max-width:none;overflow:visible;padding:0;background:none;border:0;box-shadow:none}
.collage-controls .cell {width:auto;min-width:0;height:auto;min-height:98px;padding:6px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px}
.collage-controls .cell img {width:58px;height:58px;object-fit:contain;background:#e5d7bd;border-radius:4px}
.collage-controls .cell__name {font:12px/1.2 system-ui;white-space:normal}
.collage-footer {grid-column:1/-1;grid-row:3;min-width:0}
.collage-footer .stage__hint {font:14px system-ui;margin:0 0 8px;text-align:center}
.collage-footer .plate {font-size:16px;min-height:48px;padding:12px 22px}
#collage-loading {text-align:center;color:#ffe0a8;margin:4px 0}
@media(orientation:portrait),(max-width:850px) {
 #s-editor.is-active {grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) minmax(150px,29dvh) auto;gap:8px;padding:10px}
 .collage-workspace {grid-column:1;grid-row:2}
 .collage-controls {grid-column:1;grid-row:3;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);align-content:start}
 .collage-footer {grid-row:4}
}
@media(max-width:520px) {
 #s-editor.is-active {padding:6px;gap:5px}
 .collage-controls {grid-template-columns:minmax(0,1fr);padding:8px}
 .collage-header .badge {font-size:16px}
 .collage-header .btn {font-size:12px;padding:8px}
 .collage-footer .plate {font-size:13px;padding:8px 12px}
 .collage-footer .confirm {gap:6px}
}

#s-editor.is-active {align-items:stretch;justify-items:stretch;width:100vw;max-width:none;background:#171410}
.collage-workspace {align-self:stretch}
.collage-footer .stage__hint {position:static;inset:auto;transform:none;max-width:none;width:auto;background:none;box-shadow:none;padding:0}
.collage-header .badge {font-size:clamp(16px,2vw,23px)}
.collage-controls:disabled {opacity:.5}
