/* style.css — Mind Blink: Neon glassmorphism theme, highly animated, mobile-first */

/* ── SEO-only content: readable by crawlers & screen readers, invisible on screen ── */
.seo-hidden {
  position: fixed;
  top: -9999px; left: -9999px;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  width: 100%; height: 100%;
  /* NO overflow:hidden on html — required on iOS Safari for touch scroll
     to reach position:absolute .screen children */
}

body {
  width: 100%; height: 100%;
  overflow: hidden; /* body clips viewport; .screen elements scroll inside */
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  font-weight: 700;
  background: #0d0d1a;
  color: #e0e0ff;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Animated background gradient mesh ── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0,245,255,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(255,45,120,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(57,255,20,0.05) 0%, transparent 50%),
    linear-gradient(135deg, #0d0d1a 0%, #1a0a2e 30%, #0d0d1a 50%, #0a1a2e 70%, #0d0d1a 100%);
  background-size: 400% 400%;
  animation: bgShift 25s ease infinite;
  z-index: -2;
}
body::after {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(circle at 50% 50%, transparent 30%, rgba(0,0,0,0.4) 100%);
  z-index: -1;
  pointer-events: none;
}

@keyframes bgShift {
  0%, 100% { background-position: 0% 50%; }
  25% { background-position: 50% 0%; }
  50% { background-position: 100% 50%; }
  75% { background-position: 50% 100%; }
}

/* ═══════════════════════════════════
   LOADER SCREEN
   ═══════════════════════════════════ */
#loader-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: #0d0d1a;
  z-index: 9999;
  transition: opacity 0.5s ease;
}
#loader-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.loader-title {
  font-size: 2rem;
  background: linear-gradient(135deg, #00f5ff, #ff2d78, #ffe600);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientText 3s ease infinite;
  margin-bottom: 32px;
}
@keyframes gradientText {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.loader-spinner {
  width: 48px; height: 48px;
  border: 3px solid rgba(0,245,255,0.15);
  border-top-color: #00f5ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loader-dots {
  margin-top: 16px;
  display: flex; gap: 8px;
}
.loader-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #00f5ff;
  animation: dotPulse 1.2s ease infinite;
}
.loader-dot:nth-child(2) { animation-delay: 0.2s; }
.loader-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* ═══════════════════════════════════
   FIRST VISIT OVERLAY
   ═══════════════════════════════════ */
#first-visit-overlay {
  position: fixed; inset: 0;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 8000;
  background: rgba(13,13,26,0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: opacity 0.4s ease;
}
#first-visit-overlay.active {
  display: flex;
}
#first-visit-overlay.fade-out {
  opacity: 0;
}
.fv-title {
  font-size: 3rem;
  background: linear-gradient(135deg, #00f5ff, #ff2d78);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  animation: titleFloat 3s ease-in-out infinite;
  letter-spacing: 3px;
}
@keyframes titleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.fv-subtitle {
  font-size: 1rem;
  color: rgba(255,255,255,0.5);
  margin-top: 8px;
  text-align: center;
}
.fv-tap {
  margin-top: 48px;
  font-size: 1.3rem;
  color: #ffe600;
  animation: tapPulse 1.5s ease-in-out infinite;
}
@keyframes tapPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}
.fv-hand {
  font-size: 2.5rem;
  margin-top: 16px;
  animation: handBounce 1s ease-in-out infinite;
}
@keyframes handBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

/* First visit content z-ordering */
.fv-content {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  position: relative;
  z-index: 2;
}

/* Floating demo background */
.fv-demo-bg {
  position: absolute; inset: 0;
  overflow: hidden;
  z-index: 1;
  pointer-events: none;
}
.fv-float {
  position: absolute;
  opacity: 0.12;
  animation: fvDrift 6s ease-in-out infinite;
}
.fv-float-word {
  font-size: 2.2rem;
  color: #ff2d78;
  text-shadow: 0 0 20px currentColor;
  letter-spacing: 6px;
}
.fv-float-num {
  font-size: 1.4rem;
  color: #00f5ff;
  text-shadow: 0 0 12px currentColor;
}
.fv-float-score {
  font-size: 1.2rem;
  color: #ffe600;
  text-shadow: 0 0 12px currentColor;
  transform: translateX(-50%);
}
.fv-float-grid {
  display: grid;
  grid-template-columns: repeat(3, 24px);
  gap: 4px;
}
.fv-tile {
  display: block;
  width: 24px; height: 24px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.06);
}
.fv-tile.on {
  background: rgba(0,245,255,0.4);
  box-shadow: 0 0 8px rgba(0,245,255,0.4);
}
@keyframes fvDrift {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.1; }
  50% { transform: translateY(-20px) scale(1.05); opacity: 0.2; }
}

