/* =========================================================
   Olya's Birthday: styles
   1. Theme & base   2. Party decorations   3. Buttons & cards
   4. Greeting       5. Game                6. Final screen
   7. Responsive     8. Animations
   ========================================================= */

/* ---------- 1. Theme & base ---------- */
:root {
  --plum: #3b1f5c;
  --plum-soft: #6b4a8f;
  --pink: #ff5d8f;
  --orange: #ff9f1c;
  --gold: #ffc53d;
  --violet: #9b5de5;
  --card-bg: rgba(255, 255, 255, 0.82);
  --shadow: 0 24px 60px rgba(59, 31, 92, 0.25);
  --font-display: 'Rubik', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-hand: 'Caveat', 'Segoe Print', cursive;
}

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

html, body { min-height: 100%; }

body {
  font-family: var(--font-body);
  color: var(--plum);
  background: linear-gradient(135deg, #ffd1dc 0%, #ffe8b8 35%, #dccbff 70%, #bfe6ff 100%);
  background-size: 300% 300%;
  animation: bgShift 18s ease infinite;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* The game keeps the same pastel party background as the greeting */
body[data-screen="game"] { overflow: hidden; }

main { position: relative; z-index: 1; }

.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; animation: screenIn 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }

.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

/* ---------- 2. Party decorations ---------- */
.party-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.balloon {
  position: absolute;
  bottom: -180px;
  width: var(--size, 60px);
  height: calc(var(--size, 60px) * 1.22);
  border-radius: 50% 50% 48% 52% / 55% 55% 45% 45%;
  background: var(--color);
  box-shadow: inset -8px -12px 0 rgba(0, 0, 0, 0.12);
  opacity: 0.85;
  animation: floatUp 20s linear infinite;
}
/* Shiny highlight */
.balloon::before {
  content: '';
  position: absolute;
  top: 16%;
  left: 20%;
  width: 22%;
  height: 28%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transform: rotate(25deg);
}
/* String */
.balloon::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  width: 1.5px;
  height: 80px;
  background: rgba(59, 31, 92, 0.3);
}

.floaty {
  position: absolute;
  opacity: 0.55;
  animation: bob 7s ease-in-out infinite;
}

/* ---------- 3. Buttons & cards ---------- */
.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  touch-action: manipulation;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--orange));
  box-shadow: 0 10px 25px rgba(255, 93, 143, 0.45);
}
.btn-secondary {
  color: var(--plum);
  background: #fff;
  box-shadow: 0 8px 20px rgba(59, 31, 92, 0.15);
}
.btn-big {
  font-size: 1.35rem;
  padding: 18px 44px;
  animation: pulseGlow 2.2s ease-in-out infinite;
}

.card {
  position: relative;
  width: 100%;
  max-width: 640px;
  text-align: center;
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 32px;
  padding: 40px 36px 34px;
  box-shadow: var(--shadow);
}

/* ---------- 4. Greeting ---------- */
#greeting-screen,
#final-screen {
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.greeting-card {
  max-width: 1040px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  align-items: center;
  gap: 44px;
  padding: 48px;
}

/* Polaroid-style photo, slightly tilted like it's glued into a card */
.photo-frame {
  position: relative;
  margin: 0;
  padding: 14px;
  background: #fff;
  border-radius: 18px;
  box-shadow:
    0 2px 4px rgba(59, 31, 92, 0.08),
    0 22px 48px rgba(59, 31, 92, 0.28);
  transform: rotate(-2.5deg);
  animation: photoIn 1.1s 0.15s cubic-bezier(0.2, 1.2, 0.4, 1) backwards;
  transition: transform 0.4s ease;
}
.photo-frame:hover { transform: rotate(-1deg) scale(1.02); }

.photo-frame img {
  display: block;
  width: 100%;
  height: auto;          /* keeps the photo's own proportions */
  border-radius: 12px;
}

/* Hidden-photo surprise: blurred photo under a gift-wrap cover until tapped */
.photo-reveal {
  position: relative;
  overflow: hidden;      /* keeps the blur from bleeding past the corners */
  border-radius: 12px;
}
.photo-reveal img {
  transition: filter 0.9s ease, transform 0.9s ease;
}
.photo-reveal.is-hidden img {
  filter: blur(26px) saturate(1.3);
  transform: scale(1.15); /* hides the soft transparent edges a blur leaves */
}

