:root {
  --green: oklch(0.34 0.07 155);
  --green-deep: oklch(0.27 0.06 155);
  --ground: oklch(0.58 0.19 358);
  --ground-glow: oklch(0.65 0.18 358);
  --on-ground: oklch(0.99 0.012 355);
  --sheet: oklch(0.985 0.004 140);
  --ink: oklch(0.27 0.03 155);
  --ink-soft: oklch(0.46 0.03 155);
  --rule: oklch(0.82 0.02 150);
  --pink: oklch(0.66 0.21 355);
  --pink-deep: oklch(0.56 0.21 355);
  --pink-pale: oklch(0.9 0.06 355);
  --tape: oklch(0.95 0.012 95 / 0.78);
  --glassine: oklch(0.97 0.008 140 / 0.62);

  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --typed: "Courier Prime", "Courier New", monospace;
  --hand: "Kalam", cursive;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sheet-shadow: 0 1px 1px oklch(0.25 0.1 355 / 0.3), 0 14px 32px -10px oklch(0.22 0.12 355 / 0.6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  background-image:
    radial-gradient(120% 80% at 50% 0%, var(--ground-glow) 0%, transparent 60%),
    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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--on-ground);
  font-family: var(--display);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

::selection { background: var(--green); color: white; }

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--on-ground); outline-offset: 4px; border-radius: 6px; }

#app { min-height: 100svh; position: relative; z-index: 1; }

/* ---------- Scenes ---------- */

