/* =============================================================
   RESET & BASE
   ============================================================= */

/* Height of the top ad banner – used to offset the app below it */
:root {
  --ad-banner-height: 90px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Arial Rounded MT Bold',
               'Nunito', cursive;
  user-select: none;
  -webkit-user-select: none;
  /* Animated rainbow gradient background (overridden by theme classes) */
  background-image: linear-gradient(-45deg, #FF6B6B, #FFD93D, #6BCB77, #4D96FF, #FF6FC8, #B042FF);
  background-size: 400% 400%;
  animation: gradientShift 14s ease infinite;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50%       { background-position: 100% 50%; }
}

/* =============================================================
   CANVAS  (particle / sparkle overlay)
   ============================================================= */
#particles-canvas {
  position: fixed;
  top: var(--ad-banner-height);
  left: 0;
  width: 100%;
  height: calc(100% - var(--ad-banner-height));
  pointer-events: none;
  z-index: 100;
}

/* =============================================================
   AD CONTAINERS  (non-intrusive, positioned away from interactive areas)
   ============================================================= */

/* Top banner ad – fixed at the very top, clear of play area */
.ad-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--ad-banner-height);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  z-index: 50;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* "Ad" label so the ad area is clearly identified */
.ad-label {
  position: absolute;
  top: 2px;
  right: 8px;
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  pointer-events: none;
}

/* Responsive ad slot – fills available width up to standard sizes */
.ad-slot-top {
  max-width: 728px;
  width: 100%;
  height: 90px;
}

/* Mobile: shorter ad banner to save vertical space */
@media (max-width: 768px) {
  :root {
    --ad-banner-height: 50px;
  }

  .ad-container {
    max-height: 50px;
  }

  .ad-slot-top {
    max-width: 320px;
    height: 50px;
  }
}

/* =============================================================
   APP CONTAINER
   ============================================================= */
#app {
  position: relative;
  width: 100vw;
  height: calc(100vh - var(--ad-banner-height));
  margin-top: var(--ad-banner-height);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* =============================================================
   SKIP LINK  (keyboard / screen-reader shortcut)
   ============================================================= */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =============================================================
   WELCOME SCREEN
   ============================================================= */
#welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 28px);
  text-align: center;
  padding: 20px;
}

.welcome-title {
  font-size: clamp(38px, 9vw, 96px);
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 4px 0 rgba(0,0,0,0.18),
    0 8px 24px rgba(0,0,0,0.18);
  letter-spacing: 2px;
  animation: pulse 2.2s ease-in-out infinite;
}

.welcome-prompt {
  font-size: clamp(18px, 4vw, 42px);
  font-weight: 700;
  color: rgba(255,255,255,0.95);
  background: rgba(255,255,255,0.22);
  padding: clamp(8px,1.5vw,14px) clamp(18px,4vw,40px);
  border-radius: 50px;
  backdrop-filter: blur(6px);
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
  animation: pulse 2.2s ease-in-out infinite 0.5s;
}

.emoji-row {
  display: flex;
  gap: clamp(8px, 2vw, 20px);
  flex-wrap: wrap;
  justify-content: center;
}

.bounce-icon {
  font-size: clamp(36px, 7vw, 74px);
  display: inline-block;
  animation: floatBounce 3s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.18));
}

@keyframes floatBounce {
  0%, 100% { transform: translateY(0)    rotate(0deg); }
  33%       { transform: translateY(-14px) rotate(6deg); }
  66%       { transform: translateY(-7px)  rotate(-4deg); }
}

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

/* =============================================================
   MAIN DISPLAY  (letter / number result)
   ============================================================= */
#main-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.5vw, 16px);
  text-align: center;
  padding: 20px;
  max-width: 94vw;
}

#main-display.hidden {
  display: none;
}

/* Big letter / digit */
#key-letter {
  font-size: clamp(110px, 26vw, 260px);
  font-weight: 900;
  line-height: 1;
  -webkit-text-stroke: 3px rgba(0,0,0,0.12);
  text-shadow:
    0 8px 0 rgba(0,0,0,0.12),
    0 14px 30px rgba(0,0,0,0.2);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.12));
}

/* Lowercase mirror of the letter (hidden for numbers) */
.letter-lower {
  font-size: clamp(50px, 12vw, 120px);
  font-weight: 700;
  line-height: 1;
  color: rgba(255,255,255,0.88);
  text-shadow: 0 4px 12px rgba(0,0,0,0.18);
  margin-top: -0.25em;
}

.letter-lower.hidden {
  display: none;
}

/* Emoji (letter association or counting stars) */
#key-emoji {
  line-height: 1.15;
  max-width: 86vw;
  word-break: break-all;
  overflow-wrap: anywhere;
  text-align: center;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.2));
  /* default size; JS may override for numbers */
  font-size: clamp(60px, 13vw, 130px);
}

/* Educational phrase / word */
#key-word {
  font-size: clamp(22px, 4.5vw, 52px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.22);
  background: rgba(255,255,255,0.25);
  padding: clamp(8px,1.5vw,14px) clamp(18px,4vw,40px);
  border-radius: 50px;
  backdrop-filter: blur(8px);
  max-width: 90vw;
  text-align: center;
}

