:root {
  color-scheme: dark;
  --bg: #090806;
  --bg-deep: #171207;
  --ink: #fff9df;
  --muted: rgba(255, 247, 213, .72);
  --gold: #ffd84a;
  --gold-deep: #f5be25;
  --petal: #ffd84a;
  --petal-dark: #f2af00;
  --center: #5a3510;
  --paper: rgba(22, 18, 10, 0.74);
  --paper-solid: #1b160c;
  --line: rgba(255, 222, 102, 0.18);
  --shadow: 0 34px 100px rgba(0, 0, 0, 0.56);
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 18% 16%, rgba(188, 127, 7, .22), transparent 28%),
    radial-gradient(ellipse at 84% 14%, rgba(255, 214, 55, .16), transparent 24%),
    radial-gradient(circle at 50% 120%, rgba(128, 77, 0, .14), transparent 42%),
    linear-gradient(145deg, #050503, var(--bg) 48%, #0e0b05);
  overflow: hidden;
}

button {
  font: inherit;
}

.flower-cursor {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  body,
  button,
  .app button,
  input {
    cursor: none;
  }

  .flower-cursor {
    position: fixed;
    z-index: 100;
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    pointer-events: none;
    background: url("assets/flowers/ai-generated-vibrant-yellow-cosmos-flower-with-delicate-petals-on-transparent-background-stock-png.png") center / contain no-repeat;
    filter: drop-shadow(0 0 7px rgba(255, 205, 40, .64)) drop-shadow(0 3px 6px rgba(0, 0, 0, .55));
    transform: translate3d(-80px, -80px, 0) rotate(-18deg);
    transition: width 160ms ease, height 160ms ease, filter 160ms ease;
    will-change: transform;
  }

  .flower-cursor.is-over-action {
    width: 43px;
    height: 43px;
    filter: drop-shadow(0 0 11px rgba(255, 231, 111, .88)) drop-shadow(0 3px 6px rgba(0, 0, 0, .55));
  }
}

.app,
.scene {
  min-height: 100dvh;
}

.scene {
  position: relative;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.ambient {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(2px);
  opacity: .7;
}

.orb-one {
  width: clamp(180px, 38vw, 460px);
  height: clamp(180px, 38vw, 460px);
  left: -9vw;
  bottom: -14vh;
  background: radial-gradient(circle, rgba(255, 192, 25, .28), transparent 68%);
}

.orb-two {
  width: clamp(140px, 32vw, 360px);
  height: clamp(140px, 32vw, 360px);
  right: -8vw;
  top: -10vh;
  background: radial-gradient(circle, rgba(255, 222, 80, .2), transparent 70%);
}

.petal-fall {
  position: absolute;
  width: 22px;
  height: 34px;
  border-radius: 80% 10% 80% 10%;
  background: linear-gradient(135deg, #fff176, #f6bd16);
  box-shadow: inset -4px -8px 12px rgba(176, 111, 0, .16);
  animation: fall 8s linear infinite;
  opacity: .7;
}

.p1 { left: 12%; animation-delay: -1s; }
.p2 { left: 34%; animation-delay: -4s; transform: scale(.72); }
.p3 { left: 68%; animation-delay: -2.4s; transform: scale(.9); }
.p4 { left: 87%; animation-delay: -6s; transform: scale(.65); }

@keyframes fall {
  0% { translate: 0 -14vh; rotate: 0deg; }
  45% { translate: 34px 48vh; rotate: 150deg; }
  100% { translate: -22px 112vh; rotate: 360deg; }
}

.letter-card {
  position: relative;
  z-index: 1;
  width: min(680px, 94vw);
  padding: clamp(26px, 6vw, 58px);
  border: 1px solid var(--line);
  border-radius: clamp(28px, 5vw, 46px);
  background:
    linear-gradient(135deg, rgba(255, 244, 183, .07), transparent 36%),
    var(--paper);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.13);
  backdrop-filter: blur(24px) saturate(1.1);
  text-align: left;
}

.letter-card::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(255, 221, 107, .13);
  border-radius: calc(clamp(28px, 5vw, 46px) - 12px);
  pointer-events: none;
}

.kicker {
  margin: 0 0 14px;
  text-transform: uppercase;
  letter-spacing: .2em;
  font-size: 11px;
  font-weight: 800;
  color: var(--gold-deep);
}

h1,
h2 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  line-height: .95;
  letter-spacing: -.05em;
}

