/* =========================================================
   SMARTPREP HINDI MASTER STYLESHEET
   Unified Hub & Cinematic TV-Series Conversation App
   ========================================================= */

:root {
  /* Classic SmartPrep Palette */
  --primary: #2563eb;       
  --primary-dark: #1e3a8a;  
  --success: #10b981;       
  --danger: #ef4444;        
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --border-color: #e2e8f0;

  /* Premium Cinematic Palette */
  --bg-page: #f4f0e8;
  --brand-blue: #1e3a8a;
  --brand-gold: #f6b73c;
  --brand-green: #10b981;
  --brand-red: #ef4444;

  --glass-bg: rgba(255, 255, 255, 0.84);
  --glass-border: rgba(255, 255, 255, 0.55);

  --shadow-soft: 0 12px 34px rgba(15, 23, 42, 0.16);
  --shadow-strong: 0 20px 55px rgba(15, 23, 42, 0.26);

  --ease-main: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
}

body {
  margin: 0;
  padding: 0;
  width: 100%; /* Forces the body to span the full screen */
  min-height: 100vh;
  /* Updated to Devanagari */
  font-family: "Noto Sans Devanagari", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  
  /* Blended Premium Background */
  background:
    radial-gradient(circle at top left, rgba(255, 215, 140, 0.28), transparent 35%),
    linear-gradient(135deg, #fdf7ec 0%, #eef6ff 100%);
  color: var(--text-main);
  
  /* Flex layout to center the Hub elements naturally */
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* =========================================================
   1. MAIN HUB STYLES (index.html, tracing.html, etc.)
   ========================================================= */

/* Classic Solid Header for standard apps */
header:not(.app-header) {
  background-color: var(--primary-dark);
  color: white;
  width: 100%;
  text-align: center;
  padding: 20px 0;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

header:not(.app-header) h1 {
  margin: 0 0 5px 0;
  font-size: 1.8rem;
}

header:not(.app-header) p {
  margin: 0;
  font-size: 1rem;
  opacity: 0.8;
}

/* Hub Grid Layout */
.container {
  max-width: 900px;
  width: 90%;
  margin: 40px auto;
  flex: 1; /* Pushes footer down */
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.card {
  background: white;
  border-radius: 16px;
  padding: 25px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  border: 1px solid var(--border-color);
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 15px rgba(0,0,0,0.1);
}

.card .icon {
  font-size: 3rem;
  margin-bottom: 15px;
}

.card h2 {
  margin: 0 0 10px 0;
  font-size: 1.4rem;
  color: var(--text-main);
}

.card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

/* Foundation Navigation Badge */
  .level-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    height: 44px;
    background-color: #e0f2fe; 
    border: 1.5px solid #3b82f6; 
    border-radius: 8px;
    /* Updated to Devanagari */
    font-family: 'Noto Sans Devanagari', sans-serif;
    font-weight: 700;
    color: #1e40af;
    font-size: 1rem;
    cursor: default;
    user-select: none;
  }
/* =========================================================
   2. CINEMATIC APP HEADER & NAV (converse.html)
   ========================================================= */

.app-header {
  padding: 14px 18px 8px;
  display: flex;
  justify-content: center;
  width: 100%;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  border-radius: 22px;
  padding: 10px 18px;
  backdrop-filter: blur(12px);
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #fff0bd, #ffd166);
  font-size: 1.35rem;
  box-shadow: 0 8px 20px rgba(246, 183, 60, 0.35);
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.5vw, 1.65rem);
  color: var(--brand-blue);
  letter-spacing: -0.03em;
}

.app-header p {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.nav-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px 16px;
  width: 100%;
}

.nav-bar select, .nav-bar button, .nav-bar a {
  min-height: 42px;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.10);
}

.nav-bar select { background: white; color: var(--ink-dark); outline: none; }

.start-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(16, 185, 129, 0.32);
}

.hub-btn { background: #4b5563; color: white; text-decoration: none; }

/* =========================================================
   3. CINEMATIC STAGE (converse.html)
   ========================================================= */

.page-shell {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0 14px 26px;
  flex: 1;
}

.episode-card { width: min(100%, 1180px); }

.module-title {
  margin: 0 auto 12px;
  width: fit-content;
  max-width: 90%;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  color: var(--brand-blue);
  font-weight: 800;
  text-align: center;
}

.cinematic-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 72vh;
  min-height: 420px;
  isolation: isolate;
  margin-bottom: 40px; 
}

