/* Kid-Centric, Bubbly & Cohesive Stylesheet (Designed for Ages 5-7) */

:root {
  --color-primary: #4D96FF;     /* Sky Blue */
  --color-success: #6BCB77;     /* Happy Green */
  --color-danger: #FF6B6B;      /* Cherry Red */
  --color-warning: #FFD93D;     /* Sunshine Yellow */
  --color-orange: #FF9F29;      /* Playful Orange */
  --bg-gradient: linear-gradient(135deg, #F0F9FF 0%, #E0F2FE 100%);
  --border-radius-bubbly: 24px;
  --border-radius-sm: 12px;
  --box-shadow-3d: 0 8px 0px rgba(0, 0, 0, 0.12), 0 12px 20px rgba(0,0,0,0.08);
  --box-shadow-3d-active: 0 2px 0px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0,0,0,0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: 'Fredoka', 'Quicksand', 'Comic Sans MS', 'Segoe UI', system-ui, sans-serif;
  background-color: #BAE6FD;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(255, 255, 255, 0.45) 0%, rgba(255, 255, 255, 0.45) 4px, transparent 4px),
    radial-gradient(circle at 55% 75%, rgba(255, 255, 255, 0.45) 0%, rgba(255, 255, 255, 0.45) 4px, transparent 4px),
    radial-gradient(circle at 35% 45%, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.3) 7px, transparent 7px),
    radial-gradient(circle at 75% 25%, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.3) 7px, transparent 7px),
    linear-gradient(135deg, #E0F2FE 0%, #90CDF4 100%);
  background-size: 80px 80px, 80px 80px, 120px 120px, 120px 120px, 100% 100%;
  color: #2D3748;
  touch-action: manipulation;
}

/* Base Screens */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 3vh 5vw;
  position: absolute;
  top: 0; left: 0;
  animation: screenEnter 0.28s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.screen-exit {
  animation: screenExit 0.15s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
}

@keyframes screenEnter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes screenExit {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.99);
  }
}

/* Screen Transition Curtain Overlay */
.transition-curtain {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle, #4D96FF 0%, #2F6ED6 100%);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(100%); /* Starts off-screen at the bottom */
  pointer-events: all; /* Blocks clicks during transition */
  will-change: transform;
}

.transition-curtain.slide-in {
  animation: curtainSlideIn 0.35s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.transition-curtain.slide-out {
  animation: curtainSlideOut 0.35s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes curtainSlideIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes curtainSlideOut {
  from { transform: translateY(0); }
  to { transform: translateY(-100%); }
}

.transition-star {
  font-size: 5.5rem;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.15));
  animation: starRotate 0.7s infinite ease-in-out;
  transform-origin: center;
}

@keyframes starRotate {
  0% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.35) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

/* Typography Bubbly */
h1 {
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--color-primary);
  text-shadow: 3px 3px 0px #2F6ED6, 0 10px 20px rgba(0,0,0,0.1);
  text-align: center;
  letter-spacing: 1px;
}

h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: #4A5568;
  text-align: center;
}

h3 {
  font-size: 1.1rem;
  font-weight: 900;
  color: #2D3748;
}

/* Bubbly Buttons - Thick physical look with tactile elastic transitions */
button, .path-btn, .level-btn, .start-game-btn, .diff-btn, .player-btn, .voice-btn {
  font-family: inherit;
  border: none;
  cursor: pointer;
  outline: none;
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease, filter 0.2s ease;
}

/* Active Pressing squishy tactile bubble press effect */
button:active, .path-btn:active, .level-btn:active, .start-game-btn:active {
  transform: translateY(6px) scale(0.95, 0.9) !important;
}

/* Path buttons on Welcome Screen */
#welcome-screen {
  background: radial-gradient(circle, #FFFDE7 0%, #DFF9FB 100%);
  justify-content: center;
}

