/* Core Design System & Theme Customization */
:root {
  --font-primary: 'Fredoka', 'Quicksand', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Color Palette - Vibrant & Playful HSL Colors */
  --bg-sky: #E0F7FA;
  --bg-sky-gradient: linear-gradient(135deg, #E0F7FA 0%, #80DEEA 100%);
  --color-primary: #0288D1; /* Ocean Blue */
  --color-accent-yellow: #FFEB3B; /* Sun Yellow */
  --color-accent-yellow-dark: #FBC02D;
  --color-accent-pink: #FF8A80; /* Salmon Pink */
  --color-accent-pink-dark: #FF5252;
  --color-accent-purple: #B388FF; /* Playful Violet */
  --color-accent-purple-dark: #7C4DFF;
  --color-success-green: #A5D6A7; /* Pastel Mint Green */
  --color-success-green-dark: #4CAF50;
  
  /* Card Themes */
  --card-border-color: #FFFFFF;
  --chunky-shadow: 0 10px 0px rgba(2, 136, 209, 0.15);
  --card-shadow: 0 12px 24px rgba(0, 0, 0, 0.08), 0 8px 0px rgba(0, 0, 0, 0.05);
  
  --transition-bouncy: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --transition-smooth: all 0.3s ease;
}

.hidden {
  display: none !important;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-sky-gradient);
  color: #37474F;
  min-height: 100vh;
  overflow: hidden; /* Lock scroll to app-only horizontal gestures */
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Background Decorations (Clouds, Sun) */
.decorations {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.sun {
  position: absolute;
  top: 40px;
  right: 50px;
  width: 90px;
  height: 90px;
  background: radial-gradient(circle, #FFF176 30%, #FFB300 100%);
  border-radius: 50%;
  box-shadow: 0 0 40px rgba(255, 235, 59, 0.6);
  animation: pulse-sun 4s ease-in-out infinite alternate;
}

.cloud {
  position: absolute;
  background: #FFFFFF;
  border-radius: 100px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.05);
  opacity: 0.85;
}

.cloud::before, .cloud::after {
  content: '';
  position: absolute;
  background: #FFFFFF;
  border-radius: 50%;
}

.cloud-1 {
  width: 150px;
  height: 50px;
  top: 80px;
  left: 10%;
  animation: float-cloud 45s linear infinite;
}
.cloud-1::before { width: 70px; height: 70px; top: -30px; left: 20px; }
.cloud-1::after { width: 50px; height: 50px; top: -20px; left: 80px; }

.cloud-2 {
  width: 200px;
  height: 60px;
  top: 180px;
  left: 65%;
  animation: float-cloud 60s linear infinite reverse;
}
.cloud-2::before { width: 90px; height: 90px; top: -45px; left: 30px; }
.cloud-2::after { width: 70px; height: 70px; top: -30px; left: 100px; }

.cloud-3 {
  width: 120px;
  height: 40px;
  bottom: 120px;
  left: 30%;
  animation: float-cloud 35s linear infinite;
}
.cloud-3::before { width: 50px; height: 50px; top: -20px; left: 15px; }
.cloud-3::after { width: 40px; height: 40px; top: -15px; left: 55px; }

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

@keyframes pulse-sun {
  0% { transform: scale(1); filter: brightness(1); }
  100% { transform: scale(1.08); filter: brightness(1.1); }
}

/* App Container Layout */
.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%; /* Full screen width */
  height: 96vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 0; /* Remove left/right padding for edge-to-edge scroll */
  box-sizing: border-box;
}

/* Header Styles */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px max(120px, calc((100% - 1180px) / 2)); /* Dynamic gutter matching grid content limits */
  box-sizing: border-box;
  margin-bottom: 5px;
}

.logo-area {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 30px;
  border-radius: 40px;
  border: 4px solid var(--color-primary);
  box-shadow: 0 8px 0 rgba(2, 136, 209, 0.2);
  gap: 12px;
  transform: rotate(-1deg);
  animation: bounce-logo 3s ease-in-out infinite alternate;
}

.logo-text {
  font-family: 'Fredoka', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--color-primary);
  text-shadow: 2px 2px 0px rgba(0,0,0,0.05);
}