.scene-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transform: scale(1.015);
  filter: saturate(1.03) brightness(1.02);
  border-radius: 34px;
  overflow: hidden;
}

.cinematic-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  border-radius: 34px;
  overflow: hidden;
}

.stage-light {
  position: absolute;
  bottom: 12%;
  width: 30%;
  height: 42%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 224, 170, 0.24), transparent 70%);
  z-index: 2;
  pointer-events: none;
}
.stage-light-left { left: 6%; }
.stage-light-right { right: 6%; }

/* =========================================================
   CHARACTER SPRITES
   ========================================================= */

.character-sprite {
  position: absolute;
  z-index: 4;
  bottom: 9%; 
  width: clamp(260px, 35vw, 480px); 
  height: 75%; 
  max-height: 82%;
  object-fit: contain;
  object-position: bottom center;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 18px 24px rgba(15, 23, 42, 0.20));
  transition: opacity 0.3s var(--ease-main);
}

.char-pos-left { left: 7%; }
.char-pos-right { right: 7%; }

.character-sprite.speaking { opacity: 1; z-index: 6; }
.character-sprite.listening { opacity: 1; z-index: 4; }

.character-sprite.enter { animation: characterEntrance 0.8s var(--ease-main) forwards; }

@keyframes characterEntrance {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- CHARACTER SCALE CORRECTIONS --- */

/* Shrinks Kabir so he looks like a young boy next to adults */
.character-sprite[data-character="Kabir"] {
    transform: scale(0.87); 
    transform-origin: bottom center; /* Keeps his feet perfectly planted */
}

/* Optional: Slightly boosts Nani's size if she feels too small on screen */
.character-sprite[data-character="Nani"] {
    transform: scale(1.05); 
    transform-origin: bottom center;
}

/* Optional: Slightly boosts Masterji's size if he feels too small on screen */
.character-sprite[data-character="Masterji"] {
    transform: scale(1.10); 
    transform-origin: bottom center;
}

/* =========================================================
   UI LAYER & BUBBLES
   ========================================================= */

.ui-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.hint-bubble {
  position: absolute;
  bottom: 115px; 
  left: 50%;
  transform: translateX(-50%);
  z-index: 20; 
  width: min(88%, 560px);
  padding: 12px 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
  color: var(--ink-dark);
  font-size: 0.96rem;
  line-height: 1.5;
  pointer-events: auto;
  animation: popInCentered 0.32s var(--ease-main);
}
.hint-bubble strong { color: #92400e; }

/* =========================================================
   DIALOGUE BOX
   ========================================================= */

.dialogue-box {
  position: absolute;
  left: 50%;
  bottom: -35px; 
  transform: translateX(-50%);
  width: min(92%, 900px);
  padding: 14px 24px 12px; 
  border-radius: 28px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow-strong); 
  pointer-events: auto;
  animation: dialogueRise 0.45s var(--ease-main);
}

@keyframes dialogueRise {
  from { opacity: 0; transform: translateX(-50%) translateY(18px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes popInCentered {
  from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.speaker-name {
  margin-bottom: 8px;
  font-size: 0.96rem;
  font-weight: 800;
  color: #9a5b13;
  letter-spacing: 0.02em;
}

.speaker-text {
  min-height: 32px; 
  font-size: clamp(1.35rem, 2.3vw, 2.05rem);
  line-height: 1.55;
  font-weight: 700;
  color: #111827;
  animation: textFade 0.35s ease;
  margin: 0;
}

.subtitle-text {
  margin-top: 6px;
  min-height: 24px;
  font-size: clamp(0.92rem, 1.2vw, 1.06rem);
  line-height: 1.45;
  color: rgba(17, 24, 39, 0.68);
  font-style: italic;
  animation: textFade 0.4s ease;
}

@keyframes textFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   CONTROLS
   ========================================================= */

.controls-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.action-btn {
  border: none;
  outline: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.action-btn:hover { transform: translateY(-2px); }
.action-btn:active { transform: scale(0.965); }

.next-btn {
  background: linear-gradient(135deg, #ffd166, #f6a623);
  color: #432818;
  box-shadow: 0 10px 22px rgba(246, 166, 35, 0.32);
}

.speak-btn {
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: white;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.32);
}

.speak-btn.listening {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.42); }
  70% { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* =========================================================
   FEEDBACK & PROGRESS
   ========================================================= */

.feedback {
  margin: 16px auto 0;
  min-height: 34px;
  width: min(92%, 850px);
  text-align: center;
  font-size: 1.14rem;
  font-weight: 800;
}

.progress-bar {
  width: min(94%, 900px);
  height: 12px;
  margin: 12px auto 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(15, 23, 42, 0.12);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #10b981, #34d399, #f6b73c);
  transition: width 0.45s var(--ease-main);
}

.final-screen-container {
  width: min(94%, 720px);
  margin: 24px auto;
  padding: 34px 24px;
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-soft);
  text-align: center;
  animation: popIn 0.45s var(--ease-main);
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#visual-focus-box { animation: focusPop 0.32s var(--ease-main); }
@keyframes focusPop {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.94); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* =========================================================
   MOBILE OPTIMISATION & DEVICES
   ========================================================= */

@media (max-width: 768px) and (orientation: portrait) {
  .app-header { padding-top: 10px; }
  .brand-lockup { padding: 8px 12px; border-radius: 18px; }
  .brand-icon { width: 38px; height: 38px; border-radius: 14px; }
  .nav-bar { gap: 8px; padding-bottom: 10px; }
  .nav-bar select, .nav-bar button, .nav-bar a { font-size: 0.82rem; padding: 9px 12px; }
  .page-shell { padding: 0 8px 18px; }
  
  .cinematic-stage { 
    min-height: 380px; 
    max-height: 60vh; 
    aspect-ratio: 4 / 5; 
    border-radius: 24px; 
    margin-bottom: 35px; 
  }
  
  .character-sprite { 
    bottom: 26%; 
    width: clamp(180px, 48vw, 300px); 
    max-height: 60%; 
  }
  .char-pos-left { left: 1%; }
  .char-pos-right { right: 1%; }
  
  #visual-focus-box { top: 18%; } 

  .dialogue-box { 
    bottom: -25px; 
    width: 94%; 
    padding: 12px 18px; 
    border-radius: 22px; 
  }
  .speaker-text { font-size: 1.28rem; line-height: 1.5; min-height: 28px; }
  .subtitle-text { font-size: 0.88rem; }
  .controls-bar { justify-content: center; }
  .action-btn { width: 100%; padding: 12px 18px; }
  .hint-bubble { bottom: 100px; font-size: 0.86rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .cinematic-stage { 
    min-height: 280px; 
    max-height: 75vh; 
    margin-bottom: 20px; 
  }
  .character-sprite { 
    width: clamp(140px, 20vw, 220px); 
    bottom: 12%; 
  }
  .dialogue-box { 
    bottom: -15px; 
    padding: 8px 18px; 
    width: 88%; 
  }
  .speaker-text { font-size: 1.15rem; min-height: 24px; margin: 0; }
  .subtitle-text { font-size: 0.85rem; margin-top: 2px; }
  .hint-bubble { bottom: 80px; padding: 6px 12px; }
  #visual-focus-box { top: 5%; font-size: clamp(1.5rem, 3vw, 2rem); }
}

@media (max-height: 650px) and (min-width: 769px) {
  .cinematic-stage { max-height: 68vh; min-height: 360px; }
  .character-sprite { width: clamp(200px, 28vw, 360px); }
  .dialogue-box { padding: 16px 20px; bottom: -20px; }
  .speaker-text { font-size: clamp(1.2rem, 2vw, 1.7rem); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* --- TRACING CANVAS WIDE-WORD FIX --- */
#tracingCanvas {
    max-width: none !important; /* Prevents the browser from squashing the wide canvas */
    height: auto; 
    touch-action: none; /* Keeps finger tracing smooth without the screen bouncing */
}

/* Add this class to whatever <div> wraps your <canvas> in the HTML */
.canvas-wrapper {
    width: 100%;
    overflow-x: auto; /* Allows horizontal swipe to see the rest of long words */
    display: flex;
    justify-content: flex-start; /* Aligns wide canvas to the left edge to start tracing */
}

/* =========================================================
   PICTURE BOOK STYLES (Two-Page Spread)
   ========================================================= */

.book-wrapper {
    width: 100%;
    max-width: 900px;
    margin: 20px auto;
    padding: 0 15px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.picture-book {
    display: flex;
    width: 100%;
    background: white;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.1);
    border: 2px solid #e2e8f0;
    position: relative;
    min-height: 400px;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* The touch zones for turning pages */
.book-nav-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 15%;
    z-index: 10;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.nav-left { left: 0; }
.nav-right { right: 0; }

.nav-left:hover {
    opacity: 1;
    background: linear-gradient(to right, rgba(0,0,0,0.05), transparent);
}
.nav-right:hover {
    opacity: 1;
    background: linear-gradient(to left, rgba(0,0,0,0.05), transparent);
}

/* Page Layout */
.book-page {
    flex: 1;
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.book-left {
    background: #f8fafc;
    border-right: 2px solid #e2e8f0; /* The Spine */
}

.book-right {
    background: #ffffff;
}

/* Content Styling */
.book-visual {
    font-size: 7rem;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 180px;
}

.book-visual img {
    max-width: 100%;
    max-height: 360px;
    object-fit: contain;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.1));
}

/* Updated class name to target Hindi */
.book-devanagari {
    /* Updated to Devanagari */
    font-family: 'Noto Sans Devanagari', sans-serif;
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--brand-blue);
    margin-bottom: 5px;
}

.book-roman {
    font-size: 1.3rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 25px;
}

.book-english {
    font-size: 1.5rem; /* Reduced from 2rem */
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 30px;
}

/* Play Button */
/* Minimalist Audio Icon Button */
.hear-btn {
    background: transparent;
    border: none;
    font-size: 2.2rem; /* Much larger icon */
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 15; 
    position: relative; 
    transition: opacity 0.2s ease, transform 0.1s ease;
    margin-top: 15px; /* Creates breathing room below the English text */
    padding: 15px; /* Invisible padding creates a large, forgiving touch target */
    border-radius: 50%; /* Ensures the touch ripple/active state is circular */
}

.hear-btn:hover {
    opacity: 0.6;
}

.hear-btn:active {
    transform: scale(0.85); /* Satisfying physical 'press' effect */
}

.hear-btn:active {
    transform: scale(0.95);
    background: #d97706;
}

.book-pagination {
    margin-top: 15px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #94a3b8;
}

/* Mobile Responsiveness: Stacks pages into a single view */
@media (max-width: 600px) {
    .picture-book {
        flex-direction: column;
    }
    .book-left {
        border-right: none;
        border-bottom: 2px dashed #e2e8f0;
        padding: 20px; /* Reduced padding */
    }
    .book-right {
        padding: 20px; /* Reduced padding */
    }
    .book-nav-zone {
        width: 25%; 
    }
    
    /* NEW: Scale down the image for mobile screens */
    .book-visual {
        height: 180px; /* Scaled down from 180px */
    }
    .book-visual img {
        max-height: 240px;
    }
    
    /* NEW: Slightly shrink the main Devanagari text to ensure everything fits on screen */
    .book-devanagari {
        font-size: 2.8rem; /* Scaled down from 3.5rem */
    }
}

/* Matra Highlight for Story Phase */
.matra-glow {
  color: #eab308; /* Vibrant yellow/gold */
  text-shadow: 0 0 10px rgba(234, 179, 8, 0.4);
  font-weight: 900;
}

/* Tap-to-Fill Comprehension Slots */
.slot {
  display: inline-block;
  min-width: 100px;
  height: 40px;
  border-bottom: 4px dashed #94a3b8;
  margin: 0 12px;
  text-align: center;
  color: transparent; /* Hides the placeholder '?' */
  vertical-align: bottom;
  transition: all 0.3s ease;
}

.slot.filled {
  color: #1e3a8a;
  border-bottom-style: solid;
}

.slot.filled.success {
  border-color: #10b981;
  color: #047857;
  transform: scale(1.05);
}

.slot.error {
  border-color: #ef4444;
  color: #b91c1c;
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}