/* ================================================
   IMPORTS
   ================================================ */

/*
  Load two Google Fonts:
    - Fredoka One  : bold, rounded display font used only for the game title headings.
    - Nunito       : friendly rounded body font used for all other text.
  Weights 400 / 600 / 700 / 800 cover regular, semi-bold, bold, and extra-bold usage.
*/
@import url("https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;700;800&display=swap");

/* ================================================
   BASE STYLES
   ================================================ */

/*
  Apply border-box sizing globally so padding and borders are included
  in an element's declared width/height (avoids layout surprises).
*/
* {
  box-sizing: border-box;
}

/*
  Make html and body fill the viewport so full-screen layouts work.
  margin:0 removes the browser's default body whitespace.
  font-family sets Nunito as the default with a generic sans-serif fallback.
*/
html,
body {
  height: 100%;
  margin: 0;
  font-family: "Nunito", sans-serif;
}

/* ================================================
   TYPOGRAPHY
   ================================================ */

/* Applied to the main <h1> and the result <h2>. Fredoka One has no weight variants
   so only the font-family declaration is needed here. */
.game-title {
  font-family: "Fredoka One", cursive;
}

/* ================================================
   KEYFRAME ANIMATIONS
   ================================================ */

/* Gentle up-down bob used on the .animal-emoji class. */
@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  } /* resting position */
  50% {
    transform: translateY(-10px);
  } /* peak of the bounce */
}

/* Scale-from-zero spring entrance. The overshoot to 1.2 creates a satisfying pop feel.
   Used by .pop-in (game content entrance) and .star (result stars). */
@keyframes pop {
  0% {
    transform: scale(0);
    opacity: 0;
  } /* invisible and tiny */
  50% {
    transform: scale(1.2);
  } /* slightly overshoot */
  100% {
    transform: scale(1);
    opacity: 1;
  } /* settle at normal size */
}

/* Left-right rock. Applied to letter tiles (.wrong) and the hint button when score is too low. */
@keyframes wiggle {
  0%,
  100% {
    transform: rotate(-3deg);
  } /* lean left */
  50% {
    transform: rotate(3deg);
  } /* lean right */
}

/* Slow gentle floating used on the emoji animals in the start-screen header.
   Combines Y translation with slight rotation for an organic feel. */
@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-5px) rotate(2deg);
  } /* drift up and tilt right */
  75% {
    transform: translateY(5px) rotate(-2deg);
  } /* drift down and tilt left */
}

/* Pulsing opacity + scale used on .sparkle::after pseudo-elements. */
@keyframes sparkle {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.5);
  }
}

/* Wobble + scale pulse used on correct letter tiles and correct quiz options. */
@keyframes celebrate {
  0% {
    transform: scale(1) rotate(0deg);
  } /* start normal */
  25% {
    transform: scale(1.1) rotate(-5deg);
  } /* grow, tilt left */
  50% {
    transform: scale(1.2) rotate(5deg);
  } /* peak size, tilt right */
  75% {
    transform: scale(1.1) rotate(-5deg);
  } /* shrink back, tilt left */
  100% {
    transform: scale(1) rotate(0deg);
  } /* return to normal */
}

/* ================================================
   ANIMATION UTILITY CLASSES
   ================================================ */

/* Large emoji shown above question content in the spelling game. Applies the bounce loop. */
.animal-emoji {
  font-size: 4rem;
  animation: bounce 2s infinite; /* loops forever, 2-second cycle */
}

/* One-shot pop entrance used on every dynamically injected game card/panel.
   cubic-bezier(0.68, -0.55, 0.265, 1.55) is the classic spring easing curve. */
