:root {
  --ink: #5b3a4a;
  --ink-soft: #8a6575;
  --accent: #e0648c;
  --paper: #fffaf5;
  --envelope-back: #f6c9d6;
  --envelope-back-dark: #ecb0c3;
  --envelope-flap: #eeb9cc;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* явный приоритет над display:flex у .envelope-wrap/.note той же специфичности */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: 'Cormorant Garamond', Georgia, serif;
  color: var(--ink);
  background: linear-gradient(135deg, #ffe3ec, #ffd8ea 35%, #f1defc 70%, #fff3e6);
  background-size: 300% 300%;
  animation: driftBg 22s ease-in-out infinite alternate;
  position: relative;
}

@keyframes driftBg {
  0%   { background-position: 0% 20%; }
  50%  { background-position: 100% 60%; }
  100% { background-position: 30% 100%; }
}

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

.stage {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6vh 5vw;
  text-align: center;
}

.date-badge {
  position: fixed;
  top: max(20px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Caveat', cursive;
  font-size: clamp(1.1rem, 1.6vw, 1.5rem);
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  opacity: 0.8;
  z-index: 3;
}

/* ---------- Конверт ---------- */

.envelope-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.envelope {
  --w: min(300px, 78vw);
  --h: calc(var(--w) * 0.62);
  position: relative;
  width: var(--w);
  height: var(--h);
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  perspective: 1400px;
  filter: drop-shadow(0 18px 30px rgba(150, 60, 95, 0.28));
  transition: transform 0.35s ease;
}

.envelope:hover { transform: translateY(-4px); }
.envelope:focus-visible { outline: 3px solid var(--accent); outline-offset: 6px; border-radius: 12px; }
.envelope:active { transform: translateY(-1px) scale(0.98); }

.envelope__back,
.envelope__flap,
.envelope__letter,
.envelope__shadow {
  position: absolute;
  left: 0;
  right: 0;
}

.envelope__back {
  top: 0;
  bottom: 0;
  background: linear-gradient(160deg, var(--envelope-back), var(--envelope-back-dark));
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.envelope__back::before,
.envelope__back::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 52%;
  height: 78%;
  background: rgba(255,255,255,0.16);
  clip-path: polygon(0 100%, 100% 100%, 0 0);
}
.envelope__back::before { left: 0; }
.envelope__back::after  { right: 0; transform: scaleX(-1); }

.envelope__letter {
  top: 6%;
  bottom: 6%;
  margin: 0 6%;
  background: var(--paper);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(120, 60, 90, 0.15);
  z-index: 2;
  transform: translateY(6%) scale(0.94);
  opacity: 0.9;
  transition: transform 0.7s cubic-bezier(.2,.8,.2,1) 0.35s, opacity 0.5s ease 0.35s;
}

.envelope__letter::before,
.envelope__letter::after {
  content: '';
  position: absolute;
  left: 14%;
  right: 14%;
  height: 2px;
  background: rgba(224, 100, 140, 0.25);
  border-radius: 2px;
}
.envelope__letter::before { top: 30%; }
.envelope__letter::after  { top: 46%; }

.envelope__flap {
  top: 0;
  height: 62%;
  background: linear-gradient(200deg, var(--envelope-flap), var(--envelope-back-dark));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  border-radius: 10px 10px 0 0;
  transform-origin: top center;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(.6,-0.28,.44,1.4);
  z-index: 3;
  box-shadow: 0 1px 0 rgba(255,255,255,0.3) inset;
}

.envelope__seal {
  position: absolute;
  top: 46%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #ff89ab, var(--accent) 70%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff8f2;
  font-size: 20px;
  box-shadow: 0 3px 8px rgba(150, 40, 80, 0.4);
  z-index: 4;
  transition: opacity 0.35s ease, transform 0.5s ease;
}

.envelope__shadow {
  bottom: -14px;
  height: 18px;
  background: radial-gradient(ellipse at center, rgba(120,60,90,0.25), transparent 70%);
  z-index: 0;
  transition: opacity 0.4s ease;
}

.envelope.is-open .envelope__flap {
  transform: rotateX(-178deg);
}
.envelope.is-open .envelope__letter {
  transform: translateY(-46%) scale(1.02);
  opacity: 1;
}
.envelope.is-open .envelope__seal {
  opacity: 0;
  transform: translate(-50%, -140%) scale(0.6);
}
.envelope.is-open .envelope__shadow {
  opacity: 0.4;
}

.hint {
  margin: 0;
  font-family: 'Caveat', cursive;
  font-size: 1.3rem;
  color: var(--ink-soft);
  animation: bob 2.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* ---------- Записка на весь экран ---------- */

.note {
  max-width: 760px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  animation: fadeUp 0.8s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.note__image {
  display: block;
  max-width: min(420px, 80vw);
  max-height: 42vh;
  width: auto;
  height: auto;
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(120, 60, 90, 0.28);
  object-fit: cover;
}

.note__text {
  font-size: clamp(1.5rem, 1.1rem + 2vw, 2.6rem);
  line-height: 1.5;
  font-weight: 500;
  color: var(--ink);
  text-wrap: balance;
}

.note__text p {
  margin: 0 0 0.6em;
}
.note__text p:last-child { margin-bottom: 0; }

.word {
  display: inline-block;
  opacity: 0;
  transform: translateY(10px);
  animation: wordIn 0.55s ease forwards;
}

@keyframes wordIn {
  to { opacity: 1; transform: translateY(0); }
}

.note__footer {
  font-family: 'Caveat', cursive;
  font-size: 1.5rem;
  color: var(--accent);
  opacity: 0;
  animation: fadeUp 0.8s ease 1.1s both;
}

/* ---------- Пустое состояние ---------- */

.empty {
  animation: fadeUp 0.7s ease both;
  color: var(--ink-soft);
}
.empty__title {
  font-size: clamp(1.3rem, 1rem + 1.4vw, 1.9rem);
  margin: 0 0 10px;
}
.empty__sub {
  font-family: 'Caveat', cursive;
  font-size: 1.3rem;
  margin: 0;
}

/* ---------- Тост о новой записке ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(91, 58, 74, 0.92);
  color: #fff5f8;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 1rem;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 24px rgba(60, 20, 40, 0.3);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  z-index: 5;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Доступность ---------- */

@media (prefers-reduced-motion: reduce) {
  body { animation: none; }
  .hint { animation: none; }
  .envelope, .envelope__flap, .envelope__letter, .envelope__seal, .envelope__shadow {
    transition-duration: 0.01ms !important;
  }
  .word { animation-duration: 0.01ms !important; }
}

@media (max-width: 420px) {
  .note__footer { font-size: 1.25rem; }
}
