/* ============ Шрифты (лежат локально в /fonts) ============ */
@font-face {
  font-family: 'Caveat';
  src: url('../fonts/caveat-cyrillic.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Caveat';
  src: url('../fonts/caveat-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Nunito';
  src: url('../fonts/nunito-cyrillic.woff2') format('woff2');
  font-weight: 400 800;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Nunito';
  src: url('../fonts/nunito-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============ Токены ============
   Радиусы: кнопки — пилюли, карточки/панели — 22px, поля/чипы — 14px. */
:root {
  color-scheme: light;
  --bg: #FCEEF1;
  --blob-1: #FFD7E1;
  --blob-2: #FFEFD0;
  --blob-3: #EBE3FF;
  --ink: #3A2131;
  --ink-soft: #7B5868;
  --accent: #CF365C;
  --accent-deep: #A3213F;
  --accent-ink: #FFF7F9;
  --surface: #FFFBFC;
  --surface-2: #FFF2F5;
  --surface-glass: rgb(255 251 252 / .72);
  --line: #EDCBD5;
  --shadow: 92 36 62;

  --paper: #FFFCF8;
  --card-ink: #3A2131;
  --card-ink-soft: #6E4D5D;
  --t-pink: #FFD5DE;
  --t-butter: #FFE9A6;
  --t-mint: #CDEBD8;
  --t-lilac: #E3DAFF;
  --t-sky: #D2E6FF;
  --t-peach: #FFD8C4;

  --env: #F7BCC9;
  --env-side: #F3ABBC;
  --env-flap: #FAC8D3;
  --env-inside: #E58FA4;
  --seal: #C42E55;
  --ribbon: #CF365C;

  --radius: 22px;
  --radius-sm: 14px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);

  --z-sky: 0;
  --z-stage: 1;
  --z-confetti: 40;
  --z-grain: 50;
  --z-ui: 60;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1D1220;
    --blob-1: #3B1D35;
    --blob-2: #2E1A26;
    --blob-3: #251A3B;
    --ink: #FBEAF0;
    --ink-soft: #CFB0BE;
    --accent: #FF7D9C;
    --accent-deep: #C9506F;
    --accent-ink: #2B0E1B;
    --surface: #2A1A2C;
    --surface-2: #341F36;
    --surface-glass: rgb(42 26 44 / .72);
    --line: #4E3049;
    --shadow: 8 2 10;

    --paper: #F7EEE8;
    --t-pink: #F3C7D2;
    --t-butter: #F0DC9E;
    --t-mint: #C0DDCB;
    --t-lilac: #D5CCF0;
    --t-sky: #C4D9F1;
    --t-peach: #F1CBB7;
  }
}

/* ============ База ============ */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* мягкие пятна цвета на фоне */
body::before {
  content: '';
  position: fixed;
  inset: -10%;
  z-index: var(--z-sky);
  pointer-events: none;
  background:
    radial-gradient(38% 32% at 12% 10%, var(--blob-1), transparent 70%),
    radial-gradient(42% 34% at 96% 32%, var(--blob-3), transparent 70%),
    radial-gradient(52% 40% at 28% 98%, var(--blob-2), transparent 70%);
}

/* бумажное зерно */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: .09;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .18 0 0 0 0 .25 0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  body::after { mix-blend-mode: screen; opacity: .05; }
}

[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
[tabindex="-1"]:focus { outline: none; }

.hand {
  font-family: 'Caveat', 'Segoe Print', cursive;
  font-weight: 700;
}

/* ============ Летающие сердечки на фоне ============ */
.sky {
  position: fixed;
  inset: 0;
  z-index: var(--z-sky);
  overflow: hidden;
  pointer-events: none;
}
.sky span {
  position: absolute;
  bottom: -40px;
  left: var(--x);
  font-size: var(--s);
  line-height: 1;
  color: var(--accent);
  opacity: var(--o);
  animation: drift var(--d) linear var(--delay) infinite;
}
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  50%  { transform: translate3d(var(--sway), -58vh, 0) rotate(14deg); }
  100% { transform: translate3d(0, -118vh, 0) rotate(-8deg); }
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: var(--z-confetti);
  pointer-events: none;
}

/* ============ Кнопка звука ============ */
.sound {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  right: calc(env(safe-area-inset-right) + 14px);
  z-index: var(--z-ui);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .2s var(--ease-out);
}
.sound:active { transform: scale(.92); }
.sound:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.sound[aria-pressed="false"] .sound-note { opacity: .4; }
.sound[aria-pressed="false"]::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  rotate: -45deg;
}