.scene {
  min-height: 100svh;
  padding: max(24px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.scene[hidden] { display: none; }

.scene.is-entering { animation: scene-in 900ms var(--ease-out) both; }

@keyframes scene-in {
  from { opacity: 0; transform: translateY(24px); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

.hint {
  margin: 0;
  font-family: var(--typed);
  font-size: 0.9rem;
  color: var(--on-ground);
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  min-height: 52px;
  padding: 0 28px;
  border-radius: 999px;
  background: var(--sheet);
  color: var(--pink-deep);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 20px -8px oklch(0.25 0.12 355 / 0.7);
  transition: transform 300ms var(--ease-out), background 200ms, box-shadow 300ms var(--ease-out);
}
.btn:hover { background: var(--pink-pale); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; }

.btn--ghost {
  background: transparent;
  color: var(--on-ground);
  box-shadow: inset 0 0 0 1.5px oklch(0.99 0.012 355 / 0.6);
  padding: 0;
  width: 52px;
}
.btn--ghost:hover { background: oklch(1 0 0 / 0.07); }
.btn--ghost svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn--light { width: auto; padding: 0 24px; }

/* ---------- Packet (glassine seed envelope) ---------- */

.packet {
  position: relative;
  width: min(78vw, 320px);
  aspect-ratio: 3 / 4;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  perspective: 900px;
  transition: transform 500ms var(--ease-out);
  animation: packet-breathe 4.5s ease-in-out infinite;
}
.packet:hover { transform: rotate(-1.5deg) translateY(-4px); }

@keyframes packet-breathe {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -6px; }
}

.packet__back,
.packet__front {
  position: absolute;
  inset: 0;
  border-radius: 3px;
}

.packet__back {
  background: oklch(0.95 0.01 140 / 0.9);
  box-shadow: var(--sheet-shadow);
}

.packet__flower {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 82%;
  translate: -50% 0;
  transition: transform 900ms var(--ease-out), opacity 600ms;
}
.packet__flower svg { display: block; width: 100%; height: auto; }

.packet__front {
  top: 22%;
  background: var(--glassine);
  -webkit-backdrop-filter: blur(3px) saturate(0.85);
  backdrop-filter: blur(3px) saturate(0.85);
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 9%;
}

/* fold lines on the glassine */
.packet__front::before,
.packet__front::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: oklch(1 0 0 / 0.55);
}
.packet__front::before { left: 7%; }
.packet__front::after { right: 7%; }

.packet__flap {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 32%;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  background: oklch(0.96 0.01 140 / 0.85);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  clip-path: polygon(0 0, 100% 0, 100% 52%, 50% 100%, 0 52%);
  transition: transform 700ms var(--ease-out);
  z-index: 2;
}

.seal {
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: 64px;
  height: 64px;
  translate: -50% 0;
  border-radius: 50%;
  background: var(--pink) url("photos/seal.jpg") center / cover no-repeat;
  box-shadow: 0 2px 6px oklch(0.3 0.15 355 / 0.45), inset 0 0 0 4px var(--pink);
}

.packet.is-open { animation: none; }
.packet.is-open .packet__flap { transform: rotateX(178deg); }
.packet.is-open .seal { opacity: 0; transition: opacity 200ms; }
.packet.is-lifting .packet__flower { transform: translateY(-38%) rotate(-6deg) scale(1.05); }
.packet.is-lifting .packet__front,
.packet.is-lifting .packet__back,
.packet.is-lifting .packet__flap { opacity: 0; transition: opacity 600ms 200ms; }

/* ---------- Specimen labels (typed) ---------- */

.label {
  display: block;
  font-family: var(--typed);
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--ink);
  padding: 8px 10px;
  font-size: 0.8rem;
  line-height: 1.5;
  text-align: left;
}
.label__row { display: flex; gap: 8px; border-bottom: 1px dotted var(--rule); }
.label__row:last-child { border-bottom: 0; }
.label__key { color: var(--ink-soft); min-width: 5.5em; }
.label__val { color: var(--ink); }

.label--packet { width: 80%; font-size: 0.85rem; position: relative; z-index: 1; }
.label--packet .label__val.js-name { font-weight: 700; color: var(--pink-deep); }

/* ---------- Sheets ---------- */

.sheet {
  position: relative;
  background: var(--sheet);
  color: var(--ink);
  border-radius: 2px;
  box-shadow: var(--sheet-shadow);
}

.tape {
  position: absolute;
  width: 84px;
  height: 26px;
  background: var(--tape);
  box-shadow: 0 1px 2px oklch(0.2 0.03 155 / 0.15);
  z-index: 3;
  clip-path: polygon(0 0, 100% 0, 97% 20%, 100% 40%, 97% 60%, 100% 80%, 97% 100%, 0 100%, 3% 80%, 0 60%, 3% 40%, 0 20%);
}
.tape--tl { top: -10px; left: -14px; rotate: -32deg; }
.tape--tr { top: -10px; right: -14px; rotate: 32deg; }

.sheet--letter {
  width: min(100%, 560px);
  padding: 44px 28px 40px;
}

.letter__title {
  margin: 0 0 22px;
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  text-wrap: balance;
  color: var(--ink);
}
.accent { color: var(--pink-deep); }

.letter__body p {
  margin: 0 0 1em;
  font-size: 1.08rem;
  line-height: 1.6;
  max-width: 62ch;
  color: oklch(0.32 0.03 155);
}

.letter__sign {
  margin: 28px 0 0;
  font-family: var(--hand);
  font-size: 1.4rem;
  line-height: 1.3;
  color: var(--ink);
}
.letter__from { color: var(--pink-deep); }

.sheet__flower {
  position: absolute;
  right: 18px;
  bottom: 14px;
  width: 52px;
  opacity: 0.9;
  pointer-events: none;
}
.sheet__flower svg { display: block; width: 100%; height: auto; }

.scene__foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  max-width: 420px;
}
.intro {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--on-ground);
  text-wrap: balance;
}

/* letter reveal */
.scene--letter.is-entering .sheet--letter {
  animation: unfold 1100ms var(--ease-out) both;
  transform-origin: 50% 0;
}
@keyframes unfold {
  0% { clip-path: inset(0 0 92% 0); transform: translateY(40px) rotate(-2deg); }
  100% { clip-path: inset(0 0 -10% 0); transform: none; }
}
.scene--letter.is-entering .letter__body p,
.scene--letter.is-entering .letter__sign {
  animation: line-in 800ms var(--ease-out) both;
}

@keyframes line-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Deck ---------- */

.scene--deck { gap: 18px; }