.pop-in {
  animation: pop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Applied temporarily by JS to elements that answer incorrectly (letter tiles, quiz options). */
.wiggle {
  animation: wiggle 0.5s ease-in-out;
}

/* Applied to the decorative animal emojis on the start-screen header.
   animation-delay is set inline per element (0s, 0.2s, 0.4s...) to stagger them. */
.float {
  animation: float 3s ease-in-out infinite;
}

/* Applied by JS to trigger the wobble reward animation. */
.celebrate {
  animation: celebrate 0.6s ease-in-out;
}

/* ================================================
   BACKGROUND PATTERN
   ================================================ */

/*
  Applied to <body>. Overlays four soft radial gradients at different corners
  on top of Tailwind's bg-gradient-to-br base gradient.
  Each gradient is a pastel color at low opacity so the effect is subtle:
    bottom-left  — pink (20% 80%)
    top-right    — sky blue (80% 20%)
    centre       — light green (40% 40%)
    bottom-right — peach (90% 90%)
*/
.bg-pattern {
  background-image:
    radial-gradient(
      circle at 20% 80%,
      rgba(255, 182, 193, 0.3) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(135, 206, 250, 0.3) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 40% 40%,
      rgba(144, 238, 144, 0.2) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 90% 90%,
      rgba(255, 218, 185, 0.3) 0%,
      transparent 40%
    );
}

/* ================================================
   LETTER TILES  (Spelling Game)
   ================================================ */

/*
  Each clickable letter button in the spelling game.
  transition uses the spring cubic-bezier so hover/active states feel bouncy.
  user-select:none prevents text highlight on rapid taps (important on mobile).
*/
.letter-tile {
  transition: all 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  user-select: none;
}

/* Slight scale-up plus a small tilt on hover to make tiles feel interactive. */
.letter-tile:hover {
  transform: scale(1.1) rotate(-2deg);
}

/* Brief press-down effect so the tap feels physical. */
.letter-tile:active {
  transform: scale(0.95);
}

/*
  Applied by JS (slot.classList.add('correct')) when the player spells correctly.
  !important overrides the inline Tailwind gradient classes added at render time.
  The celebrate animation provides the brief wobble reward.
*/
.letter-tile.correct {
  background: linear-gradient(
    135deg,
    #10b981,
    #059669
  ) !important; /* emerald green */
  color: white !important;
  animation: celebrate 0.5s ease-in-out;
}

/*
  Applied by JS (slot.classList.add('wrong')) when the answer is incorrect.
  Red gradient + wiggle shakes the tiles to communicate the mistake clearly.
*/
.letter-tile.wrong {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important; /* red */
  color: white !important;
  animation: wiggle 0.5s ease-in-out;
}

/* ================================================
   PROGRESS BAR
   ================================================ */

/*
  The emoji that rides at the right edge of the progress bar fill.
  The spring easing makes it visually "jump" forward as progress increases
  rather than sliding smoothly, giving it a lively character.
*/
.progress-animal {
  transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/*
  Each star on the result screen. `forwards` keeps the final animation state
  (scale 1, opacity 1) so the stars don't reset after the pop completes.
  animation-delay is set inline per star in JS to stagger the cascade.
*/
.star {
  animation: pop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

/* ================================================
   GAME BUTTONS
   ================================================ */

/*
  Applied to all primary action buttons (Home, Play Again, Clear, Check).
  position:relative + overflow:hidden are required to contain the ::before shine sweep.
*/
.game-btn {
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

/*
  A white semi-transparent stripe that sweeps left-to-right on hover.
  Starts off-screen to the left (-100%) and moves to off-screen right (100%).
  Creates the "sheen" effect without any extra markup.
*/
.game-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%; /* hidden off the left edge */
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  transition: left 0.5s; /* controls how fast the sheen sweeps across */
}

/* On hover, slide the sheen stripe all the way to the right (off-screen). */
.game-btn:hover::before {
  left: 100%;
}

/* Lift the button on hover with a translate + drop shadow for a 3-D press feel. */
.game-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

/* ================================================
   CONFETTI
   ================================================ */

/*
  Each animated emoji particle spawned by createConfetti().
  position:fixed keeps particles in viewport coordinates (independent of scroll).
  pointer-events:none prevents accidental taps on the falling particles.
  z-index:100 ensures they render above all game UI.
*/
.confetti {
  position: fixed;
  pointer-events: none;
  z-index: 100;
}

/* ================================================
   CATEGORY CARDS  (Start Screen)
   ================================================ */

/*
  The three mode-selection buttons on the start screen (Spelling / Match / Quiz).
  The spring cubic-bezier gives the hover lift a bouncy, playful character
  that matches the game's tone.
*/
.category-card {
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Float the card up 8px and slightly scale it on hover to indicate interactivity. */
.category-card:hover {
  transform: translateY(-8px) scale(1.02);
}

/* ================================================
   QUIZ OPTIONS  (Quiz Game)
   ================================================ */

/* Each of the four multiple-choice answer buttons. */
.quiz-option {
  transition: all 0.2s ease;
}

/* Gentle scale-up on hover so players can see which option they are about to select. */
.quiz-option:hover {
  transform: scale(1.05);
}

/*
  Applied by JS (btn.classList.add('correct')) to the correct answer button.
  !important overrides the indigo gradient set in the HTML template string.
*/
.quiz-option.correct {
  background: linear-gradient(
    135deg,
    #10b981,
    #059669
  ) !important; /* emerald green */
  color: white !important;
  animation: celebrate 0.5s ease-in-out;
}

/*
  Applied by JS (btn.classList.add('wrong')) to the incorrect answer button.
  The wiggle shake communicates the mistake without being harsh.
*/
.quiz-option.wrong {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important; /* red */
  color: white !important;
  animation: wiggle 0.5s ease-in-out;
}

/* ================================================
   WRONG ANSWER FEEDBACK
   ================================================ */

/*
  Full animation for the toast pill:
    0–45%  → spring bounce-in with a playful tilt (boing feel)
    45–68% → hold at full size so the player can read it
    68–100% → float upward while shrinking + fading out
*/
@keyframes wrong-toast-anim {
  0% {
    transform: translateX(-50%) scale(0) rotate(-10deg);
    opacity: 0;
  }
  20% {
    transform: translateX(-50%) scale(1.28) rotate(4deg);
    opacity: 1;
  }
  35% {
    transform: translateX(-50%) scale(0.9) rotate(-2deg);
    opacity: 1;
  }
  45% {
    transform: translateX(-50%) scale(1.04) rotate(0deg);
    opacity: 1;
  }
  68% {
    transform: translateX(-50%) scale(1) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateX(-50%) translateY(-55px) scale(0.75);
    opacity: 0;
  }
}

/* Rapid horizontal shake with a slight tilt to sell the "wrong" physicality */
@keyframes card-shake {
  0%,
  100% {
    transform: translateX(0) rotate(0);
  }
  14% {
    transform: translateX(-8px) rotate(-1.5deg);
  }
  28% {
    transform: translateX(8px) rotate(1.5deg);
  }
  42% {
    transform: translateX(-6px) rotate(-1deg);
  }
  57% {
    transform: translateX(6px) rotate(1deg);
  }
  71% {
    transform: translateX(-3px) rotate(-0.5deg);
  }
  85% {
    transform: translateX(3px) rotate(0.5deg);
  }
}

/*
  The floating pill badge that pops up when a wrong answer is submitted.
  Centred horizontally via left:50% + translateX(-50%).
  top:38% places it over the game content area without covering buttons.
  z-index:90 ensures it is above game UI but below the drawer.
*/
.wrong-toast {
  position: fixed;
  left: 50%;
  top: 38%;
  z-index: 90;
  pointer-events: none;
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  color: white;
  font-family: "Nunito", sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 0.65rem 1.6rem;
  border-radius: 9999px;
  box-shadow:
    0 8px 24px rgba(238, 90, 36, 0.45),
    0 4px 8px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  animation: wrong-toast-anim 1.6s cubic-bezier(0.68, -0.55, 0.265, 1.55)
    forwards;
}

/* Applied to answer-slot containers or card buttons to add the shake jolt. */
.card-shake {
  animation: card-shake 0.55s ease-in-out;
}

/* ================================================
   TOP NAVIGATION BAR
   ================================================ */

/*
  Fixed-position header bar that persists across all three game screens.
  Sits above the scrollable content; z-index:50 keeps it above any cards.
  backdrop-blur + white/90 creates the frosted-glass look matching the design.
*/
.app-navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: 70px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(139, 92, 246, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2.3rem;
  box-shadow: 0 2px 12px rgba(109, 40, 217, 0.08);
}

/* Brand / logo group */
.app-navbar__brand {
  display: flex;
  align-items: center;
  gap: 1.8rem;
}

.app-navbar__logo-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.app-navbar__logo-text {
  font-family: "Fredoka One", cursive;
  font-size: 1.15rem;
  color: #7c3aed; /* purple-600 */
  letter-spacing: 0.01em;
}

/* Avatar button on the right */
.app-navbar__avatar-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(139, 92, 246, 0.08);
  border: 1.5px solid rgba(139, 92, 246, 0.2);
  border-radius: 9999px;
  padding: 0.3rem 0.75rem 0.3rem 0.35rem;
  cursor: pointer;
  transition:
    background 0.2s ease,
    box-shadow 0.2s ease;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 0.875rem;
  color: #374151; /* gray-700 */
}

.app-navbar__avatar-btn:hover {
  background: rgba(139, 92, 246, 0.15);
  box-shadow: 0 2px 8px rgba(109, 40, 217, 0.15);
}

/* Circular avatar image/emoji inside the button */
.app-navbar__avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  overflow: hidden;
  flex-shrink: 0;
}

/* Username label inside the avatar button */
.app-navbar__avatar-name {
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Push the main content down so it clears the fixed navbar */
.app-with-navbar {
  padding-top: 80px;
}

/* ================================================
   PROFILE DRAWER OVERLAY + PANEL
   ================================================ */

/* Full-screen translucent backdrop — hidden until drawer opens */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* When the drawer is open, show the backdrop */
.drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: all;
}

/* The actual drawer panel that slides in from the right */
.profile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  max-width: 90vw;
  background: #ffffff;
  border-radius: 1.25rem 0 0 1.25rem;
  z-index: 70;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transform: translateX(100%); /* starts off-screen to the right */
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 40px rgba(109, 40, 217, 0.15);
}

/* Slide in when open */
.profile-drawer.is-open {
  transform: translateX(0);
}

/* ——— Drawer Header ——— */
.profile-drawer__header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1.5rem 1.25rem 1rem;
  background: linear-gradient(
    135deg,
    rgba(167, 139, 250, 0.12),
    rgba(236, 72, 153, 0.07)
  );
  border-bottom: 1px solid rgba(139, 92, 246, 0.1);
}

