/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  direction: rtl;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Tajawal', sans-serif;
  background: linear-gradient(135deg, #1a0011, #2d0a1f, #1a0011);
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport height for mobile */
  overflow-x: hidden;
  color: #fff;
  -webkit-tap-highlight-color: transparent; /* remove tap highlight on mobile */
}

.hidden {
  display: none !important;
}

/* ===== FLOATING HEARTS BACKGROUND ===== */
.floating-hearts {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.floating-heart {
  position: absolute;
  font-size: 1.5rem;
  opacity: 0.15;
  animation: heartFloat linear infinite;
  will-change: transform; /* GPU accelerate */
}

@keyframes heartFloat {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.15;
  }
  90% {
    opacity: 0.15;
  }
  100% {
    transform: translateY(-10vh) rotate(360deg);
    opacity: 0;
  }
}

/* ===== SECTIONS ===== */
section {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  padding: 20px 0;
  padding: env(safe-area-inset-top, 20px) 0 env(safe-area-inset-bottom, 20px) 0; /* iPhone notch safe */
}

/* Allow scrolling when content overflows (e.g. Yes button grows huge) */
#question-page {
  align-items: flex-start;
  overflow-y: auto;
  padding-top: 30px;
}

#celebration-page {
  overflow-y: auto;
}

/* ===== QUESTION PAGE ===== */
.question-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px 15px;
  text-align: center;
  max-width: 600px;
  width: 100%;
  margin: auto; /* center vertically when content is small */
}

.reaction-gif {
  width: 280px;
  max-width: 70vw;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(255, 105, 180, 0.3);
  transition: all 0.4s ease;
}

.question-text {
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1.6;
  background: linear-gradient(135deg, #ff6b9d, #ff1493, #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  padding: 0 10px;
}

.buttons-container {
  display: flex;
  gap: 15px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
  width: 100%;
  padding: 0 10px;
}

/* ===== BUTTONS ===== */
.btn {
  font-family: 'Tajawal', sans-serif;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  outline: none;
  -webkit-appearance: none; /* fix iOS button styling */
  touch-action: manipulation; /* prevent 300ms delay on mobile */
}

.btn:hover {
  transform: scale(1.05);
}

.btn:active {
  transform: scale(0.95);
}

.yes-btn {
  padding: 15px 50px;
  font-size: 20px;
  background: linear-gradient(135deg, #ff6b9d, #e74c3c);
  color: #fff;
  box-shadow: 0 5px 25px rgba(255, 107, 157, 0.4);
  max-width: 90vw;
  overflow: hidden;
  word-break: keep-all;
  white-space: nowrap;
}

.yes-btn:hover {
  box-shadow: 0 8px 35px rgba(255, 107, 157, 0.6);
}

.no-btn {
  padding: 15px 40px;
  font-size: 18px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffb6c1;
  border: 2px solid rgba(255, 182, 193, 0.3);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  white-space: nowrap;
}

.no-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Shake animation for No button */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
  animation: shake 0.5s ease;
}

/* ===== CELEBRATION PAGE ===== */
.celebration-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 30px 15px;
  text-align: center;
  z-index: 2;
  animation: fadeInUp 0.8s ease;
  margin: auto;
}

.happy-gif {
  width: 250px;
  max-width: 65vw;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(255, 105, 180, 0.3);
}

.celebration-text {
  font-size: 1.9rem;
  font-weight: 900;
  background: linear-gradient(135deg, #ffd700, #ff69b4, #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.6;
}

.celebration-sub {
  font-size: 1.2rem;
  color: #ffb6c1;
  opacity: 0;
  animation: fadeInUp 0.8s ease 0.4s forwards;
}

.game-btn {
  padding: 16px 40px;
  font-size: 20px;
  background: linear-gradient(135deg, #9b59b6, #8e44ad);
  color: #fff;
  box-shadow: 0 5px 25px rgba(155, 89, 182, 0.4);
  opacity: 0;
  animation: fadeInUp 0.8s ease 0.8s forwards;
}

.game-btn:hover {
  box-shadow: 0 8px 35px rgba(155, 89, 182, 0.6);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== BALLOONS ===== */
.balloons-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.balloon {
  position: fixed;
  bottom: -180px;
  width: 50px;
  height: 65px;
  background: var(--color);
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  animation: floatUp 5s ease-in-out var(--delay) infinite;
  opacity: 0.85;
  will-change: transform; /* GPU accelerate */
}

.balloon::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  height: 40%;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
}

.balloon::after {
  content: '';
  position: absolute;
  bottom: -45px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 45px;
  background: rgba(255, 255, 255, 0.3);
}

@keyframes floatUp {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 0.85;
  }
  50% {
    transform: translateY(-55vh) rotate(8deg) scale(1.05);
    opacity: 0.85;
  }
  100% {
    transform: translateY(-120vh) rotate(-5deg) scale(0.95);
    opacity: 0;
  }
}

/* ===== GAME PAGE ===== */
#game-page {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 15px 0;
  overflow-y: auto;
  align-items: flex-start;
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 15px 10px;
  text-align: center;
  width: 100%;
  max-width: 700px;
  margin: auto;
}

