:root {
  --bg: #26104f;
  --fg: #ffffff;
  --muted: #d9c9ff;
  --gold: #ffd23f;
  --line: rgba(255, 255, 255, 0.28);
  --warmth: 0.4;
  /* the party's colours, taken in turn by letters, candles and fireworks */
  --pink: #ff5fa2;
  --orange: #ff8a3d;
  --yellow: #ffd23f;
  --green: #7be08a;
  --blue: #4fc3ff;
  --purple: #a98bff;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: radial-gradient(ellipse 120% 80% at 50% 0%, #5a2196 0%, #2e1260 45%, #150735 100%) fixed;
  color: var(--fg);
  font-family: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* the room grows warmer the more candles are lit */
.glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 55% 45% at 50% 55%, rgba(255, 190, 90, 0.3), rgba(255, 95, 162, 0.1) 45%, transparent 75%);
  opacity: var(--warmth);
  transition: opacity 1.6s ease;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.top {
  position: relative;
  padding: 12px 16px 4px;
}

.brand {
  font-size: 1.3rem;
  font-weight: 700;
  text-decoration: none;
  background: linear-gradient(90deg, var(--pink), var(--orange), var(--yellow), var(--green), var(--blue), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

main {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
  padding: 0 16px 3rem;
  text-align: center;
}

/* ---------- the party ---------- */

/* fireworks and confetti, drawn by script.js */
.sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* balloons drifting up behind everything */
.balloons {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.balloons span {
  position: absolute;
  left: var(--x);
  bottom: -160px;
  width: calc(54px * var(--s));
  height: calc(66px * var(--s));
  border-radius: 50% 50% 48% 48% / 58% 58% 42% 42%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.75) 0 7%, transparent 9%), var(--c);
  box-shadow: inset -6px -8px 0 rgba(0, 0, 0, 0.12);
  opacity: 0.85;
  animation: float var(--t) linear var(--d) infinite;
}

/* the knot and the string */
.balloons span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 1px;
  height: calc(90px * var(--s));
  background: linear-gradient(rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));
  border-top: 5px solid var(--c);
}

@keyframes float {
  0% { transform: translate(0, 0) rotate(-4deg); }
  25% { transform: translate(18px, -30vh) rotate(4deg); }
  50% { transform: translate(-14px, -60vh) rotate(-3deg); }
  75% { transform: translate(16px, -90vh) rotate(3deg); }
  100% { transform: translate(0, calc(-100vh - 320px)) rotate(-4deg); }
}

/* ---------- the cake ---------- */

.scene {
  width: 100%;
}

/* the message in big, bouncing letters of every colour */
.message {
  min-height: 1.2em;
  max-width: 60rem;
  margin: 0 auto;
  font-size: clamp(2.4rem, 8vw, 5rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.message .word,
.wish .word {
  display: inline-block;
  white-space: nowrap;
}

.message .ch,
.wish .ch {
  display: inline-block;
  color: var(--c);
  text-shadow: 0 0.06em 0 rgba(0, 0, 0, 0.28), 0 0 0.35em color-mix(in srgb, var(--c) 55%, transparent);
  animation: wave 1.6s ease-in-out var(--i) infinite;
}

@keyframes wave {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-0.12em) rotate(-4deg); }
  50% { transform: translateY(0) rotate(0deg); }
  75% { transform: translateY(0.05em) rotate(3deg); }
}

.message.placeholder {
  opacity: 0.55;
}

/* the cake fills the page: as wide as the screen allows, or as tall */
.cake-art {
  position: relative;
  width: min(100%, calc((100vh - 8.5rem) * 400 / 340));
  width: min(100%, calc((100svh - 8.5rem) * 400 / 340));
  aspect-ratio: 400 / 340;
  margin: 0.2rem auto 0;
}

/* while making a cake, it leaves room on the screen for the form under it */
.making .cake-art {
  width: min(100%, calc((100vh - 25rem) * 400 / 340), 30rem);
  width: min(100%, calc((100svh - 25rem) * 400 / 340), 30rem);
  /* sizes inside are in units of the cake's own width */
  container-type: inline-size;
}