/* Avatar circle in drawer header */
.profile-drawer__avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.profile-drawer__avatar-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  line-height: 1;
  border: 2.5px solid white;
  box-shadow: 0 4px 12px rgba(109, 40, 217, 0.25);
}

/* Small badge (star icon) at the bottom-right of the avatar */
.profile-drawer__avatar-badge {
  position: absolute;
  bottom: 0;
  right: -2px;
  width: 20px;
  height: 20px;
  background: #7c3aed;
  border-radius: 50%;
  border: 2px solid white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
}

.profile-drawer__name {
  font-family: "Nunito", sans-serif;
  font-weight: 800;
  font-size: 1rem;
  color: #1f2937; /* gray-800 */
  margin: 0 0 0.15rem;
}

.profile-drawer__level {
  font-size: 0.78rem;
  color: #7c3aed;
  font-weight: 600;
  margin: 0;
}

/* ——— Drawer Menu ——— */
.profile-drawer__menu {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0;
  flex: 1;
}

/* Individual menu row */
.drawer-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1.25rem;
  text-decoration: none;
  color: #374151;
  font-family: "Nunito", sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition:
    background 0.15s ease,
    color 0.15s ease;
  border-radius: 0;
}

.drawer-menu-item:hover {
  background: rgba(139, 92, 246, 0.07);
  color: #7c3aed;
}