.welcome-box {
  background: white;
  padding: 40px 30px;
  border-radius: var(--border-radius-bubbly);
  box-shadow: 0 15px 35px rgba(47, 110, 214, 0.1);
  text-align: center;
  max-width: 460px;
  width: 90%;
  border: 4px solid #BEE3F8;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.menu-paths {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 30px;
}

/* Main buttons on first screen */
#btn-path-levels {
  background: var(--color-orange);
  border-bottom: 6px solid #C67210;
  color: white;
  font-size: 1.3rem;
  font-weight: 900;
  padding: 16px 20px;
  border-radius: var(--border-radius-bubbly);
  box-shadow: var(--box-shadow-3d);
}

#btn-path-levels:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 0px #C67210, 0 14px 25px rgba(198, 114, 16, 0.25);
}

#btn-path-levels:active {
  border-bottom: 2px solid #C67210;
  box-shadow: var(--box-shadow-3d-active);
}

#btn-path-custom {
  background: var(--color-primary);
  border-bottom: 6px solid #1A5FB4;
  color: white;
  font-size: 1.3rem;
  font-weight: 900;
  padding: 16px 20px;
  border-radius: var(--border-radius-bubbly);
  box-shadow: var(--box-shadow-3d);
}

#btn-path-custom:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 0px #1A5FB4, 0 14px 25px rgba(26, 95, 180, 0.25);
}

#btn-path-custom:active {
  border-bottom: 2px solid #1A5FB4;
  box-shadow: var(--box-shadow-3d-active);
}

/* Shared Game Header */
.game-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 650px;
  align-items: center;
  background: white;
  padding: 10px 20px;
  border-radius: 20px;
  box-shadow: 0 6px 15px rgba(0,0,0,0.04);
  border: 3px solid #E2E8F0;
}

/* Bubbly Back/Home buttons */
.back-to-menu-btn, #btn-exit-game, .game-header button {
  background: var(--color-danger);
  border-bottom: 4px solid #C53030;
  color: white;
  font-weight: 900;
  padding: 8px 16px;
  font-size: 0.95rem;
  border-radius: 14px;
  box-shadow: 0 4px 0px #C53030;
}

.back-to-menu-btn:active, #btn-exit-game:active {
  border-bottom: 1px solid #C53030;
  transform: translateY(3px) !important;
}

/* Levels Screen Layout */
.quick-voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  padding: 8px 16px;
  border-radius: 30px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.05);
  margin-top: 1.5vh;
  border: 3px solid #EDF2F7;
}

.quick-voice-bar span {
  font-weight: 900;
  font-size: 0.9rem;
  color: #4A5568;
}

.voice-btn-quick {
  padding: 6px 12px !important;
  font-size: 0.85rem !important;
  border-radius: 14px !important;
  border: 2px solid #E2E8F0 !important;
  background: white !important;
  color: #4A5568 !important;
  font-weight: bold;
}

.voice-btn-quick.active {
  background: var(--color-primary) !important;
  color: white !important;
  border-color: #2F6ED6 !important;
  box-shadow: 0 3px 0px #1A5FB4;
}

.section-desc {
  font-size: 1rem;
  font-weight: 700;
  color: #718096;
  margin-top: 1vh;
}

