/* ═══════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════ */
:root {
  --sky:    #38bdf8;
  --sky2:   #0ea5e9;
  --mint:   #34d399;
  --sun:    #fbbf24;
  --coral:  #fb7185;
  --purple: #a78bfa;
  --dark:   #0f172a;
  --mid:    #475569;
  --muted:  #94a3b8;
  --light:  #f0f9ff;
  --melia:  #ec4899;
  --nael:   #3b82f6;
  --r:      20px;
  --shadow: 0 8px 32px rgba(15,23,42,.12);
  --shadow-sm: 0 2px 12px rgba(15,23,42,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Nunito', sans-serif;
  background: #e0f2fe;
  color: var(--dark);
  overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }

/* ── UTILITY ── */
.hidden { display: none !important; }

/* ── SPLASH ── */
.splash {
  position: fixed; inset: 0;
  background: linear-gradient(145deg, #0ea5e9 0%, #6366f1 50%, #ec4899 100%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 100;
}
.splash-logo {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(2.4rem, 7vw, 4rem);
  color: white; text-shadow: 0 4px 20px rgba(0,0,0,.2);
  animation: popIn .6s cubic-bezier(.34,1.56,.64,1) both;
}
.splash-sub {
  color: rgba(255,255,255,.85); font-size: 1rem; font-weight: 600;
  margin-top: 8px;
  animation: popIn .6s .1s cubic-bezier(.34,1.56,.64,1) both;
}
.orbs { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.orb {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,.08);
  animation: drift 8s ease-in-out infinite;
}
.orb:nth-child(1) { width:300px;height:300px; top:-80px;  left:-80px;  }
.orb:nth-child(2) { width:200px;height:200px; bottom:-60px; right:-40px; animation-delay:-3s; }
.orb:nth-child(3) { width:150px;height:150px; top:40%; left:60%;       animation-delay:-6s; }

/* ── CHILD SELECT ── */
.screen {
  min-height: 100vh;
  display: flex; flex-direction: column;
}
#childScreen {
  background: linear-gradient(160deg,#e0f2fe 0%,#fce7f3 100%);
  align-items: center; justify-content: center;
  gap: 32px; padding: 32px 20px;
}
.child-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem; color: var(--dark); text-align: center;
}
.child-cards { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; }
.child-card {
  background: white; border-radius: 28px; padding: 36px 44px;
  text-align: center; cursor: pointer;
  box-shadow: var(--shadow);
  border: 3px solid transparent;
  transition: transform .2s, box-shadow .2s;
  min-width: 200px;
  display: flex; flex-direction: column; align-items: center;
}
.child-card:hover { transform: translateY(-6px); box-shadow: 0 16px 48px rgba(15,23,42,.16); }
.child-card.melia { border-color: var(--melia); }
.child-card.nael  { border-color: var(--nael); }
.child-avatar { font-size: 4rem; margin-bottom: 12px; }
.child-name   { font-family: 'Fredoka One', cursive; font-size: 1.8rem; }
.child-card.melia .child-name { color: var(--melia); }
.child-card.nael  .child-name { color: var(--nael); }
.child-grade  { color: var(--mid); font-size: .9rem; font-weight: 600; margin-top: 4px; }

/* ── AUTH ── */
#setupScreen, #pinScreen {
  background: linear-gradient(160deg,#e0f2fe 0%,#fce7f3 100%);
  align-items: center; justify-content: center;
}
.auth-box {
  background: white; border-radius: 28px;
  padding: 40px 36px; text-align: center;
  box-shadow: var(--shadow); width: min(360px, 90vw);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.auth-icon  { font-size: 3.2rem; }
.auth-title { font-family: 'Fredoka One', cursive; font-size: 1.8rem; color: var(--dark); }
.auth-sub   { color: var(--mid); font-size: .95rem; font-weight: 600; margin-bottom: 4px; }
.pin-input {
  width: 100%; text-align: center; letter-spacing: .4em;
  font-size: 2rem; font-weight: 800; font-family: 'Nunito', sans-serif;
  border: 2.5px solid #e2e8f0; border-radius: 16px;
  padding: 14px 12px; outline: none;
  transition: border-color .2s;
}
.pin-input:focus { border-color: var(--sky); }
.auth-btn {
  width: 100%; padding: 14px; border: none; border-radius: 16px;
  background: linear-gradient(135deg, var(--sky), var(--sky2));
  color: white; font-family: 'Fredoka One', cursive;
  font-size: 1.2rem; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 16px rgba(14,165,233,.35);
}
.auth-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(14,165,233,.4); }
.auth-back {
  background: none; border: none; color: var(--muted);
  font-size: .9rem; cursor: pointer; padding: 4px;
}
.auth-back:hover { color: var(--mid); }
.auth-error {
  color: var(--coral); font-weight: 700; font-size: .9rem;
  background: #fff1f2; border-radius: 10px; padding: 8px 16px; width: 100%;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60%  { transform: translateX(-8px); }
  40%,80%  { transform: translateX(8px); }
}
.shake { animation: shake .4s ease; }

/* ── TOP BAR ── */
.top-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; background: white;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 10;
}
.top-bar-title { font-family: 'Fredoka One', cursive; font-size: 1.3rem; flex: 1; }
.top-bar-child-badge {
  padding: 4px 14px; border-radius: 20px;
  font-weight: 800; font-size: .85rem; color: white;
}
.top-bar-child-badge.melia { background: var(--melia); }
.top-bar-child-badge.nael  { background: var(--nael); }