/* ============ Экраны ============ */
.stage {
  position: relative;
  z-index: var(--z-stage);
  /* улетающие карточки не должны расширять страницу */
  overflow: hidden;
  overflow: clip;
}

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding:
    calc(env(safe-area-inset-top) + 68px)
    calc(env(safe-area-inset-right) + 20px)
    calc(env(safe-area-inset-bottom) + 32px)
    calc(env(safe-area-inset-left) + 20px);
  text-align: center;
}
.screen.is-active,
.screen.is-leaving { display: flex; }

.screen.is-active > * { animation: rise .8s var(--ease-out) backwards; }
.screen.is-active > :nth-child(2) { animation-delay: .08s; }
.screen.is-active > :nth-child(3) { animation-delay: .16s; }
.screen.is-active > :nth-child(4) { animation-delay: .24s; }
.screen.is-active > :nth-child(5) { animation-delay: .32s; }
.screen.is-active > :nth-child(6) { animation-delay: .4s; }

.screen.is-leaving {
  position: absolute;
  inset: 0 0 auto;
  pointer-events: none;
  animation: leave .36s ease-in forwards;
}

@keyframes rise {
  from { opacity: 0; translate: 0 22px; }
}
@keyframes leave {
  to { opacity: 0; transform: translateY(-14px) scale(.98); }
}

/* ============ Типографика ============ */
.title {
  margin: 0;
  font-size: clamp(40px, 11vw, 56px);
  line-height: 1.05;
  color: var(--ink);
  text-wrap: balance;
}
.above {
  margin: 0;
  font-size: clamp(44px, 13vw, 60px);
  line-height: 1;
}
.lead {
  margin: 0;
  max-width: 32ch;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1.5;
  white-space: pre-line;
  text-wrap: pretty;
}
.hint {
  margin: 0;
  font-size: 25px;
  line-height: 1.1;
  color: var(--ink-soft);
  font-weight: 600;
}
.head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.bob {
  display: inline-block;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob {
  50% { transform: translateY(-5px); }
}

/* ============ Плавное появление / смена блоков ============ */
.fade {
  transition: opacity .5s ease, translate .6s var(--ease-out), visibility 0s;
}
.fade.is-off {
  opacity: 0;
  translate: 0 12px;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .3s ease, translate .3s ease, visibility 0s .3s;
}
.swap {
  display: grid;
  justify-items: center;
  align-items: start;
  width: 100%;
}
.swap > * { grid-area: 1 / 1; }

.after {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* ============ Кнопки ============ */
.btn {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 32px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 800 18px/1 'Nunito', system-ui, sans-serif;
  letter-spacing: .01em;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 5px 0 var(--accent-deep),
    0 16px 28px -10px rgb(var(--shadow) / .5);
  transition: transform .15s var(--ease-out), box-shadow .15s var(--ease-out), opacity .2s;
}
.btn:active {
  transform: translateY(4px);
  box-shadow:
    0 1px 0 var(--accent-deep),
    0 6px 12px -6px rgb(var(--shadow) / .45);
}
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }
.btn[disabled] { cursor: progress; opacity: .8; }

.btn--soft {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line);
  box-shadow:
    0 4px 0 var(--line),
    0 12px 22px -12px rgb(var(--shadow) / .35);
}
.btn--soft:active { box-shadow: 0 1px 0 var(--line); }
.btn--wide { width: 100%; }