h1 {
  max-width: 8ch;
  font-size: clamp(54px, 13vw, 116px);
  text-wrap: balance;
  text-shadow: 0 10px 42px rgba(0, 0, 0, .36);
}

h2 {
  font-size: clamp(34px, 8vw, 76px);
}

.letter-copy {
  display: grid;
  gap: 14px;
  margin: clamp(24px, 5vw, 38px) 0 28px;
  max-width: 58ch;
  color: var(--muted);
  font-size: clamp(16px, 3.6vw, 19px);
  line-height: 1.62;
}

.letter-copy p {
  margin: 0;
}

.primary-button,
.ghost-button,
.control-button {
  border: 0;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.primary-button {
  width: 100%;
  min-height: 58px;
  padding: 16px 22px;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f2dfab, #d9b967);
  color: #1b1305;
  font-weight: 500;
  letter-spacing: .03em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
}

.primary-button::after {
  display: none;
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 28%, rgba(255,255,255,.46) 47%, transparent 64%);
  translate: -130% 0;
  animation: buttonShine 4.6s ease-in-out infinite;
}

.primary-button:hover,
.ghost-button:hover,
.control-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.ghost-button:active,
.control-button:active {
  transform: translateY(1px) scale(.99);
}

.letter-card h1,
.letter-copy p,
.primary-button {
  opacity: 0;
  transform: translateY(16px);
  animation: introReveal 820ms cubic-bezier(.2, .78, .2, 1) forwards;
}

.letter-card h1 { animation-delay: 120ms; }
.letter-copy p:nth-child(1) { animation-delay: 350ms; }
.letter-copy p:nth-child(2) { animation-delay: 620ms; }
.letter-copy p:nth-child(3) { animation-delay: 890ms; }
.letter-copy p:nth-child(4) { animation-delay: 1160ms; }
.primary-button { animation-delay: 1460ms; }

@keyframes introReveal {
  from { opacity: 0; transform: translateY(16px); filter: blur(8px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

@keyframes buttonShine {
  0%, 60% { translate: -130% 0; }
  84%, 100% { translate: 130% 0; }
}

.camera-scene {
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 229, 85, .42), transparent 30%),
    linear-gradient(145deg, #171004, #3a2500 56%, #7b5600);
  color: #fff7d2;
  overflow: hidden;
  padding: 0;
}

.camera-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.camera-header {
  position: absolute;
  z-index: 5;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  padding: 18px 24px;
  pointer-events: none;
  justify-content: center;
}

.camera-header h2 {
  max-width: 28ch;
  margin: 0 auto;
  font-size: clamp(23px, 3.2vw, 38px);
  line-height: 1.24;
  letter-spacing: -.025em;
  text-align: center;
  text-wrap: balance;
  color: #fff9ea;
  text-shadow: 0 2px 12px #000c, 0 0 40px #0009;
}

.camera-header.asking-for-smile h2 {
  animation: cameraMessageIn 700ms ease both;
}

@keyframes cameraMessageIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.ghost-button,
.control-button {
  border: 1px solid rgba(255, 238, 161, .24);
  background: linear-gradient(145deg, rgba(255,255,255,.18), rgba(255,255,255,.07));
  color: #fff7d2;
  border-radius: 999px;
  box-shadow: 0 10px 32px rgba(0,0,0,.20), inset 0 1px 0 rgba(255,255,255,.18);
  backdrop-filter: blur(16px) saturate(1.25);
}

.ghost-button {
  padding: 12px 16px;
  font-weight: 800;
}

.camera-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 0;
  border: 0;
  background: #080602;
  box-shadow: 0 24px 90px rgba(0,0,0,.35);
  touch-action: none;
}

#cameraVideo,
.three-layer,
#flowerCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cameraVideo {
  object-fit: cover;
  background: #050301;
  transform: scaleX(-1);
  transition: opacity 900ms ease, filter 900ms ease;
}

.camera-stage.final-reveal.covering #cameraVideo {
  opacity: .72;
  filter: blur(1px) brightness(.82) saturate(.86);
}

.camera-stage.final-reveal.covered #cameraVideo,
.camera-stage.final-reveal.opened #cameraVideo {
  opacity: 0;
  filter: blur(10px) brightness(.25) saturate(.6);
}

.camera-stage.final-reveal .three-layer {
  opacity: 0;
}

.three-layer,
#flowerCanvas {
  z-index: 2;
  pointer-events: none;
}