/* ═══════════════════════════════════
   SCREENS BASE
   ═══════════════════════════════════ */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  /* Enable smooth native scroll on all screens */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* iOS momentum scroll */
  overscroll-behavior-y: contain;    /* prevent pull-to-refresh bleeding */
  /* Ensure the element itself is the scroll container */
  height: 100%;
  max-height: 100%;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
}
.screen-enter {
  animation: screenSlideIn 0.35s ease;
}
@keyframes screenSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Glassmorphism card ── */
.glass {
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 28px;
}

/* ═══════════════════════════════════
   MAIN MENU
   ═══════════════════════════════════ */
#menu-screen {
  justify-content: center;
  gap: 18px;
  padding: 40px 24px;
}
.menu-logo {
  font-size: 2.8rem;
  background: linear-gradient(135deg, #00f5ff 0%, #ff2d78 50%, #ffe600 100%);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientText 4s ease infinite;
  text-align: center;
  letter-spacing: 3px;
  text-shadow: none;
  filter: drop-shadow(0 0 20px rgba(0,245,255,0.3));
}
.menu-subtitle {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.4);
  text-align: center;
  letter-spacing: 4px;
  text-transform: uppercase;
}
.menu-points {
  font-size: 1.5rem;
  color: #ffe600;
  text-align: center;
  text-shadow: 0 0 12px rgba(255,230,0,0.4);
}
.menu-streak {
  font-size: 1rem;
  color: #ff2d78;
  text-align: center;
  min-height: 1.3em;
}

.menu-btn {
  width: 100%; max-width: 300px;
  padding: 18px 24px;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: inherit;
  border: 2px solid #00f5ff;
  border-radius: 14px;
  background: rgba(0,245,255,0.08);
  color: #00f5ff;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.25s ease;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}
.menu-btn::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(0,245,255,0.1) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s;
}
.menu-btn:hover::after { opacity: 1; }
.menu-btn:active { transform: scale(0.96); }
.menu-btn:hover {
  box-shadow: 0 0 24px rgba(0,245,255,0.4), 0 0 48px rgba(0,245,255,0.1);
}

.menu-btn.secondary {
  border-color: #ff2d78;
  color: #ff2d78;
  background: rgba(255,45,120,0.08);
}
.menu-btn.secondary:hover {
  box-shadow: 0 0 24px rgba(255,45,120,0.4);
}

.menu-btn.daily {
  border-color: #ffe600;
  color: #ffe600;
  background: rgba(255,230,0,0.08);
  animation: dailyGlow 2s ease-in-out infinite;
}
@keyframes dailyGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(255,230,0,0.2); }
  50% { box-shadow: 0 0 24px rgba(255,230,0,0.5), 0 0 48px rgba(255,230,0,0.15); }
}

/* Sound toggle — absolute inside #menu-screen, never overlaps content */
#sound-toggle {
  position: absolute;
  top: 14px; right: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50%;
  width: 40px; height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s, background 0.2s;
  flex-shrink: 0;
}
#sound-toggle:active { transform: scale(0.9); }
#sound-toggle:hover { background: rgba(255,255,255,0.1); }

/* ═══════════════════════════════════
   LEVEL SELECT
   ═══════════════════════════════════ */
#level-screen {
  padding: 20px;
  gap: 16px;
}
.level-header {
  font-size: 1.6rem;
  background: linear-gradient(90deg, #00f5ff, #ff2d78);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}
.level-back-btn {
  align-self: flex-start;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  color: #e0e0ff;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  transition: transform 0.1s, background 0.2s;
}
.level-back-btn:active { transform: scale(0.95); }
.level-back-btn:hover { background: rgba(255,255,255,0.1); }

#level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%; max-width: 400px;
  padding-bottom: 40px;
}
.level-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 16px 8px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.25s ease, border-color 0.25s;
  animation: levelCardIn 0.4s ease backwards;
}
.level-card:active { transform: scale(0.94); }