.back-btn {
  background: #f1f5f9; border: none; border-radius: 12px;
  padding: 8px 14px; cursor: pointer; font-size: 1.1rem;
  transition: background .15s;
}
.back-btn:hover { background: #e2e8f0; }

/* ── SUBJECT SIDEBAR ── */
#subjectSidebar {
  position: fixed; top: 0; left: 0;
  width: 220px; height: 100vh;
  background: white;
  border-right: 1px solid #e2e8f0;
  display: flex; flex-direction: column;
  padding: 24px 0 24px;
  z-index: 40;
  overflow-y: auto;
}
.sidebar-heading {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 0 20px 12px;
}
.subject-nav-list {
  list-style: none; padding: 0; margin: 0;
}
.subject-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
  font-weight: 700; font-size: .95rem;
}
.subject-nav-item:hover   { background: #f0f9ff; }
.subject-nav-item.active  { background: #e0f2fe; border-left-color: var(--sky2); color: var(--sky2); }
.subject-nav-emoji { font-size: 1.3rem; }
.sidebar-close-btn {
  display: none;
  background: none; border: none;
  font-size: 1.2rem; cursor: pointer;
  color: var(--muted); padding: 0 20px 12px;
  align-self: flex-end;
}
.hamburger-btn {
  display: none;
  background: #f1f5f9; border: none; border-radius: 12px;
  padding: 8px 14px; cursor: pointer; font-size: 1.2rem;
  transition: background .15s; line-height: 1;
}
.hamburger-btn:hover { background: #e2e8f0; }

/* Sidebar overlay (mobile) */
#sidebarOverlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.4);
  z-index: 39;
  backdrop-filter: blur(2px);
}
#sidebarOverlay.visible { display: block; }

/* Desktop: push main content right of sidebar */
#topicScreen, #progressTab {
  margin-left: 220px;
}

/* Mobile: off-canvas drawer */
@media (max-width: 700px) {
  #subjectSidebar {
    left: -240px; width: 240px;
    transition: left .28s cubic-bezier(.4,0,.2,1);
    box-shadow: none;
  }
  #subjectSidebar.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(15,23,42,.18);
  }
  .sidebar-close-btn { display: flex; }
  .hamburger-btn     { display: block; }
  #topicScreen, #progressTab { margin-left: 0; }
}