.final-letter {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: min(680px, calc(100% - 40px));
  height: min(780px, calc(100% - 64px));
  display: flex;
  flex-direction: column;
  translate: -50% -50%;
  padding: 0;
  background: transparent;
  color: #2f240b;
  text-align: left;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: #bda579 transparent;
  opacity: 0;
  transform: translateY(18px) scale(.94);
  filter: blur(12px);
  transition: opacity 450ms ease, transform 450ms cubic-bezier(.2, .9, .2, 1), filter 450ms ease;
}

.camera-stage.opened .final-letter {
  animation: letterBloom 450ms cubic-bezier(.16, 1, .3, 1) both;
  opacity: 1;
  transform: translateY(0) scale(1);
  filter: blur(0);
}

.letter-sheet::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(164, 107, 0, .18);
  border-radius: 1px;
  pointer-events: none;
}

.final-letter .kicker {
  color: var(--gold-deep);
}

.final-letter h2 {
  flex-shrink: 0;
  color: #3a2608;
  font-size: clamp(34px, 5vw, 48px);
  margin: 0 0 30px;
  line-height: 1.12;
  text-wrap: balance;
}

.final-letter p:not(.kicker) {
  margin: 0 0 22px;
  color: #5f4a18;
  font-family: Georgia, serif;
  font-size: clamp(17px, 3.4vw, 20px);
  line-height: 1.85;
  white-space: pre-line;
}