.btn.is-sending { animation: sending 1s ease-in-out infinite; }
@keyframes sending {
  50% { opacity: .75; }
}

.round-btn {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 var(--line);
  transition: transform .15s var(--ease-out), opacity .3s, box-shadow .15s;
}
.round-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line); }
.round-btn:disabled { opacity: .3; cursor: default; transform: none; }
.round-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.link-btn {
  border: 0;
  background: none;
  padding: 10px 12px;
  color: var(--ink-soft);
  font: 700 16px/1.2 'Nunito', system-ui, sans-serif;
  text-decoration: underline wavy;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 6px;
  cursor: pointer;
}

/* ============ 1. Конверт ============ */
.envelope {
  --w: min(80vw, 340px);
  position: relative;
  width: var(--w);
  height: calc(var(--w) / 1.5);
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  perspective: 1000px;
  filter: drop-shadow(0 18px 22px rgb(var(--shadow) / .22));
}
.envelope:focus-visible { outline: 3px solid var(--accent); outline-offset: 8px; border-radius: 14px; }
.envelope.is-open { cursor: default; }

.env-back {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: var(--env-inside);
}

.env-letter {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 5%;
  height: 90%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 12px;
  border-radius: 8px;
  background-color: var(--paper);
  background-image: repeating-linear-gradient(transparent 0 25px, rgb(207 54 92 / .1) 25px 26px);
  color: #CF365C;
  box-shadow: 0 -2px 10px rgb(var(--shadow) / .1);
  transition: translate .9s var(--ease-spring) .5s;
}
.envelope.is-open .env-letter { translate: 0 -54%; }

.env-letter-text {
  font-size: calc(var(--w) * .1);
  line-height: 1;
  white-space: pre-line;
}
.env-letter-heart {
  font-size: calc(var(--w) * .07);
  line-height: 1;
}

.env-pocket {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 12px;
  background: var(--env);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
}
.env-pocket::before,
.env-pocket::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--env-side);
}
.env-pocket::before { clip-path: polygon(0 0, 50% 56%, 0 100%); }
.env-pocket::after { clip-path: polygon(100% 0, 50% 56%, 100% 100%); }

.env-to {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9%;
  z-index: 4;
  font-size: calc(var(--w) * .085);
  line-height: 1;
  color: #8E3350;
  rotate: -3deg;
}

.env-flap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 60%;
  z-index: 4;
  transform-origin: 50% 0;
  filter: drop-shadow(0 3px 2px rgb(var(--shadow) / .14));
  transition: transform .7s var(--ease-out), z-index 0s linear .28s;
}
.env-flap::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px 12px 0 0;
  background: var(--env-flap);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.envelope.is-open .env-flap {
  transform: rotateX(180deg);
  z-index: 1;
}

.env-seal {
  position: absolute;
  left: 50%;
  top: 60%;
  z-index: 5;
  width: calc(var(--w) * .17);
  height: calc(var(--w) * .17);
  translate: -50% -50%;
  display: grid;
  place-items: center;
  border-radius: 47% 53% 50% 50% / 52% 46% 54% 48%;
  background: radial-gradient(circle at 34% 30%, #EE6F8E, var(--seal) 58%, #9E1F41);
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / .15),
    inset 0 2px 1px rgb(255 255 255 / .25),
    0 4px 10px rgb(var(--shadow) / .35);
  color: #FFD9E3;
  font-size: calc(var(--w) * .075);
  line-height: 1;
  animation: seal-breathe 2.6s ease-in-out infinite;
}
.env-seal span { text-shadow: 0 -1px 0 rgb(0 0 0 / .25); }
.envelope.is-open .env-seal { animation: seal-pop .4s ease-in forwards; }

@keyframes seal-breathe {
  50% { transform: scale(1.07); }
}
@keyframes seal-pop {
  40% { transform: scale(1.3); }
  100% { transform: scale(0); opacity: 0; }
}

/* ============ 2. Карточки ============ */
.screen--cards { gap: 20px; }

