/* ------------------------------------------------------------------
   Письмо — a folded paper note in a dark room.
   The page is the room; the letter is the only source of light.
   ------------------------------------------------------------------ */

/* @font-face rules live in fonts.css, generated by scripts/fetch-fonts.js */

:root {
  --night: #16111d;
  --night-lift: #221a2c;
  --paper: #f7efe3;
  --crease: #d3bda0;
  --ink: #33262b;
  --ink-soft: #6b5a5f;
  --garnet: #9e3b54;
  --glow: #f2c57c;

  --hand: 'Caveat', 'Segoe Script', cursive;
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --measure: 34rem;
}

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

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

/* An explicit display in our own rules would otherwise outrank the browser's
   [hidden] rule and leave "hidden" elements on screen. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--night);
  color: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.night {
  background:
    radial-gradient(120% 80% at 50% 30%, #241b31 0%, transparent 60%),
    var(--night);
}

.night--plain {
  padding: 2rem 1.25rem 4rem;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--glow);
  outline-offset: 3px;
}

/* ---------------------------- the stage ---------------------------- */

/* The page itself scrolls. A letter longer than the screen is read by
   swiping, the way every other page works — nothing hides in an inner box. */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  padding: max(clamp(1.5rem, 5vh, 3rem), env(safe-area-inset-top)) 1.25rem
    max(clamp(1.5rem, 5vh, 3rem), env(safe-area-inset-bottom));
}

/* ------------------------- envelope and seal ------------------------ */

.sprite {
  position: absolute;
}

.envelope {
  position: relative;
  width: clamp(15rem, 82vw, 21rem);
  aspect-ratio: 1.45 / 1;
  margin-bottom: 3.75rem;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  perspective: 1100px;
}

.envelope__glow {
  position: absolute;
  inset: -60% -40%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(242, 197, 124, 0.26) 0%, transparent 64%);
  filter: blur(8px);
  animation: breathe 5.5s ease-in-out infinite;
  pointer-events: none;
}

/* Tucked in with the letter, the way a flower actually travels: leaning out
   of the envelope rather than facing the camera. */
.envelope__sprig {
  position: absolute;
  right: -14%;
  bottom: 4%;
  height: 142%;
  width: auto;
  filter: drop-shadow(0 1rem 1.5rem rgba(0, 0, 0, 0.5));
  transform-origin: bottom center;
  rotate: -7deg;
  animation: sway 7s ease-in-out infinite;
}

/* What the flower blocks from the light behind it. */
.envelope__cast {
  position: absolute;
  right: 0;
  top: 0;
  width: 56%;
  height: 44%;
  background: radial-gradient(
    52% 72% at 58% 0%,
    rgba(52, 32, 12, 0.32) 0%,
    transparent 70%
  );
  transition: opacity 400ms ease;
  pointer-events: none;
  z-index: 4;
}

.stage.is-opening .envelope__cast {
  opacity: 0;
}

.envelope__paper,
.envelope__pocket,
.envelope__flap {
  position: absolute;
  inset: 0;
}