.letter-placeholder {
  height: 300px;
  max-height: 38dvh;
  opacity: .45;
  background: repeating-linear-gradient(transparent 0 35px, #d5c9ac 35px 36px);
}
.final-letter .final-letter-closing { margin-top: 36px; font-style: italic; }
.letter-voice { margin-top: 32px; padding-top: 24px; border-top: 1px solid #d5c9ac; }
.letter-voice audio { display: block; width: 100%; color-scheme: light; }
.final-letter .letter-voice p { font-family: Inter, sans-serif; font-size: 12px; margin-bottom: 12px; color: #86785e; }
.final-letter:focus { outline: none; }

.final-letter-body { --letter-illustration-gap: 32px; flex: 1; min-height: 0; overflow: hidden; }
.letter-paper-stack { position: relative; flex: 1; min-height: 0; perspective: 1800px; isolation: isolate; }
.letter-paper-stack::before { content: ''; position: absolute; inset: 0; background: #e8ddc2; border: 1px solid #d6c7a5; border-radius: 3px; box-shadow: 0 5px 14px #38270726; transform: translate(5px, 5px) rotate(.7deg); z-index: -1; }
.letter-sheet { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; padding: clamp(30px, 6vw, 64px); transform-origin: left center; transition: transform 650ms cubic-bezier(.2,.8,.2,1); }
.letter-sheet::before { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(145deg, #fffcf3, #f1e8d1); border: 1px solid #daceb3; border-radius: 3px; box-shadow: 0 20px 60px #0005; }
.letter-sheet { transform: translateZ(0); }
.letter-turning-sheet { z-index: 3; pointer-events: none; backface-visibility: hidden; transition: none; }
.letter-photo { height: 100%; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.letter-photo img { display: block; flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.letter-photo figcaption { flex-shrink: 0; text-align: center; font-family: Georgia, serif; font-size: clamp(16px, 2.5vw, 20px); font-style: italic; line-height: 1.5; color: #5f4a18; }
@media (prefers-reduced-motion: reduce) { .letter-sheet { transition: none; } }
.final-letter-body > p:last-of-type { margin-bottom: 0; }
.letter-page-illustration { display: block; max-width: 100%; margin: var(--letter-illustration-gap) auto 0; object-fit: contain; border-radius: 8px; }
.letter-illustration-page { display: flex; align-items: center; justify-content: center; height: 100%; margin: 0; }
.letter-illustration-page .letter-page-illustration { width: 100%; height: 100%; margin: 0; }
.letter-pagination { position: relative; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; width: 100%; margin: 24px 0 0; padding: 0; }
.letter-pagination span { font-size: 13px; color: #867044; }
.letter-pagination button { min-height: 44px; border: 1px solid #ccb477; border-radius: 999px; cursor: pointer; transition: background 180ms, box-shadow 180ms; }
.letter-page-back,
.letter-page-next { width: 44px; padding: 0; background: transparent; color: #73571c; font-size: 20px; }
.letter-pagination button svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.letter-pagination button:hover:not(:disabled) { background: #a0803b; color: #fff9e8; box-shadow: 0 4px 16px #795b2033; }
.letter-pagination button:disabled { opacity: .3; cursor: default; }
@media (hover: hover) and (pointer: fine) {
  .letter-pagination button,
  .letter-pagination button:disabled { cursor: none; }
}
@media (max-width: 420px) {
  .letter-pagination { gap: 8px; }
}
@media (max-height: 600px) {
  .final-letter { height: calc(100% - 32px); }
  .letter-sheet { padding: 24px 30px; }
  .final-letter h2 { font-size: 28px; margin-bottom: 14px; }
  .final-letter p:not(.kicker) { font-size: 16px; line-height: 1.55; }
  .letter-pagination { margin-top: 14px; }
}

@keyframes letterBloom {
  from { opacity: 0; transform: translateY(36px) rotate(-2deg) scale(.96); }
  to { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}

button:focus-visible { outline: 2px solid #c79e4e; outline-offset: 5px; }
.camera-shell:has(.final-reveal) .camera-header,
.camera-shell:has(.final-reveal) .controls,
.camera-shell:has(.final-reveal) .tracking-status { opacity: 0; visibility: hidden; pointer-events: none; }
.camera-header, .controls, .tracking-status { transition: opacity 500ms, visibility 500ms; }
.letter-scene { max-height: 100dvh; overflow-y: auto; }

.three-layer canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.camera-message {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 3;
  width: min(390px, calc(100% - 36px));
  translate: -50% 0;
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 238, 161, .24);
  border-radius: 18px;
  background: rgba(20, 13, 0, .66);
  color: #fff8d8;
  text-align: center;
  backdrop-filter: blur(14px);
}

.camera-message span {
  color: rgba(255, 248, 216, .72);
  font-size: 13px;
}

.camera-message.error {
  background: rgba(76, 17, 0, .72);
}

.controls {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 28px);
  translate: -50% 0;
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 8px;
  border: 1px solid rgba(255, 238, 161, .18);
  border-radius: 999px;
  background: rgba(20, 17, 10, .72);
  box-shadow: 0 18px 70px rgba(0,0,0,.24), inset 0 1px 0 rgba(255,255,255,.12);
  backdrop-filter: blur(20px) saturate(1.25);
}

.control-button {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: #fff3ce;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.control-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.control-button-center {
  background: rgba(240, 214, 145, .14);
  border-color: rgba(240, 214, 145, .2);
  color: #f0d691;
}

@media (hover: hover) {
  .control-button:hover {
    background: rgba(240, 214, 145, .22);
    border-color: rgba(240, 214, 145, .3);
  }
}

.control-button:active {
  transform: scale(.92);
  background: rgba(240, 214, 145, .28);
}

.control-button:focus-visible {
  outline: 2px solid #f0d691;
  outline-offset: 3px;
}

.tracking-notice {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 25;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(20, 12, 9, .88);
  color: #fff;
  text-align: center;
  font-size: 13px;
}
.tracking-notice[hidden] { display: none; }
.tracking-notice p { margin: 0; }
.tracking-notice button { margin-top: 8px; padding: 7px 12px; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

[hidden] { display: none !important; }

@media (max-width: 640px) {
  .camera-header {
    align-items: center;
    padding: 10px 10px 10px 14px;
    border-radius: 20px;
  }

  .camera-header h2 {
    font-size: clamp(20px, 7vw, 30px);
  }

  .ghost-button {
    padding: 10px 12px;
    font-size: 13px;
  }

}

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

/* Shared button treatment across the introduction, camera, and letter. */
.primary-button,
.control-button,
.letter-pagination button {
  border: 1px solid #ccb477;
  border-radius: 999px;
  background: #fff9eb;
  color: #73571c;
  box-shadow: none;
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
  -webkit-tap-highlight-color: transparent;
}
.control-button,
.letter-pagination button {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
}
@media (hover: hover) {
  .primary-button:hover:not(:disabled),
  .control-button:hover:not(:disabled),
  .letter-pagination button:hover:not(:disabled) {
    background: #f2e5c5;
    border-color: #b89a58;
    color: #73571c;
    box-shadow: 0 3px 12px #795b2026;
    transform: translateY(-1px);
  }
}
.primary-button:active:not(:disabled),
.control-button:active:not(:disabled),
.letter-pagination button:active:not(:disabled) {
  background: #ead8ac;
  transform: scale(.96);
}
.primary-button:focus-visible,
.control-button:focus-visible,
.letter-pagination button:focus-visible {
  outline: 2px solid #c79e4e;
  outline-offset: 4px;
}
@media (hover: hover) and (pointer: fine) {
  .app button,
  .app button:disabled { cursor: none; }
}
