:root {
  color-scheme: dark;
  --ink: #f6f1ff;
  --gold: #ffe56a;
  --pink: #ff4d8d;
  --night: #070a1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  color: var(--ink);
  font-family: Nunito, "Segoe UI", sans-serif;
  background:
    radial-gradient(ellipse at 50% 120%, #24306e 0%, transparent 55%),
    var(--night);
}

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.balloons {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.balloons i {
  position: absolute;
  left: var(--x);
  bottom: -20vh;
  width: 46px;
  height: 60px;
  border-radius: 50% 50% 50% 50% / 42% 42% 58% 58%;
  background: radial-gradient(circle at 32% 30%, #fff8, transparent 40%), var(--c);
  animation: float 9s ease-in-out var(--t) infinite;
}

.balloons i::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 70px;
  background: #ffffff55;
}

@keyframes float {
  0% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-105vh) rotate(5deg); }
  100% { transform: translateY(0) rotate(-4deg); }
}

.burst {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: 42%;
  margin: 0;
  transform: translate(-50%, -50%) scale(0.4);
  font-family: "Lilita One", "Segoe Print", system-ui;
  font-size: clamp(3rem, 12vw, 7rem);
  color: #fff;
  letter-spacing: 0.08em;
  text-shadow: 0 6px 0 var(--pink);
  opacity: 0;
  pointer-events: none;
}

.burst.show {
  animation: puff-text 1.5s ease forwards;
}

@keyframes puff-text {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.4) rotate(-6deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(2deg); }
  62% { opacity: 1; transform: translate(-50%, -54%) scale(1.08) rotate(-1deg); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1.3) rotate(-2deg); }
}

