:root {
  color-scheme: dark;
  --ink: #f9fafb;
  --muted: #c7d2fe;
  --paper: #fff7ed;
  --paper-ink: #1f2937;
  --line: rgba(255, 255, 255, 0.18);
  --blue: #2563eb;
  --gold: #fbbf24;
  --rose: #fb7185;
  --green: #34d399;
  --deep: #111827;
  --panel: rgba(17, 24, 39, 0.76);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  min-height: 100%;
  min-height: 100svh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background:
    radial-gradient(
      circle at 20% 18%,
      rgba(251, 191, 36, 0.22),
      transparent 28%
    ),
    radial-gradient(
      circle at 90% 10%,
      rgba(52, 211, 153, 0.2),
      transparent 24%
    ),
    linear-gradient(145deg, #111827 0%, #172554 46%, #1f2937 100%);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
}

.scene {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: calc(16px + var(--safe-top)) 16px calc(108px + var(--safe-bottom));
  opacity: 0;
  pointer-events: none;
  transform: translateX(26px) scale(0.98);
  transition:
    opacity 320ms ease,
    transform 320ms ease;
}

.scene.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

.scene[data-scene="cover"] {
  display: grid;
  place-items: stretch center;
  padding: calc(16px + var(--safe-top)) 20px calc(118px + var(--safe-bottom));
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.cover-stage {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: space-evenly;
  justify-items: center;
  gap: 8px;
  width: min(100%, 420px);
  height: 100%;
  text-align: center;
}

.kicker,
.letter-label {
  margin: 0;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 10ch;
  margin-bottom: 0;
  font-size: clamp(2.7rem, 15.5vw, 4.75rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.7rem, 8vw, 2.7rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.cover-copy {
  max-width: 25ch;
  margin-bottom: 0;
  color: #dbeafe;
  font-size: 1.05rem;
  line-height: 1.45;
}

.age-medallion {
  position: relative;
  display: grid;
  place-items: center;
  width: min(45vw, 185px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background:
    conic-gradient(
      from 180deg,
      var(--gold),
      var(--rose),
      var(--green),
      #93c5fd,
      var(--gold)
    ),
    radial-gradient(
      circle,
      rgba(255, 255, 255, 0.16),
      rgba(255, 255, 255, 0.02)
    );
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  animation: floaty 4s ease-in-out infinite;
}

.age-medallion::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: rgba(17, 24, 39, 0.9);
}

.age-medallion span {
  position: relative;
  font-size: clamp(4rem, 20vw, 6.4rem);
  font-weight: 900;
  line-height: 1;
}

.primary-action {
  display: inline-grid;
  min-height: 52px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: #111827;
  font-weight: 850;
  padding: 0 24px;
  box-shadow: 0 14px 32px rgba(251, 191, 36, 0.25);
  touch-action: manipulation;
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  color: #dbeafe;
  font-size: 0.86rem;
  font-weight: 800;
  text-align: center;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 1.8rem;
  line-height: 1;
}

.memory-stage {
  align-self: center;
  display: grid;
  align-content: center;
  gap: 14px;
  min-height: 0;
  padding-bottom: 8px;
}

.scene[data-scene="memory"].letter-open .memory-stage {
  align-self: stretch;
  align-content: center;
}

.scene[data-scene="memory"].letter-open .photo-card {
  display: none;
}

.photo-card {
  display: grid;
  justify-items: center;
}

.photo-frame {
  position: relative;
  width: min(100%, 330px);
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 10px solid rgba(255, 247, 237, 0.96);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.35), rgba(251, 191, 36, 0.24)),
    #243244;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
}

.photo-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(17, 24, 39, 0.2);
  pointer-events: none;
}

.photo-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 220ms ease;
}

.photo-frame.has-photo img {
  opacity: 1;
}

.cake-stage p,
.letter p {
  color: #dbeafe;
  line-height: 1.5;
}

.cake-stage,
.note-card {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  min-height: 0;
  text-align: center;
}

.note-card {
  gap: 10px;
  width: min(100%, 330px);
  margin-inline: auto;
}

.note-toggle {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 14px;
  width: 100%;
  min-height: 72px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 12px 16px;
  text-align: left;
}

.note-copy {
  display: grid;
  gap: 2px;
}