.deck {
  --card-h: min(56vh, 470px);
  --card-w: min(86vw, 350px, calc(var(--card-h) * .8));
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  margin-top: 6px;
}
@supports (height: 1dvh) {
  .deck { --card-h: min(56dvh, 470px); }
}

.card {
  position: absolute;
  inset: 0;
  perspective: 1400px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: grab;
  will-change: transform;
  transition: transform .55s var(--ease-out), opacity .45s ease;
}
.card:focus-visible { outline: none; }
.card:focus-visible .face { outline: 3px solid var(--accent); outline-offset: 4px; }
.card.is-dragging { transition: none; cursor: grabbing; }
.card.is-snapping { transition: transform .5s var(--ease-spring); }
.card.is-flying { transition: transform .6s cubic-bezier(.2, .6, .3, 1), opacity .5s ease .1s; }

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .7s var(--ease-spring);
}
.card.is-flipped .card-inner { transform: rotateY(180deg); }
.card.is-nudge .card-inner { animation: nudge .45s ease-in-out; }
@keyframes nudge {
  25% { transform: rotate(-3deg); }
  60% { transform: rotate(2.5deg); }
}

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 34px 22px 18px;
  border-radius: var(--radius);
  background: var(--tint, var(--t-pink));
  color: var(--card-ink);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / .6),
    0 2px 4px rgb(var(--shadow) / .08),
    0 22px 40px -16px rgb(var(--shadow) / .42);
}
.face--back {
  transform: rotateY(180deg);
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 30px, rgb(207 54 92 / .28) 30px 31.5px, transparent 31.5px),
    repeating-linear-gradient(transparent 0 33px, rgb(var(--shadow) / .1) 33px 34px);
  background-position: 0 0, 0 18px;
}

.tape {
  position: absolute;
  top: -12px;
  left: 50%;
  width: 96px;
  height: 26px;
  translate: -50% 0;
  rotate: var(--tape-r, -3deg);
  border-radius: 2px;
  background: repeating-linear-gradient(-45deg, rgb(255 255 255 / .72) 0 7px, rgb(255 236 241 / .5) 7px 14px);
  box-shadow: 0 1px 3px rgb(var(--shadow) / .14);
}

.card-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-size: 18px;
}
.card-content-inner {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .45em;
}

