:root {
  --paper: #f3eadd;
  --paper-2: #e8d9c5;
  --card: #fbf6ee;
  --ink: #2b1b18;
  --ink-soft: #7a635b;
  --wine: #8a1f2d;
  --wine-deep: #5e121d;
  --blush: #e7b3a4;
  --gold: #b08a4a;
  --serif: 'Cormorant Garamond', 'Times New Roman', serif;
  --hand: 'Caveat', 'Segoe Script', cursive;
  --sans: 'Manrope', system-ui, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(120% 60% at 100% 0%, #f1cfc0 0%, transparent 60%),
    radial-gradient(90% 50% at 0% 100%, #ecd9b8 0%, transparent 65%),
    var(--paper);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

/* бумажное зерно */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .35 0 0 0 0 .28 0 0 0 .35 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

#petals {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

#app { position: relative; z-index: 1; }

.screen {
  min-height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  padding:
    calc(28px + env(safe-area-inset-top)) 24px
    calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}
.screen[hidden] { display: none; }

/* ---------- типографика ---------- */

h1 {
  margin: 0;
  font: 600 clamp(2.6rem, 12.5vw, 3.6rem)/.98 var(--serif);
  letter-spacing: -.01em;
  text-wrap: balance;
}
h1 em {
  font-style: italic;
  font-weight: 500;
  color: var(--wine);
}

.hand { font-family: var(--hand); color: var(--wine); }

.eyebrow {
  margin: 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold);
}

.tip {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  font-size: .9rem;
  color: var(--ink-soft);
}

.hello {
  margin: 0;
  text-align: center;
  font-size: clamp(2.6rem, 13vw, 3.4rem);
  line-height: 1;
  rotate: -3deg;
}

/* ---------- кнопки ---------- */

.btn {
  appearance: none;
  border: 1.5px solid var(--wine);
  border-radius: 999px;
  min-height: 58px;
  padding: 0 28px;
  font: 700 1.02rem/1 var(--sans);
  letter-spacing: .02em;
  color: var(--card);
  background: var(--wine);
  box-shadow: 0 10px 24px -12px var(--wine-deep);
  cursor: pointer;
  touch-action: manipulation;
  transition: scale .18s var(--ease), background .2s, opacity .2s;
}
.btn:active { scale: .97; }
.btn:disabled {
  opacity: .35;
  box-shadow: none;
  cursor: default;
}
.btn-ghost {
  color: var(--wine);
  background: transparent;
  box-shadow: none;
}
.btn:focus-visible, .back:focus-visible, .chip:focus-visible, .seal:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: auto;
}
.bar ~ .btn { margin-top: auto; }

.back {
  appearance: none;
  width: 44px;
  height: 44px;
  margin-left: -10px;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 1.4rem;
  color: var(--ink);
  cursor: pointer;
}

.dots { display: flex; gap: 6px; }
.dots i {
  width: 22px;
  height: 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ink) 14%, transparent);
}
.dots i.on { background: var(--wine); }

/* ---------- 0. конверт ---------- */