.level-card.unlocked {
  border-color: rgba(0,245,255,0.25);
}
.level-card.unlocked:hover {
  box-shadow: 0 0 20px rgba(0,245,255,0.25);
  border-color: rgba(0,245,255,0.5);
}
.level-card.locked {
  opacity: 0.4;
  border-color: rgba(255,255,255,0.05);
}
.level-card.can-unlock {
  opacity: 0.85;
  border-color: rgba(57,255,20,0.4);
  animation: levelCardIn 0.4s ease backwards, canUnlockPulse 2s ease-in-out infinite;
}
@keyframes canUnlockPulse {
  0%, 100% { box-shadow: 0 0 4px rgba(57,255,20,0.1); }
  50% { box-shadow: 0 0 16px rgba(57,255,20,0.3); }
}
@keyframes levelCardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.level-num {
  font-size: 1.6rem;
  color: #00f5ff;
  text-shadow: 0 0 8px rgba(0,245,255,0.3);
}
.level-name {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.5);
  margin: 4px 0;
  letter-spacing: 0.5px;
}
.level-stars { font-size: 0.95rem; }
.star { color: rgba(255,255,255,0.15); }
.star.filled { color: #ffe600; text-shadow: 0 0 6px rgba(255,230,0,0.4); }
.level-best { font-size: 0.65rem; color: rgba(255,255,255,0.35); margin-top: 2px; }
.level-req { font-size: 0.68rem; color: #ff2d78; margin-top: 4px; }
.level-unlock-ready {
  font-size: 0.6rem;
  color: #39ff14;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

/* ═══════════════════════════════════
   GAME SCREEN
   ═══════════════════════════════════ */
#game-screen {
  position: relative;
  padding: 0;
  /* Hard lock: never scroll — everything must fit vertically */
  overflow: hidden !important;
  /* Explicit height: fill the viewport (inset:0 already does this, but be safe) */
  height: 100%;
  max-height: 100%;
}

/* ── Dynamic atmosphere backgrounds ── */
#game-bg {
  position: absolute; inset: 0;
  z-index: 0;
  pointer-events: none;
}
.gbg {
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity 0.65s ease;
  pointer-events: none;
}
.gbg.active { opacity: 1; }

/* Color/Stroop — vivid pink-magenta clash */
.gbg-color {
  background:
    radial-gradient(ellipse at 18% 30%, rgba(255,45,120,0.30) 0%, transparent 55%),
    radial-gradient(ellipse at 82% 68%, rgba(180,0,255,0.20) 0%, transparent 55%),
    radial-gradient(ellipse at 52% 52%, rgba(255,200,0,0.06) 0%, transparent 40%);
}
/* Math — electric cyan-blue calculation */
.gbg-math {
  background:
    radial-gradient(ellipse at 78% 28%, rgba(0,245,255,0.28) 0%, transparent 55%),
    radial-gradient(ellipse at 18% 72%, rgba(0,80,255,0.20) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(0,200,255,0.07) 0%, transparent 40%);
}
/* Chain — amber-gold memory warmth */
.gbg-chain {
  background:
    radial-gradient(ellipse at 50% 22%, rgba(255,200,0,0.28) 0%, transparent 55%),
    radial-gradient(ellipse at 78% 72%, rgba(255,100,0,0.20) 0%, transparent 55%),
    radial-gradient(ellipse at 24% 60%, rgba(255,160,0,0.10) 0%, transparent 40%);
}
/* Pattern — emerald-green spatial recognition */
.gbg-pattern {
  background:
    radial-gradient(ellipse at 28% 62%, rgba(57,255,20,0.26) 0%, transparent 55%),
    radial-gradient(ellipse at 72% 28%, rgba(0,200,100,0.20) 0%, transparent 55%),
    radial-gradient(ellipse at 54% 50%, rgba(0,255,150,0.08) 0%, transparent 40%);
}

/* Ensure all direct flex children of game-screen stay above bg layer */
.hud, #combo-badge, #challenge-area, #timer-ring, #answer-buttons, #countdown-overlay {
  position: relative;
  z-index: 1;
}