.sticker {
  font-size: 3.1em;
  line-height: 1.1;
  rotate: var(--sticker-r, -6deg);
  filter:
    drop-shadow(2px 0 0 #fff)
    drop-shadow(-2px 0 0 #fff)
    drop-shadow(0 2px 0 #fff)
    drop-shadow(0 -2px 0 #fff)
    drop-shadow(0 6px 6px rgb(var(--shadow) / .22));
}
.card-title {
  margin: 0;
  font-family: 'Caveat', cursive;
  font-weight: 700;
  font-size: 1.9em;
  line-height: 1.05;
  text-wrap: balance;
}
.card-text {
  margin: 0;
  font-size: 1em;
  line-height: 1.5;
  white-space: pre-line;
  text-wrap: pretty;
}
.face--back .card-text {
  font-family: 'Caveat', cursive;
  font-weight: 600;
  font-size: 1.6em;
  line-height: 1.25;
}
.card-foot {
  flex: none;
  margin: 10px 0 0;
  font-family: 'Caveat', cursive;
  font-weight: 600;
  font-size: 21px;
  line-height: 1;
  color: var(--card-ink-soft);
}

.deck-end {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  opacity: 0;
  scale: .92;
  pointer-events: none;
  transition: opacity .5s ease, scale .6s var(--ease-spring);
}
.deck.is-done .deck-end {
  opacity: 1;
  scale: 1;
  pointer-events: auto;
}

.deck-nav {
  display: flex;
  align-items: center;
  gap: 18px;
}
.deck-progress {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 80px;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  color: var(--line);
}
.deck-progress span { transition: color .3s ease, transform .4s var(--ease-spring); }
.deck-progress span.is-on { color: var(--accent); transform: scale(1.2); }
.deck-progress.is-text {
  font-family: 'Caveat', cursive;
  font-weight: 700;
  font-size: 24px;
  color: var(--ink-soft);
}

/* ============ 3. Торт ============ */
.screen--cake { gap: 26px; }

.cake {
  --cw: min(68vw, 270px);
  position: relative;
  width: var(--cw);
  padding-top: 86px;
}

.candles {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 0;
  height: 96px;
  z-index: 2;
  display: flex;
  justify-content: space-evenly;
  align-items: flex-end;
}

.candle {
  position: relative;
  width: 14px;
  height: var(--ch, 50px);
  padding: 0;
  border: 0;
  border-radius: 4px 4px 2px 2px;
  background: repeating-linear-gradient(135deg, #fff 0 5px, var(--c) 5px 10px);
  box-shadow: inset -3px 0 0 rgb(0 0 0 / .07);
  cursor: pointer;
  touch-action: manipulation;
}
/* фитиль */
.candle::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 2px;
  height: 8px;
  translate: -50% 0;
  border-radius: 1px;
  background: #5A4048;
}
/* увеличенная зона нажатия */
.candle::after {
  content: '';
  position: absolute;
  inset: -46px -12px -4px;
}
.candle:disabled { cursor: default; }
.candle:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }

.flame {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  width: 16px;
  height: 28px;
  margin-left: -8px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse at 50% 76%, #FFFBE3 0 20%, #FFD65E 42%, #FF9E3D 72%, #FF6F3F);
  box-shadow:
    0 0 14px 4px rgb(255 190 90 / .55),
    0 0 40px 14px rgb(255 170 70 / .18);
  transform-origin: 50% 90%;
  rotate: calc(var(--lean, 0deg) * var(--dir, 1));
  animation: flicker var(--fd, .16s) ease-in-out infinite alternate;
  transition: rotate .12s linear, opacity .3s ease, scale .3s ease;
  pointer-events: none;
}
@keyframes flicker {
  from { transform: scale(1, 1) skewX(-2deg); }
  to   { transform: scale(.93, 1.08) skewX(2deg); }
}
.candle.is-out .flame { opacity: 0; scale: .2; }

.smoke {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: rgb(160 145 155 / .55);
  filter: blur(2px);
  pointer-events: none;
  animation: smoke 1.7s ease-out forwards;
}
@keyframes smoke {
  from { opacity: .85; transform: translate(0, 0) scale(.6); }
  to   { opacity: 0; transform: translate(var(--sx), -74px) scale(2.6); }
}

.cake-body {
  position: relative;
  z-index: 1;
  height: calc(var(--cw) * .5);
  border-radius: 18px 18px 12px 12px;
  background: linear-gradient(#FFE5CF, #FFD2B3);
  box-shadow: inset 0 -10px 0 rgb(0 0 0 / .04);
}
.cake-frosting {
  position: absolute;
  left: -5px;
  right: -5px;
  top: -6px;
  height: 34%;
  border-radius: 20px 20px 8px 8px;
  background: #FF9EB7;
  box-shadow: inset 0 5px 0 rgb(255 255 255 / .35);
}
.drip {
  position: absolute;
  top: 70%;
  left: var(--dx);
  width: var(--dw);
  height: var(--dh);
  border-radius: 0 0 999px 999px;
  background: #FF9EB7;
}
.cake-cream {
  position: absolute;
  left: 0;
  right: 0;
  top: 68%;
  height: 10px;
  background: radial-gradient(circle at 8px 5px, #FFF7F0 5px, transparent 5.5px) 0 0 / 16px 10px repeat-x;
}
.cake-sprinkles span {
  position: absolute;
  width: 9px;
  height: 3.5px;
  border-radius: 2px;
  background: var(--c);
  left: var(--x);
  top: var(--y);
  rotate: var(--r);
}
.cake-plate {
  position: relative;
  z-index: 0;
  height: 22px;
  margin: -11px -9% 0;
  border-radius: 50%;
  background: linear-gradient(#FFFFFF, #EFE0E6);
  box-shadow: 0 12px 20px -8px rgb(var(--shadow) / .45);
}

.cake-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.mic-status {
  margin: 0;
  min-height: 1.5em;
  max-width: 30ch;
  font-size: 15px;
  color: var(--ink-soft);
}
.mic-status.is-live {
  font-family: 'Caveat', cursive;
  font-weight: 700;
  font-size: 26px;
  color: var(--accent);
  animation: bob 1.2s ease-in-out infinite;
}

/* ============ 4. Коробка ============ */
.gift {
  --gw: min(54vw, 210px);
  position: relative;
  width: calc(var(--gw) * 1.2);
  height: calc(var(--gw) * 1.5);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
.gift:focus-visible { outline: 3px solid var(--accent); outline-offset: 8px; border-radius: 16px; }
.gift.is-open { cursor: default; }

.gift-wobble {
  position: absolute;
  inset: 0;
  transform-origin: 50% 100%;
}
.gift:not(.is-open) .gift-wobble { animation: idle-hop 3.2s ease-in-out 1.2s infinite; }
.gift.is-wiggle .gift-wobble { animation: wiggle .5s ease-in-out; }
.gift.is-wiggle-big .gift-wobble { animation: wiggle-big .65s ease-in-out; }

@keyframes idle-hop {
  0%, 70%, 100% { transform: none; }
  78% { transform: translateY(-8px) rotate(-2deg); }
  86% { transform: translateY(0) rotate(1.5deg); }
  92% { transform: translateY(-3px); }
}
@keyframes wiggle {
  20% { transform: rotate(-6deg); }
  40% { transform: rotate(5deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(2deg); }
}
@keyframes wiggle-big {
  15% { transform: translateY(-8px) rotate(-9deg); }
  35% { transform: translateY(-12px) rotate(8deg); }
  55% { transform: translateY(-4px) rotate(-6deg); }
  75% { transform: rotate(4deg); }
}

.gift-box {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 2;
  width: var(--gw);
  height: calc(var(--gw) * .72);
  translate: -50% 0;
  border-radius: 6px 6px 12px 12px;
  background-color: #FFC3D2;
  background-image: radial-gradient(circle, rgb(255 255 255 / .8) 0 4px, transparent 4.5px);
  background-size: 26px 26px;
  box-shadow:
    inset 0 -8px 0 rgb(0 0 0 / .05),
    0 18px 28px -12px rgb(var(--shadow) / .45);
}
.gift-ribbon-v {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 18%;
  translate: -50% 0;
  background: var(--ribbon);
  box-shadow: inset 2px 0 0 rgb(255 255 255 / .2), inset -2px 0 0 rgb(0 0 0 / .1);
}
.gift-lid {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gw) * .72 - 6px);
  z-index: 3;
  width: calc(var(--gw) * 1.1);
  height: calc(var(--gw) * .22);
  translate: -50% 0;
  border-radius: 8px;
  background: #FFB1C4;
  box-shadow: 0 6px 0 -2px rgb(0 0 0 / .06);
  transition: transform .8s var(--ease-out), opacity .5s ease .3s;
}
.gift-lid .gift-ribbon-v { border-radius: 2px; }
.gift.is-open .gift-lid {
  transform: translate(46%, -190%) rotate(32deg);
  opacity: 0;
}

.bow {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 0;
  height: 0;
}
.bow-l,
.bow-r {
  position: absolute;
  bottom: -6px;
  width: calc(var(--gw) * .27);
  height: calc(var(--gw) * .2);
  border: calc(var(--gw) * .055) solid var(--ribbon);
  border-radius: 55% 45% 45% 55% / 60% 50% 50% 40%;
}
.bow-l { right: 2px; rotate: -22deg; transform-origin: 100% 100%; }
.bow-r { left: 2px; rotate: 22deg; transform-origin: 0 100%; }
.bow-knot {
  position: absolute;
  bottom: -9px;
  left: calc(var(--gw) * -.07);
  width: calc(var(--gw) * .14);
  height: calc(var(--gw) * .13);
  border-radius: 40%;
  background: var(--ribbon);
  box-shadow: inset 0 2px 0 rgb(255 255 255 / .25);
}

.gift-note {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gw) * .02);
  z-index: 1;
  width: calc(var(--gw) * .88);
  height: calc(var(--gw) * .86);
  translate: -50% 0;
  rotate: -2deg;
  padding: 14px 12px;
  border-radius: 12px;
  background: var(--paper);
  color: var(--card-ink);
  font-size: calc(var(--gw) * .112);
  line-height: 1.1;
  white-space: pre-line;
  box-shadow: 0 10px 24px -10px rgb(var(--shadow) / .4);
  transition: transform 1s var(--ease-spring) .35s;
}
.gift.is-open .gift-note { transform: translateY(calc(var(--gw) * -.6)); }

/* ============ 5. Форма ============ */
.screen--form { justify-content: flex-start; }

.sheet {
  position: relative;
  width: min(100%, 440px);
  margin-top: 4px;
  padding: 32px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  box-shadow:
    0 2px 4px rgb(var(--shadow) / .06),
    0 26px 50px -24px rgb(var(--shadow) / .45);
}
.sheet > .title,
.sheet > .lead { align-self: center; text-align: center; }
.sheet > .lead { margin-top: -12px; }
.sheet-tape {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 110px;
  height: 28px;
  translate: -50% 0;
  rotate: 2deg;
  border-radius: 2px;
  background: repeating-linear-gradient(-45deg, rgb(255 211 222 / .9) 0 7px, rgb(255 236 241 / .8) 7px 14px);
  box-shadow: 0 1px 3px rgb(var(--shadow) / .14);
}

.field {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.label {
  padding: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}
legend.label { margin-bottom: 10px; }
.label--small { font-size: 14px; }

.chips { display: grid; gap: 10px; }
.chips--time { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chips--date { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
@media (max-width: 340px) {
  .chips--time { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.chip {
  position: relative;
  display: block;
  cursor: pointer;
  touch-action: manipulation;
}
.chip input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chip-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  height: 100%;
  padding: 11px 6px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  box-shadow: 0 3px 0 var(--line);
  text-align: center;
  transition: transform .3s var(--ease-spring), background-color .2s, border-color .2s, box-shadow .2s, color .2s;
}
.chips--date .chip-face { padding: 14px 10px; font-weight: 800; }
.chip-emoji { font-size: 22px; line-height: 1.15; }
.chip-time {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.chip-note { font-size: 13px; line-height: 1.2; color: var(--ink-soft); }
.chip--wide { grid-column: 1 / -1; }
.chip--wide .chip-face {
  flex-direction: row;
  justify-content: center;
  gap: 10px;
  padding: 12px;
}
.chip--wide .chip-emoji { font-size: 20px; }
.chip--wide .chip-time { font-size: 17px; }
.chip:active .chip-face { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.chip input:checked + .chip-face {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 3px 0 var(--accent-deep);
  transform: translateY(-2px) rotate(-1.5deg);
}
.chip input:checked + .chip-face .chip-note { color: var(--accent-ink); }
.chip input:focus-visible + .chip-face { outline: 3px solid var(--ink); outline-offset: 2px; }

.date-fixed {
  margin: 0;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--line);
  background: var(--surface-2);
  font-weight: 700;
}

.custom-time {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: 600 17px/1.4 'Nunito', system-ui, sans-serif;
  transition: border-color .2s, box-shadow .2s;
}
.input::placeholder { color: var(--ink-soft); opacity: 1; font-weight: 500; }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgb(207 54 92 / .18);
}
input[type="time"].input {
  -webkit-appearance: none;
  appearance: none;
  display: block;
}
input[type="time"].input::-webkit-date-and-time-value { text-align: left; }
textarea.input { min-height: 78px; resize: vertical; }

.help { margin: 0; font-size: 14px; color: var(--ink-soft); }
.error {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}
.field.is-invalid .input { border-color: var(--accent); }
.field.is-invalid .chips { animation: shake .4s ease-in-out; }
@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* ============ 6. Финал ============ */
.screen--done { gap: 18px; }

.done-sticker {
  font-size: 84px;
  line-height: 1;
}
.done-sticker span {
  display: inline-block;
  rotate: -8deg;
  filter:
    drop-shadow(3px 0 0 #fff)
    drop-shadow(-3px 0 0 #fff)
    drop-shadow(0 3px 0 #fff)
    drop-shadow(0 -3px 0 #fff)
    drop-shadow(0 10px 10px rgb(var(--shadow) / .25));
  animation: float 3.6s ease-in-out infinite;
}
@keyframes float {
  50% { transform: translateY(-8px) rotate(4deg); }
}

.ticket {
  width: min(100%, 330px);
  margin-top: 6px;
  filter: drop-shadow(0 16px 22px rgb(var(--shadow) / .22));
}
.ticket-main,
.ticket-stub {
  background: var(--paper);
  color: var(--card-ink);
}
.ticket-main {
  padding: 20px 22px 18px;
  border-radius: 18px;
}
.ticket.has-stub .ticket-main {
  border-radius: 18px 18px 0 0;
  -webkit-mask:
    radial-gradient(circle 12px at 0 100%, #0000 97%, #000) 0 0 / 51% 100% no-repeat,
    radial-gradient(circle 12px at 100% 100%, #0000 97%, #000) 100% 0 / 51% 100% no-repeat;
  mask:
    radial-gradient(circle 12px at 0 100%, #0000 97%, #000) 0 0 / 51% 100% no-repeat,
    radial-gradient(circle 12px at 100% 100%, #0000 97%, #000) 100% 0 / 51% 100% no-repeat;
}
.ticket-stub {
  padding: 16px 22px 18px;
  border-radius: 0 0 18px 18px;
  background-image: repeating-linear-gradient(90deg, rgb(92 36 62 / .28) 0 7px, transparent 7px 13px);
  background-size: calc(100% - 40px) 2px;
  background-position: 20px 0;
  background-repeat: no-repeat;
  -webkit-mask:
    radial-gradient(circle 12px at 0 0, #0000 97%, #000) 0 0 / 51% 100% no-repeat,
    radial-gradient(circle 12px at 100% 0, #0000 97%, #000) 100% 0 / 51% 100% no-repeat;
  mask:
    radial-gradient(circle 12px at 0 0, #0000 97%, #000) 0 0 / 51% 100% no-repeat,
    radial-gradient(circle 12px at 100% 0, #0000 97%, #000) 100% 0 / 51% 100% no-repeat;
}
.ticket-label {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--card-ink-soft);
}
.ticket-date { margin: 10px 0 0; font-weight: 700; }
.ticket-time {
  margin: 2px 0 0;
  font-size: 68px;
  line-height: 1;
  color: #CF365C;
}
.ticket-address {
  margin: 0;
  font-size: 15px;
  color: var(--card-ink-soft);
  overflow-wrap: anywhere;
}

.fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ============ Служебное ============ */
.dev-badge {
  position: fixed;
  left: calc(env(safe-area-inset-left) + 12px);
  top: calc(env(safe-area-inset-top) + 14px);
  z-index: var(--z-ui);
  max-width: min(250px, calc(100vw - 90px));
  padding: 9px 12px;
  border-radius: 12px;
  background: #2B1A24;
  color: #FFEFF4;
  font: 700 12px/1.35 'Nunito', system-ui, sans-serif;
  text-align: left;
  opacity: .92;
}

.noscript {
  position: relative;
  z-index: var(--z-ui);
  padding: 40px 20px;
  text-align: center;
  font-size: 20px;
}

/* ============ Меньше движения ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
  .sky { display: none; }
}
