/* ==========================================================================
   Times Table Tower - Stylesheet
   Theme: Vibrant, cheerful, modern educational web game
   ========================================================================== */

/* --- CSS Variables & Design Tokens --- */
:root {
  --font-primary: 'Fredoka', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Palette */
  --bg-sky-day-top: #38bdf8;
  --bg-sky-day-bot: #bae6fd;
  --color-primary: #f59e0b;
  --color-primary-dark: #d97706;
  --color-success: #10b981;
  --color-success-dark: #059669;
  --color-danger: #ef4444;
  --color-danger-dark: #dc2626;
  --color-warning: #f59e0b;
  --color-dark: #1e293b;
  --color-card: #ffffff;
  --color-shadow: rgba(0, 0, 0, 0.15);

  /* Dimensions */
  --block-width: 220px;
  --block-height: 44px;
  --max-app-width: 100vw;
  --max-content-width: 1200px;
}

/* --- Global Reset & Box Sizing --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
  font-family: var(--font-body);
  background-color: #0f172a;
  color: var(--color-dark);
  -webkit-font-smoothing: antialiased;
}

/* --- Main App Container (Full-Screen Experience) --- */
#game-app {
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  background-color: #38bdf8;
  overflow: hidden;
  box-shadow: none;
}

/* Utility hidden class */
.hidden {
  display: none !important;
}

/* ==========================================================================
   1. Header Stats Bar & Indicators
   ========================================================================== */
#stats-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 3px solid rgba(226, 232, 240, 0.8);
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.stat-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #f1f5f9;
  padding: 4px 8px;
  border-radius: 16px;
  border: 2px solid #e2e8f0;
  flex-shrink: 0;
}

.stat-icon {
  font-size: 1.1rem;
}

.stat-text {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.58rem;
  font-weight: 800;
  color: #64748b;
  letter-spacing: 0.5px;
  line-height: 1;
}

.stat-value {
  font-family: var(--font-primary);
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.1;
}

/* Category & Level Badge */
.level-badge {
  background: #ede9fe;
  border-color: #c4b5fd;
}

.level-badge .stat-label {
  color: #6d28d9;
  max-width: 95px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-badge .stat-value {
  color: #5b21b6;
}

/* Timer Badge & Warning */
.timer-badge {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.timer-badge.timer-warning {
  background: #fee2e2;
  border-color: #ef4444;
  animation: pulseTimer 0.6s infinite alternate;
}

.timer-badge.timer-warning .stat-value {
  color: #dc2626;
}

@keyframes pulseTimer {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
  100% { transform: scale(1.06); box-shadow: 0 0 10px rgba(239, 68, 68, 0.6); }
}

/* Instability Meter System (Step 5) */
.instability-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f8fafc;
  border: 2px solid #cbd5e1;
  padding: 3px 8px;
  border-radius: 14px;
  min-width: 96px;
  transition: all 0.2s;
}

.instability-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 4px;
  margin-bottom: 2px;
}

.instability-label {
  font-size: 0.55rem;
  font-weight: 800;
  color: #64748b;
  letter-spacing: 0.5px;
}

.instability-status-text {
  font-family: var(--font-primary);
  font-size: 0.6rem;
  font-weight: 800;
  color: #10b981;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.instability-meter {
  display: flex;
  gap: 3px;
  width: 100%;
}

.instability-pip {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  transition: background-color 0.2s, transform 0.2s;
}