/* Kraft paper: warm brown, with the faint fibre grain it always has. */
.envelope__paper {
  background:
    repeating-linear-gradient(
      64deg,
      rgba(74, 49, 22, 0.035) 0 1px,
      transparent 1px 5px
    ),
    linear-gradient(166deg, #bd9560 0%, #ab8149 55%, #946c39 100%);
  border-radius: 5px;
  box-shadow:
    0 0 5rem rgba(242, 197, 124, 0.12),
    0 1.5rem 3rem rgba(0, 0, 0, 0.6);
  z-index: 1;
}

.envelope__pocket {
  background:
    repeating-linear-gradient(
      64deg,
      rgba(74, 49, 22, 0.035) 0 1px,
      transparent 1px 5px
    ),
    linear-gradient(172deg, #b78e57 0%, #a37a44 100%);
  clip-path: polygon(0 26%, 50% 67%, 100% 26%, 100% 100%, 0 100%);
  border-radius: 0 0 5px 5px;
  z-index: 2;
}

/* The shadow the closed flap casts on the pocket beneath it. */
.envelope__pocket::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(178deg, rgba(70, 46, 22, 0.3) 0%, transparent 24%);
  clip-path: polygon(0 26%, 50% 67%, 100% 26%, 100% 100%, 0 100%);
  opacity: 1;
  transition: opacity 400ms ease;
}

.stage.is-opening .envelope__pocket::after {
  opacity: 0;
}

.envelope__flap {
  inset: 0 0 auto 0;
  height: 67%;
  background:
    repeating-linear-gradient(
      64deg,
      rgba(74, 49, 22, 0.035) 0 1px,
      transparent 1px 5px
    ),
    linear-gradient(178deg, #c49a66 0%, #ac8149 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  border-radius: 5px 5px 0 0;
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 560ms cubic-bezier(0.45, 0.05, 0.25, 1);
  z-index: 3;
}

.envelope__seal {
  position: absolute;
  left: 50%;
  top: 67%;
  width: 27%;
  translate: -50% -50%;
  filter: drop-shadow(0 0.25rem 0.4rem rgba(46, 12, 8, 0.55));
  transform-origin: center;
  animation: heartbeat 2.6s ease-in-out infinite;
  z-index: 4;
}

.envelope__hint {
  position: absolute;
  left: 50%;
  bottom: -2.5rem;
  translate: -50% 0;
  white-space: nowrap;
  font-size: 0.8125rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(247, 239, 227, 0.55);
}

.envelope:hover .envelope__seal {
  animation-duration: 1.5s;
}

@keyframes sway {
  0%, 100% { transform: rotate(2.5deg); }
  50% { transform: rotate(-2deg); }
}

/* A real cardiac rhythm: two beats, then the long rest. */
@keyframes heartbeat {
  0% { transform: scale(1); }
  8% { transform: scale(1.055); }
  16% { transform: scale(1); }
  24% { transform: scale(1.04); }
  34% { transform: scale(1); }
  100% { transform: scale(1); }
}

@keyframes breathe {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* The seal gives way, then the flap swings open. */
.stage.is-opening .envelope {
  pointer-events: none;
}

.stage.is-opening .envelope__seal {
  opacity: 0;
  scale: 0.55;
  animation: none;
  transition: opacity 180ms ease, scale 220ms cubic-bezier(0.5, 0, 0.9, 0.4);
}

.stage.is-opening .envelope__flap {
  transform: rotateX(-166deg);
}

.stage.is-open .envelope {
  display: none;
}

/* ----------------------------- the sheet ---------------------------- */

.sheet {
  display: none;
  position: relative;
  width: min(100%, var(--measure));
  /* Paper is never one flat colour: warm at the top, cooler in the fold. */
  background:
    radial-gradient(120% 60% at 50% 0%, #fdf7ee 0%, transparent 60%),
    linear-gradient(180deg, #f8f1e6 0%, #f4ebdd 55%, #efe4d3 100%);
  color: var(--ink);
  border-radius: 2px;
  box-shadow:
    0 0 7rem rgba(242, 197, 124, 0.15),
    0 1.5rem 4rem rgba(0, 0, 0, 0.55);
}

.stage.is-open .sheet {
  display: block;
  animation: unfold 760ms cubic-bezier(0.2, 0.85, 0.3, 1) both;
}

@keyframes unfold {
  from { opacity: 0; transform: scale(0.4, 0.07); }
  30% { opacity: 1; }
  to { opacity: 1; transform: none; }
}

/* The note remembers being folded: a fold is a thin highlight with a
   shadow beside it, not a drawn line. */
.sheet__crease {
  position: absolute;
  inset-block: 0;
  width: 3px;
  background: linear-gradient(
    to right,
    rgba(150, 121, 86, 0.14),
    rgba(255, 253, 248, 0.75) 55%,
    rgba(150, 121, 86, 0.08)
  );
  opacity: 0;
  pointer-events: none;
}

.sheet__crease--left { left: 33%; }
.sheet__crease--right { left: 67%; }

.stage.is-open .sheet__crease {
  animation: settle 900ms ease 420ms both;
}

@keyframes settle {
  from { opacity: 0; }
  to { opacity: 0.85; }
}

.sheet__inner {
  padding: clamp(1.75rem, 6vw, 3rem);
}

.sheet__inner > * {
  opacity: 0;
}

.stage.is-open .sheet__inner > * {
  animation: rise 700ms cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

.stage.is-open .sheet__crown { animation-delay: 180ms; }
.stage.is-open .sheet__greeting { animation-delay: 320ms; }
.stage.is-open .sheet__body { animation-delay: 460ms; }
.stage.is-open .sheet__photo { animation-delay: 620ms; }
.stage.is-open .sheet__signature { animation-delay: 760ms; }
.stage.is-open .rsvp { animation-delay: 940ms; }

/* The flower the letter came with, printed at the head of the page. */
.sheet__crown {
  display: grid;
  justify-items: center;
  gap: 0.875rem;
  margin-bottom: 1.75rem;
}

.sheet__flower {
  width: clamp(3.5rem, 15vw, 4.5rem);
  filter: drop-shadow(0 0.375rem 0.625rem rgba(51, 38, 43, 0.2));
}

.sheet__rule {
  width: 6rem;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent,
    rgba(150, 121, 86, 0.65),
    transparent
  );
}

@keyframes rise {
  from { opacity: 0; transform: translateY(0.75rem); }
  to { opacity: 1; transform: none; }
}

.sheet__greeting {
  margin: 0 0 0.75rem;
  font-family: var(--hand);
  font-size: clamp(2.25rem, 9vw, 3rem);
  line-height: 1;
  color: var(--garnet);
}

.sheet__body {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.125rem, 4.4vw, 1.3125rem);
  line-height: 1.72;
  text-wrap: pretty;
}

.sheet__photo {
  margin: 2rem 0 0;
  padding: 0.625rem 0.625rem 2.25rem;
  background: #fffdf8;
  box-shadow: 0 0.75rem 1.75rem rgba(51, 38, 43, 0.22);
  rotate: -1.6deg;
}

.sheet__photo img {
  display: block;
  width: 100%;
  max-height: 44svh;
  object-fit: cover;
}

.sheet__signature {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin: 2rem 0 0;
  font-family: var(--hand);
  font-size: clamp(1.75rem, 7vw, 2.125rem);
  line-height: 1;
  color: var(--garnet);
}

.sheet__heart {
  width: 0.7em;
  height: 0.7em;
  color: var(--garnet);
  animation: heartbeat 2.6s ease-in-out infinite;
}

/* ------------------------------- rsvp ------------------------------- */

.rsvp {
  margin-top: 2.5rem;
  padding-top: 1.75rem;
  border-top: 1px solid rgba(211, 189, 160, 0.7);
}

.rsvp__ask {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.rsvp__buttons {
  display: flex;
  gap: 0.75rem;
}

.rsvp__yes,
.rsvp__no {
  flex: 1 1 0;
  padding: 1rem 1.25rem;
  border-radius: 3px;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1;
}

.rsvp__yes {
  background: var(--garnet);
  color: #fdf6ee;
  border: 1px solid var(--garnet);
  cursor: pointer;
  box-shadow: 0 0.5rem 1.25rem rgba(158, 59, 84, 0.32);
  transition: background-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.rsvp__yes:hover {
  background: #8b3149;
  transform: translateY(-1px);
  box-shadow: 0 0.75rem 1.5rem rgba(158, 59, 84, 0.4);
}

.rsvp__yes:active {
  transform: translateY(0);
}

.rsvp__yes:disabled {
  opacity: 0.6;
  cursor: default;
}

/* It bolts the moment a finger comes near, and there is nothing behind it to
   press even if it were caught. */
.rsvp__no {
  position: relative;
  z-index: 5;
  background: rgba(158, 59, 84, 0.06);
  color: var(--garnet);
  border: 1px solid rgba(158, 59, 84, 0.35);
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
  transition: transform 320ms cubic-bezier(0.22, 1, 0.3, 1);
}

.rsvp__done {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------------------------- no letter yet -------------------------- */

.waiting {
  display: grid;
  justify-items: center;
  text-align: center;
}

.waiting__flower {
  width: clamp(4rem, 20vw, 5.5rem);
  margin-bottom: 1.5rem;
  opacity: 0.85;
  filter: drop-shadow(0 0.75rem 1.5rem rgba(0, 0, 0, 0.5));
  animation: sway 7s ease-in-out infinite;
}

.waiting__line {
  margin: 0 0 0.5rem;
  font-family: var(--serif);
  font-size: 1.25rem;
  color: rgba(247, 239, 227, 0.8);
}

.waiting__line--quiet {
  font-size: 1rem;
  color: rgba(247, 239, 227, 0.45);
}

/* ------------------------------- admin ------------------------------- */

.panel {
  width: min(100%, 42rem);
  margin: 0 auto;
}

.panel--narrow {
  width: min(100%, 22rem);
  margin-top: 18vh;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel__title {
  margin: 0;
  font-family: var(--hand);
  font-size: 2.5rem;
  font-weight: 400;
  color: var(--glow);
}

.panel__meta {
  margin: 0.25rem 0 1.5rem;
  font-size: 0.8125rem;
  color: rgba(247, 239, 227, 0.45);
}

.form {
  display: grid;
  gap: 1.25rem;
}

.field {
  display: grid;
  gap: 0.5rem;
}

.field__label {
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(247, 239, 227, 0.6);
}

.field__optional {
  text-transform: none;
  letter-spacing: 0;
  color: rgba(247, 239, 227, 0.35);
}

.field__input {
  width: 100%;
  padding: 0.75rem 0.875rem;
  background: var(--night-lift);
  color: var(--paper);
  border: 1px solid rgba(247, 239, 227, 0.14);
  border-radius: 3px;
  font-family: var(--serif);
  font-size: 1.0625rem;
}

.field__input:focus {
  border-color: rgba(242, 197, 124, 0.5);
  outline: none;
}

.field__input--tall {
  min-height: 16rem;
  line-height: 1.6;
  resize: vertical;
}

.filepick {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filepick__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.filepick__button {
  padding: 0.5rem 1rem;
  border: 1px solid rgba(247, 239, 227, 0.24);
  border-radius: 3px;
  font-size: 0.875rem;
  color: rgba(247, 239, 227, 0.8);
  cursor: pointer;
}

.filepick:hover .filepick__button {
  border-color: rgba(247, 239, 227, 0.45);
  color: var(--paper);
}

.filepick__input:focus-visible + .filepick__button {
  outline: 2px solid var(--glow);
  outline-offset: 3px;
}

.filepick__name {
  font-size: 0.8125rem;
  color: rgba(247, 239, 227, 0.45);
}

.field__help {
  margin: 0;
  font-size: 0.8125rem;
  color: rgba(247, 239, 227, 0.4);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: rgba(247, 239, 227, 0.7);
}

.photo-current {
  display: grid;
  gap: 0.625rem;
  justify-items: start;
}

.photo-current__image,
.photo-preview {
  max-width: 12rem;
  border-radius: 3px;
}

.form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.button {
  display: inline-block;
  padding: 0.75rem 1.375rem;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 0.9375rem;
  text-decoration: none;
  cursor: pointer;
}

.button--primary {
  background: var(--garnet);
  color: var(--paper);
}

.button--primary:hover {
  background: #8b3149;
}

.button--ghost {
  background: none;
  color: rgba(247, 239, 227, 0.7);
  border-color: rgba(247, 239, 227, 0.2);
}

.button--ghost:hover {
  color: var(--paper);
  border-color: rgba(247, 239, 227, 0.4);
}

.notice {
  margin: 0;
  padding: 0.75rem 0.875rem;
  border-radius: 3px;
  font-size: 0.9375rem;
}

.notice--good {
  background: rgba(242, 197, 124, 0.12);
  color: var(--glow);
}

.notice--bad {
  background: rgba(158, 59, 84, 0.18);
  color: #f0a8b6;
}

.answers {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(247, 239, 227, 0.12);
}

.answers__title {
  margin: 0 0 1rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(247, 239, 227, 0.6);
}

.answers__empty {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  color: rgba(247, 239, 227, 0.4);
}

.answers__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.5rem;
}

.answers__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.875rem;
  background: var(--night-lift);
  border-radius: 3px;
}

.answers__answer {
  font-size: 1rem;
}

.answers__answer--yes {
  color: var(--glow);
}

.answers__when {
  font-size: 0.8125rem;
  color: rgba(247, 239, 227, 0.4);
}

/* --------------------------- reduced motion --------------------------- */

@media (prefers-reduced-motion: reduce) {
  .envelope__seal,
  .envelope__glow,
  .envelope__sprig {
    animation: none;
  }

  .stage.is-opening .envelope__seal,
  .stage.is-opening .envelope__flap {
    transition-duration: 1ms;
  }

  .stage.is-open .sheet,
  .stage.is-open .sheet__crease,
  .stage.is-open .sheet__inner > * {
    animation-duration: 1ms;
    animation-delay: 0ms;
  }

  .stage.is-open .sheet__inner > * {
    opacity: 1;
  }
}