/* ── TOPIC GRID ── */
#topicScreen { background: #f0f9ff; padding-bottom: 72px; }
.subject-section { margin-bottom: 8px; }
.topic-group { width: 100%; }
.subject-header {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem; color: var(--ink);
  padding: 20px 20px 0;
  display: flex; align-items: center; gap: 8px;
}
.subject-header::after {
  content: ''; flex: 1; height: 2px;
  background: #e2e8f0; border-radius: 1px;
  margin-left: 8px;
}
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px,1fr));
  gap: 16px; padding: 24px 20px;
}
.topic-card {
  background: white; border-radius: var(--r);
  padding: 24px 16px; text-align: center;
  box-shadow: var(--shadow-sm);
  border: 2.5px solid #e2e8f0;
  transition: all .2s; position: relative;
  display: flex; flex-direction: column; align-items: center;
}
.topic-card:hover { transform: translateY(-4px); border-color: var(--sky); box-shadow: var(--shadow); }
.topic-emoji   { font-size: 2.8rem; margin-bottom: 10px; }
.topic-name    { font-weight: 800; font-size: 1rem; }
.topic-subject { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.topic-badges {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 4px; align-items: center;
}
.topic-lesson {
  position: absolute; bottom: 10px; right: 10px;
  min-width: 24px; height: 24px;
  background: var(--sky); color: white;
  border-radius: 20px; padding: 0 7px;
  font-size: .72rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.topic-progress-badge {
  position: absolute; top: 10px; right: 10px;
  background: #94a3b8; color: white;
  border-radius: 20px; padding: 2px 8px;
  font-size: .72rem; font-weight: 800;
}
.topic-progress-badge.done { background: var(--mint); }

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: white; border-top: 1px solid #e2e8f0;
  padding: 8px 0 12px;
  display: flex; justify-content: space-around; z-index: 10;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; cursor: pointer; padding: 6px 20px; border-radius: 14px;
  transition: background .15s;
}
.nav-item:hover { background: #f0f9ff; }
.nav-icon  { font-size: 1.5rem; }
.nav-label { font-size: .68rem; font-weight: 800; color: var(--muted); }
.nav-item.active .nav-icon, .nav-item.active .nav-label { color: var(--sky2); }

/* ── EXERCISE SCREEN ── */
#exerciseScreen { background: #f0f9ff; min-height: 100vh; }
.exercise-header {
  padding: 14px 20px 10px; background: white;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 10;
}
.exercise-header-row1 {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.ex-title { font-family: 'Fredoka One', cursive; font-size: 1.2rem; flex: 1; }
.score-badge {
  background: var(--sun); color: #7c2d12;
  border-radius: 20px; padding: 4px 14px;
  font-weight: 800; font-size: .9rem;
}
.progress-track {
  background: #e2e8f0; border-radius: 10px; height: 8px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 10px;
  background: linear-gradient(90deg, var(--mint), var(--sky));
  transition: width .4s ease; width: 0%;
}

.exercise-body { padding: 20px; }

.ex-card {
  background: white; border-radius: var(--r);
  padding: 22px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm); border: 2px solid transparent;
  animation: slideUp .3s ease both;
}
.ex-card.correct { border-color: var(--mint); background: #f0fdf4; }
.ex-card.wrong   { border-color: var(--coral); background: #fff1f2; }

.ex-question-row {
  display: flex; align-items: flex-start; gap: 8px; margin-bottom: 14px;
}
.ex-question { font-weight: 800; font-size: 1.05rem; line-height: 1.4; flex: 1; }
.ex-scene {
  font-size: 2.8rem; text-align: center;
  padding: 14px; background: #f0f9ff;
  border-radius: 14px; margin-bottom: 14px;
}

/* TTS buttons */
.tts-btn {
  background: #f1f5f9; border: none; border-radius: 10px;
  padding: 6px 10px; font-size: 1.1rem; cursor: pointer;
  transition: background .15s;
}
.tts-btn:hover, .tts-btn.tts-active { background: #dbeafe; }
.tts-inline {
  background: none; border: none; font-size: 1rem;
  cursor: pointer; opacity: .5; padding: 2px 4px;
  border-radius: 6px; transition: opacity .15s;
  flex-shrink: 0;
}
.tts-inline:hover { opacity: 1; background: #e0f2fe; }

/* ── MC ── */
.mc-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.mc-opt {
  background: #f1f5f9; border: 2.5px solid #e2e8f0;
  border-radius: 14px; padding: 10px 20px;
  font-family: 'Nunito', sans-serif; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: all .18s; color: var(--dark);
}
.mc-opt:hover   { background: #e0f2fe; border-color: var(--sky); }
.mc-opt.correct-a { background: #dcfce7; border-color: var(--mint); color: #166534; }
.mc-opt.wrong-a   { background: #ffe4e6; border-color: var(--coral); color: #9f1239; }
.mc-opt:disabled  { cursor: default; }

/* ── FILL ── */
.word-bank { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.wb-word {
  background: linear-gradient(135deg,#fde68a,#fbbf24);
  border: none; border-radius: 10px; padding: 8px 18px;
  font-family: 'Nunito', sans-serif; font-size: .95rem; font-weight: 800;
  cursor: pointer; color: #451a03;
  box-shadow: 0 2px 8px rgba(251,191,36,.3);
  transition: transform .15s;
}
.wb-word:hover { transform: scale(1.06); }
.wb-word.used  { opacity: .3; cursor: default; }
.fill-sent {
  font-size: 1rem; font-weight: 700; line-height: 2.4; margin-bottom: 6px;
}
.drop-slot {
  display: inline-block; min-width: 110px;
  border-bottom: 3px dashed var(--sky);
  padding: 2px 10px; border-radius: 6px;
  background: #e0f2fe; font-weight: 800; color: var(--sky2);
  cursor: pointer; vertical-align: middle; transition: background .18s; margin: 0 4px;
}
.drop-slot:hover { background: #bae6fd; }
.drop-slot.filled   { border-bottom-style: solid; background: #bae6fd; }
.drop-slot.slot-ok  { background: #dcfce7; border-color: var(--mint); color: #166534; }
.drop-slot.slot-err { background: #ffe4e6; border-color: var(--coral); color: #9f1239; }

/* ── MATCH ── */
.match-area { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.match-col  { display: flex; flex-direction: column; gap: 8px; }
.match-item {
  background: #f1f5f9; border: 2.5px solid #e2e8f0;
  border-radius: 14px; padding: 10px 14px;
  font-weight: 800; text-align: center; cursor: pointer;
  transition: all .18s; font-size: .95rem;
}
.match-item:hover   { background: #e0f2fe; border-color: var(--sky); }
.match-item.sel     { background: #fef9c3; border-color: var(--sun); }
.match-item.matched { background: #dcfce7; border-color: var(--mint); cursor: default; }
.match-item.mis     { background: #ffe4e6; border-color: var(--coral); }

/* ── WRITE ── */
.text-ans {
  border: 2.5px solid #e2e8f0; border-radius: 12px;
  padding: 10px 16px; font-family: 'Nunito', sans-serif;
  font-size: 1rem; font-weight: 700; color: var(--dark);
  width: 100%; outline: none; transition: border .2s; background: #f8faff;
  margin-bottom: 2px;
}
.text-ans:focus { border-color: var(--sky); background: white; }
.text-ans.ok  { border-color: var(--mint); background: #dcfce7; }
.text-ans.err { border-color: var(--coral); background: #ffe4e6; }

/* ── CHECK / ACTION BUTTONS ── */
.check-btn {
  background: linear-gradient(135deg, var(--sky2), var(--purple));
  color: white; border: none; border-radius: 14px;
  padding: 11px 28px; font-family: 'Nunito', sans-serif;
  font-size: 1rem; font-weight: 800; cursor: pointer;
  box-shadow: 0 4px 14px rgba(14,165,233,.3);
  transition: transform .15s, box-shadow .15s; margin-top: 12px;
}
.check-btn:hover     { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(14,165,233,.35); }
.check-btn:disabled  { opacity: .45; transform: none; cursor: default; }
.check-btn.sm        { padding: 7px 14px; font-size: .82rem; margin: 0; }

/* ── FEEDBACK ── */
.feedback-msg {
  margin-top: 10px; font-weight: 800; font-size: .95rem;
  display: flex; align-items: center; gap: 6px; min-height: 24px;
}
.feedback-msg.ok  { color: #166534; }
.feedback-msg.err { color: #9f1239; }

/* ── RESULT ── */
.result-box {
  background: linear-gradient(135deg, var(--sky2) 0%, var(--purple) 100%);
  border-radius: var(--r); padding: 32px 24px;
  text-align: center; color: white; margin-top: 8px;
  box-shadow: var(--shadow);
}
.result-emoji { font-size: 4rem; margin-bottom: 8px; }
.result-score { font-family: 'Fredoka One', cursive; font-size: 3.5rem; }
.result-msg   { opacity: .9; font-weight: 700; font-size: 1rem; margin-top: 4px; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.result-btn {
  background: rgba(255,255,255,.2); border: 2px solid rgba(255,255,255,.5);
  color: white; border-radius: 14px; padding: 10px 24px;
  font-family: 'Nunito', sans-serif; font-size: .95rem; font-weight: 800;
  cursor: pointer; transition: background .2s;
}
.result-btn:hover { background: rgba(255,255,255,.35); }
.result-btn.primary { background: white; color: var(--sky2); border-color: white; }
.result-btn.primary:hover { background: #e0f2fe; }

/* ── PROGRESS SCREEN ── */
#progressTab { background: #f0f9ff; padding-bottom: 72px; }
.progress-cards { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.prog-card {
  background: white; border-radius: var(--r);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.prog-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.prog-card-emoji  { font-size: 2rem; }
.prog-card-title  { font-weight: 800; font-size: 1.05rem; }
.prog-card-sub    { color: var(--mid); font-size: .82rem; }
.prog-bar-wrap    { background: #e2e8f0; border-radius: 10px; height: 10px; overflow: hidden; margin-bottom: 4px; }
.prog-bar-fill    { height: 100%; border-radius: 10px; background: linear-gradient(90deg,var(--mint),var(--sky)); transition: width .6s ease; }
.prog-pct         { text-align: right; font-size: .78rem; color: var(--muted); font-weight: 700; }
.prog-stat-row    { display: flex; gap: 12px; margin-top: 10px; }
.prog-stat        { flex: 1; text-align: center; background: #f8faff; border-radius: 10px; padding: 8px; }
.prog-stat-val    { font-family: 'Fredoka One', cursive; font-size: 1.4rem; color: var(--sky2); }
.prog-stat-lbl    { font-size: .72rem; color: var(--muted); font-weight: 700; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--dark); color: white; padding: 10px 24px;
  border-radius: 20px; font-weight: 700; font-size: .9rem;
  z-index: 200; white-space: nowrap;
  animation: toastIn .3s ease, toastOut .3s 1.9s ease forwards;
}

/* ── ANIMATIONS ── */
@keyframes popIn {
  from { opacity: 0; transform: scale(.8) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes drift {
  0%,100% { transform: translate(0,0) scale(1); }
  50%      { transform: translate(20px,-20px) scale(1.05); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastIn  { from { opacity:0; transform:translateX(-50%) translateY(10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; } }