/* ── HUD ── */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: clamp(6px, 1.5vh, 10px) 14px clamp(5px, 1.2vh, 8px);
  background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.2) 100%);
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}
.hud-left {
  display: flex; align-items: center; gap: 6px;
  font-size: 1rem;
}
.heart-empty { opacity: 0.3; }
.hud-center {
  display: flex; flex-direction: column; align-items: center;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
}
#hud-progress {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.35);
  margin-top: 1px;
}
.hud-right {
  font-size: 1.2rem;
  color: #ffe600;
  text-shadow: 0 0 8px rgba(255,230,0,0.3);
  min-width: 48px;
  text-align: right;
}
.score-pop {
  animation: scoreBounce 0.3s ease;
}
@keyframes scoreBounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); color: #fff; }
  100% { transform: scale(1); }
}

#extra-life-btn {
  font-size: 0.65rem;
  padding: 5px 10px;
  border: 1px solid #39ff14;
  border-radius: 8px;
  background: rgba(57,255,20,0.08);
  color: #39ff14;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  transition: transform 0.1s, box-shadow 0.2s;
}
#extra-life-btn:active { transform: scale(0.92); }
#extra-life-btn:hover { box-shadow: 0 0 10px rgba(57,255,20,0.3); }

/* ── Combo Badge ── */
.combo-badge {
  position: absolute;
  top: 56px; right: 14px;
  font-size: 1.4rem;
  color: #ffe600;
  text-shadow: 0 0 12px rgba(255,230,0,0.6);
  opacity: 0;
  pointer-events: none;
  z-index: 25;
  transition: opacity 0.2s;
}
.combo-badge.visible { opacity: 1; }
.combo-badge.combo-pop {
  animation: comboPop 0.35s ease;
}
@keyframes comboPop {
  0% { transform: scale(0.4) rotate(-10deg); }
  50% { transform: scale(1.5) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ── Challenge Area ── */
#challenge-area {
  /* Take all remaining space between HUD and timer ring */
  flex: 1 1 0;
  min-height: 0;       /* allow shrinking below intrinsic size */
  overflow: hidden;    /* clip content — never let it push buttons off screen */
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 100%;
  padding: clamp(8px, 2vh, 16px) 20px;
  position: relative;
}
.flip-in {
  animation: flipIn 0.35s ease;
}
@keyframes flipIn {
  0% { transform: perspective(600px) rotateY(90deg); opacity: 0; }
  100% { transform: perspective(600px) rotateY(0); opacity: 1; }
}

.challenge-instruction {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.45);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Stroop word */
.stroop-word {
  font-size: 3.2rem;
  text-transform: uppercase;
  letter-spacing: 5px;
  text-shadow: 0 0 30px currentColor;
  animation: stroopPulse 1.5s ease-in-out infinite;
}
@keyframes stroopPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}

/* Math equation */
.math-equation {
  font-size: 2.8rem;
  color: #e0e0ff;
  letter-spacing: 3px;
  text-shadow: 0 0 16px rgba(224,224,255,0.2);
}

/* Chain sequence */
.chain-show-container {
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
}
.chain-sequence {
  display: flex; gap: 10px;
  flex-wrap: wrap; justify-content: center;
}
.chain-num {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  background: rgba(0,245,255,0.12);
  border: 2px solid rgba(0,245,255,0.35);
  border-radius: 12px;
  color: #00f5ff;
  text-shadow: 0 0 8px rgba(0,245,255,0.4);
  animation: chainNumIn 0.4s ease backwards;
}
.chain-num:nth-child(1) { animation-delay: 0s; }
.chain-num:nth-child(2) { animation-delay: 0.12s; }
.chain-num:nth-child(3) { animation-delay: 0.24s; }
.chain-num:nth-child(4) { animation-delay: 0.36s; }
.chain-num:nth-child(5) { animation-delay: 0.48s; }
.chain-num:nth-child(6) { animation-delay: 0.60s; }
.chain-num:nth-child(7) { animation-delay: 0.72s; }
.chain-num:nth-child(8) { animation-delay: 0.84s; }
.chain-num:nth-child(9) { animation-delay: 0.96s; }
@keyframes chainNumIn {
  from { opacity: 0; transform: scale(0) rotate(-20deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.memorize-hint {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.35);
  animation: memBlink 0.8s ease-in-out infinite;
}
@keyframes memBlink {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.7; }
}

.chain-selected {
  font-size: 1rem;
  color: #00f5ff;
  min-height: 28px;
  margin-bottom: 10px;
  text-shadow: 0 0 6px rgba(0,245,255,0.3);
}

.chain-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 240px;
  width: 100%;
}
.grid-btn {
  width: 100%;
  aspect-ratio: 1;
  font-size: 1.5rem;
  font-weight: 700;
  font-family: inherit;
  border: 2px solid rgba(0,245,255,0.35);
  border-radius: 12px;
  background: rgba(0,245,255,0.06);
  color: #00f5ff;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, box-shadow 0.2s;
}
.grid-btn:active { transform: scale(0.9); }
.grid-btn:hover { box-shadow: 0 0 12px rgba(0,245,255,0.25); }
.grid-btn.tapped {
  background: rgba(0,245,255,0.25);
  border-color: #00f5ff;
  opacity: 0.4;
  pointer-events: none;
  transform: scale(0.9);
}