.counter {
  margin: 0;
  font-family: var(--typed);
  font-size: 0.95rem;
  color: var(--on-ground);
}

.deck {
  position: relative;
  width: min(86vw, 380px);
  aspect-ratio: 3 / 4.1;
  margin-bottom: 20px;
}

.card {
  position: absolute;
  inset: 0;
  perspective: 1400px;
  transition: transform 700ms var(--ease-out), opacity 500ms;
  cursor: pointer;
  border: 0;
  padding: 0;
  background: none;
  text-align: left;
}
.card[data-pos="1"] { transform: translate(8px, 10px) rotate(3deg); z-index: 2; }
.card[data-pos="2"] { transform: translate(-6px, 18px) rotate(-3deg); z-index: 1; }
.card[data-pos="0"] { z-index: 3; }
.card[data-pos="far"] { transform: translate(0, 22px) rotate(0); opacity: 0; z-index: 0; pointer-events: none; }
.card[data-pos="gone"] { transform: translate(-120%, -4%) rotate(-14deg); opacity: 0; z-index: 4; pointer-events: none; }
.card:not([data-pos="0"]) { pointer-events: none; }

.card__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 800ms var(--ease-out);
}
.card.is-flipped .card__inner { transform: rotateY(180deg); }

.card__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--sheet);
  border-radius: 2px;
  box-shadow: var(--sheet-shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  color: var(--ink);
}
.card__back { transform: rotateY(180deg); justify-content: center; padding: 28px 26px; }

.card__specimen {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}

.card__photo {
  position: relative;
  width: 86%;
  max-height: 100%;
  aspect-ratio: 4 / 5;
  background: white;
  padding: 8px 8px 8px;
  box-shadow: 0 1px 2px oklch(0.2 0.03 155 / 0.2), 0 6px 14px -6px oklch(0.2 0.03 155 / 0.35);
  rotate: -2deg;
}
.card__photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card__photo .tape { width: 70px; height: 22px; top: -9px; left: 50%; translate: -50% 0; rotate: 3deg; }

.card__pressed { width: 78%; max-height: 100%; }
.card__pressed svg { display: block; width: 100%; height: auto; max-height: 100%; }

.card__pressed .tape { width: 54px; height: 18px; }
.card__pressed { position: relative; }
.card__pressed .tape--stem { left: 44%; bottom: 14%; rotate: -12deg; }
.card__pressed .tape--leaf { left: 12%; top: 54%; rotate: 24deg; }

.card__foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}
.card__no {
  font-family: var(--display);
  font-weight: 800;
  font-size: 2.6rem;
  line-height: 0.8;
  color: var(--pink);
  letter-spacing: -0.04em;
}

.wish {
  margin: 0;
  font-family: var(--hand);
  font-size: clamp(1.45rem, 6.4vw, 1.85rem);
  line-height: 1.35;
  color: var(--ink);
  text-wrap: pretty;
}
.wish__mark { color: var(--pink); }
.card__back .sheet__flower { width: 60px; right: 20px; bottom: 18px; }
.card__back .wish-label {
  position: absolute;
  top: 22px;
  left: 26px;
  font-family: var(--typed);
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.card__back .wish-from {
  margin: 18px 0 0;
  font-family: var(--hand);
  font-size: 1.1rem;
  color: var(--pink-deep);
}

.hint--deck { font-size: 0.82rem; }

.deck__nav {
  display: flex;
  gap: 12px;
  align-items: center;
}
.deck__nav #next { min-width: 160px; }

/* ---------- Finale ---------- */

.scene--finale { text-align: center; gap: 32px; }

.finale__line {
  margin: 0;
  max-width: 14ch;
  font-size: clamp(2.6rem, 12vw, 5.5rem);
  font-weight: 800;
  line-height: 0.98;
  letter-spacing: -0.035em;
  color: var(--sheet);
  text-wrap: balance;
}
.finale__line .accent { color: oklch(0.9 0.14 92); }

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

/* ---------- Desktop ---------- */

@media (min-width: 720px) {
  .sheet--letter { padding: 60px 56px 56px; }
  .deck { width: 400px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