.cake-art svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.candles {
  position: absolute;
  inset: 0;
}

/* a birthday candle: --h is its height in the cake's units (400 across) */
.bday {
  --u: 0.25cqw;
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -100%);
}

.stick {
  width: calc(var(--h) * 0.16 * var(--u));
  min-width: 3px;
  height: calc(var(--h) * var(--u));
  border-radius: 2px 2px 1px 1px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.25), transparent 35%, rgba(255, 255, 255, 0.35) 55%, rgba(0, 0, 0, 0.2)),
    repeating-linear-gradient(-55deg, var(--c1) 0 calc(var(--h) * 0.1 * var(--u)), var(--c2) calc(var(--h) * 0.1 * var(--u)) calc(var(--h) * 0.2 * var(--u)));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.wick {
  width: max(1px, calc(var(--h) * 0.025 * var(--u)));
  height: calc(var(--h) * 0.13 * var(--u));
  background: linear-gradient(#1a120c, #3b2b1c);
}

.lit .wick {
  background: linear-gradient(#ffb15a 0 25%, #2a1a10 25% 100%);
}

.flame-wrap {
  position: absolute;
  left: 50%;
  bottom: calc(var(--h) * 1.08 * var(--u));
  width: calc(var(--h) * 0.24 * var(--u));
  min-width: 5px;
  height: calc(var(--h) * 0.5 * var(--u));
  min-height: 11px;
  transform: translateX(-50%) scale(0.2, 0);
  transform-origin: 50% 100%;
  opacity: 0;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.3, 1.3), opacity 0.3s ease;
}

.lit .flame-wrap {
  transform: translateX(-50%) scale(1);
  opacity: 1;
}

.flame {
  position: absolute;
  inset: 0;
  border-radius: 50% 50% 50% 50% / 66% 66% 34% 34%;
  background: radial-gradient(ellipse 60% 52% at 50% 74%, #fffdf3 0%, #fff0b5 26%, #ffc75a 52%, #ff8a1c 78%, rgba(255, 110, 10, 0) 100%);
  box-shadow:
    0 0 calc(var(--h) * 0.18 * var(--u) + 4px) calc(var(--h) * 0.04 * var(--u) + 1px) rgba(255, 175, 70, 0.55),
    0 calc(var(--h) * -0.1 * var(--u)) calc(var(--h) * 0.5 * var(--u) + 8px) calc(var(--h) * 0.12 * var(--u)) rgba(255, 120, 30, 0.2);
  transform-origin: 50% 100%;
  animation: flicker var(--d, 1.8s) ease-in-out var(--delay, 0s) infinite;
}

@keyframes flicker {
  0%, 100% { transform: scale(1, 1) skewX(0deg); }
  20% { transform: scale(0.94, 1.07) skewX(2deg); }
  40% { transform: scale(1.04, 0.96) skewX(-1.5deg); }
  60% { transform: scale(0.96, 1.05) skewX(2.6deg); }
  80% { transform: scale(1.02, 0.98) skewX(-1deg); }
}

/* ---------- blowing the candles out ---------- */

/* big letters over the cake, bobbing, pushed along by the blowing */
.blow-letters {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  justify-content: center;
  gap: 0.5cqw;
  font-size: 17cqw;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  pointer-events: none;
  opacity: 0;
  transform: translateX(calc(var(--gust, 0) * 7cqw)) skewX(calc(var(--gust, 0) * -14deg)) scale(0.6);
  transition: opacity 0.6s ease, transform 0.5s cubic-bezier(0.2, 0.8, 0.3, 1.4);
}

.blow-letters.shown {
  opacity: 1;
  transform: translateX(calc(var(--gust, 0) * 7cqw)) skewX(calc(var(--gust, 0) * -14deg)) scale(1);
}

.blow-letters span {
  display: inline-block;
  animation: bob 1.1s ease-in-out infinite alternate;
}

.blow-letters span {
  text-shadow: 0 0.8cqw 0 rgba(0, 0, 0, 0.3), 0 0 3cqw rgba(255, 255, 255, 0.35);
}

.blow-letters span:nth-child(1) { color: var(--pink); }
.blow-letters span:nth-child(2) { color: var(--yellow); animation-delay: -0.2s; }
.blow-letters span:nth-child(3) { color: var(--green); animation-delay: -0.4s; }
.blow-letters span:nth-child(4) { color: var(--blue); animation-delay: -0.6s; }
.blow-letters span:nth-child(5) { color: var(--orange); animation-delay: -0.8s; }

@keyframes bob {
  from { transform: translateY(-1.2cqw) rotate(-4deg); }
  to { transform: translateY(1.2cqw) rotate(4deg); }
}

/* in the wind, lit candles shiver and their flames lean and flutter */
.windy .bday.lit {
  animation: shiver 0.09s linear infinite alternate;
}

@keyframes shiver {
  from { translate: calc(var(--gust) * var(--sway) * -1.5 * var(--u)) 0; }
  to { translate: calc(var(--gust) * var(--sway) * 1.5 * var(--u)) 0; }
}

.windy .lit .flame-wrap {
  transform: translateX(-50%) rotate(calc(var(--gust) * var(--lean) * var(--sway) * 34deg)) scale(calc(1 - var(--gust) * 0.15), calc(1 - var(--gust) * var(--sway) * 0.45));
  transition: transform 0.15s ease-out;
}

.windy .lit .flame {
  animation: flutter 0.11s linear infinite alternate;
}

@keyframes flutter {
  from { transform: skewX(calc(var(--gust) * var(--sway) * -18deg)) scaleY(calc(1 - var(--gust) * var(--sway) * 0.25)); }
  to { transform: skewX(calc(var(--gust) * var(--sway) * 18deg)) scaleY(1); }
}

/* a wisp of smoke from a candle just blown out */
.smoke {
  position: absolute;
  left: 50%;
  bottom: calc(var(--h) * 1.1 * var(--u));
  width: calc(var(--h) * 0.2 * var(--u) + 4px);
  height: calc(var(--h) * 0.6 * var(--u) + 10px);
  margin-left: calc((var(--h) * 0.2 * var(--u) + 4px) / -2);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 70%, rgba(215, 200, 180, 0.55), rgba(160, 145, 130, 0) 70%);
  filter: blur(1.5px);
  opacity: 0;
  pointer-events: none;
  animation: smoke 2.2s ease-out forwards;
}

@keyframes smoke {
  0% { opacity: 0; transform: translate(0, 4px) scale(0.6, 0.4); }
  15% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--sx), -12cqw) scale(2.6, 1.8) skewX(14deg); }
}