.logo-emoji {
  font-size: 2.2rem;
  animation: wiggle-emoji 2s ease-in-out infinite alternate;
}

.subtitle {
  margin-top: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #455A64;
  text-shadow: 1px 1px 0px #FFF;
}

@keyframes bounce-logo {
  0% { transform: translateY(0) rotate(-1deg); }
  100% { transform: translateY(-6px) rotate(1deg); }
}

@keyframes wiggle-emoji {
  0% { transform: scale(1) rotate(-10deg); }
  100% { transform: scale(1.1) rotate(10deg); }
}

/* Main Content Area (Slider + Nav Arrows) */
.main-content {
  position: relative;
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 0;
  height: 68vh;
}

/* Nav Arrows */
.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 70px;
  height: 70px;
  background: var(--color-accent-yellow);
  border: 4px solid #FFF;
  border-radius: 50%;
  color: #E65100;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 6px 0px #F57F17, 0 10px 20px rgba(0,0,0,0.15);
  transition: var(--transition-bouncy);
}

.nav-arrow:hover {
  background: #FFF176;
  transform: translateY(-54%) scale(1.1);
}

.nav-arrow:active {
  transform: translateY(-48%) scale(0.95);
  box-shadow: 0 2px 0px #F57F17, 0 4px 10px rgba(0,0,0,0.15);
}

.prev-btn {
  left: 20px;
}

.next-btn {
  right: 20px;
}

.nav-arrow.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: translateY(-50%) scale(0.9) !important;
  box-shadow: 0 4px 0px #BCAAA4 !important;
  background: #ECEFF1 !important;
  color: #90A4AE !important;
}

/* Horizontal Scroll Container (Swipeable Viewport) - stretched full width */
.scroll-container {
  display: flex;
  width: 100%;
  height: 100%;
  overflow-x: scroll;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none; /* Hide scrollbar Firefox */
  -ms-overflow-style: none; /* Hide scrollbar IE/Edge */
}

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

/* Page Grid System: 2 rows x 5 columns */
.page-grid {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: auto auto; /* Rows sized exactly to card content (no stretching) */
  gap: 20px;
  padding: 10px max(120px, calc((100% - 1180px) / 2)); /* Dynamic gutter matching header */
  box-sizing: border-box;
  align-content: center; /* Pack rows tightly at the vertical center */
  justify-items: center; /* Center cards in cells */
  align-items: center;
}

/* Story Card Item Styling */
.story-card {
  position: relative;
  background: #FFFFFF;
  border-radius: 24px;
  border: 4px solid var(--card-border-color);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: var(--transition-bouncy);
  aspect-ratio: 1 / 1; /* Make thumbnails perfectly square */
  width: 100%;
  max-width: 220px; /* Limit size on desktop/tablet to prevent massive cards */
  margin: 0 auto;
}