/* =============================================================
   POP-IN ANIMATIONS  (applied via JS class toggle)
   ============================================================= */
.animate-in #key-letter {
  animation: letterPop 0.55s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

.animate-in .letter-lower {
  animation: letterPop 0.55s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.07s both;
}

.animate-in #key-emoji {
  animation: emojiPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.14s both;
}

.animate-in #key-word {
  animation: wordSlide 0.4s ease-out 0.28s both;
}

@keyframes letterPop {
  0%   { transform: scale(0.2) rotate(-18deg); opacity: 0; }
  55%  { transform: scale(1.25) rotate(6deg);  opacity: 1; }
  75%  { transform: scale(0.92) rotate(-2deg); }
  100% { transform: scale(1)    rotate(0deg);  opacity: 1; }
}

@keyframes emojiPop {
  0%   { transform: scale(0) translateY(20px); opacity: 0; }
  60%  { transform: scale(1.3) translateY(-6px); }
  100% { transform: scale(1)   translateY(0);    opacity: 1; }
}

@keyframes wordSlide {
  0%   { opacity: 0; transform: translateY(22px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* =============================================================
   UTILITY
   ============================================================= */
.hidden {
  display: none !important;
}

/* =============================================================
   THEME-SPECIFIC BACKGROUNDS
   Each overrides background-image only; size + animation stay on body.
   ============================================================= */
body.theme-zoo {
  background-image: linear-gradient(-45deg, #5a9e6f, #e8a225, #8d6e63, #7ecba1, #f47c3c, #c5e17a);
}

body.theme-space {
  background-image: linear-gradient(-45deg, #0d1b3e, #3d1b8e, #0a2a60, #4a1070, #0050a0, #1a0050);
}

body.theme-sports {
  background-image: linear-gradient(-45deg, #1a6b3a, #c0392b, #1a3090, #e67e22, #16a085, #8e44ad);
}

body.theme-fairy {
  background-image: linear-gradient(-45deg, #FF69B4, #DA70D6, #FFB6C1, #E0B0FF, #FF1493, #DDA0DD);
}

/* =============================================================
   THEME SWITCHER  (fixed pill bar at bottom)
   ============================================================= */
#theme-switcher {
  position: fixed;
  bottom: clamp(12px, 3vh, 24px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: clamp(8px, 1.5vw, 14px);
  background: rgba(0, 0, 0, 0.38);
  padding: clamp(8px, 1.2vw, 12px) clamp(12px, 2vw, 20px);
  border-radius: 60px;
  backdrop-filter: blur(14px);
  z-index: 10;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  /* Don't absorb pointer events outside the visible bar */
  pointer-events: auto;
}

.theme-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 2px solid transparent;
  cursor: pointer;
  border-radius: 48px;
  padding: clamp(6px, 1vw, 10px) clamp(14px, 2.5vw, 22px);
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(11px, 1.8vw, 15px);
  color: rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s, transform 0.15s, color 0.2s, border-color 0.2s;
  min-width: clamp(64px, 10vw, 90px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.theme-btn > span:first-child {
  font-size: clamp(26px, 5vw, 38px);
  line-height: 1;
}

.theme-btn-label {
  line-height: 1;
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  transform: scale(1.1);
}

.theme-btn.active {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.55);
  transform: scale(1.1);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
}

.theme-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

/* =============================================================
   REDUCED-MOTION PREFERENCES
   Respect the user's OS-level motion settings (WCAG 2.3.3).
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  body {
    background-size: 100% 100%;
  }
}

/* =============================================================
   MOBILE NAVIGATION  (visible only on touch / small screens)
   ============================================================= */

/* Hidden by default (desktop) */
.mobile-only {
  display: none !important;
}

@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  .mobile-only {
    display: flex !important;
  }

  /* Adjust main display so it doesn't overlap mobile controls */
  #main-display {
    padding-bottom: 140px;
  }

  #welcome-screen {
    padding-bottom: 140px;
  }

  /* Bump theme switcher up to make room for mobile nav */
  #theme-switcher {
    bottom: clamp(72px, 14vh, 110px);
  }
}

#mobile-nav {
  position: fixed;
  bottom: clamp(10px, 2vh, 18px);
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
  gap: clamp(10px, 3vw, 20px);
  z-index: 11;
  pointer-events: auto;
}

.mobile-nav-btn {
  width: clamp(56px, 14vw, 72px);
  height: clamp(56px, 14vw, 72px);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  color: #fff;
  font-size: clamp(22px, 6vw, 32px);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s, background 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-nav-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.25);
}

.mobile-nav-mode {
  min-width: clamp(72px, 20vw, 100px);
  height: clamp(48px, 12vw, 60px);
  border-radius: 50px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  color: #fff;
  font-size: clamp(16px, 4.5vw, 22px);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s, background 0.12s;
  letter-spacing: 1px;
}

.mobile-nav-mode:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.25);
}