main {
  position: relative;
  z-index: 2;
  max-width: 760px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(2.2rem, env(safe-area-inset-top)) max(1.2rem, env(safe-area-inset-right)) max(3rem, env(safe-area-inset-bottom)) max(1.2rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  text-align: center;
  pointer-events: none;
}

button,
dialog,
dialog button {
  pointer-events: auto;
}

.from {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: #ffd0e4;
}

.card {
  pointer-events: none;
  padding: 2rem 1.8rem 1.7rem;
  border-radius: 2rem;
  background:
    linear-gradient(180deg, #ffffff1c, #ffffff08 40%, #12081a33);
  border: 1px solid #ffffff2e;
  box-shadow:
    0 24px 70px #0008,
    inset 0 1px 0 #fff4;
  backdrop-filter: blur(10px);
}

h1 {
  margin: 0.55rem 0 0.15rem;
  font-family: "Lilita One", "Segoe Print", system-ui;
  font-weight: 400;
  font-size: clamp(2.4rem, 7vw, 4.4rem);
  line-height: 1.12;
  color: var(--gold);
  text-shadow: 0 4px 0 var(--pink), 0 14px 28px #ff4d8d66;
}

h1 .word {
  display: inline-block;
  animation: hop 2.6s ease-in-out var(--d, 0s) infinite;
}

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

.age {
  margin: 0.85rem 0 0;
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.days,
.extra,
.aside {
  margin: 0.7rem 0 0;
  color: #d9d2ef;
  line-height: 1.45;
}

.aside {
  min-height: 2.8rem;
  margin-top: 1rem;
  font-weight: 800;
  color: #ffe56a;
}

.wish {
  min-height: 3.4rem;
  margin: 1.35rem auto 0;
  max-width: 34rem;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.5;
}

.portrait {
  width: 104px;
  height: 104px;
  margin: 1.3rem auto 0;
  position: relative;
  overflow: visible;
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  border: 4px solid var(--gold);
  box-shadow: 0 8px 0 var(--pink);
}

.portrait::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: -22px;
  left: 58%;
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-bottom: 28px solid #ff4d8d;
  transform: rotate(18deg);
}

.stage { margin-top: 1.35rem; }

.cake {
  width: 250px;
  margin: 0.4rem auto 0;
  position: relative;
  pointer-events: auto;
  cursor: pointer;
}

.candles {
  display: flex;
  justify-content: center;
  gap: 10px;
  height: 54px;
  align-items: flex-end;
}

.candle {
  width: 9px;
  height: 32px;
  border-radius: 3px;
  background: linear-gradient(#fff6c2, #ffb703);
  position: relative;
}

.flame {
  position: absolute;
  left: 50%;
  top: -16px;
  width: 12px;
  height: 16px;
  transform: translateX(-50%);
  border-radius: 50% 50% 45% 45%;
  background: radial-gradient(circle at 50% 80%, #fff6c8, #ffb703 45%, #ff4d00 80%);
  transform-origin: center bottom;
  animation: flicker 0.12s infinite alternate;
}

@keyframes flicker {
  from { transform: translateX(-50%) scale(1) rotate(-4deg); }
  to { transform: translateX(-50%) scale(0.85, 1.08) rotate(4deg); }
}

.cake.out .flame {
  animation: die 0.45s ease forwards;
}

.cake.out .candle.stubborn .flame {
  animation: flicker 0.08s infinite alternate;
  opacity: 1;
  filter: none;
}

@keyframes die {
  to { transform: translateX(-50%) translateY(-8px) scale(1.6); opacity: 0; filter: blur(2px); }
}

.cake.jelly {
  animation: jelly 0.55s ease;
}

@keyframes jelly {
  0% { transform: scale(1, 1); }
  30% { transform: scale(1.06, 0.92); }
  60% { transform: scale(0.96, 1.05); }
  100% { transform: scale(1, 1); }
}

.tier {
  margin: 0 auto;
  position: relative;
  border-radius: 10px;
}

.tier.top {
  width: 116px;
  height: 42px;
  background: #fff0f6;
  z-index: 3;
}

.tier.mid {
  width: 168px;
  height: 52px;
  margin-top: -6px;
  background: #ffb3d1;
  z-index: 2;
}

.tier.base {
  width: 230px;
  height: 70px;
  margin-top: -6px;
  background:
    radial-gradient(circle at 12% 40%, #ffe56a 4px, transparent 5px),
    radial-gradient(circle at 28% 62%, #7ae1ff 4px, transparent 5px),
    radial-gradient(circle at 48% 38%, #fff 4px, transparent 5px),
    radial-gradient(circle at 70% 58%, #c9a0ff 4px, transparent 5px),
    radial-gradient(circle at 86% 36%, #ffe56a 4px, transparent 5px),
    linear-gradient(#ff8ab5, #ff5d97);
  border-radius: 12px 12px 18px 18px;
  box-shadow: 0 12px 0 #c4386d;
}

.frost {
  position: absolute;
  left: 4px;
  right: 4px;
  top: -9px;
  height: 16px;
  background: linear-gradient(#fff, #ffe9f3);
  border-radius: 40%;
  z-index: 1;
}

.drip {
  position: absolute;
  top: 14px;
  left: 16px;
  width: 12px;
  height: 18px;
  background: #fff;
  border-radius: 0 0 10px 10px;
  box-shadow: 28px 4px 0 #fff, 62px -2px 0 #fff, 98px 6px 0 #fff;
}

.tier.top .drip { box-shadow: 34px 3px 0 #fff, 70px -1px 0 #fff; }
.tier.base .drip { left: 22px; box-shadow: 48px 5px 0 #fff, 96px -2px 0 #fff, 150px 4px 0 #fff, 190px 1px 0 #fff; }

.plate {
  height: 18px;
  margin: 10px auto 0;
  width: 250px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, #fff, #eadfff 70%);
  box-shadow: 0 8px 0 #b9a8d4;
}

.tier.top::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  width: 16px;
  height: 16px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff8fab, #d90429);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 0.75rem;
  justify-content: center;
  width: 100%;
  margin-top: 1.7rem;
}

button {
  border: 0;
  cursor: pointer;
  font: 800 1rem Nunito, "Segoe UI", sans-serif;
  color: #2a1230;
  background: #efe7ff;
  border-radius: 999px;
  padding: 0.75rem 1.15rem;
  box-shadow: 0 5px 0 #b9a6e6;
}

@media (hover: hover) and (pointer: fine) {
  button:hover { transform: translateY(-1px); }
  button.polaroid:hover { transform: rotate(var(--tilt, -2.5deg)) translateY(-2px); }
}

button:active { transform: translateY(3px); box-shadow: 0 2px 0 #b9a6e6; }

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

button.primary {
  background: linear-gradient(#fff1a8, var(--gold));
  box-shadow: 0 5px 0 #d7a317;
}

button.primary:active { box-shadow: 0 2px 0 #d7a317; }

.album { margin: 1.15rem auto 0; }

button.polaroid {
  display: block;
  width: 168px;
  margin: 0 auto;
  padding: 0.45rem 0.45rem 0.35rem;
  border-radius: 0.3rem;
  background: #fff8ee;
  color: #5c3b52;
  box-shadow: 0 8px 0 #e7b8cf;
  transform: rotate(var(--tilt, -2.5deg));
}

button.polaroid img {
  width: 100%;
  height: 132px;
  object-fit: cover;
  display: block;
  background: #2a1230;
  pointer-events: none;
}

button.polaroid span {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  pointer-events: none;
}

button.polaroid:active {
  transform: rotate(var(--tilt, -2.5deg)) translateY(3px);
  box-shadow: 0 2px 0 #e7b8cf;
}

button.polaroid.flip { animation: pop-in 0.35s ease; }

.vow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  justify-content: center;
  margin-top: 1.15rem;
  pointer-events: auto;
}

.vow input {
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  min-width: min(16rem, 100%);
  font: 800 1rem Nunito, "Segoe UI", sans-serif;
  color: #2a1230;
}

.vow input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.flash {
  position: fixed;
  inset: 0;
  z-index: 6;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.flash.on { animation: blink 0.4s ease; }

@keyframes blink {
  0% { opacity: 0.92; }
  100% { opacity: 0; }
}

.card.shake { animation: shake 0.4s linear; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.wish-fly {
  position: fixed;
  z-index: 5;
  left: 50%;
  top: 42%;
  max-width: min(18rem, 80vw);
  margin: 0;
  font-family: "Lilita One", "Segoe Print", system-ui;
  font-size: clamp(1.5rem, 4vw, 2.6rem);
  color: #fff;
  text-shadow: 0 4px 0 var(--pink);
  pointer-events: none;
  animation: puff-text 1.6s ease forwards;
}

.joke.pop {
  animation: pop-in 0.35s ease;
}

@keyframes pop-in {
  from { transform: scale(0.92) rotate(-1deg); }
  to { transform: none; }
}

.bunting {
  position: fixed;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.bunting i {
  width: 22px;
  height: 30px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  animation: sway 1.8s ease-in-out infinite alternate;
}

.bunting i:nth-child(4n + 1) { background: #ff4d8d; }
.bunting i:nth-child(4n + 2) { background: #ffe56a; animation-delay: 0.2s; }
.bunting i:nth-child(4n + 3) { background: #7ae1ff; animation-delay: 0.4s; }
.bunting i:nth-child(4n) { background: #c9a0ff; animation-delay: 0.15s; }

@keyframes sway {
  from { transform: rotate(-6deg); }
  to { transform: rotate(7deg); }
}

.cheer {
  position: fixed;
  z-index: 5;
  bottom: 16%;
  margin: 0;
  font-family: "Lilita One", "Segoe Print", system-ui;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  color: #fff;
  text-shadow: 0 4px 0 #ff4d8d;
  pointer-events: none;
  animation: rise 1.5s ease forwards;
}

@keyframes rise {
  0% { transform: translateY(0) rotate(-6deg); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-38vh) rotate(8deg); opacity: 0; }
}

.joke {
  min-height: 3.4rem;
  margin: 1.35rem auto 0;
  max-width: 36rem;
  padding: 1rem 1.2rem;
  border-radius: 1.2rem 1.2rem 1.2rem 0.3rem;
  background: #ffffff14;
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.5;
}

dialog {
  border: 0;
  border-radius: 1.4rem;
  padding: 1.4rem 1.3rem 1.2rem;
  max-width: min(26rem, calc(100vw - 2rem));
  color: #2a1230;
  background: #fff8ee;
  box-shadow: 0 18px 0 #ff4d8d;
}

dialog::backdrop {
  background: #070a1ccc;
}

dialog h2 {
  margin: 0.2rem 0;
  font-family: "Lilita One", "Segoe Print", system-ui;
  font-size: 2rem;
  font-weight: 400;
  color: #ff4d8d;
}

.ribbon { font-size: 2rem; margin: 0; }

dialog button { margin-top: 0.6rem; }

.config-error {
  position: relative;
  z-index: 5;
  margin: 1rem;
  padding: 1rem;
  background: #3a1020;
  border: 2px solid #ff4d8d;
  border-radius: 1rem;
}

@media (max-width: 980px) {
  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
  }

  .actions button {
    width: 100%;
    min-height: 44px;
  }

  #blow { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  main {
    justify-content: flex-start;
    padding-top: max(2.4rem, env(safe-area-inset-top));
    padding-inline: max(0.65rem, env(safe-area-inset-left));
  }

  .card {
    padding: 1.35rem 1rem 1.2rem;
    border-radius: 1.35rem;
  }

  h1 { font-size: clamp(1.85rem, 9vw, 2.6rem); }

  .wish {
    min-height: 0;
    margin-top: 1rem;
    font-size: 1.05rem;
  }

  .portrait {
    width: 76px;
    height: 76px;
    margin-top: 0.7rem;
  }

  .stage { margin-top: 1rem; }

  .cake { width: 210px; }
  .tier.top { width: 98px; height: 36px; }
  .tier.mid { width: 146px; height: 44px; }
  .tier.base { width: 196px; height: 58px; }
  .tier.base .drip {
    left: 14px;
    box-shadow: 34px 4px 0 #fff, 70px -2px 0 #fff, 108px 3px 0 #fff, 142px 1px 0 #fff;
  }
  .plate { width: 210px; }

  button.polaroid { width: min(148px, 70%); }
  button.polaroid img { height: 108px; }

  .actions {
    gap: 0.75rem;
    margin-top: 1.25rem;
  }

  .actions button {
    width: 100%;
    min-height: 44px;
    font-size: 0.92rem;
    padding: 0.65rem 0.45rem;
  }

  #blow { grid-column: 1 / -1; }

  .vow { flex-direction: column; align-items: stretch; }
  .vow input,
  .vow button { width: 100%; min-height: 44px; }

  .joke { margin-top: 1.1rem; }

  .bunting { gap: 4px; }
  .bunting i { width: 14px; height: 20px; }

  .balloons i { width: 32px; height: 42px; }
  .balloons i:nth-child(2),
  .balloons i:nth-child(3) { display: none; }
}

@media (max-height: 500px) and (orientation: landscape) {
  main { justify-content: flex-start; }
  .bunting { display: none; }
  .cake { width: 180px; }
  .tier.base { width: 168px; height: 48px; }
  .tier.mid { width: 124px; height: 36px; }
  .tier.top { width: 84px; height: 30px; }
  .plate { width: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
  }
}