/* Give cards different cute themes based on indexing/data */
.story-card.theme-animals { --card-border-color: #AED581; --badge-color: #81C784; } /* Green */
.story-card.theme-space { --card-border-color: #81D4FA; --badge-color: #4FC3F7; }   /* Blue */
.story-card.theme-ocean { --card-border-color: #4DD0E1; --badge-color: #26C6DA; }   /* Cyan */
.story-card.theme-magic { --card-border-color: #D1C4E9; --badge-color: #B388FF; }   /* Purple */
.story-card.theme-adventure { --card-border-color: #FFCC80; --badge-color: #FFA726; } /* Orange */

.story-card:hover {
  transform: translateY(-8px) scale(1.03) rotate(1deg);
  box-shadow: 0 18px 30px rgba(0,0,0,0.12), 0 12px 0px rgba(0, 0, 0, 0.05);
}

.story-card:active {
  transform: translateY(-2px) scale(0.97);
  box-shadow: 0 6px 12px rgba(0,0,0,0.08), 0 4px 0px rgba(0, 0, 0, 0.05);
}

/* Image Inside Card */
.card-img-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.story-card:hover .card-img {
  transform: scale(1.08);
}

/* Little Play Badge overlaying image */
.play-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  background: var(--badge-color, var(--color-primary));
  border-radius: 50%;
  border: 3px solid #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  transition: var(--transition-bouncy);
  z-index: 4;
}

.story-card:hover .play-badge {
  transform: scale(1.15) rotate(15deg);
}

/* Card Title Banner */
.card-details {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border-top: 3px solid var(--card-border-color);
  z-index: 3;
}

/* Character specific styling */
.character-card .card-img {
  object-fit: contain;
  padding-bottom: 35px;
}

.character-card .card-details {
  background: transparent;
  border-top: none;
}

.card-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: #37474F;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Floating index number badge */
.card-number {
  position: absolute;
  top: 10px;
  left: 10px;
  background: #FFFFFF;
  color: #37474F;
  font-weight: 700;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  border: 3px solid var(--card-border-color);
  box-shadow: 0 3px 6px rgba(0,0,0,0.1);
  z-index: 2;
}

/* Footer & Indicators */
.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
  padding-bottom: 10px;
}

.page-indicators {
  display: flex;
  gap: 10px;
  background: rgba(255, 255, 255, 0.7);
  padding: 6px 16px;
  border-radius: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #CFD8DC;
  cursor: pointer;
  transition: var(--transition-bouncy);
  border: 1.5px solid #FFF;
}

.dot.active {
  background: var(--color-primary);
  transform: scale(1.25);
  box-shadow: 0 0 6px rgba(2, 136, 209, 0.3);
}

.dot:nth-child(1).active { background: #81C784; } /* Green page 1 */
.dot:nth-child(2).active { background: #4FC3F7; } /* Blue page 2 */
.dot:nth-child(3).active { background: #E040FB; } /* Violet page 3 */
.dot:nth-child(4).active { background: #FFA726; } /* Orange page 4 */
.dot:nth-child(5).active { background: #FF8A80; } /* Coral page 5 */

/* Modal Backdrop */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(38, 50, 56, 0.6);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Confetti Canvas Overlay */
.confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 102;
}

/* Modal Content Card */
.modal-card {
  position: relative;
  background: #FFFDE7; /* Light creamy warm yellow */
  width: 90%;
  max-width: 800px;
  border-radius: 40px;
  border: 8px solid #FFFFFF;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3), inset 0 0 20px rgba(255, 235, 59, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.7);
  transition: var(--transition-bouncy);
  z-index: 101;
  padding: 24px;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

/* Modal Header Options */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 12px;
}

.parent-lock-trigger {
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid #CFD8DC;
  border-radius: 20px;
  padding: 6px 14px;
  color: #546E7A;
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition-smooth);
}

.parent-lock-trigger:hover {
  background: #ECEFF1;
  color: #37474F;
  border-color: #B0BEC5;
}

/* Close Button (Fades / Elastic Pops in when audio ended) */
.modal-close-btn {
  background: #E8F5E9; /* Light soft green */
  color: #2E7D32; /* Soft dark green text */
  border: 3px solid #A5D6A7; /* Pastel green border */
  border-radius: 20px;
  padding: 6px 14px;
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition-smooth);
  animation: pop-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.modal-close-btn:hover {
  background: #C8E6C9;
  border-color: #81C784;
  color: #1B5E20;
  transform: scale(1.05);
}

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

.modal-close-btn.hidden {
  display: none !important;
}

@keyframes pop-in {
  0% { transform: scale(0) rotate(-15deg); opacity: 0; }
  70% { transform: scale(1.15) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Modal Main Body */
.modal-body {
  display: flex;
  gap: 30px;
  align-items: center;
}

/* Left: Vinyl rotating thumbnail */
.modal-thumb-container {
  position: relative;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  border: 10px solid #FFFFFF;
  box-shadow: 0 15px 30px rgba(0,0,0,0.15);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FFF;
}

.modal-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Vinyl Rotating State */
.modal-thumb-container.playing {
  animation: rotate-vinyl 15s linear infinite;
}

@keyframes rotate-vinyl {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Bouncing Music Notes in Modal */
.music-note {
  position: absolute;
  font-size: 24px;
  opacity: 0;
  pointer-events: none;
}

.playing ~ .music-note,
.modal-thumb-container.playing .music-note {
  animation: float-note 3s linear infinite;
}

.note-1 { top: 20px; left: 20px; animation-delay: 0s !important; }
.note-2 { bottom: 30px; right: 20px; animation-delay: 1s !important; }
.note-3 { top: 50%; right: 10px; animation-delay: 2s !important; }

@keyframes float-note {
  0% { transform: translate(0, 0) scale(0.6) rotate(0deg); opacity: 0; }
  20% { opacity: 0.8; }
  100% { transform: translate(var(--dx, -30px), var(--dy, -80px)) scale(1.1) rotate(var(--dr, 20deg)); opacity: 0; }
}
.note-1 { --dx: -40px; --dy: -90px; --dr: -30deg; }
.note-2 { --dx: 40px; --dy: -70px; --dr: 25deg; }
.note-3 { --dx: -20px; --dy: -100px; --dr: 15deg; }

/* Right: Player Controls */
.modal-player-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.modal-story-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: #37474F;
  margin-bottom: 6px;
  line-height: 1.3;
}

.modal-category-tag {
  align-self: flex-start;
  font-size: 0.95rem;
  font-weight: 700;
  color: #FFFFFF;
  background: var(--color-primary);
  padding: 6px 16px;
  border-radius: 20px;
  margin-bottom: 24px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 8px rgba(2, 136, 209, 0.25);
}

/* Custom Player Interface */
.custom-player {
  background: #FFF;
  border-radius: 28px;
  padding: 20px;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.03), 0 8px 16px rgba(0, 0, 0, 0.03);
  border: 3px solid #FFF59D;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* Time Indicator */
.time-display {
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Quicksand', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #78909C;
  gap: 5px;
}

.time-separator {
  color: #B0BEC5;
}

/* Progress Bar (Theme: Playful Vine Track & Star Slider) */
.progress-bar-outer {
  width: 100%;
  padding: 10px 0;
  cursor: pointer;
}

.progress-track {
  position: relative;
  width: 100%;
  height: 16px;
  background: #C8E6C9; /* Soft green vine path */
  border-radius: 10px;
  border: 2px solid #81C784;
}

.progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(
    45deg,
    #66BB6A,
    #66BB6A 10px,
    #81C784 10px,
    #81C784 20px
  );
  border-radius: 8px;
}

.progress-handle {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  cursor: grab;
  z-index: 10;
  transition: transform 0.15s ease;
}

.progress-handle:active {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.2);
}

.handle-avatar {
  font-size: 32px;
  line-height: 1;
  text-shadow: 0 3px 6px rgba(0,0,0,0.15);
  animation: float-handle 2s ease-in-out infinite alternate;
}

@keyframes float-handle {
  0% { transform: rotate(-5deg); }
  100% { transform: rotate(5deg); }
}

/* Control Row (Buttons + Centered Play) */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.control-side {
  flex: 1;
  display: flex;
}
.control-side.left {
  justify-content: flex-start;
}
.control-side.right {
  justify-content: flex-end;
}

/* Friendly Lock Instruction Notice Banner */
.lock-instructions-notice {
  font-family: var(--font-primary);
  font-size: 1rem;
  color: #E65100;
  background: #FFF3E0;
  padding: 8px 18px;
  border-radius: 16px;
  border: 2.5px dashed #FFE082;
  margin: 0;
  text-align: center;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  width: fit-content;
  box-shadow: 0 4px 8px rgba(255, 179, 0, 0.05);
  animation: pulse-notice 2s infinite alternate;
}

@keyframes pulse-notice {
  0% { transform: scale(1); filter: brightness(1); }
  100% { transform: scale(1.02); filter: brightness(1.03); }
}

.control-circle-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-bouncy);
}

.volume-btn {
  background: var(--color-accent-purple);
  color: #FFFFFF;
  box-shadow: 0 6px 0px var(--color-accent-purple-dark), 0 6px 12px rgba(124, 77, 255, 0.3);
}

.volume-btn:hover {
  background: #D1C4E9;
  color: var(--color-accent-purple-dark);
}

.volume-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 0px var(--color-accent-purple-dark), 0 2px 4px rgba(124, 77, 255, 0.3);
}

.play-btn {
  width: auto;
  height: 64px;
  padding: 0 24px;
  border-radius: 32px;
  gap: 8px;
  background: var(--color-accent-pink);
  color: #FFFFFF;
  box-shadow: 0 8px 0px var(--color-accent-pink-dark), 0 8px 16px rgba(255, 138, 128, 0.3);
}

.play-btn:hover {
  background: #FFCDD2;
  color: var(--color-accent-pink-dark);
}

.play-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 0px var(--color-accent-pink-dark), 0 2px 4px rgba(255, 138, 128, 0.3);
}

/* Stack outside lock notice vertically above the player card */
#detail-modal.modal-overlay {
  flex-direction: column;
  gap: 15px;
}


/* Parent Lock bypass challenge modal */
.parent-lock-overlay {
  background: rgba(38, 50, 56, 0.85);
  z-index: 200;
}

.parent-lock-card {
  background: #FFFFFF;
  padding: 30px;
  border-radius: 30px;
  border: 6px solid var(--color-primary);
  width: 90%;
  max-width: 400px;
  box-shadow: 0 15px 30px rgba(0,0,0,0.3);
  text-align: center;
  transform: scale(0.8);
  transition: var(--transition-bouncy);
}

.parent-lock-overlay.active .parent-lock-card {
  transform: scale(1);
}

.parent-lock-card h3 {
  font-size: 1.5rem;
  color: var(--color-primary);
  margin-bottom: 10px;
}

.parent-lock-card p {
  color: #546E7A;
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.math-question {
  font-size: 2.2rem;
  font-weight: 700;
  color: #37474F;
  margin-bottom: 20px;
  background: #ECEFF1;
  padding: 10px;
  border-radius: 15px;
}

.math-inputs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.math-inputs input {
  flex-grow: 1;
  padding: 12px;
  border-radius: 15px;
  border: 3px solid #CFD8DC;
  font-family: var(--font-primary);
  font-size: 1.2rem;
  text-align: center;
  color: #37474F;
  outline: none;
}

.math-inputs input:focus {
  border-color: var(--color-primary);
}

.btn {
  border: none;
  font-family: var(--font-primary);
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 15px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-primary {
  background: var(--color-primary);
  color: #FFF;
  box-shadow: 0 4px 0 #01579B;
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #01579B;
}

.parent-lock-close {
  background: transparent;
  border: none;
  color: #78909C;
  font-family: var(--font-primary);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

.parent-lock-close:hover {
  color: #37474F;
}

.math-error {
  color: #D32F2F;
  font-weight: 600;
  margin-top: 10px;
  display: none;
}

/* View Sections Toggles */
.view-section {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: opacity 0.3s ease;
}

.view-section.hidden {
  display: none !important;
}

/* App Navigation Tabs */
.app-tabs {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 5px;
  margin-bottom: 5px;
  z-index: 10;
}

.tab-btn {
  font-family: var(--font-primary);
  font-size: 1.1rem;
  font-weight: 700;
  color: #37474F;
  background: rgba(255, 255, 255, 0.85);
  border: 4px solid #FFFFFF;
  border-radius: 24px;
  padding: 8px 24px;
  cursor: pointer;
  box-shadow: 0 6px 0px rgba(0, 0, 0, 0.05), 0 6px 12px rgba(0,0,0,0.05);
  transition: var(--transition-bouncy);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn:hover {
  transform: translateY(-4px) scale(1.03);
  background: #FFFFFF;
}

.tab-btn:active {
  transform: translateY(2px) scale(0.97);
  box-shadow: 0 2px 0px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0,0,0,0.05);
}

.tab-btn.active {
  color: #FFFFFF;
  background: var(--color-primary);
  border-color: #FFFFFF;
  box-shadow: 0 6px 0px #01579B, 0 6px 12px rgba(2, 136, 209, 0.3);
}

.tab-btn.active:hover {
  background: #0288D1;
}

/* Characters View Styles removed - now uses standard page-grid */

/* Character Badge custom details */
.play-badge.char-badge {
  background: var(--color-primary);
  box-shadow: 0 4px 8px rgba(2, 136, 209, 0.3), 0 3px 0px var(--color-primary-dark);
}

/* Character Modal custom layout */
.char-modal-card {
  max-width: 900px;
}

/* Character Modal Close Button at top-right corner */
.char-modal-close-btn {
  position: absolute;
  top: 24px;
  right: 24px;
  background: var(--color-accent-pink);
  color: #FFFFFF;
  border: 3px solid #FFFFFF;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 6px 12px rgba(255, 138, 128, 0.3);
  transition: var(--transition-bouncy);
  z-index: 105;
}

.char-modal-close-btn:hover {
  transform: scale(1.1) rotate(-10deg);
  background: var(--color-accent-pink-dark);
}

.char-modal-close-btn:active {
  transform: scale(0.95);
}

.char-modal-body {
  display: flex;
  gap: 30px;
  align-items: center;
}

.char-modal-img-container {
  flex: 1; /* 1 phần */
  aspect-ratio: 1 / 1;
  background: none !important; /* Remove background */
  border: none !important; /* Remove border */
  box-shadow: none !important; /* Remove shadows */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.char-modal-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.12)); /* Realistic drop shadow for transparent WebP */
}

.char-modal-info {
  flex: 2; /* 2 phần */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 15px;
}

.char-modal-title {
  font-family: var(--font-primary);
  color: var(--color-primary);
  font-size: 2.8rem;
  margin: 0;
  padding-right: 45px; /* Prevent close button from overlapping title */
}

.char-modal-desc {
  font-family: var(--font-primary);
  font-size: 1.5rem;
  color: #37474F;
  line-height: 1.6;
  margin: 0;
}



/* Tablet Optimizations (Responsive Grid sizing) */
@media (max-width: 1024px) {
  .logo-text { font-size: 1.8rem; }
  .logo-emoji { font-size: 1.8rem; }
  .story-card { border-radius: 20px; }
  .card-title { font-size: 0.95rem; }
  .nav-arrow { width: 60px; height: 60px; }
}

@media (max-width: 768px) {
  body { overflow-y: hidden; } /* Lock vertical scroll on phone */
  .app-container { height: 99vh; padding: 4px; justify-content: flex-start; }
  
  /* Stacked header: logo centered in Row 1, tabs centered in Row 2 */
  .app-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 6px 20px; /* Padding for margins increased to 20px */
    margin-bottom: 6px;
    width: 100%;
  }
  .header-top {
    width: 100%;
    display: flex;
    justify-content: center;
  }
  .logo-area {
    padding: 6px 18px; /* Slightly larger padding for a bigger logo look */
    border-width: 3px;
    box-shadow: 0 4px 0 rgba(2, 136, 209, 0.15);
  }
  .logo-text { font-size: 1.55rem; } /* Logo text made larger */
  .logo-emoji { display: none; }
  .subtitle { display: none; }
  
  /* Centered tab menu below logo */
  .app-tabs {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 2px;
  }
  .tab-btn {
    font-size: 1.05rem; /* Tab text made larger */
    padding: 6px 22px; /* Tab button made slightly larger */
    border-width: 3px;
    border-radius: 18px;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.05);
  }
  
  /* Scroll container acts as a block vertical viewport */
  .scroll-container { 
    display: block;
    width: 100%; 
    height: 80vh; /* Adjusted slightly to fit the larger header */
    overflow-y: auto;
    overflow-x: hidden;
    scroll-snap-type: none; /* Disable horizontal snaps */
    padding: 8px 20px; /* Left/Right padding increased to 20px for wider margins */
  }
  
  /* Active 2-column grid container for mobile files */
  .page-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 0;
    margin-bottom: 12px;
    height: auto;
    width: 100%;
  }
  
  /* Full-width square cards inside 2-column mobile grid */
  .story-card {
    width: 100%;
    max-width: 100%; /* Override desktop max-width constraints */
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 16px;
    border-width: 3px;
    box-shadow: 0 4px 0px rgba(0,0,0,0.05);
    position: relative;
  }
  
  .card-title {
    font-size: 0.85rem;
    line-height: 1.2;
  }
  
  .card-details {
    padding: 6px 8px;
    border-top-width: 2.5px;
  }
  
  .card-number {
    width: 22px;
    height: 22px;
    font-size: 0.75rem;
    border-width: 2px;
    top: 6px;
    left: 6px;
  }
  
  .play-badge {
    width: 22px;
    height: 22px;
    top: 6px;
    right: 6px;
    border-width: 2px;
  }
  
  .play-badge svg {
    width: 10px;
    height: 10px;
  }
  
  .prev-btn, .next-btn { display: none; }
  
  /* Hide the page indicators on mobile since it's a single vertical list */
  .app-footer {
    display: none !important;
  }
  
  /* Modal Player Mobile Optimization */
  .modal-card {
    padding: 12px;
    border-radius: 20px;
    border-width: 4px;
    width: 96%;
    max-height: 96vh;
    overflow-y: auto;
  }
  
  .modal-body {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
  
  .modal-thumb-container {
    width: 160px;
    height: 160px;
    border-width: 4px;
    margin: 0 auto;
  }
  
  .modal-story-title {
    font-size: 1.15rem;
    margin-top: 4px;
  }
  
  .modal-category-tag {
    margin-bottom: 8px;
    font-size: 0.7rem;
    padding: 3px 10px;
    align-self: center;
  }
  
  .modal-player-container {
    width: 100%;
  }

  .custom-player {
    padding: 40px;
    width: 100%;
    box-sizing: border-box;
    gap: 6px;
    border-radius: 16px;
  }
  
  .time-display {
    font-size: 0.85rem;
  }
  
  .progress-track {
    height: 10px;
  }
  
  .progress-handle {
    width: 24px;
    height: 24px;
  }
  
  .handle-avatar {
    font-size: 20px;
  }
  
  .control-circle-btn {
    width: 42px;
    height: 42px;
    border-width: 2px;
  }
  
  .play-btn {
    width: auto;
    height: 42px;
    padding: 0 16px;
    border-radius: 21px;
    gap: 6px;
  }
  
  .play-btn span {
    font-size: 0.95rem !important;
  }
  
  .play-btn svg {
    width: 20px;
    height: 20px;
  }
  
  .volume-btn svg {
    width: 16px;
    height: 16px;
  }
  
  .modal-close-btn {
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 0.85rem;
    border-width: 2px;
  }
  
  .listen-lock-status {
    max-width: 100%;
    margin-top: 0;
    padding: 4px 8px;
    font-size: 0.7rem;
    border-radius: 10px;
  }
  
  /* Characters Mobile view */
  .char-modal-body {
    flex-direction: column;
    gap: 15px;
    text-align: center;
    align-items: center;
  }
  .char-modal-img-container {
    flex: 0 0 auto;
    width: 200px;
    height: auto;
    aspect-ratio: 1 / 1;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
  }
  .char-modal-info {
    align-items: center;
  }
  .char-modal-title {
    font-size: 2.1rem;
  }
  .char-modal-desc {
    font-size: 1.25rem;
    line-height: 1.5;
  }
  .lock-instructions-notice {
    font-size: 0.85rem;
    padding: 6px 12px;
    margin: 0;
    border-width: 1.5px;
  }
}

/* Premium Kids App Loader */
.app-loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #FFFDE7 0%, #E0F7FA 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.app-loader.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.loader-avatar {
  font-size: 4rem;
  animation: bounce-star 1.5s infinite ease-in-out;
}

.loader-progress-container {
  width: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.loader-progress-bar {
  width: 100%;
  height: 16px;
  background: rgba(2, 136, 209, 0.1);
  border-radius: 10px;
  border: 2px solid #FFFFFF;
  overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
  position: relative;
}

.loader-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-success-green) 0%, var(--color-primary) 100%);
  border-radius: 10px;
  transition: width 0.3s ease;
}

.loader-percentage {
  font-family: var(--font-primary);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-primary);
}

.loader-text {
  font-family: var(--font-primary);
  font-size: 1.8rem;
  color: var(--color-primary);
  margin: 0;
  font-weight: 700;
}

.loader-subtext {
  font-family: var(--font-primary);
  font-size: 1.1rem;
  color: #546E7A;
  margin: 0;
}

@keyframes bounce-star {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-20px) scale(1.15) rotate(15deg); }
}