.photo-cover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border: 0;
  cursor: pointer;
  font: inherit;
  color: #fff;
  text-align: center;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.14) 0 14px, transparent 14px 28px),
    linear-gradient(135deg, rgba(255, 93, 143, 0.55), rgba(155, 93, 229, 0.55));
  transition: opacity 0.6s ease, transform 0.6s ease;
  -webkit-tap-highlight-color: transparent;
}
.photo-cover:focus-visible { outline: 4px solid var(--gold); outline-offset: -6px; }
.photo-cover-gift {
  font-size: clamp(3rem, 9vw, 4.5rem);
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(59, 31, 92, 0.35));
  animation: wiggle 2.4s ease-in-out infinite;
}
.photo-reveal:not(.is-hidden) .photo-cover {
  opacity: 0;
  transform: scale(1.3);
  pointer-events: none;
}


/* Little birthday stickers around the photo */
.deco {
  position: absolute;
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(59, 31, 92, 0.25));
  animation: bob 4s ease-in-out infinite;
}
.deco-balloon { top: -34px; left: -26px; font-size: 3.2rem; animation-duration: 5s; }
.deco-cake    { bottom: -18px; right: -22px; font-size: 3.2rem; animation-name: bounce; animation-duration: 2.6s; }
.deco-party   { top: -28px; right: -20px; font-size: 2.6rem; animation-name: wiggle; animation-duration: 2.4s; }
.deco-heart   { bottom: 34px; left: -22px; font-size: 2.2rem; animation-name: heartbeat; animation-duration: 1.6s; }
.deco-sparkle { top: 42%; right: -26px; font-size: 1.9rem; animation-name: twinkle; animation-duration: 2s; }

.greeting-text { text-align: center; }

.title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 4.4vw, 3.3rem);
  line-height: 1.12;
  animation: popIn 0.9s 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.name {
  background: linear-gradient(90deg, var(--pink), var(--orange), var(--violet), var(--pink));
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 6s linear infinite;
}

.title-emoji { display: inline-block; animation: wiggle 2s ease-in-out infinite; }

.message {
  max-width: 30em;
  margin: 20px auto 30px;
  font-size: clamp(1.02rem, 1.7vw, 1.18rem);
  line-height: 1.7;
  color: var(--plum-soft);
  animation: fadeUp 0.8s 0.7s ease both;
}

.greeting-text .btn-big { animation: fadeUp 0.8s 0.9s ease both, pulseGlow 2.2s 1.7s ease-in-out infinite; }

.hint {
  margin-top: 16px;
  font-size: 0.92rem;
  color: var(--plum-soft);
  opacity: 0.85;
}

/* More photos under the greeting: a row of small tilted polaroids */
.memories {
  grid-column: 1 / -1;
  padding-top: 8px;
  animation: fadeUp 0.8s 1.1s ease both;
}

.memories-title {
  margin-bottom: 26px;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(1.8rem, 3.6vw, 2.4rem);
  line-height: 1.1;
  color: var(--plum);
}

.memories-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 26px;
}

.memory {
  margin: 0;
  padding: 10px 10px 14px;
  background: #fff;
  border-radius: 14px;
  box-shadow:
    0 2px 4px rgba(59, 31, 92, 0.08),
    0 14px 30px rgba(59, 31, 92, 0.22);
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.memory:nth-child(1) { --tilt: -3deg; }
.memory:nth-child(2) { --tilt: 2deg; }
.memory:nth-child(3) { --tilt: -1.5deg; }
.memory:nth-child(4) { --tilt: 3deg; }
.memory:hover {
  transform: rotate(0deg) scale(1.05);
  box-shadow: 0 2px 4px rgba(59, 31, 92, 0.08), 0 22px 44px rgba(59, 31, 92, 0.3);
}

.memory img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;   /* same shape for every polaroid, whatever the photo's size */
  object-fit: cover;
  border-radius: 9px;
}