.envelope {
  --w: min(78vw, 310px);
  position: relative;
  width: var(--w);
  height: calc(var(--w) * .66);
  margin: 34px auto 10px;
  perspective: 900px;
  filter: drop-shadow(0 26px 26px rgb(94 18 29 / .22));
  animation: bob 4s ease-in-out infinite;
  --animation-reduced: none;
}
.env-back, .env-front, .env-flap, .env-letter {
  position: absolute;
  inset: 0;
  border-radius: 8px;
}
.env-back { background: #d9c3a6; }
.env-letter {
  inset: 8% 7% 6%;
  padding: 16% 12% 0;
  display: grid;
  align-content: start;
  gap: 10px;
  background: var(--card);
  border-radius: 4px;
  transition: translate .9s var(--ease) .35s;
}
.env-letter span {
  height: 3px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--wine) 22%, transparent);
}
.env-letter span:nth-child(2) { width: 80%; }
.env-letter span:nth-child(3) { width: 55%; }
.env-front {
  background: linear-gradient(#ead8bf, #e2ccae);
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
}
.env-flap {
  background: linear-gradient(#f0dfc8, #e6d2b6);
  clip-path: polygon(0 0, 100% 0, 50% 58%);
  transform-origin: top;
  transition: transform .7s var(--ease);
  backface-visibility: hidden;
}
.seal {
  appearance: none;
  position: absolute;
  left: 50%;
  top: 56%;
  width: 72px;
  height: 72px;
  translate: -50% -50%;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #b3394a, var(--wine) 55%, var(--wine-deep));
  box-shadow: 0 6px 14px rgb(94 18 29 / .45), inset 0 0 0 5px rgb(255 255 255 / .08);
  cursor: pointer;
  touch-action: manipulation;
  transition: scale .3s var(--ease), opacity .3s;
  animation: pulse 2.2s ease-in-out infinite;
  --animation-reduced: none;
}
.seal svg { width: 30px; fill: #f6d9cf; }

.envelope.open { animation: none; }
.envelope.open .seal { scale: .4; opacity: 0; animation: none; }
.envelope.open .env-flap { transform: rotateX(180deg); }
.envelope.open .env-letter { translate: 0 -62%; }

@keyframes bob { 50% { translate: 0 -8px; } }
@keyframes pulse { 50% { box-shadow: 0 6px 14px rgb(94 18 29 / .45), 0 0 0 12px rgb(138 31 45 / .12); } }

/* ---------- 1. письмо ---------- */

.letter {
  padding: 30px 26px 34px;
  background: var(--card);
  border-radius: 6px;
  box-shadow: 0 30px 40px -28px rgb(94 18 29 / .45), 0 0 0 1px rgb(43 27 24 / .05);
  rotate: -1.2deg;
  font: 500 1.5rem/1.3 var(--serif);
}
.letter p { margin: 0 0 .7em; }
.letter p:last-child { margin-bottom: 0; }
.letter-hi { font-size: 2.6rem; line-height: 1; }
.letter-sign { margin-top: 1em !important; text-align: right; font-size: 1.9rem; }

.screen:not([hidden]) .letter p {
  animation: rise .7s var(--ease) both;
  --animation-reduced: none;
}
.letter p:nth-child(2) { animation-delay: .35s !important; }
.letter p:nth-child(3) { animation-delay: .9s !important; }
.letter p:nth-child(4) { animation-delay: 1.5s !important; }
.letter p:nth-child(5) { animation-delay: 2s !important; }

@keyframes rise { from { opacity: 0; translate: 0 10px; } }

/* ---------- 2. вопрос ---------- */

.answers {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 26px;
}
.btn-yes {
  min-width: 132px;
  scale: var(--grow, 1);
  z-index: 2;
  transition: scale .35s var(--ease);
}
.btn-yes:active { scale: calc(var(--grow, 1) * .97); }
.btn-no {
  min-width: 112px;
  background: var(--card);
  translate: var(--dx, 0) var(--dy, 0);
  rotate: var(--rot, 0deg);
  transition: translate .28s var(--ease), rotate .28s var(--ease), background .3s, color .3s;
  z-index: 3;
}
.btn-no.gave-up {
  color: var(--card);
  background: var(--wine);
}

/* ---------- 3. дни ---------- */

.days {
  display: flex;
  gap: 10px;
  margin: 6px -24px 0;
  padding: 10px 24px 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 24px;
  scrollbar-width: none;
}
.days::-webkit-scrollbar { display: none; }

.chip {
  appearance: none;
  border: 1.5px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--sans);
  cursor: pointer;
  touch-action: manipulation;
  transition: background .2s, color .2s, border-color .2s, scale .2s var(--ease), translate .2s var(--ease);
}
.chip:active { scale: .96; }
.chip[aria-pressed='true'] {
  background: var(--wine);
  border-color: var(--wine);
  color: var(--card);
  box-shadow: 0 12px 22px -12px var(--wine-deep);
}

.day {
  flex: 0 0 78px;
  height: 112px;
  display: grid;
  place-content: center;
  gap: 4px;
  scroll-snap-align: start;
  text-align: center;
}
.day[aria-pressed='true'] { translate: 0 -6px; }
.day small {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .65;
}
.day b { font: 600 2.3rem/1 var(--serif); }
.day.weekend:not([aria-pressed='true']) small:first-child { color: var(--wine); opacity: 1; }

/* ---------- 4. время ---------- */

.times {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.time {
  height: 56px;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- 5. план ---------- */

.plans {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.plan {
  padding: 16px 14px;
  display: grid;
  gap: 4px;
  text-align: left;
}
.plan span { font-size: 1.6rem; }
.plan b { font: 600 1.3rem/1.1 var(--serif); }
.plan small { font-size: .78rem; opacity: .7; }

.note { display: grid; gap: 8px; }
.note span { font-size: .8rem; color: var(--ink-soft); }
.note textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  font: 500 1rem/1.4 var(--sans); /* 16px — чтобы iOS не зумил */
  resize: none;
}
.note textarea:focus { outline: none; border-color: var(--wine); }

/* ---------- 6. билет ---------- */

.ticket-wrap {
  filter: drop-shadow(0 28px 26px rgb(94 18 29 / .25));
  rotate: -2deg;
}
.screen:not([hidden]) .ticket-wrap {
  animation: drop .9s var(--ease) both;
  --animation-reduced: none;
}
@keyframes drop { from { opacity: 0; translate: 0 -40px; rotate: 6deg; scale: .92; } }

.ticket {
  --stub: 78px;
  --cut: calc(100% - var(--stub));
  background: var(--card);
  border-radius: 18px;
  overflow: hidden;
  -webkit-mask:
    radial-gradient(circle 11px at left var(--cut), transparent 98%, #000 100%),
    radial-gradient(circle 11px at right var(--cut), transparent 98%, #000 100%);
  -webkit-mask-composite: source-in;
  mask:
    radial-gradient(circle 11px at left var(--cut), transparent 98%, #000 100%),
    radial-gradient(circle 11px at right var(--cut), transparent 98%, #000 100%);
  mask-composite: intersect;
}
.ticket-head {
  display: flex;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--wine);
  color: #f6d9cf;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.ticket-body {
  position: relative;
  padding: 24px 22px 26px;
}
.ticket-date {
  margin: 0 0 18px;
  font: 600 clamp(2rem, 9.5vw, 2.6rem)/1 var(--serif);
  text-wrap: balance;
}
.ticket dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
}
.ticket dt {
  margin-bottom: 4px;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold);
}
.ticket dd {
  margin: 0;
  font: 600 1.5rem/1.1 var(--serif);
}
.ticket-note {
  margin: 16px 0 0;
  max-width: 68%;
  font: 500 1.35rem/1.15 var(--hand);
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}
.stamp {
  position: absolute;
  right: 14px;
  bottom: 12px;
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  border: 2px solid var(--wine);
  border-radius: 50%;
  outline: 1px solid var(--wine);
  outline-offset: -6px;
  color: var(--wine);
  font-size: .56rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: .1em;
  text-align: center;
  text-transform: uppercase;
  rotate: 14deg;
  opacity: .8;
}
.screen:not([hidden]) .stamp {
  animation: stamp .45s cubic-bezier(.3, 1.6, .5, 1) .9s both;
  --animation-reduced: none;
}
@keyframes stamp { from { opacity: 0; scale: 2.2; } }

.ticket-stub {
  height: var(--stub);
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 2px dashed color-mix(in srgb, var(--ink) 20%, transparent);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.ticket-stub .hand {
  font-size: 1.7rem;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}

.final-actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
}

/* ---------- переходы между экранами ---------- */

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) { animation: vt-out .26s ease both; }
  ::view-transition-new(root) { animation: vt-in .5s var(--ease) both; }
}
@keyframes vt-out { to { opacity: 0; translate: 0 -14px; } }
@keyframes vt-in { from { opacity: 0; translate: 0 22px; } }

@property --animation-reduced {
  syntax: '*';
  inherits: false;
  initial-value: none;
}
@media (prefers-reduced-motion: reduce) {
  * { animation: var(--animation-reduced) !important; }
}