/* Active / highlighted item (e.g. Change Avatar in the design) */
.drawer-menu-item--active {
  background: rgba(139, 92, 246, 0.08);
  color: #7c3aed;
  border-radius: 0.75rem;
  margin: 0 0.75rem;
  width: calc(100% - 1.5rem);
  padding: 0.75rem 1rem;
}

.drawer-menu-item--active:hover {
  background: rgba(139, 92, 246, 0.14);
}

/* Danger / logout item */
.drawer-menu-item--danger {
  color: #ef4444; /* red-500 */
}

.drawer-menu-item--danger:hover {
  background: rgba(239, 68, 68, 0.07);
  color: #dc2626;
}

/* Emoji icon inside a menu item */
.drawer-menu-item__icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

/* Lucide SVG icon inside a menu item */
.drawer-menu-item__icon-lucide {
  width: 20px;
  height: 20px;
  color: #6b7280; /* gray-500 */
  flex-shrink: 0;
}

.drawer-menu-item__icon-lucide--danger {
  color: #ef4444;
}

.drawer-menu-item__label {
  flex: 1;
}

/* Hairline separator */
.profile-drawer__divider {
  height: 1px;
  background: rgba(0, 0, 0, 0.07);
  margin: 0.5rem 1.25rem;
}

/* ——— Pro Status Footer ——— */
.profile-drawer__pro {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(
    135deg,
    rgba(167, 139, 250, 0.15),
    rgba(236, 72, 153, 0.1)
  );
  border-top: 1px solid rgba(139, 92, 246, 0.12);
  margin-top: auto;
}

/* ================================================
   PROFILE MODAL
   Small, accessible modal used to update username / email / password
   ================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 120;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-backdrop.is-open {
  opacity: 1;
  pointer-events: all;
}

.profile-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: 92%;
  max-width: 520px;
  background: #ffffff;
  border-radius: 12px;
  z-index: 130;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.22s cubic-bezier(0.2, 0, 0, 1.2);
}
.profile-modal.is-open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}
.profile-modal__close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  color: #6b7280;
}
.profile-modal__content {
  padding: 1.25rem 1.25rem 1.5rem 1.25rem;
}
.profile-form {
  margin-top: 0.5rem;
}
.profile-form .input-field {
  border: 1px solid rgba(15, 23, 42, 0.06);
}

@media (min-width: 768px) {
  .profile-modal {
    width: 480px;
  }
}

.profile-drawer__pro-icon {
  font-size: 1.5rem;
}

.profile-drawer__pro-label {
  font-weight: 800;
  font-size: 0.8rem;
  color: #7c3aed;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 0.1rem;
}

.profile-drawer__pro-sub {
  font-size: 0.72rem;
  color: #9ca3af;
  margin: 0;
}

/* Prevent body scroll when drawer is open */
body.drawer-open {
  overflow: hidden;
}