.note-copy span {
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.note-copy strong {
  font-size: 1.15rem;
}

.note-action {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: var(--gold);
  color: #111827;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}

.cake {
  position: relative;
  display: grid;
  justify-items: center;
  width: min(100%, 380px);
  padding-top: 96px;
}

.candles {
  position: absolute;
  top: 2px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  width: min(100%, 350px);
  align-items: end;
}

.candle {
  position: relative;
  width: 42px;
  height: 92px;
  margin: 0 auto;
  border: 0;
  border-radius: 12px;
  background: transparent;
}

.candle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 24px;
  height: 74px;
  border-radius: 7px 7px 3px 3px;
  background: repeating-linear-gradient(
    -35deg,
    #bfdbfe 0 8px,
    #ffffff 8px 16px
  );
  box-shadow: inset 0 -10px 16px rgba(17, 24, 39, 0.18);
  transform: translateX(-50%);
}

.candle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -17px;
  width: 18px;
  height: 24px;
  border-radius: 60% 60% 50% 50%;
  background: #64748b;
  opacity: 0;
  transform: translateX(-50%) scale(0.55);
  transition:
    background 180ms ease,
    opacity 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.candle.is-lit::before {
  background: radial-gradient(
    circle at 50% 72%,
    #fff7ed 0 18%,
    #fbbf24 30%,
    #f97316 70%
  );
  opacity: 1;
  transform: translateX(-50%) scale(1);
  box-shadow:
    0 0 16px rgba(251, 191, 36, 0.95),
    0 0 34px rgba(249, 115, 22, 0.72),
    0 0 58px rgba(251, 191, 36, 0.38);
}

.candle.is-lit::after {
  box-shadow:
    inset 0 -10px 16px rgba(17, 24, 39, 0.18),
    0 0 18px rgba(251, 191, 36, 0.2);
}

.wish-button {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(50vw, 190px);
  aspect-ratio: 1;
  place-items: center;
  border: 8px solid #fff7ed;
  border-radius: 50%;
  background: linear-gradient(135deg, #fb7185, #fbbf24);
  color: #111827;
  font-size: clamp(4rem, 20vw, 6.5rem);
  font-weight: 950;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.28);
}

.cake-base {
  width: min(92%, 350px);
  height: 110px;
  margin-top: -38px;
  border-radius: 8px 8px 24px 24px;
  background:
    radial-gradient(circle at 28px 22px, #fff7ed 0 9px, transparent 10px),
    radial-gradient(circle at 98px 48px, #fff7ed 0 7px, transparent 8px),
    radial-gradient(circle at 168px 24px, #fff7ed 0 10px, transparent 11px),
    radial-gradient(circle at 250px 52px, #fff7ed 0 8px, transparent 9px),
    linear-gradient(180deg, #93c5fd 0 34%, #2563eb 35% 100%);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.25);
}

.wish-status {
  min-height: 48px;
  max-width: 26ch;
  font-weight: 750;
}

.letter-shell {
  position: relative;
  width: 100%;
  max-height: min(62svh, 520px);
}

.letter-shell[hidden] {
  display: none;
}

.letter {
  width: 100%;
  max-height: min(62svh, 520px);
  overflow: auto;
  padding: 16px 16px 58px;
  border-radius: 8px;
  background: var(--paper);
  color: var(--paper-ink);
  text-align: left;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.3);
  -webkit-user-select: text;
  user-select: text;
}

.letter.is-visible {
  animation: letterIn 360ms ease both;
}

.letter-photo {
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: 14px;
  overflow: hidden;
  border-radius: 6px;
  background: #111827;
}

.letter-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 34%;
}

.letter h2 {
  color: #111827;
  font-size: 1.9rem;
}

.letter p {
  color: #374151;
  font-size: 1rem;
}

.signature {
  margin-bottom: 0;
  color: #111827;
  font-weight: 850;
}

.scroll-cue {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: grid;
  grid-template-columns: 1fr 28px;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.88);
  color: #fff7ed;
  box-shadow: 0 -18px 28px rgba(255, 247, 237, 0.82);
  font-size: 0.86rem;
  font-weight: 850;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.scroll-cue strong {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: var(--gold);
  color: #111827;
  font-size: 1.15rem;
  line-height: 1;
}

.letter-shell.is-scrolled .scroll-cue,
.letter-shell.is-at-end .scroll-cue {
  opacity: 0;
  transform: translateY(8px);
}

.dock {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(88vw, 350px);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.68);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.nav-button {
  display: grid;
  min-width: 0;
  min-height: 48px;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #dbeafe;
  padding: 6px 10px;
  text-align: left;
}

.nav-button span {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.78rem;
  font-weight: 950;
}

.nav-button strong {
  overflow: hidden;
  font-size: 0.84rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-button.is-active {
  border-color: rgba(251, 191, 36, 0.55);
  background: var(--gold);
  color: #111827;
}

.nav-button.is-active span {
  background: rgba(17, 24, 39, 0.16);
}

@keyframes floaty {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-10px) rotate(1deg);
  }
}

@keyframes letterIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (min-width: 720px) {
  body {
    display: grid;
    place-items: center;
  }

  .app-shell {
    width: 430px;
    height: min(932px, 100dvh);
    height: min(932px, 100svh);
    border-inline: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.4);
  }
}

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