/* Levels Winding Path Board Game Style */
.levels-path-container {
  width: 100%;
  max-width: 520px;
  flex-grow: 1;
  overflow-y: auto; /* Allow scrolling the board game path */
  padding: 10px 20px 40px 20px;
  margin-top: 1.5vh;
  border-radius: var(--border-radius-bubbly);
  background: rgba(255, 255, 255, 0.4);
  border: 3px solid rgba(255, 255, 255, 0.6);
  position: relative;
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

.levels-path-container::-webkit-scrollbar {
  display: none; /* Hide Chrome/Safari scrollbar */
}

.levels-path {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column; /* Standard non-reversed column to avoid browser scroll axis bugs */
  align-items: center; /* Center-align all buttons perfectly down the straight line */
  gap: 30px; /* Space out the levels */
  padding: 20px 0;
}

/* Config/Reset button */
.config-btn {
  background: var(--color-orange) !important;
  border-bottom: 4px solid #D97706 !important;
  color: white !important;
  font-weight: 900;
  padding: 8px 16px;
  font-size: 0.95rem;
  border-radius: 14px;
  box-shadow: 0 4px 0px #D97706;
}

.config-btn:active {
  border-bottom: 1px solid #D97706 !important;
  transform: translateY(3px) !important;
}

/* Surprise Mix Button style */
.surprise-mix-btn {
  background: var(--color-orange) !important;
  border-bottom: 4px solid #D97706 !important;
  color: white !important;
  font-weight: 900;
  padding: 12px 16px;
  font-size: 0.92rem;
  border-radius: 16px;
  box-shadow: 0 4px 0px #D97706;
  width: 100%;
  text-align: center;
  transition: all 0.1s;
  border: none;
  cursor: pointer;
  margin-bottom: 12px;
}

.surprise-mix-btn:active {
  border-bottom: 1px solid #D97706 !important;
  transform: translateY(3px) !important;
}

/* Winding smooth dashed path line behind the buttons using custom SVG sine wave background */
.levels-path::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0; right: 0;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 240"><path d="M50 0 C 15 60, 15 60, 50 120 C 85 180, 85 180, 50 240" fill="none" stroke="%23F6AD55" stroke-width="5" stroke-dasharray="10, 8" stroke-linecap="round" opacity="0.85"/></svg>');
  background-size: 100% 240px;
  background-repeat: repeat-y;
  z-index: 1;
}

/* Circular stepping stone level buttons */
.level-btn {
  position: relative;
  width: 90px;
  height: 90px;
  border-radius: 50% !important; /* Forces perfect circle shape */
  background: white;
  border: 4px solid #E2E8F0;
  border-bottom: 8px solid #CBD5E0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 12px rgba(0,0,0,0.06);
  transition: all 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 2; /* Sits above the dashed line */
  aspect-ratio: 1 / 1;
}

/* Winding zig-zag displacement for stepping stones (aligns perfectly with SVG sine wave peaks) */
.level-btn:nth-child(odd) {
  margin-right: 70px;
}

.level-btn:nth-child(even) {
  margin-left: 70px;
}

.level-btn .emoji-icon {
  font-size: 2.2rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Number badge floating at the bottom right of the stepping stone */
.level-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 28px;
  height: 28px;
  background: var(--color-warning);
  border: 2.5px solid white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 900;
  color: #2D3748;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.level-btn:not(.locked):hover {
  transform: scale(1.12) !important;
  border-color: var(--color-primary) !important;
  box-shadow: 0 10px 18px rgba(66, 153, 225, 0.25) !important;
}

/* Locked / Pending Levels (Grayscaled, semi-transparent, and scaled down) */
.level-btn.locked {
  background: #E2E8F0 !important;
  border-color: #CBD5E0 !important;
  border-bottom: 6px solid #94A3B8 !important;
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  transform: scale(0.92) !important;
  filter: grayscale(80%);
  box-shadow: none !important;
}

.level-btn.locked .emoji-icon {
  opacity: 0.35 !important;
}

.level-btn.locked .level-badge {
  background: #64748B !important;
  color: #CBD5E0 !important;
}