/* Pattern grid */
.pattern-grid {
  display: grid;
  gap: 6px;
  max-width: 260px;
  width: 100%;
  margin: 0 auto;
}
.pattern-tile {
  aspect-ratio: 1;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  transition: background 0.2s, transform 0.12s, box-shadow 0.2s;
}
.pattern-tile.active {
  background: #00f5ff;
  box-shadow: 0 0 16px rgba(0,245,255,0.6), inset 0 0 8px rgba(255,255,255,0.2);
  animation: tileFlash 0.4s ease backwards;
}
@keyframes tileFlash {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.pattern-tile.input-tile {
  cursor: pointer;
}
.pattern-tile.input-tile:active { transform: scale(0.9); }
.pattern-tile.input-tile:hover { border-color: rgba(0,245,255,0.3); }
.pattern-tile.selected {
  background: #00f5ff;
  box-shadow: 0 0 14px rgba(0,245,255,0.5);
  border-color: #00f5ff;
}

/* ── Answer Buttons ── */
#answer-buttons {
  display: flex;
  gap: clamp(6px, 1.5vw, 10px);
  /* Use clamp so padding auto-shrinks on short phones */
  padding: clamp(8px, 1.5vh, 14px) 16px clamp(10px, 2vh, 20px);
  width: 100%;
  flex-wrap: wrap;
  justify-content: center;
  flex-shrink: 0;  /* never shrink the buttons area away */
}
.answer-btn {
  flex: 1 1 calc(50% - 10px);
  min-width: 80px;
  /* clamp height so buttons always remain tappable but don't overflow */
  min-height: clamp(50px, 9vh, 70px);
  max-height: clamp(60px, 12vh, 90px);
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  font-weight: 700;
  font-family: inherit;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  color: #e0e0ff;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  animation: btnSlideIn 0.3s ease backwards;
  position: relative;
  overflow: hidden;
}
@keyframes btnSlideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.answer-btn:active { transform: scale(0.94); }
.answer-btn:hover {
  box-shadow: 0 0 18px rgba(0,245,255,0.25);
  transform: scale(1.03);
}
.color-btn:hover {
  box-shadow: 0 0 18px currentColor;
}

.done-btn {
  width: 100%; max-width: 220px;
  min-height: 52px;
  border-color: #39ff14;
  color: #39ff14;
  background: rgba(57,255,20,0.08);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.done-btn:hover {
  box-shadow: 0 0 18px rgba(57,255,20,0.3);
}

/* ── Timer Ring — centred between challenge and answer buttons ── */
#timer-ring {
  position: relative;
  /* Shrink slightly on small screens with clamp */
  width:  clamp(72px, 14vmin, 92px);
  height: clamp(72px, 14vmin, 92px);
  /* Proportional margin so it never crowds other zones */
  margin: clamp(6px, 1.5vh, 14px) auto clamp(6px, 1.5vh, 18px);
  flex-shrink: 0;
  pointer-events: none;
  z-index: 2;
  display: none;
  filter: drop-shadow(0 0 10px rgba(0,245,255,0.45));
  transition: filter 0.4s ease;
}
#timer-ring svg {
  width: 100%; height: 100%;
  transform: rotate(-90deg);
}
#timer-ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.07);
  stroke-width: 5;
}
#timer-ring-progress {
  fill: none;
  stroke: #00f5ff;
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke 0.4s ease;
}
/* Seconds text centred inside the ring */
.timer-text {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  font-weight: 900;
  color: #00f5ff;
  line-height: 1;
  pointer-events: none;
  transition: color 0.4s ease;
  font-family: inherit;
  letter-spacing: -1px;
}