.game-back-btn {
  align-self: flex-end;
  padding: 8px 20px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffb6c1;
  border: 1px solid rgba(255, 182, 193, 0.3);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.game-back-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.game-title {
  font-size: 1.6rem;
  font-weight: 900;
  background: linear-gradient(135deg, #ff6b9d, #ff1493);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-subtitle {
  font-size: 0.95rem;
  color: #ffb6c1;
  opacity: 0.7;
}

.game-stats {
  display: flex;
  gap: 25px;
  font-size: 0.95rem;
  color: #ffb6c1;
}

/* ===== HEART-SHAPED GAME BOARD ===== */
.game-board {
  display: grid;
  /* grid-template-columns set dynamically by JS based on heart size */
  gap: 6px;
  width: 100%;
  max-width: 650px;
  direction: ltr;
  touch-action: manipulation; /* fast taps on mobile */
}

.card-slot {
  aspect-ratio: 1;
}

.card-slot.empty {
  visibility: hidden;
}

.card-slot.decorative {
  background: linear-gradient(135deg, #ff6b9d, #c0392b);
  border-radius: 5px;
  box-shadow: 0 2px 6px rgba(255, 105, 180, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.card {
  width: 100%;
  height: 100%;
  perspective: 800px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  will-change: transform;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-front {
  background: linear-gradient(135deg, #ff6b9d, #c0392b);
  font-size: 1rem;
  box-shadow: 0 2px 6px rgba(255, 105, 180, 0.2);
}

.card-back {
  transform: rotateY(180deg);
  background: #2d0a1f;
  border: 2px solid rgba(255, 107, 157, 0.3);
}

.card-back img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 3px;
}

.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card.matched .card-back {
  border-color: #ffd700;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
}

@keyframes matchPulse {
  0% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.08); }
  100% { transform: rotateY(180deg) scale(1); }
}

.card.matched .card-inner {
  animation: matchPulse 0.5s ease;
}

/* ===== GAME COMPLETE OVERLAY ===== */
.game-complete {
  position: fixed;
  inset: 0;
  background: rgba(26, 0, 17, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.game-complete-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 35px 25px;
  animation: fadeInUp 0.6s ease;
}

.game-complete-content h1 {
  font-size: 2.2rem;
  background: linear-gradient(135deg, #ffd700, #ff69b4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-complete-content p {
  font-size: 1.2rem;
  color: #ffb6c1;
}

/* ===== MUSIC FALLBACK BUTTON (if autoplay blocked) ===== */
.music-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 50;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b9d, #e74c3c);
  color: #fff;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(255, 107, 157, 0.4);
  border: none;
  cursor: pointer;
  animation: pulse 2s ease infinite;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.music-btn.playing {
  animation: none;
  opacity: 0.7;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* ===== RESPONSIVE — TABLETS ===== */
@media (max-width: 768px) {
  .question-text {
    font-size: 1.5rem;
  }

  .celebration-text {
    font-size: 1.6rem;
  }
}

/* ===== RESPONSIVE — PHONES ===== */
@media (max-width: 600px) {
  section {
    padding: 15px 0;
  }

  .question-container {
    gap: 15px;
    padding: 15px 10px;
  }

  .question-text {
    font-size: 1.3rem;
    padding: 0 5px;
  }

  .reaction-gif {
    width: 200px;
  }

  .buttons-container {
    gap: 12px;
  }

  .yes-btn {
    padding: 12px 35px;
    font-size: 18px;
  }

  .no-btn {
    padding: 12px 35px;
    font-size: 16px;
  }

  .celebration-text {
    font-size: 1.35rem;
  }

  .celebration-sub {
    font-size: 1rem;
  }

  .happy-gif {
    width: 200px;
  }

  .game-btn {
    padding: 14px 35px;
    font-size: 18px;
  }

  .game-board {
    max-width: 95vw;
    gap: 4px;
  }

  .card-front {
    font-size: 0.8rem;
  }

  .game-title {
    font-size: 1.3rem;
  }

  .game-stats {
    font-size: 0.85rem;
    gap: 20px;
  }

  .game-complete-content h1 {
    font-size: 1.7rem;
  }

  .game-complete-content p {
    font-size: 1rem;
  }

  .balloon {
    width: 40px;
    height: 52px;
  }

  .music-btn {
    width: 42px;
    height: 42px;
    font-size: 1.1rem;
    bottom: 15px;
    left: 15px;
  }
}

/* ===== RESPONSIVE — SMALL PHONES ===== */
@media (max-width: 380px) {
  .question-text {
    font-size: 1.15rem;
  }

  .reaction-gif {
    width: 170px;
  }

  .game-board {
    max-width: 95vw;
    gap: 3px;
  }

  .card-front {
    font-size: 0.7rem;
    border-radius: 3px;
  }

  .card-back {
    border-radius: 3px;
    border-width: 1px;
  }

  .celebration-text {
    font-size: 1.2rem;
  }
}

/* ===== REDUCE MOTION for accessibility ===== */
@media (prefers-reduced-motion: reduce) {
  .floating-heart,
  .balloon {
    animation: none;
    display: none;
  }

  .card-inner {
    transition: none;
  }
}