/* Completed Levels (Awarded desaturated, soft sage green medal theme) */
.level-btn.completed-level {
  background: radial-gradient(circle, #F4FBF7 0%, #E2F2E9 100%) !important;
  border-color: #A5D6A7 !important;
  border-bottom: 8px solid #81C784 !important;
  box-shadow: 0 4px 10px rgba(129, 199, 132, 0.14) !important;
}

.level-btn.completed-level .level-badge {
  background: #81C784 !important;
  color: white !important;
}

/* Completed Special Levels (Muted green star medal style) */
.level-btn.completed-level.special-level {
  background: radial-gradient(circle, #F0FAF3 0%, #D1ECD6 100%) !important;
  border-color: #81C784 !important;
  border-bottom: 8px solid #4CAF50 !important;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.14) !important;
}

.level-btn.completed-level.special-level .level-badge {
  background: #4CAF50 !important;
  color: white !important;
}

/* Muted Completed Emojis (Slightly transparent and desaturated, spring-lights up on hover) */
.level-btn.completed-level .emoji-icon {
  opacity: 0.65 !important;
  filter: grayscale(25%);
  transition: opacity 0.25s cubic-bezier(0.25, 0.8, 0.25, 1), filter 0.25s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.level-btn.completed-level:hover .emoji-icon {
  opacity: 0.95 !important;
  filter: none;
  transform: scale(1.15) !important;
}

.level-btn.completed-level:hover {
  transform: scale(1.12) !important;
  border-color: #81C784 !important;
  box-shadow: 0 10px 20px rgba(129, 199, 132, 0.28) !important;
}

/* Active Level (The player's current progression target, pulsing glowing orange theme) */
.level-btn.active-level {
  background: radial-gradient(circle, #FFF7ED 0%, #FFEDD5 100%) !important;
  border-color: var(--color-orange) !important;
  border-bottom: 8px solid #DD6B20 !important;
  box-shadow: 0 0 25px rgba(255, 159, 41, 0.8) !important;
  animation: activePulse 1.8s infinite ease-in-out;
  transform: scale(1.06);
}

.level-btn.active-level .level-badge {
  background: var(--color-orange) !important;
  color: white !important;
}

@keyframes activePulse {
  0% { transform: scale(1.04, 1.04) rotate(0deg); }
  50% { transform: scale(1.12, 1.08) rotate(3deg); box-shadow: 0 0 35px rgba(255, 159, 41, 0.95) !important; }
  100% { transform: scale(1.04, 1.04) rotate(0deg); }
}

/* Shiny Golden Special Level Buttons (Levels 5, 10, 15, 20, 25, 30) */
.level-btn.special-level {
  background: radial-gradient(circle, #FFFDF5 0%, #FEF3C7 100%) !important;
  border-color: #F59E0B !important;
  border-bottom: 8px solid #D97706 !important;
  box-shadow: 0 6px 15px rgba(217, 119, 6, 0.15);
}

.level-btn.special-level:not(.locked):hover {
  transform: scale(1.10) !important;
  border-color: #D97706 !important;
  box-shadow: 0 10px 20px rgba(217, 119, 6, 0.3) !important;
}

.level-btn.special-level.active-level {
  border-color: #EF4444 !important;
  border-bottom: 8px solid #B91C1C !important;
  animation: activePulse 2s infinite ease-in-out;
  box-shadow: 0 0 25px rgba(239, 68, 68, 0.6) !important;
}

.level-btn.special-level .level-badge {
  background: #EF4444 !important;
  color: white !important;
}

/* Floating Scroll Target Button */
.floating-target-btn {
  position: absolute;
  bottom: 5vh;
  right: 8vw;
  width: 70px;
  height: 70px;
  border-radius: 50% !important;
  background: var(--color-orange) !important;
  border: 4px solid white !important;
  color: white !important;
  font-size: 2.25rem !important;
  font-weight: 900 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  box-shadow: 0 8px 18px rgba(217, 119, 6, 0.45), inset 0 -4px 0 rgba(0,0,0,0.15) !important;
  animation: floatBounce 2s infinite ease-in-out;
  transition: opacity 0.25s ease, transform 0.2s;
  padding: 0 !important;
}

@media (min-width: 550px) {
  .floating-target-btn {
    right: calc(50% - 240px) !important; /* Docks precisely to the right edge of the centered levels box on desktop */
  }
}

.floating-target-btn:hover {
  transform: scale(1.1) !important;
  background: #D97706 !important;
}

.floating-target-btn:active {
  transform: translateY(2px) scale(0.95) !important;
  box-shadow: 0 2px 4px rgba(217, 119, 6, 0.2) !important;
}

@keyframes floatBounce {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

/* Floating Custom Game Button */
.floating-custom-btn {
  position: absolute;
  bottom: 5vh;
  left: 8vw;
  width: 70px;
  height: 70px;
  border-radius: 50% !important;
  background: white !important;
  border: 4px solid var(--color-primary) !important;
  font-size: 2.25rem !important;
  font-weight: 900 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  box-shadow: 0 8px 18px rgba(77, 150, 255, 0.45), inset 0 -4px 0 rgba(77, 150, 255, 0.2) !important;
  animation: floatBounceCustom 2s infinite ease-in-out;
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.2s, box-shadow 0.2s;
  padding: 0 !important;
}

@media (min-width: 550px) {
  .floating-custom-btn {
    left: calc(50% - 240px) !important; /* Docks precisely to the left edge of the centered levels box on desktop */
  }
}

.floating-custom-btn:hover {
  transform: scale(1.1) !important;
  background: #EBF8FF !important; /* Very light pastel blue, keeping maximum contrast */
  border-color: #2F6ED6 !important; /* Deeper blue border on hover */
}

.floating-custom-btn:active {
  transform: translateY(2px) scale(0.95) !important;
  box-shadow: 0 2px 4px rgba(77, 150, 255, 0.2) !important;
}

@keyframes floatBounceCustom {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

/* Custom Config Screen */
.custom-layout-scroll {
  width: 100%;
  max-width: 620px;
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 8px;
  margin-top: 1.5vh;
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

.custom-layout-scroll::-webkit-scrollbar {
  display: none; /* Hide Chrome/Safari scrollbar */
}

.config-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.config-section {
  background: white;
  padding: 20px;
  border-radius: var(--border-radius-bubbly);
  border: 3px solid #EDF2F7;
  box-shadow: 0 4px 10px rgba(0,0,0,0.02);
}

.config-section h3 {
  font-size: 0.95rem;
  font-weight: 900;
  color: #4A5568;
  margin-bottom: 12px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.buttons-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.buttons-row button {
  flex-grow: 1;
  padding: 12px 14px;
  font-size: 0.9rem;
  border-radius: 16px;
  font-weight: 900;
  background: #F7FAFC;
  border: 3px solid #E2E8F0;
  border-bottom: 6px solid #CBD5E0;
  color: #4A5568;
  box-shadow: 0 4px 0px #CBD5E0;
}

.buttons-row button:active {
  border-bottom: 2px solid #CBD5E0;
  transform: translateY(4px);
}

.buttons-row button.active {
  background: var(--color-primary);
  color: white;
  border-color: #2F6ED6;
  border-bottom: 6px solid #1A5FB4;
  box-shadow: 0 4px 0px #1A5FB4;
}

.buttons-row button.active:active {
  border-bottom: 2px solid #1A5FB4;
}

/* Name prompt input styling */
.name-input-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.name-input-group span {
  font-weight: 900;
  font-size: 0.95rem;
  color: var(--color-primary);
}

.name-input-group input {
  flex-grow: 1;
  padding: 12px 16px;
  border: 3px solid #E2E8F0;
  border-radius: 16px;
  font-size: 0.95rem;
  font-weight: 700;
  outline: none;
  text-transform: uppercase;
  background: #F7FAFC;
}

.name-input-group input:focus {
  border-color: var(--color-primary);
  background: white;
}

/* Category Selection Layout */
.categories-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.category-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #F7FAFC;
  padding: 12px;
  border-radius: 16px;
  border: 3px solid #EDF2F7;
  border-bottom: 5px solid #E2E8F0;
  cursor: pointer;
  transition: all 0.15s;
}

.category-item:not(.disabled):hover {
  transform: scale(1.02);
  border-color: #BEE3F8;
}

.category-item.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-bottom: 3px solid #EDF2F7;
}

.category-item input {
  width: 22px;
  height: 22px;
  accent-color: var(--color-primary);
}

.category-item span {
  font-size: 0.88rem;
  font-weight: 800;
  color: #4A5568;
}

/* Play/Start Custom Game Button */
.start-game-btn {
  background: var(--color-success) !important;
  color: white !important;
  font-size: 1.3rem !important;
  font-weight: 900;
  padding: 16px 20px !important;
  border-radius: var(--border-radius-bubbly) !important;
  width: 100%;
  max-width: 600px;
  border-bottom: 6px solid #38A169 !important;
  box-shadow: var(--box-shadow-3d);
}

.start-game-btn:disabled {
  background: #A0AEC0 !important;
  border-bottom: 4px solid #718096 !important;
  cursor: not-allowed;
  box-shadow: none;
}

.start-game-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 0px #38A169, 0 14px 25px rgba(56, 161, 105, 0.25);
}

.start-game-btn:not(:disabled):active {
  border-bottom: 2px solid #38A169 !important;
  box-shadow: var(--box-shadow-3d-active);
}

/* Screen 4: Active Game Board Screen */
#memory-players-stats {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 650px;
  justify-content: center;
  margin-bottom: 1.5vh;
}

.player-stat {
  padding: 12px 18px;
  background: white;
  border-radius: 18px;
  font-weight: 900;
  font-size: 1rem;
  border: 3px solid #E2E8F0;
  border-bottom: 6px solid #CBD5E0;
  opacity: 0.5;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Color Coding for Players */
.player-stat[data-player="0"].active-turn {
  background: #EBF8FF;
  border-color: #4D96FF;
  border-bottom-color: #1A5FB4;
  color: #2B6CB0;
  opacity: 1;
  transform: scale(1.05);
  box-shadow: var(--box-shadow-3d-active);
}
.player-stat[data-player="1"].active-turn {
  background: #E6FFFA;
  border-color: #6BCB77;
  border-bottom-color: #2F855A;
  color: #234E52;
  opacity: 1;
  transform: scale(1.05);
  box-shadow: var(--box-shadow-3d-active);
}
.player-stat[data-player="2"].active-turn {
  background: #FFF5F5;
  border-color: #FF6B6B;
  border-bottom-color: #9B2C2C;
  color: #9B2C2C;
  opacity: 1;
  transform: scale(1.05);
  box-shadow: var(--box-shadow-3d-active);
}
.player-stat[data-player="3"].active-turn {
  background: #FFFFF0;
  border-color: #FFD93D;
  border-bottom-color: #B7791F;
  color: #744210;
  opacity: 1;
  transform: scale(1.05);
  box-shadow: var(--box-shadow-3d-active);
}

/* Adaptive Cards Grid */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(8px, 1.8vh, 18px);
  width: 100%;
  max-width: 630px;
  flex-grow: 1;
  align-content: center; /* Centers cards vertically in the available screen space */
  justify-content: center;
}

/* Extreme 6-column Grid Layout (24 Cards) */
.memory-grid.grid-extremo {
  grid-template-columns: repeat(6, 1fr);
  max-width: 720px; /* Wider max-width for 6 columns */
}

/* Gigante 8-column Grid Layout (32 Cards) */
.memory-grid.grid-gigante {
  grid-template-columns: repeat(8, 1fr);
  max-width: 880px; /* Wider max-width for 8 columns */
}

/* Interactive 3D Cards */
.memory-card {
  aspect-ratio: 1 / 1.15;
  perspective: 1000px;
  cursor: pointer;
  width: 100%;
  container-type: inline-size; /* Enables container-relative units (cqw) for inner elements */
}

.memory-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.48s cubic-bezier(0.25, 0.8, 0.25, 1.15), box-shadow 0.2s ease;
  transform-style: preserve-3d;
}

/* Snappy, playful float-and-tilt hover effect on unflipped active cards */
.memory-card:not(.flipped):not(.matched):hover .memory-card-inner {
  transform: translateY(-6px) rotate(2.5deg) scale(1.035);
  box-shadow: 0 12px 24px rgba(0,0,0,0.15) !important;
}

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

.memory-card-front, .memory-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: clamp(10px, 18cqw, 24px);
  border: clamp(2.5px, 4cqw, 5px) solid #718096;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6%;
  box-shadow: var(--box-shadow-3d);
}

/* Front Face: Cheerful Question Mark / Star pattern */
.memory-card-front {
  background: radial-gradient(circle, #63B3ED 0%, #4D96FF 100%);
  border-color: #2F6ED6;
  color: white;
  font-size: clamp(20px, 40cqw, 60px);
  font-weight: 900;
  text-shadow: 2px 2px 0 #1A5FB4;
}

/* Back Face: Playful card with borders */
.memory-card-back {
  background-color: white;
  transform: rotateY(180deg);
}

.back-en { border-color: #E53E3E !important; }
.back-es { border-color: #38A169 !important; }
.back-fr { border-color: #3182CE !important; }
.back-zh { border-color: #D69E2E !important; }
.back-bn { border-color: #805AD5 !important; }

.mem-emoji {
  font-size: clamp(18px, 36cqw, 52px);
  margin-bottom: 4cqw;
  filter: drop-shadow(0px 4px 6px rgba(0,0,0,0.1));
  display: flex;
  align-items: center;
  justify-content: center;
}

.mem-emoji svg {
  width: 1.1em;
  height: 1.1em;
  display: inline-block;
  vertical-align: middle;
}

.mem-text {
  font-size: clamp(9px, 14cqw, 18px);
  font-weight: 900;
  line-height: 1.1;
  word-break: break-word;
  color: #2D3748;
}

.mem-lang-badge {
  position: absolute;
  bottom: 4cqw;
  right: 4cqw;
  font-size: clamp(8px, 10cqw, 12px);
  font-weight: 900;
  background-color: #EDF2F7;
  padding: 1px 4cqw;
  border-radius: 4px;
  color: #4A5568;
}

.back-en .mem-lang-badge {
  background-color: #FFF5F5;
  color: #E53E3E;
}

.back-es .mem-lang-badge {
  background-color: #E6FFFA;
  color: #319795;
}

.back-fr .mem-lang-badge {
  background-color: #EBF8FF;
  color: #2B6CB0;
}

.back-zh .mem-lang-badge {
  background-color: #FEFCBF;
  color: #B7791F;
}

.back-bn .mem-lang-badge {
  background-color: #FAF5FF;
  color: #6B46C1;
}

/* Matching and success overlays */
.memory-card.matched .memory-card-front,
.memory-card.matched .memory-card-back {
  border-color: var(--color-success) !important;
  background: #F0FFF4;
  box-shadow: 0 4px 0px rgba(0,0,0,0.05);
  opacity: 0.85;
}

.memory-card.matched {
  animation: bounceSuccess 0.5s ease;
  pointer-events: none;
}

/* Scoreboard stats configuration */
#memory-players-stats {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 650px;
  justify-content: center;
  margin-bottom: 1.5vh;
  flex-wrap: wrap; /* Allows wrapping on narrow screens */
}

/* Turn Banner Overlay */
#turn-banner {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(45, 55, 72, 0.92);
  color: white;
  font-size: 7vw;
  font-weight: 900;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-shadow: 3px 3px 0px rgba(0,0,0,0.5);
  animation: bannerPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Victory Overlay */
#victory-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  z-index: 1000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#victory-modal .welcome-box {
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  0% { transform: scale(0.65) translateY(25px); opacity: 0; }
  75% { transform: scale(1.05) translateY(-4px); opacity: 0.95; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes bannerPop {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.08); opacity: 0.95; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes bounceSuccess {
  0% { transform: scale(1); }
  25% { transform: scale(1.2) rotate(-8deg); filter: brightness(1.08); }
  50% { transform: scale(0.92) rotate(6deg); }
  75% { transform: scale(1.08) rotate(-3deg); }
  100% { transform: scale(1) rotate(0); }
}

/* Extreme Mobile height resizing */
@media (max-height: 520px) {
  .memory-grid { gap: 1.2vh; max-width: 440px; }
  h1 { font-size: 2.2rem; }
  .welcome-box { padding: 25px 20px; }
  
  /* Scale down the 24 cards on short devices to guarantee zero-scroll */
  .memory-grid.grid-extremo {
    gap: 0.8vh;
    max-width: 580px;
  }
}

/* Mobile Screens optimization */
@media (max-width: 600px) {
  .player-stat {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 12px;
    border-width: 2px;
    border-bottom-width: 4px;
    flex: 1 1 calc(50% - 8px);
    max-width: calc(50% - 4px);
    justify-content: center;
  }
}

/* Medium & Narrow viewports sizing (iPhones, Android screens down to 320px) */
@media (max-width: 480px) {
  h1 { font-size: 2rem; }
  
  .screen {
    padding: 2vh 3vw !important;
  }
  
  /* Force 4 columns on narrow mobile for extreme/gigante difficulties to increase card sizing and keep symmetries */
  .memory-grid.grid-extremo, .memory-grid.grid-gigante {
    grid-template-columns: repeat(4, 1fr) !important;
    max-width: 630px !important;
  }
  
  /* Compact 2-column categories list to prevent massive vertical scrolls */
  .categories-list {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .category-item {
    padding: 8px !important;
    gap: 6px !important;
    border-radius: 12px !important;
    border-bottom-width: 3px !important;
  }
  .category-item span {
    font-size: 0.75rem !important;
  }
  .category-item input {
    width: 16px !important;
    height: 16px !important;
  }

  /* Compact Welcome Screen */
  .welcome-box {
    padding: 24px 16px !important;
    border-radius: 20px !important;
  }
  .menu-paths {
    gap: 12px !important;
    margin-top: 20px !important;
  }
  #btn-path-levels, #btn-path-custom {
    padding: 12px 16px !important;
    font-size: 1.1rem !important;
    border-radius: 18px !important;
  }

  /* Compact and non-wrapping Header */
  .game-header {
    padding: 8px 12px !important;
    border-radius: 14px !important;
    gap: 6px !important;
  }
  .game-header div {
    font-size: 1.1rem !important;
  }
  .back-to-menu-btn, #btn-exit-game, .game-header button {
    padding: 6px 10px !important;
    font-size: 0.8rem !important;
    border-radius: 10px !important;
  }
  .game-title {
    font-size: 0.95rem !important;
  }

  /* Clean symmetrical 2x2 grids for custom config options */
  .buttons-row {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .buttons-row button {
    padding: 8px 6px !important;
    font-size: 0.75rem !important;
    border-radius: 12px !important;
    margin: 0 !important;
    width: 100% !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    line-height: 1.2 !important;
  }
}

/* Active Game Screen height-based auto-scaling for zero-scroll on mobile */
#memory-screen {
  overflow: hidden !important; /* No scroll allowed, as per user direct instruction */
}

#memory-grid {
  padding-bottom: 0vh; /* Revert bottom padding since we don't scroll */
}

/* Dynamically scale down the card grid on devices with limited vertical space */
@media (max-height: 780px) {
  .memory-grid.grid-extremo {
    max-width: 440px !important; /* Shrunk from 720px */
    gap: 1vh !important;
  }
  .memory-grid.grid-gigante {
    max-width: 380px !important; /* Shrunk from 880px */
    gap: 0.8vh !important;
  }
}

@media (max-height: 680px) {
  .memory-grid.grid-extremo {
    max-width: 360px !important;
    gap: 0.8vh !important;
  }
  .memory-grid.grid-gigante {
    max-width: 320px !important;
    gap: 0.6vh !important;
  }
}