.memory .photo-reveal { border-radius: 9px; }
.memory .photo-cover-gift { font-size: clamp(2.2rem, 5vw, 3rem); }

.memory figcaption { padding-top: 10px; }

.memory-title {
  display: block;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.05;
  color: var(--plum);
}


/* Floating music toggle (hidden during the game, which has its own sound button) */
.music-btn {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 60;
  width: 48px;
  height: 48px;
  font-size: 1.4rem;
  line-height: 1;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 8px 20px rgba(59, 31, 92, 0.2);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s ease;
}
.music-btn:hover { transform: scale(1.08); }
.music-btn:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; }
.music-btn.playing { animation: heartbeat 1.6s ease-in-out infinite; }
.music-btn.muted { opacity: 0.6; }
body[data-screen="game"] .music-btn { display: none; }

/* ---------- 5. Game ---------- */
#game-screen {
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 860px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.score-line {
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.05rem, 3.8vw, 1.6rem);
  white-space: nowrap;
}

.score {
  display: inline-block;
  font-weight: 700;
  color: #e07b00;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8), 0 0 18px rgba(255, 197, 61, 0.45);
}
.score.bump { animation: bump 0.35s ease; }

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.timer {
  min-width: 74px;
  padding: 8px 12px;
  font-family: var(--font-display);
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 12px;
}
.timer.hurry { color: var(--pink); animation: heartbeat 1s ease-in-out infinite; }

.icon-btn {
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  font-size: 1rem;
  color: var(--plum);
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(59, 31, 92, 0.12);
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.9); }

.game-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-radius: 20px;
  /* Frosted glass over the balloons, so the falling money stays easy to see */
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.35));
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow:
    0 0 0 3px rgba(255, 197, 61, 0.6),
    var(--shadow);
}

#game-canvas { display: block; touch-action: none; cursor: grab; }

/* "+$100" texts popping up above the character */
.float-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.float-text {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.1rem, 3.6vw, 1.5rem);
  white-space: nowrap;
  color: var(--gold);
  text-shadow: 0 2px 0 #8a5200, 0 0 14px rgba(255, 197, 61, 0.6);
  animation: floatAway 0.9s ease-out forwards;
}
.float-text.big { font-size: clamp(1.5rem, 5vw, 2.1rem); color: #ffe27a; }

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  color: #fff;
  background: rgba(59, 31, 92, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}
.game-overlay h3 { font-family: var(--font-display); font-size: 1.8rem; color: var(--gold); }
.game-overlay p { opacity: 0.85; line-height: 1.4; }
.overlay-emoji { font-size: 3.2rem; animation: bounce 2s ease-in-out infinite; }
#pause-overlay { cursor: pointer; }

.controls-hint {
  text-align: center;
  font-size: 0.88rem;
  opacity: 0.75;
}

kbd {
  display: inline-block;
  min-width: 24px;
  margin-right: 3px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.8rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.75);
  border-bottom: 2px solid rgba(59, 31, 92, 0.25);
  border-radius: 6px;
}

.touch-controls { display: none; }
.touch-controls button {
  height: 64px;
  font-size: 1.7rem;
  color: var(--plum);
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(59, 31, 92, 0.12);
  border-radius: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 0.08s ease, background 0.08s ease;
}
.touch-controls button.pressed { background: rgba(255, 197, 61, 0.6); transform: scale(0.95); }

/* ---------- 6. Final screen ---------- */
.final-card { max-width: 600px; }

.final-photo {
  display: block;
  width: min(230px, 62%);  /* portrait photo, so a bit narrower to keep the card short */
  height: auto;
  margin: 0 auto 20px;
  border: 8px solid #fff;
  border-radius: 16px;
  box-shadow: 0 14px 32px rgba(59, 31, 92, 0.25);
  transform: rotate(2deg);
  animation: photoIn 1s cubic-bezier(0.2, 1.2, 0.4, 1) backwards;
}

.final-amount-line {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.4rem, 4.6vw, 2rem);
  line-height: 1.3;
}