/* ═══════════════════════════════════
   COUNTDOWN OVERLAY (3-2-1-GO)
   ═══════════════════════════════════ */
#countdown-overlay {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(13,13,26,0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
}
#countdown-overlay.active { display: flex; }

.countdown-num {
  font-size: 5rem;
  color: #00f5ff;
  text-shadow: 0 0 40px rgba(0,245,255,0.6);
  transition: color 0.2s;
}
.countdown-anim {
  animation: cdPop 0.6s ease;
}
.countdown-go {
  color: #39ff14;
  text-shadow: 0 0 40px rgba(57,255,20,0.6);
  animation: cdPop 0.6s ease;
}
@keyframes cdPop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ═══════════════════════════════════
   FEEDBACK ANIMATIONS
   ═══════════════════════════════════ */
.feedback {
  position: absolute;
  top: 38%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  font-weight: 700;
  pointer-events: none;
  z-index: 35;
  animation: feedbackFloat 0.9s ease forwards;
}
.feedback.correct {
  color: #39ff14;
  text-shadow: 0 0 24px rgba(57,255,20,0.8);
}
.feedback.wrong {
  color: #ff2d78;
  text-shadow: 0 0 24px rgba(255,45,120,0.8);
}
.feedback.life-lost {
  font-size: 3.5rem;
  animation: heartShatter 0.9s ease forwards;
}

@keyframes feedbackFloat {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); }
  30% { opacity: 1; transform: translate(-50%, -70%) scale(1.3); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(0.8); }
}
@keyframes heartShatter {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  25% { transform: translate(-50%, -50%) scale(1.4); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.1) rotate(60deg); }
}

/* Screen shake */
.shake {
  animation: shakeIt 0.45s ease;
}
@keyframes shakeIt {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-10px) rotate(-0.5deg); }
  30% { transform: translateX(10px) rotate(0.5deg); }
  45% { transform: translateX(-7px); }
  60% { transform: translateX(7px); }
  75% { transform: translateX(-3px); }
}

/* ═══════════════════════════════════
   GAME OVER & LEVEL COMPLETE
   ═══════════════════════════════════ */
#gameover-screen, #complete-screen {
  justify-content: center;
  gap: 18px;
  padding: 40px 24px;
}
.go-title {
  font-size: 2.2rem;
  color: #ff2d78;
  text-shadow: 0 0 24px rgba(255,45,120,0.5);
  animation: goTitlePulse 2s ease-in-out infinite;
}
@keyframes goTitlePulse {
  0%, 100% { text-shadow: 0 0 24px rgba(255,45,120,0.3); }
  50% { text-shadow: 0 0 40px rgba(255,45,120,0.6); }
}
.lc-title {
  font-size: 1.9rem;
  color: #39ff14;
  text-shadow: 0 0 24px rgba(57,255,20,0.5);
}
.result-card {
  text-align: center;
  padding: 28px 36px;
  max-width: 320px;
  width: 100%;
}
.result-score {
  font-size: 2.5rem;
  color: #ffe600;
  margin: 10px 0;
  text-shadow: 0 0 16px rgba(255,230,0,0.4);
}
.result-score-anim {
  animation: resultScoreIn 0.6s ease;
}
@keyframes resultScoreIn {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}
.result-best {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.4);
}
.result-stars {
  font-size: 2rem;
  margin: 10px 0;
}
.result-total {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.35);
}

/* ── Particles ── */
.particle {
  position: absolute;
  border-radius: 50%;
  animation: particleBurst 1.5s ease forwards;
  pointer-events: none;
  z-index: 60;
}
@keyframes particleBurst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0);
  }
  40% {
    opacity: 1;
    transform: translate(calc(var(--dx, 0) * 100px), calc(var(--dy, 0) * -100px)) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translate(calc(var(--dx, 0) * 160px), calc(var(--dy, 0) * 60px)) scale(0.3);
  }
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 70px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(0,0,0,0.88);
  border: 1px solid rgba(255,230,0,0.2);
  color: #ffe600;
  padding: 12px 28px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  z-index: 500;
  text-align: center;
  max-width: 88%;
  white-space: nowrap;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── No Lives Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 850;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}