.wished {
  margin-top: 0.4rem;
}

.wish {
  margin: 0.2rem 0 0;
  font-size: clamp(2.4rem, 9vw, 4rem);
  font-weight: 700;
  line-height: 1.15;
  animation: rise 1s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.9); }
}

/* ---------- making a cake ---------- */

.make,
.share {
  width: 100%;
  max-width: 24rem;
  margin-top: 1.2rem;
}

.field,
.go,
.count input {
  font: inherit;
}

.field {
  width: 100%;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--fg);
  font-size: 1.15rem;
  text-align: center;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.field::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.field:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 0 4px rgba(255, 210, 63, 0.25);
}

.count {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 1rem;
}

.count-word {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--yellow);
}

.count input {
  width: 3.4em;
  padding: 0.15rem 0.2rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--fg);
  font-size: 1.6rem;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}

.count input::-webkit-outer-spin-button,
.count input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.count input:focus {
  border-bottom-color: rgba(255, 200, 130, 0.7);
}

.step {
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.step:hover:not(:disabled) {
  filter: brightness(1.12);
}

.step:disabled {
  opacity: 0.35;
  cursor: default;
}

.flavours {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 6px;
  margin: 1.1rem 0 0;
  padding: 0;
  border: 0;
}

.flavour {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 4.6rem;
  cursor: pointer;
}

.flavour input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dot {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(246, 234, 216, 0.12);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.flavour-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
}

.flavour input:checked ~ .dot {
  transform: translateY(-3px) scale(1.08);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18), 0 0 0 3px var(--yellow), 0 0 18px rgba(255, 210, 63, 0.6);
}