/* Instability progressive alert states */
.instability-level-0 .instability-status-text { color: #10b981; }
.instability-level-0 { border-color: #cbd5e1; background: #f8fafc; }

.instability-level-1 .instability-status-text { color: #eab308; }
.instability-level-1 { border-color: #fde047; background: #fefce8; }
.instability-level-1 #pip-1 { background: #eab308; }

.instability-level-2 .instability-status-text { color: #f59e0b; }
.instability-level-2 { border-color: #fcd34d; background: #fffbeb; }
.instability-level-2 #pip-1, .instability-level-2 #pip-2 { background: #f59e0b; }

.instability-level-3 .instability-status-text { color: #ea580c; }
.instability-level-3 { border-color: #fdba74; background: #fff7ed; }
.instability-level-3 #pip-1, .instability-level-3 #pip-2, .instability-level-3 #pip-3 { background: #ea580c; }

.instability-level-4 .instability-status-text { color: #dc2626; animation: flashDanger 0.5s infinite alternate; }
.instability-level-4 { border-color: #fca5a5; background: #fef2f2; animation: borderPulse 0.5s infinite alternate; }
.instability-level-4 #pip-1, .instability-level-4 #pip-2, .instability-level-4 #pip-3, .instability-level-4 #pip-4 { background: #dc2626; }

.instability-level-5 #pip-1, .instability-level-5 #pip-2, .instability-level-5 #pip-3, .instability-level-5 #pip-4, .instability-level-5 #pip-5 { background: #991b1b; }

@keyframes flashDanger {
  0% { opacity: 1; }
  100% { opacity: 0.35; }
}

@keyframes borderPulse {
  0% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }
}

/* Header Action Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  background: #f1f5f9;
  border: 2px solid #cbd5e1;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}

.icon-btn:hover {
  transform: scale(1.08);
  background: #e2e8f0;
}

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

#voice-btn.muted {
  opacity: 0.55;
  background: #f1f5f9;
}

#voice-btn.active {
  background: #dbeafe;
  border-color: #3b82f6;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

/* ==========================================================================
   2. World Viewport & Sky Scenery
   ========================================================================== */
#world-viewport {
  position: relative;
  flex: 1;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#sky-scenery {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.sky-gradient {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, #38bdf8 0%, #7dd3fc 45%, #bae6fd 100%);
  transition: background 1.5s ease-in-out;
}

.sky-day {
  background: linear-gradient(180deg, #38bdf8 0%, #7dd3fc 50%, #bae6fd 100%);
}
.sky-sunset {
  background: linear-gradient(180deg, #475569 0%, #fb923c 45%, #fdba74 100%);
}
.sky-night {
  background: linear-gradient(180deg, #090d16 0%, #1e1b4b 60%, #312e81 100%);
}
.sky-space {
  background: linear-gradient(180deg, #020617 0%, #050518 50%, #0f172a 100%);
}

.celestial-body {
  position: absolute;
  top: 75px;
  right: 30px;
  font-size: 2.8rem;
  transition: transform 2s ease, opacity 1s ease;
  filter: drop-shadow(0 0 16px rgba(253, 224, 71, 0.6));
}

.stars-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  background-image: 
    radial-gradient(2px 2px at 20px 30px, #ffffff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 90px 80px, #ffffff, rgba(0,0,0,0)),
    radial-gradient(1.5px 1.5px at 150px 40px, #fef08a, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 240px 110px, #ffffff, rgba(0,0,0,0)),
    radial-gradient(1px 1px at 320px 70px, #ffffff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 400px 140px, #fef08a, rgba(0,0,0,0)),
    radial-gradient(1.5px 1.5px at 480px 50px, #ffffff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 560px 120px, #ffffff, rgba(0,0,0,0));
  background-repeat: repeat;
  background-size: 600px 400px;
  transition: opacity 1.5s ease;
}

.cloud {
  position: absolute;
  font-size: 3rem;
  opacity: 0.75;
  animation: floatClouds 35s linear infinite;
}

.cloud-1 { top: 120px; left: -100px; animation-duration: 40s; font-size: 3.5rem; }
.cloud-2 { top: 220px; left: -100px; animation-duration: 32s; animation-delay: 15s; font-size: 2.5rem; }
.cloud-3 { top: 340px; left: -100px; animation-duration: 48s; animation-delay: 6s; font-size: 3rem; }

@keyframes floatClouds {
  0% { transform: translateX(-150px); }
  100% { transform: translateX(calc(100vw + 160px)); }
}

#particle-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

/* ==========================================================================
   3. Tower Area & Physics Animations (Steps 5 & 6)
   ========================================================================== */
#tower-scroll-container {
  position: absolute;
  top: 64px;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: hidden;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

#tower-stage {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: bottom center;
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1);
  margin-bottom: 20px;
}

#tower-base {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  z-index: 2;
}

.base-pillar {
  width: calc(var(--block-width) + 40px);
  height: 48px;
  background: linear-gradient(180deg, #64748b 0%, #475569 50%, #334155 100%);
  border-radius: 8px 8px 0 0;
  border: 4px solid #1e293b;
  border-bottom: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.3), 0 8px 16px rgba(0, 0, 0, 0.3);
}

.base-text {
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: 1px;
}

.ground-grass {
  width: 100%;
  height: 22px;
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  border-top: 4px solid #15803d;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.ground-dirt {
  width: 100%;
  height: 25px;
  background: linear-gradient(180deg, #854d0e 0%, #713f12 100%);
  border-top: 3px solid #58310c;
}

#tower-blocks {
  display: flex;
  flex-direction: column-reverse; /* Stacks vertically upward */
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  gap: 6px;
  z-index: 3;
}

.tower-block {
  width: var(--block-width);
  height: var(--block-height);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border: 3.5px solid rgba(0, 0, 0, 0.3);
  box-shadow: 
    inset 0 3px 0 rgba(255, 255, 255, 0.5),
    inset 0 -3px 0 rgba(0, 0, 0, 0.25),
    0 4px 10px rgba(0, 0, 0, 0.25);
  font-family: var(--font-primary);
  font-weight: 700;
  font-size: 1.05rem;
  color: #ffffff;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.6);
  position: relative;
  transform-origin: center bottom;
  animation: dropBlockBounce 0.42s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* 12 Distinct Color Themes */
.block-theme-0 { background: linear-gradient(180deg, #f43f5e 0%, #e11d48 50%, #be123c 100%); border-color: #9f1239; }
.block-theme-1 { background: linear-gradient(180deg, #fb923c 0%, #ea580c 50%, #c2410c 100%); border-color: #9a3412; }
.block-theme-2 { background: linear-gradient(180deg, #facc15 0%, #eab308 50%, #ca8a04 100%); border-color: #a16207; color: #1e293b; text-shadow: 0 1px 0 rgba(255,255,255,0.6); }
.block-theme-3 { background: linear-gradient(180deg, #4ade80 0%, #22c55e 50%, #16a34a 100%); border-color: #15803d; }
.block-theme-4 { background: linear-gradient(180deg, #2dd4bf 0%, #14b8a6 50%, #0d9488 100%); border-color: #0f766e; }
.block-theme-5 { background: linear-gradient(180deg, #38bdf8 0%, #0ea5e9 50%, #0284c7 100%); border-color: #0369a1; }
.block-theme-6 { background: linear-gradient(180deg, #818cf8 0%, #6366f1 50%, #4f46e5 100%); border-color: #4338ca; }
.block-theme-7 { background: linear-gradient(180deg, #c084fc 0%, #a855f7 50%, #9333ea 100%); border-color: #7e22ce; }
.block-theme-8 { background: linear-gradient(180deg, #f472b6 0%, #ec4899 50%, #db2777 100%); border-color: #be185d; }
.block-theme-9 { background: linear-gradient(180deg, #34d399 0%, #10b981 50%, #059669 100%); border-color: #047857; }
.block-theme-10 { background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%); border-color: #b45309; }
.block-theme-11 { background: linear-gradient(180deg, #a78bfa 0%, #8b5cf6 50%, #7c3aed 100%); border-color: #6d28d9; }

.block-height-tag {
  font-size: 0.75rem;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.4);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.5px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
}

.block-formula {
  font-size: 1.05rem;
  letter-spacing: 0.5px;
}

@keyframes dropBlockBounce {
  0% { transform: translateY(-110px) scale(0.92, 1.15); opacity: 0; }
  60% { transform: translateY(3px) scale(1.06, 0.94); opacity: 1; }
  80% { transform: translateY(-6px) scale(0.97, 1.03); }
  92% { transform: translateY(1px) scale(1.02, 0.99); }
  100% { transform: translateY(0) scale(1, 1); opacity: 1; }
}

/* Tower Instability Wobble Animations (Levels 1 to 4) */
.stage-wobble-1 { animation: wobbleLvl1 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.stage-wobble-2 { animation: wobbleLvl2 0.55s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.stage-wobble-3 { animation: wobbleLvl3 0.65s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.stage-wobble-4 { animation: wobbleLvl4 0.8s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.tower-pre-collapse { animation: preCollapseShudder 0.4s ease-in-out infinite; }

@keyframes wobbleLvl1 {
  15%, 85% { transform: rotate(-2deg) translateX(-3px); }
  30%, 70% { transform: rotate(2.5deg) translateX(4px); }
  50% { transform: rotate(-2deg) translateX(-3px); }
  100% { transform: rotate(0deg) translateX(0); }
}

@keyframes wobbleLvl2 {
  15%, 85% { transform: rotate(-4deg) translateX(-7px); }
  30%, 70% { transform: rotate(4.5deg) translateX(8px); }
  50% { transform: rotate(-4deg) translateX(-7px); }
  100% { transform: rotate(0deg) translateX(0); }
}

@keyframes wobbleLvl3 {
  15%, 85% { transform: rotate(-6.5deg) translateX(-13px); }
  30%, 70% { transform: rotate(7deg) translateX(14px); }
  50% { transform: rotate(-7deg) translateX(-14px); }
  100% { transform: rotate(0deg) translateX(0); }
}

@keyframes wobbleLvl4 {
  15%, 85% { transform: rotate(-9deg) translateX(-18px); }
  30%, 70% { transform: rotate(9.5deg) translateX(19px); }
  50% { transform: rotate(-10deg) translateX(-20px); }
  100% { transform: rotate(0deg) translateX(0); }
}

@keyframes preCollapseShudder {
  0% { transform: rotate(-8deg) translateX(-14px); }
  50% { transform: rotate(8deg) translateX(14px); }
  100% { transform: rotate(-8deg) translateX(-14px); }
}

/* Tower Collapse (Step 6) */
.tower-topple {
  animation: toppleFall 1.3s cubic-bezier(0.55, 0.085, 0.68, 0.53) forwards;
}

@keyframes toppleFall {
  0% { transform: rotate(0deg); }
  25% { transform: rotate(14deg) translateX(25px); }
  60% { transform: rotate(45deg) translate(90px, 90px); }
  100% { transform: rotate(90deg) translate(260px, 400px); opacity: 0.1; }
}

.block-scatter-left {
  animation: scatterLeft 1.2s forwards cubic-bezier(0.25, 1, 0.5, 1) !important;
}
.block-scatter-right {
  animation: scatterRight 1.2s forwards cubic-bezier(0.25, 1, 0.5, 1) !important;
}

@keyframes scatterLeft {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-200px, 320px) rotate(-160deg); opacity: 0; }
}

@keyframes scatterRight {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(200px, 320px) rotate(160deg); opacity: 0; }
}

/* Live Tower Height Indicator */
.tower-height-display {
  position: absolute;
  top: 74px;
  left: 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #0f172a;
  padding: 6px 14px;
  border-radius: 20px;
  border: 2.5px solid #cbd5e1;
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 25;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tower-height-display strong {
  color: #2563eb;
  font-size: 1.15rem;
}

.tower-height-display.pulse-badge {
  transform: scale(1.12);
  border-color: #3b82f6;
}

/* Speech Wave Indicator */
.speech-indicator {
  position: absolute;
  top: 74px;
  right: 14px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #38bdf8;
  border: 2px solid #38bdf8;
  border-radius: 20px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 25;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
  animation: popInToast 0.3s ease;
}

.wave-bar {
  display: inline-block;
  width: 3.5px;
  height: 14px;
  background: #38bdf8;
  border-radius: 3px;
  animation: soundWave 0.8s ease-in-out infinite alternate;
}
.wave-bar:nth-child(1) { animation-delay: 0.1s; height: 8px; }
.wave-bar:nth-child(2) { animation-delay: 0.25s; height: 16px; }
.wave-bar:nth-child(3) { animation-delay: 0.4s; height: 11px; }

@keyframes soundWave {
  0% { transform: scaleY(0.4); opacity: 0.6; }
  100% { transform: scaleY(1.4); opacity: 1; }
}

.speech-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #f0f9ff;
  margin-left: 3px;
}

/* Floating Score / Combo Animations (Step 7) */
.floating-score-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 28;
}

.floating-score-tag {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-primary);
  font-size: 1.4rem;
  font-weight: 800;
  color: #15803d;
  background: #dcfce7;
  border: 2.5px solid #86efac;
  padding: 4px 14px;
  border-radius: 20px;
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.35);
  animation: floatScoreUp 1s ease-out forwards;
}

@keyframes floatScoreUp {
  0% { transform: translate(-50%, 0) scale(0.7); opacity: 0; }
  25% { transform: translate(-50%, -25px) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -75px) scale(0.95); opacity: 0; }
}

/* Toast Message */
#toast-message {
  position: absolute;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  color: #ffffff;
  padding: 8px 18px;
  border-radius: 20px;
  font-family: var(--font-primary);
  font-size: 1.1rem;
  font-weight: 700;
  z-index: 30;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  animation: popInToast 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popInToast {
  0% { transform: translate(-50%, -20px) scale(0.8); opacity: 0; }
  100% { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* Milestone notification banner */
#altitude-milestone {
  position: absolute;
  top: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  padding: 10px 24px;
  border-radius: 30px;
  border: 3px solid #fef08a;
  font-family: var(--font-primary);
  font-size: 1.2rem;
  font-weight: 800;
  z-index: 30;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.5);
  animation: pulseMilestone 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pulseMilestone {
  0% { transform: translate(-50%, -30px) scale(0.7); opacity: 0; }
  60% { transform: translate(-50%, 0) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* ==========================================================================
   4. Bottom Quiz Panel & Multiple Choice Buttons
   ========================================================================== */
#quiz-panel {
  position: relative;
  width: 100%;
  background: #ffffff;
  border-radius: 28px 28px 0 0;
  padding: 14px 20px 18px 20px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.16);
  z-index: 40;
}

.quiz-content-wrap {
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feedback-banner {
  padding: 8px 14px;
  border-radius: 12px;
  font-family: var(--font-primary);
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  transition: all 0.2s;
}

.feedback-banner.correct {
  background: #dcfce7;
  color: #15803d;
  border: 2px solid #86efac;
}

.feedback-banner.wrong {
  background: #fee2e2;
  color: #b91c1c;
  border: 2px solid #fca5a5;
}

.question-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.question-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  border: 3px solid #e2e8f0;
  border-radius: 16px;
  padding: 6px 20px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.question-pill.pulse-success {
  border-color: #22c55e;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.4);
  transform: scale(1.03);
}

.question-tag {
  font-size: 0.72rem;
  font-weight: 800;
  color: #64748b;
  background: #e2e8f0;
  padding: 3px 8px;
  border-radius: 8px;
  letter-spacing: 0.5px;
}

.equation-display {
  font-family: var(--font-primary);
  font-size: 2rem;
  font-weight: 700;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
}

.math-operator { color: #f59e0b; }
.math-equals { color: #94a3b8; }
.math-mystery {
  color: #3b82f6;
  background: #dbeafe;
  padding: 0 10px;
  border-radius: 8px;
  border: 2px dashed #93c5fd;
}

/* Read Question Aloud Button */
.read-speech-btn {
  background: #f1f5f9;
  border: 2px solid #cbd5e1;
  border-radius: 12px;
  width: 38px;
  height: 38px;
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  margin-left: 6px;
}

.read-speech-btn:hover {
  background: #e2e8f0;
  transform: scale(1.08);
  border-color: #3b82f6;
}

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

/* Visual Math Shape Container (Fractions) */
.visual-math-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: #f8fafc;
  border: 2px dashed #93c5fd;
  border-radius: 16px;
  margin-bottom: 2px;
}

.visual-fraction-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.visual-svg-pie {
  width: 58px;
  height: 58px;
  transform: rotate(-90deg);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.visual-svg-bar {
  height: 32px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.fraction-visual-label {
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
}

.answers-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
}

@media (max-width: 640px) {
  .answers-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}

.ans-btn {
  position: relative;
  background: #ffffff;
  border: 3.5px solid #cbd5e1;
  border-radius: 16px;
  padding: 10px 12px;
  font-family: var(--font-primary);
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
  cursor: pointer;
  box-shadow: 0 5px 0 #94a3b8, 0 8px 12px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, box-shadow 0.1s, background-color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}

.ans-key {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 0.7rem;
  font-family: var(--font-body);
  font-weight: 800;
  color: #94a3b8;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 1px 6px;
}

.ans-btn:hover:not(:disabled) {
  background-color: #f8fafc;
  border-color: #94a3b8;
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #94a3b8, 0 10px 15px rgba(0, 0, 0, 0.1);
}

.ans-btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #94a3b8;
}

.ans-btn.btn-correct {
  background-color: #22c55e !important;
  border-color: #15803d !important;
  color: #ffffff !important;
  box-shadow: 0 5px 0 #15803d !important;
  animation: pulseCorrect 0.4s ease;
}

.ans-btn.btn-wrong {
  background-color: #ef4444 !important;
  border-color: #b91c1c !important;
  color: #ffffff !important;
  box-shadow: 0 5px 0 #b91c1c !important;
  animation: shakeBtn 0.3s ease;
}

@keyframes pulseCorrect {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes shakeBtn {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  70% { transform: translateX(6px); }
}

.ans-btn:disabled {
  cursor: default;
}

.keyboard-tip {
  text-align: center;
  font-size: 0.75rem;
  color: #94a3b8;
}

/* ==========================================================================
   5. Overlay Screens & Modals (Start, How To Play, Pause, Game Over)
   ========================================================================== */
.overlay-modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 680px;
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), 0 0 0 6px rgba(255, 255, 255, 0.15);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  animation: modalPopIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPopIn {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Full-Screen Start / Homepage Screen --- */
#start-screen {
  background: radial-gradient(circle at 50% 12%, #1e293b 0%, #090d16 100%);
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}

.modal-card.start-card {
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  padding: 16px 24px 20px 24px;
  background: transparent;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: none;
  border: none;
  overflow-y: auto;
  overflow-x: hidden;
  animation: fadeIn 0.3s ease;
  gap: 12px;
}

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Top Arcade Bar on Start Screen */
.start-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.start-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-primary);
  font-size: 1.25rem;
  font-weight: 700;
  color: #f59e0b;
  letter-spacing: 0.5px;
}

.start-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.start-content-wrap {
  max-width: 1280px;
  width: 100%;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
  flex: 1;
  justify-content: center;
}

.title-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.logo-emoji {
  font-size: 3.2rem;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.25));
}

.game-title {
  font-family: var(--font-primary);
  font-size: clamp(2rem, 3.8vw, 3rem);
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.game-subtitle {
  font-size: clamp(0.95rem, 1.5vw, 1.15rem);
  color: #94a3b8;
  margin-top: 2px;
}

.best-score-badge {
  background: rgba(254, 243, 199, 0.15);
  border: 2px solid rgba(253, 230, 138, 0.4);
  color: #fde68a;
  border-radius: 14px;
  padding: 6px 16px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Profile Badges Row */
.profile-badges-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.stars-total-badge {
  background: rgba(253, 242, 248, 0.15);
  border: 2px solid rgba(251, 207, 232, 0.4);
  color: #fbcfe8;
  border-radius: 14px;
  padding: 6px 16px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Category Selection Grid - Responsive 5-Column Layout */
.category-selection-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  text-align: left;
}

.section-heading {
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
}

.category-cards-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  width: 100%;
  max-height: none;
  overflow: visible;
  padding: 2px;
}

@media (max-width: 1100px) {
  .category-cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 680px) {
  .category-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 440px) {
  .category-cards-grid {
    grid-template-columns: 1fr;
  }
}

.category-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  background: rgba(30, 41, 59, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
  text-align: left;
  width: 100%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  color: #f8fafc;
}

.category-card:hover {
  background: rgba(51, 65, 85, 0.95);
  border-color: #f59e0b;
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.25);
}

.category-card.active {
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.9) 0%, rgba(30, 64, 175, 0.85) 100%);
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px #3b82f6, 0 8px 24px rgba(59, 130, 246, 0.35);
}

.cat-card-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.cat-card-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  width: 100%;
}

.cat-card-title {
  font-family: var(--font-primary);
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.cat-card-desc {
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.25;
}

.cat-card-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.cat-progress {
  font-family: var(--font-primary);
  font-size: 0.82rem;
  font-weight: 700;
  color: #60a5fa;
  background: rgba(59, 130, 246, 0.2);
  padding: 2px 8px;
  border-radius: 8px;
}

.cat-stars {
  font-size: 0.8rem;
  font-weight: 700;
  color: #fbbf24;
}

.start-sub-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

/* Feature 6: Homepage Primary Actions Row & Resume Button */
.primary-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.resume-action-btn {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  border: 3.5px solid #1d4ed8;
  border-radius: 18px;
  padding: 10px 14px;
  font-family: var(--font-primary);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 5px 0 #1e40af, 0 8px 16px rgba(37, 99, 235, 0.35);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.15s, opacity 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.resume-action-btn:hover:not(.disabled) {
  filter: brightness(1.08);
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #1e40af, 0 10px 20px rgba(37, 99, 235, 0.45);
}

.resume-action-btn:active:not(.disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #1e40af;
}

.resume-action-btn.disabled {
  opacity: 0.6;
  filter: grayscale(0.4);
  background: #64748b;
  border-color: #475569;
  box-shadow: 0 4px 0 #334155;
  cursor: pointer;
}

.resume-btn-title {
  display: flex;
  align-items: center;
  gap: 4px;
}

.resume-info-tag {
  font-size: 0.68rem;
  font-family: var(--font-body);
  font-weight: 800;
  color: #dbeafe;
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 8px;
  border-radius: 10px;
  line-height: 1.2;
}

/* Feature 5: Full-Screen Level Select Modal Enhancements */
#level-select-modal {
  background: #090d16;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}

.modal-card.level-select-card {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
  padding: 16px 24px;
  background: #0f172a;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  box-shadow: none;
  border: none;
  overflow: hidden;
  gap: 10px;
}

.level-select-inner-wrap {
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 10px;
}

.back-menu-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  width: auto;
  border-radius: 14px;
  font-family: var(--font-primary);
  font-weight: 700;
  font-size: 0.92rem;
}

.category-summary-overview {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
  flex-shrink: 0;
}

@media (max-width: 1024px) {
  .category-summary-overview {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 600px) {
  .category-summary-overview {
    grid-template-columns: repeat(2, 1fr);
  }
}

.cat-summary-card {
  background: rgba(30, 41, 59, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  color: #f8fafc;
}

.cat-summary-card:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: #3b82f6;
  transform: translateY(-1px);
}

.cat-summary-card.active {
  background: rgba(30, 58, 138, 0.6);
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px #3b82f6;
}

.cat-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cat-summary-title {
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 5px;
}

.cat-summary-fraction {
  font-size: 0.78rem;
  font-weight: 800;
  color: #60a5fa;
}

.cat-progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
}

.cat-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6 0%, #10b981 100%);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.level-category-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px;
  width: 100%;
  flex-shrink: 0;
}

.cat-tab-btn {
  background: rgba(30, 41, 59, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 6px 14px;
  font-family: var(--font-primary);
  font-size: 0.88rem;
  font-weight: 700;
  color: #94a3b8;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}

.cat-tab-btn:hover {
  background: rgba(51, 65, 85, 0.9);
  color: #ffffff;
}

.cat-tab-btn.active {
  background: #3b82f6;
  color: #ffffff;
  border-color: #60a5fa;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.4);
}

.all-levels-scroll-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding-right: 6px;
}

.category-section-block {
  background: rgba(30, 41, 59, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.category-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
}

.category-section-title {
  font-family: var(--font-primary);
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.category-completion-badge {
  font-family: var(--font-primary);
  font-size: 0.82rem;
  font-weight: 800;
  color: #059669;
  background: rgba(16, 185, 129, 0.18);
  padding: 2px 10px;
  border-radius: 10px;
  border: 1.5px solid #10b981;
}

.category-completion-badge.incomplete {
  color: #60a5fa;
  background: rgba(59, 130, 246, 0.18);
  border-color: #3b82f6;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
}

@media (max-width: 1200px) {
  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 600px) {
  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
}

@media (max-width: 480px) {
  .levels-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
  }
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #ffffff;
  border: 2.5px solid #cbd5e1;
  border-radius: 14px;
  padding: 8px 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 70px;
}

.level-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  border-color: #3b82f6;
}

.level-btn.active {
  background: #eff6ff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.level-btn.completed {
  background: #ecfdf5;
  border-color: #10b981;
}

.level-btn.completed .level-btn-num {
  color: #047857;
}

.level-btn.completed .level-status-tag {
  color: #059669;
  font-size: 0.72rem;
  font-weight: 800;
}

.level-btn.locked {
  background: #f1f5f9;
  border-color: #e2e8f0;
  opacity: 0.55;
  cursor: not-allowed;
}

.level-btn.locked .level-btn-num {
  color: #94a3b8;
}

.level-btn.unlocked {
  background: #eff6ff;
  border-color: #60a5fa;
}

.level-btn.unlocked .level-status-tag {
  color: #2563eb;
  font-size: 0.65rem;
  font-weight: 800;
}

.level-btn-lock-icon {
  font-size: 1.15rem;
}

.level-btn-stars {
  font-size: 0.68rem;
  color: #f59e0b;
  letter-spacing: -1px;
  line-height: 1;
}

.level-tier-tag {
  font-family: var(--font-primary);
  font-size: 0.6rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 6px;
  letter-spacing: 0.3px;
  line-height: 1.1;
}

.level-tier-tag.tier-easy {
  color: #047857;
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.level-tier-tag.tier-medium {
  color: #1d4ed8;
  background: rgba(59, 130, 246, 0.16);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.level-tier-tag.tier-hard {
  color: #b45309;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.level-tier-tag.tier-expert {
  color: #7e22ce;
  background: rgba(168, 85, 247, 0.18);
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.level-select-title-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.levels-grid-container {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 8px 2px;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: #f8fafc;
  border: 2.5px solid #cbd5e1;
  border-radius: 14px;
  padding: 10px 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 72px;
}

.level-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  border-color: #3b82f6;
}

.level-btn.active {
  background: #eff6ff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.level-btn.completed {
  background: #ecfdf5;
  border-color: #10b981;
}

.level-btn.locked {
  background: #f1f5f9;
  border-color: #e2e8f0;
  opacity: 0.55;
  cursor: not-allowed;
}

.level-btn-num {
  font-family: var(--font-primary);
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

.level-btn.locked .level-btn-num {
  color: #94a3b8;
}

.level-btn-stars {
  font-size: 0.68rem;
  color: #f59e0b;
  letter-spacing: -1px;
}

.level-btn-lock-icon {
  font-size: 1.1rem;
}

/* Level Complete Modal */
.level-complete-card {
  max-width: 660px;
  width: 92%;
  padding: 28px;
}

.complete-stars-container {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 6px 0;
}

.complete-stars-container .star-item {
  font-size: 2.8rem;
  opacity: 0.25;
  transform: scale(0.8);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.complete-stars-container .star-item.active {
  opacity: 1;
  transform: scale(1.1);
  filter: drop-shadow(0 4px 10px rgba(234, 179, 8, 0.6));
  animation: starPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes starPop {
  0% { transform: scale(0.2) rotate(-40deg); }
  70% { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1.1) rotate(0deg); }
}

.complete-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Category Mastered Celebration Modal */
.category-complete-card {
  max-width: 660px;
  width: 92%;
  padding: 28px;
}

.trophy-badge {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 2px solid #f59e0b;
  border-radius: 16px;
  padding: 12px 18px;
  text-align: left;
}

.trophy-icon {
  font-size: 2.8rem;
}

.trophy-text strong {
  font-family: var(--font-primary);
  font-size: 1.15rem;
  color: #92400e;
  display: block;
}

.trophy-text p {
  font-size: 0.85rem;
  color: #78350f;
}

/* Settings Modal */
.settings-card {
  max-width: 680px;
  width: 92%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 28px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 10px 14px;
  gap: 10px;
}

.setting-item.column {
  flex-direction: column;
  align-items: stretch;
}

.setting-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.setting-labels strong {
  font-family: var(--font-primary);
  font-size: 0.95rem;
  color: #0f172a;
  display: block;
}

.setting-labels p {
  font-size: 0.72rem;
  color: #64748b;
}

/* Switch UI */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: 0.3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: #10b981;
}

input:checked + .slider:before {
  transform: translateX(20px);
}

.slider.round {
  border-radius: 26px;
}

.slider.round:before {
  border-radius: 50%;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 4px;
}

.styled-slider {
  width: 100%;
  accent-color: #3b82f6;
  cursor: pointer;
  height: 6px;
}

.voice-dropdown {
  width: 100%;
  padding: 8px 10px;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: #1e293b;
  background: #ffffff;
  cursor: pointer;
}

.test-voice-pill {
  background: #3b82f6;
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 3px 10px;
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.test-voice-pill:hover {
  background: #2563eb;
}

.danger-btn {
  background: #fee2e2;
  color: #dc2626;
  border: 2px solid #fca5a5;
  border-radius: 10px;
  padding: 6px 12px;
  font-family: var(--font-primary);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.danger-btn:hover {
  background: #fecaca;
}

.start-screen-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Specific Modal Card Sizes for Full-Screen Experience */
.modal-card.instruction-card {
  max-width: 760px;
  width: 92%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 28px;
}

.modal-card.pause-card {
  max-width: 520px;
  width: 90%;
  padding: 32px;
}

.modal-card.gameover-card {
  max-width: 660px;
  width: 92%;
  padding: 28px;
}

/* Step 12: How To Play List */
.instructions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  max-height: none;
  overflow-y: visible;
  padding-right: 4px;
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  color: #334155;
}

.step-badge {
  background: #3b82f6;
  color: #ffffff;
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Pause Modal */
.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* Action Buttons */
.primary-action-btn {
  background: linear-gradient(180deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  border: 3.5px solid #047857;
  border-radius: 18px;
  padding: 12px 18px;
  font-family: var(--font-primary);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 5px 0 #065f46, 0 8px 16px rgba(16, 185, 129, 0.4);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
}

.primary-action-btn:hover {
  filter: brightness(1.06);
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #065f46, 0 10px 20px rgba(16, 185, 129, 0.45);
}

.primary-action-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #065f46;
}

.secondary-action-btn {
  background: #f1f5f9;
  color: #475569;
  border: 2px solid #cbd5e1;
  border-radius: 16px;
  padding: 9px 16px;
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.secondary-action-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

/* Game Over Stats */
.gameover-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.gameover-icon { font-size: 2.8rem; }
#gameover-title { font-family: var(--font-primary); font-size: 1.7rem; font-weight: 700; color: #dc2626; }
#gameover-subtitle { font-size: 0.85rem; color: #64748b; }

.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.result-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 6px 10px;
  text-align: left;
}

.result-box.highlight-box {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.res-icon { font-size: 1.3rem; }
.res-data { display: flex; flex-direction: column; }
.res-num { font-family: var(--font-primary); font-size: 1.15rem; font-weight: 700; color: #0f172a; line-height: 1.1; }
.res-label { font-size: 0.65rem; font-weight: 700; color: #64748b; text-transform: uppercase; }

.record-banner {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 800;
  padding: 7px 12px;
  border-radius: 12px;
  border: 2px solid #fde68a;
  animation: pulseCorrect 0.5s infinite alternate;
}

.gameover-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

/* ==========================================================================
   7. Responsive Adaptations (Step 17)
   ========================================================================== */
@media (max-width: 480px) {
  :root {
    --block-width: 190px;
    --block-height: 40px;
  }

  #stats-bar {
    height: 58px;
    padding: 4px 6px;
    gap: 4px;
  }

  .stat-badge {
    padding: 2px 6px;
    gap: 3px;
  }

  .stat-icon { font-size: 0.9rem; }
  .stat-label { font-size: 0.5rem; }
  .stat-value { font-size: 0.88rem; }

  .instability-box {
    min-width: 76px;
    padding: 2px 6px;
  }
  .instability-label { font-size: 0.48rem; }
  .instability-status-text { font-size: 0.52rem; }
  .instability-pip { height: 4px; }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.88rem;
  }

  .equation-display {
    font-size: 1.7rem;
  }

  .ans-btn {
    font-size: 1.35rem;
    padding: 8px;
  }

  .modal-card {
    padding: 16px 14px;
    gap: 10px;
  }

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

  .results-grid {
    grid-template-columns: 1fr;
  }

  .primary-actions-row {
    grid-template-columns: 1fr;
  }

  .category-summary-overview {
    grid-template-columns: 1fr;
  }

  .start-sub-actions {
    grid-template-columns: 1fr;
  }

  .levels-grid-container {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .level-btn {
    min-height: 58px;
    padding: 6px 2px;
  }

  .level-btn-num {
    font-size: 1rem;
  }

  .cat-card-title {
    font-size: 0.95rem;
  }

  .cat-card-desc {
    font-size: 0.7rem;
  }

  .speech-indicator {
    top: 64px;
    right: 8px;
    padding: 4px 8px;
  }

  .tower-height-display {
    top: 64px;
    left: 8px;
    padding: 4px 10px;
    font-size: 0.85rem;
  }
}