.modal-card {
  position: relative;
  width: min(88vw, 340px);
  padding: 36px 24px 28px;
  border-radius: 24px;
  text-align: center;
  transform: translateY(40px) scale(0.9);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.active .modal-card {
  transform: translateY(0) scale(1);
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none;
  color: rgba(224,224,255,0.4);
  font-size: 1.1rem; cursor: pointer;
  padding: 6px 10px; line-height: 1;
  transition: color 0.2s;
  border-radius: 50%;
}
.modal-close:hover, .modal-close:focus { color: #e0e0ff; outline: none; }
.modal-icon {
  font-size: 3rem;
  display: block;
  animation: heartBeat 1.4s ease infinite;
}
@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  14% { transform: scale(1.25); }
  28% { transform: scale(1); }
  42% { transform: scale(1.15); }
  70% { transform: scale(1); }
}
.modal-title {
  font-size: 1.5rem;
  color: #ff2d78;
  margin: 12px 0 8px;
  text-shadow: 0 0 14px rgba(255,45,120,0.6);
}
.modal-hearts {
  font-size: 1.4rem;
  letter-spacing: 8px;
  margin: 10px 0 14px;
}
.modal-hearts .heart-empty-modal {
  opacity: 0.25;
  filter: grayscale(1);
}
.modal-sub {
  color: rgba(224,224,255,0.6);
  font-size: 0.88rem;
  margin-bottom: 22px;
}
#no-lives-timer {
  color: #00f5ff;
  font-weight: 900;
  font-size: 1rem;
}
.modal-ad-btn {
  width: 100%;
  margin-bottom: 12px;
  animation: adBtnGlow 2s ease infinite;
}
@keyframes adBtnGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,245,255,0.5), 0 4px 20px rgba(0,245,255,0.25); }
  50% { box-shadow: 0 0 0 8px rgba(0,245,255,0), 0 4px 28px rgba(0,245,255,0.45); }
}
.modal-note {
  color: rgba(224,224,255,0.35);
  font-size: 0.72rem;
  line-height: 1.4;
}

/* ── Ad Overlay ── */
#ad-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  pointer-events: none;
  z-index: 9000;
  transition: opacity 0.3s;
  color: rgba(255,255,255,0.4);
  font-size: 1rem;
}
#ad-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Fixed Footer Banner Ad ── */
#footer-ad-bar {
  position: fixed;
  bottom: 0; left: 0;
  width: 100%;
  height: 60px;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13,13,26,0.97);
  border-top: 1px solid rgba(255,255,255,0.07);
  transform: translateY(0);
  transition: transform 0.3s ease;
}
/* Slide footer off-screen during active gameplay to avoid accidental clicks */
body.game-active #footer-ad-bar {
  transform: translateY(110%);
}
/* Also hide during first-visit overlay and loader */
#first-visit-overlay.active ~ #footer-ad-bar,
#loader-screen:not([style*="display: none"]) ~ #footer-ad-bar {
  display: none;
}

/* ── In-content Display Ad Slots ── */
/* Shown inside menu / gameover / complete screens */
.display-ad-slot {
  width: 100%;
  max-width: 360px;
  margin: 14px auto 0;
  min-height: 90px;
  text-align: center;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
}

/* Add bottom padding to non-game screens so footer bar never covers buttons */
#menu-screen,
#level-screen,
#gameover-screen,
#complete-screen {
  padding-bottom: 70px;
}

/* ═══════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════ */
@media (min-width: 480px) {
  .screen { max-width: 440px; margin: 0 auto; }
  #level-grid { max-width: 380px; }
  .fv-title { font-size: 3.5rem; }
}
@media (orientation: landscape) {
  .screen { max-width: 480px; margin: 0 auto; }
}
@media (max-height: 580px) {
  .menu-logo { font-size: 2.2rem; }
  #menu-screen { gap: 12px; padding: 20px; }
  .stroop-word { font-size: 2.4rem; }
  .math-equation { font-size: 2.2rem; }
  /* Game screen compact mode for very short phones */
  #timer-ring { width: 64px; height: 64px; margin: 4px auto 4px; }
  .timer-text { font-size: 1.1rem; }
  .answer-btn { min-height: 46px; max-height: 56px; font-size: 0.9rem; }
  #answer-buttons { padding: 6px 12px 8px; gap: 6px; }
  #challenge-area { padding: 6px 16px; }
  .stroop-word { font-size: 2.2rem; }
  .math-equation { font-size: 2rem; }
  .chain-num { width: 44px; height: 44px; font-size: 1.3rem; }
}