.flavour input:checked ~ .flavour-name {
  color: var(--fg);
}

.flavour input:focus-visible ~ .dot {
  outline: 1px dashed rgba(255, 220, 160, 0.8);
  outline-offset: 4px;
}

.flavour[data-cake="vanilla"] { --dot: radial-gradient(circle at 35% 30%, #fffaf0, #f3e3c3); }
.flavour[data-cake="chocolate"] { --dot: radial-gradient(circle at 35% 30%, #8a5434, #4a2614); }
.flavour[data-cake="strawberry"] { --dot: radial-gradient(circle at 35% 30%, #fbd3dd, #e392a6); }
.flavour[data-cake="lemon"] { --dot: radial-gradient(circle at 35% 30%, #fffbe0, #ecd772); }
.flavour[data-cake="red velvet"] { --dot: radial-gradient(circle at 35% 30%, #fffbf5 0 38%, #a3192c 40%); }
.flavour[data-cake="funfetti"] { --dot: radial-gradient(circle at 30% 35%, #f5a3b8 0 9%, transparent 10%), radial-gradient(circle at 65% 40%, #8fd3f4 0 9%, transparent 10%), radial-gradient(circle at 45% 68%, #ffd36b 0 9%, transparent 10%), radial-gradient(circle at 35% 30%, #ffffff, #ece0cf); }

.go {
  margin-top: 1.3rem;
  padding: 0.65rem 1.6rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink), var(--orange));
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  box-shadow: 0 4px 0 #b83a73, 0 0 26px rgba(255, 95, 162, 0.45);
  transition: box-shadow 0.3s ease, background 0.3s ease;
  touch-action: manipulation;
}

.go:hover {
  filter: brightness(1.08);
  box-shadow: 0 4px 0 #b83a73, 0 0 34px rgba(255, 95, 162, 0.65);
}

.go:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b83a73, 0 0 26px rgba(255, 95, 162, 0.45);
}

.go:disabled {
  opacity: 0.6;
  cursor: progress;
}

.go.quiet {
  background: linear-gradient(90deg, var(--blue), var(--purple));
  box-shadow: 0 4px 0 #4b3a9c, 0 0 26px rgba(79, 195, 255, 0.35);
}

.go:focus {
  outline: none;
}

.go:focus-visible,
.step:focus-visible {
  outline: 1px dashed rgba(255, 220, 160, 0.8);
  outline-offset: 3px;
}

.oops,
.note {
  min-height: 1.3em;
  margin: 0.7rem 0 0;
  font-size: 1.05rem;
}

.oops {
  color: #ffb3c8;
}

.note {
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* ---------- a cake that's been made ---------- */

.share-head {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--muted);
}

.share-head:empty {
  display: none;
}

.link {
  margin: 0.5rem 0 0;
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}

.link a {
  color: var(--yellow);
  font-weight: 600;
  text-underline-offset: 0.2em;
  text-decoration-color: rgba(255, 210, 63, 0.5);
}

.share-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 10px;
}

.again {
  display: inline-block;
  margin-top: 1.2rem;
  font-weight: 500;
  color: var(--muted);
  text-underline-offset: 0.2em;
}

.again:hover {
  color: var(--fg);
}

/* a quiet link at the very bottom, easy to miss */
.foot {
  position: relative;
  padding: 2rem 16px 14px;
  text-align: center;
  font-size: 0.72rem;
}

.foot a {
  color: var(--muted);
  opacity: 0.4;
  text-decoration: none;
  transition: opacity 0.3s ease;
}

.foot a:hover,
.foot a:focus-visible {
  opacity: 0.85;
}

@media (prefers-reduced-motion: reduce) {
  .message .ch,
  .balloons span,
  .flame,
  .blow-letters span,
  .windy .bday.lit,
  .windy .lit .flame {
    animation: none;
  }

  .smoke {
    display: none;
  }

  .flame-wrap,
  .glow {
    transition: none;
  }
}