.final-amount {
  display: inline-block;
  font-weight: 700;
  font-size: 1.35em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffc53d, #e07b00);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.record-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 0.9rem;
  color: #8a5200;
  background: #fff1c2;
  border-radius: 999px;
  animation: popIn 0.6s 1.4s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.final-title {
  margin-top: 18px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 7vw, 3.1rem);
  letter-spacing: 0.02em;
  line-height: 1.1;
  background: linear-gradient(90deg, var(--pink), var(--orange), var(--violet), var(--pink));
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: popIn 0.8s 0.9s cubic-bezier(0.2, 1.4, 0.4, 1) both, shimmer 6s linear infinite;
}

.final-message {
  max-width: 28em;
  margin: 18px auto 0;
  padding: 16px 20px;
  font-size: 1.12rem;
  line-height: 1.6;
  background: linear-gradient(135deg, rgba(255, 93, 143, 0.12), rgba(155, 93, 229, 0.12));
  border-radius: 20px;
  animation: fadeUp 0.8s 1.3s ease both;
}

.final-best { margin: 14px 0 24px; font-size: 0.95rem; color: var(--plum-soft); }

.final-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; }

/* ---------- 7. Responsive ---------- */
@media (max-width: 860px) {
  .greeting-card {
    grid-template-columns: 1fr;
    max-width: 560px;
    gap: 30px;
    padding: 36px 26px 30px;
  }
  .photo-frame { max-width: 440px; width: 100%; margin: 0 auto; }
  .memories-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 18px; }
}

@media (max-width: 520px) {
  #greeting-screen, #final-screen { padding: 24px 12px; }
  .card { padding: 28px 18px 24px; border-radius: 26px; }
  .greeting-card { padding: 30px 18px 26px; }
  .photo-frame { padding: 10px; }
  .deco-balloon { font-size: 2.5rem; left: -12px; top: -26px; }
  .deco-cake { font-size: 2.5rem; right: -10px; }
  .deco-party { font-size: 2.1rem; right: -8px; }
  .deco-heart { left: -10px; }
  .deco-sparkle { right: -12px; }
  .memories-grid { gap: 18px 14px; }
  .memory { padding: 7px 7px 10px; }
  .memory-title { font-size: 1.25rem; }
  .music-btn { width: 42px; height: 42px; font-size: 1.2rem; right: 10px; }
  .btn-big { font-size: 1.2rem; padding: 16px 34px; }
  .timer { min-width: 0; padding: 8px; }
  .icon-btn { min-width: 36px; height: 36px; padding: 0 6px; }
}

/* Show on-screen buttons on phones and touch tablets */
@media (max-width: 760px), (hover: none) and (pointer: coarse) {
  .touch-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .desktop-only { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .party-layer { display: none; }
  body, .btn-big, .name, .title-emoji, .deco, .timer.hurry, .music-btn.playing { animation: none; }
}

/* ---------- 8. Animations ---------- */
@keyframes bgShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
@keyframes photoIn {
  from { opacity: 0; transform: translateY(30px) rotate(-10deg) scale(0.85); }
  to { opacity: 1; }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-14deg); }
  40% { transform: rotate(12deg); }
  60% { transform: rotate(-6deg); }
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.2); }
  30% { transform: scale(1); }
  45% { transform: scale(1.12); }
}
@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1) rotate(0); }
  50% { opacity: 0.4; transform: scale(0.7) rotate(20deg); }
}
@keyframes shimmer {
  from { background-position: 0% 50%; }
  to { background-position: 300% 50%; }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 10px 25px rgba(255, 93, 143, 0.45); }
  50% { box-shadow: 0 10px 40px rgba(255, 159, 28, 0.75); }
}
@keyframes floatUp {
  0% { transform: translate(0, 0) rotate(-4deg); }
  25% { transform: translate(var(--sway), -30vh) rotate(4deg); }
  50% { transform: translate(0, -60vh) rotate(-4deg); }
  75% { transform: translate(calc(var(--sway) * -1), -90vh) rotate(4deg); }
  100% { transform: translate(0, calc(-100vh - 240px)) rotate(-4deg); }
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50% { transform: translateY(-14px) rotate(8deg); }
}
@keyframes bump {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.2); }
}
@keyframes floatAway {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}
