:root {
  --text: #2a1f1a;
  --text-soft: #9c7b6e;
  --font-disp: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', sans-serif;
  --cake-main: #e8a598;
  --cake-light: #f2c4bb;
  --candle-col: #f9e04b;
  --bg-start: #fdf6f0;
  --bg-end: #fce8e2;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background: linear-gradient(160deg, var(--bg-start), var(--bg-end));
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.bg-text {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-disp);
  font-style: italic;
  font-size: clamp(3rem, 11vw, 9rem);
  color: var(--cake-main);
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
  letter-spacing: -.02em;
  user-select: none;
}

.bg-text.show { opacity: .12; }

.wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  position: relative;
  z-index: 1;
  padding: 24px 16px;
}

/* form */
.form-area {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.label {
  font-family: var(--font-disp);
  font-style: italic;
  font-size: 1.5rem;
  color: var(--text);
  letter-spacing: -.01em;
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group input {
  padding: 10px 14px;
  border: 1.5px solid var(--cake-main);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: .95rem;
  color: var(--text);
  background: #fff;
  outline: none;
}

.input-group input.error { border-color: #e05050; }

#nameInput { width: 160px; }
#ageInput  { width: 80px; text-align: center; }

.warning {
  font-size: .8rem;
  color: #e05050;
  min-height: 16px;
}

#celebrateBtn {
  padding: 11px 32px;
  background: var(--cake-main);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: .04em;
}

#celebrateBtn:hover { filter: brightness(.92); }

.form-area.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s;
}

/* cake area */
.cake-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: translateY(16px);
}

.cake-area.show {
  opacity: 1;
  transform: translateY(0);
  transition: opacity .7s ease, transform .7s ease;
}

/* candles row — exact width of cake-top, glued to it */
.candles {
  width: 280px;
  height: 46px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
  z-index: 5;
  margin-bottom: 0;
}

.candle {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(6px);
}

.candle.on {
  opacity: 1;
  transform: translateY(0);
  transition: opacity .2s, transform .2s;
}

.candle-body {
  width: 5px;
  height: 26px;
  background: var(--candle-col);
  border-radius: 1px 1px 0 0;
  position: relative;
}

.flame {
  width: 5px;
  height: 10px;
  background: radial-gradient(ellipse at 50% 100%, #ffc300, #ff8c00 55%, transparent);
  border-radius: 50% 50% 40% 40% / 60% 60% 40% 40%;
  animation: flicker .45s infinite alternate;
  box-shadow: 0 0 5px 1px rgba(255,160,0,.3);
  transition: opacity .2s;
  margin-bottom: -1px;
}

.flame.out {
  opacity: 0;
  animation: none;
}

.smoke {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(130,130,130,.5);
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  animation: puff .7s ease-out forwards;
}

@keyframes puff {
  0%   { opacity: .5; transform: translateX(-50%) scale(1); }
  100% { opacity: 0;  transform: translateX(-50%) translateY(-16px) scale(3); }
}

@keyframes flicker {
  from { transform: scaleX(.9) scaleY(1.08); }
  to   { transform: scaleX(1.1) scaleY(.93); }
}

/* cake — split into top flat surface + body */
.cake {
  width: 300px;
  position: relative;
  z-index: 2;
  cursor: pointer;
}

.cake:active { transform: scale(.99); }

/* flat top surface — straight rectangle, same width as candles area */
.cake-top {
  width: 100%;
  height: 18px;
  background: var(--cake-light);
  position: relative;
  z-index: 4;
}

/* icing drip line on top edge */
.cake-top::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 10px;
  background: var(--cake-light);
  border-radius: 0 0 8px 8px;
  z-index: 3;
}

/* main cake body */
.cake-body {
  width: 100%;
  height: 130px;
  background: linear-gradient(170deg, var(--cake-light) 0%, var(--cake-main) 70%);
  position: relative;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12);
  z-index: 2;
  overflow: hidden;
}

.cake-drips {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  padding: 0 20px;
}

.drip {
  width: 7px;
  height: 16px;
  border-radius: 0 0 5px 5px;
  opacity: .5;
}

/* bottom curved shadow to give 3d feel */
.cake-shadow {
  width: 100%;
  height: 12px;
  background: rgba(0,0,0,.08);
  border-radius: 0 0 50% 50% / 0 0 8px 8px;
  position: relative;
  z-index: 1;
}

/* plate under cake */
.plate {
  width: 340px;
  height: 10px;
  background: rgba(255,255,255,.65);
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(0,0,0,.07);
  margin-top: 4px;
}

.blow-hint {
  font-size: .75rem;
  color: var(--text-soft);
  margin-top: 10px;
  opacity: 0;
  transition: opacity .4s .6s;
}

.blow-hint.show   { opacity: 1; }
.blow-hint.hidden { opacity: 0; transition: none; }

.message {
  font-family: var(--font-disp);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text-soft);
  text-align: center;
  opacity: 0;
  min-height: 28px;
  max-width: 340px;
}

.message.show {
  opacity: 1;
  transition: opacity .8s ease .3s;
}

/* pure CSS balloon */
.balloon {
  position: fixed;
  bottom: -80px;
  pointer-events: none;
  animation: rise var(--dur, 6s) ease-out forwards;
  z-index: 99;
}

.balloon-body {
  width: 26px;
  height: 32px;
  border-radius: 50% 50% 48% 48% / 55% 55% 45% 45%;
  position: relative;
  box-shadow: inset -4px -3px 0 rgba(0,0,0,.1);
}

.balloon-string {
  width: 1px;
  height: 20px;
  background: rgba(0,0,0,.22);
  margin: 0 auto;
}

@keyframes rise {
  0%   { transform: translateY(0) rotate(-3deg); opacity: 0; }
  12%  { opacity: 1; }
  50%  { transform: translateY(-50vh) rotate(5deg); }
  100% { transform: translateY(-110vh) rotate(-3deg); opacity: 0; }
}

@media (max-width: 480px) {
  .cake, .candles { width: 88vw; }
  .cake-top       { width: 100%; }
  .plate          { width: calc(88vw + 40px); }
  .input-group    { flex-direction: column; }
  #nameInput, #ageInput { width: 200px; text-align: left; }
}
