/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 18px; scroll-behavior: smooth; }
body {
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: #f0f4ff;
  color: #333;
  display: flex;
  min-height: 100vh;
}

/* ========== Sidebar ========== */
.sidebar {
  width: 250px;
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-header {
  padding: 28px 20px 12px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.2);
}
.sidebar-header h2 { font-size: 1.3rem; }
.sidebar-header .tagline { font-size: 0.75rem; opacity: 0.85; margin-top: 4px; }

.menu { list-style: none; padding: 12px 0; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; cursor: pointer;
  font-weight: 600; font-size: 1rem;
  transition: background 0.2s;
}
.menu-item:hover, .menu-item.active { background: rgba(255,255,255,0.15); }
.menu-icon { font-size: 1.2rem; }
.menu-label { flex: 1; }
.arrow { font-size: 0.7rem; transition: transform 0.3s; }
.menu-item.active .arrow { transform: rotate(180deg); }

.submenu {
  list-style: none;
  max-height: 0; overflow: hidden;
  transition: max-height 0.3s ease;
}
.submenu.open { max-height: 300px; }
.submenu-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px 10px 36px;
  cursor: pointer; font-size: 0.9rem;
  transition: background 0.2s;
}
.submenu-item:hover { background: rgba(255,255,255,0.1); }
.submenu-item.active { background: rgba(255,255,255,0.2); font-weight: 600; }
.sub-icon { font-size: 1rem; }

.sidebar-footer {
  margin-top: auto; padding: 16px 20px;
  text-align: center; font-size: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.2);
}

/* Mobile toggle */
.menu-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 200;
  background: #6c5ce7; color: #fff; border: none;
  font-size: 1.5rem; padding: 6px 12px; border-radius: 8px;
  cursor: pointer;
}

/* ========== Content ========== */
.content {
  margin-left: 250px;
  flex: 1;
  padding: 32px 40px;
  min-height: 100vh;
}

/* Views */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Breadcrumb */
.breadcrumb {
  font-size: 0.8rem; color: #888; margin-bottom: 16px;
}
.breadcrumb a { color: #6c5ce7; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ========== Dashboard ========== */
.welcome-banner {
  background: linear-gradient(135deg, #6c5ce7, #fd79a8);
  color: #fff; border-radius: 16px; padding: 36px 32px;
  margin-bottom: 28px;
}
.welcome-banner h1 { font-size: 1.8rem; margin-bottom: 6px; }
.welcome-banner p { font-size: 1rem; opacity: 0.9; }

.section-title { font-size: 1.2rem; margin-bottom: 16px; color: #555; }

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}
.topic-card {
  background: #fff; border-radius: 16px;
  padding: 28px; cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative; overflow: hidden;
}
.topic-card:hover { transform: translateY(-4px); box-shadow: 0 8px 30px rgba(0,0,0,0.12); }
.card-emoji { font-size: 2.5rem; margin-bottom: 12px; }
.topic-card h3 { font-size: 1.3rem; margin-bottom: 8px; }
.topic-card p { font-size: 0.85rem; color: #666; margin-bottom: 12px; }
.card-tags {
  list-style: none; display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-tags li {
  background: #f0f4ff; color: #6c5ce7; padding: 4px 12px;
  border-radius: 20px; font-size: 0.7rem; font-weight: 600;
}
.card-count {
  position: absolute; top: 16px; right: 16px;
  background: #6c5ce7; color: #fff; font-size: 0.7rem;
  padding: 4px 10px; border-radius: 12px; font-weight: 600;
}

/* ========== Stories Grid ========== */
.page-title { font-size: 1.5rem; margin-bottom: 8px; }
.page-desc { font-size: 0.85rem; color: #888; margin-bottom: 24px; }

.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.story-card {
  background: #fff; border-radius: 14px; padding: 20px;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,0.06);
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: center;
}
.story-card:hover { transform: translateY(-3px); box-shadow: 0 6px 24px rgba(0,0,0,0.1); }
.story-card .story-thumb { font-size: 3rem; margin-bottom: 10px; }
.story-card h3 { font-size: 1rem; margin-bottom: 6px; color: #333; }
.story-card p { font-size: 0.75rem; color: #999; }

/* ========== Story Detail ========== */
.story-container {
  background: #fff; border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
  margin-bottom: 24px;
  max-width: 1100px;
}
.story-container h1 {
  font-size: 1.6rem; text-align: center; margin-bottom: 8px; color: #6c5ce7;
}

/* Paragraph block: illustration + lines side by side */
.story-para {
  display: flex; align-items: center; gap: 24px;
  margin-bottom: 28px; padding: 16px 0;
  border-bottom: 1px dashed #eee;
}
.story-para:last-child { border-bottom: none; margin-bottom: 0; }
.story-para.left { flex-direction: row; }
.story-para.right { flex-direction: row-reverse; }

.para-illustration {
  flex: 0 0 360px; max-width: 360px;
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 3px 16px rgba(0,0,0,0.10);
}
.para-illustration svg { display: block; width: 100%; height: auto; border-radius: 14px; }

.para-lines { flex: 1; min-width: 0; }

.story-line {
  padding: 7px 0;
  font-size: 1.15rem;
  line-height: 1.7;
  border-radius: 8px;
  transition: background 0.3s;
}
.story-line.line-highlight {
  animation: lineGlow 1.5s ease;
}
@keyframes lineGlow {
  0% { background: #e8e4ff; }
  100% { background: transparent; }
}

.story-line .line-text {
  font-weight: 500; color: #444;
}

/* Clickable words for speech */
.speak-hint {
  text-align: center; font-size: 0.8rem; color: #a29bfe;
  margin-bottom: 20px; font-style: italic;
}
.speak-word {
  cursor: pointer;
  padding: 2px 5px; border-radius: 6px;
  transition: background 0.15s, color 0.15s, transform 0.15s;
  display: inline-block;
}
.speak-word:hover {
  background: #e8e4ff; color: #6c5ce7;
  transform: scale(1.1);
}
.speak-word.speaking {
  animation: wordPulse 0.5s ease;
  background: #6c5ce7; color: #fff; border-radius: 6px;
}
@keyframes wordPulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.2); }
  100% { transform: scale(1); background: transparent; color: #444; }
}

/* Read Full Story controls */
.story-controls {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 16px; max-width: 1100px;
}
.btn-read {
  background: linear-gradient(135deg, #00b894, #00cec9);
  color: #fff; font-size: 1rem; padding: 12px 28px;
  border-radius: 12px; border: none; cursor: pointer;
  font-weight: 700; box-shadow: 0 3px 12px rgba(0,184,148,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-read:hover { transform: translateY(-2px); box-shadow: 0 5px 18px rgba(0,184,148,0.4); }
.btn-stop {
  background: #e17055; color: #fff; font-size: 1rem; padding: 12px 28px;
  border-radius: 12px; border: none; cursor: pointer;
  font-weight: 700; box-shadow: 0 3px 12px rgba(225,112,85,0.3);
}
.btn-stop:hover { background: #d63031; }
.hidden { display: none !important; }
.read-status {
  font-size: 0.85rem; color: #6c5ce7; font-weight: 600;
  font-style: italic;
}

/* Word-by-word reading highlight */
.speak-word.word-reading {
  background: #6c5ce7;
  color: #fff;
  border-radius: 6px;
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(108,92,231,0.4);
  transition: all 0.15s ease;
}

/* Active line during reading */
.story-line.reading-active {
  background: #ede7f6;
  border-radius: 8px;
  padding-left: 8px;
  padding-right: 8px;
  transition: background 0.3s;
}

/* Active illustration glow during reading */
.para-illustration.illust-active {
  box-shadow: 0 0 20px rgba(108,92,231,0.4), 0 0 40px rgba(108,92,231,0.15);
  transform: scale(1.02);
  transition: all 0.5s ease;
}

.story-nav {
  display: flex; gap: 16px; max-width: 1100px;
}

/* ========== Buttons ========== */
.btn {
  padding: 10px 24px; border: none; border-radius: 10px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-prev { background: #dfe6e9; color: #555; }
.btn-prev:hover { background: #b2bec3; }
.btn-next { background: #6c5ce7; color: #fff; }
.btn-next:hover { background: #5a4bd1; }
.btn-new-q { background: #00b894; color: #fff; margin-top: 16px; }
.btn-new-q:hover { background: #00a381; }

/* ========== Word Learning ========== */
.words-tabs {
  display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap;
}
.words-tab {
  padding: 12px 24px; border: 2px solid #ddd; border-radius: 12px;
  background: #fff; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
}
.words-tab.active { border-color: #6c5ce7; background: #6c5ce7; color: #fff; }
.words-tab:hover:not(.active) { border-color: #a29bfe; }

.words-panel { display: none; }
.words-panel.active { display: block; animation: fadeIn 0.3s ease; }

.word-card-display {
  background: #fff; border-radius: 20px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.08);
  padding: 40px; text-align: center;
  max-width: 550px;
  margin: 0 auto 24px;
}
.word-card-display .word-image {
  width: 320px; height: 320px; margin: 0 auto 28px;
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
.word-card-display .word-image svg {
  display: block; width: 100%; height: 100%;
}
.word-card-display .word-text {
  font-size: 4rem; font-weight: 800;
  letter-spacing: 18px; color: #6c5ce7;
  cursor: pointer; display: inline-block;
  padding: 12px 24px; border-radius: 16px;
  transition: background 0.2s, transform 0.15s;
  user-select: none;
}
.word-card-display .word-text:hover {
  background: #ede7f6; transform: scale(1.05);
}
.word-card-display .word-text:active {
  background: #6c5ce7; color: #fff; transform: scale(1.1);
}
.word-card-display .word-hint {
  font-size: 0.85rem; color: #a29bfe; margin-top: 10px; font-style: italic;
}

.word-nav {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  max-width: 550px; margin: 0 auto;
}
.word-counter {
  font-size: 0.9rem; color: #888; font-weight: 600; min-width: 60px; text-align: center;
}

/* ========== Maths ========== */
.maths-tabs {
  display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap;
}
.maths-tab {
  padding: 10px 20px; border: 2px solid #ddd; border-radius: 10px;
  background: #fff; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.maths-tab.active { border-color: #6c5ce7; background: #6c5ce7; color: #fff; }
.maths-tab:hover:not(.active) { border-color: #a29bfe; }

.maths-panel { display: none; }
.maths-panel.active { display: block; animation: fadeIn 0.3s ease; }
.maths-panel h2 { font-size: 1.3rem; margin-bottom: 8px; }
.maths-instruction { font-size: 0.85rem; color: #888; margin-bottom: 20px; }

.quiz-area {
  background: #fff; border-radius: 14px; padding: 28px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.06);
  text-align: center; min-height: 200px;
}
.quiz-question {
  font-size: 2rem; font-weight: 700; margin-bottom: 16px; color: #333;
}
.quiz-objects {
  font-size: 2.2rem; letter-spacing: 6px; margin-bottom: 20px;
  line-height: 1.8; word-break: break-all;
}
.quiz-options {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}
.quiz-option {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid #ddd; background: #fff;
  font-size: 1.5rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.quiz-option:hover { border-color: #6c5ce7; background: #f0f4ff; }
.quiz-option.correct { border-color: #00b894; background: #d4fce8; }
.quiz-option.wrong { border-color: #e17055; background: #ffe0d6; }

.quiz-qnum {
  font-size: 0.8rem; color: #a29bfe; font-weight: 600; margin-bottom: 8px;
}
.quiz-feedback {
  margin-top: 16px; font-size: 1.3rem; font-weight: 700;
  min-height: 40px;
}

/* Progress bar */
.quiz-progress { margin-bottom: 16px; }
.prog-bar {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 6px;
}
.prog-dot {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
  background: #e0e0e0; color: #999;
  transition: all 0.3s;
}
.prog-dot.current { background: #6c5ce7; color: #fff; transform: scale(1.15); box-shadow: 0 2px 8px rgba(108,92,231,0.4); }
.prog-dot.done { background: #00b894; color: #fff; }
.prog-score { font-size: 0.85rem; color: #666; text-align: center; font-weight: 600; }

/* Result card */
.quiz-result { text-align: center; }
.result-card {
  background: #fff; border-radius: 20px; padding: 36px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.08);
  max-width: 400px; margin: 0 auto;
  animation: fadeIn 0.4s ease;
}
.result-emoji { font-size: 4rem; margin-bottom: 12px; }
.result-score { font-size: 2.5rem; font-weight: 800; color: #6c5ce7; margin-bottom: 8px; }
.result-message { font-size: 1.1rem; color: #555; margin-bottom: 20px; font-weight: 600; }
.result-bar-container {
  background: #e0e0e0; border-radius: 10px; height: 18px;
  overflow: hidden; margin-bottom: 8px;
}
.result-bar {
  height: 100%; border-radius: 10px;
  background: linear-gradient(90deg, #00b894, #00cec9);
  transition: width 0.8s ease;
}
.result-pct { font-size: 0.9rem; color: #888; margin-bottom: 20px; font-weight: 600; }
.btn-retry {
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: #fff; font-size: 1rem; padding: 12px 28px;
  border-radius: 12px; border: none; cursor: pointer;
  font-weight: 700; transition: transform 0.15s;
}
.btn-retry:hover { transform: translateY(-2px); }
.hidden { display: none !important; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .content { margin-left: 0; padding: 20px 16px; padding-top: 56px; }
  .welcome-banner { padding: 24px 20px; }
  .welcome-banner h1 { font-size: 1.3rem; }
  .story-container { padding: 20px 14px; }
  .story-para { flex-direction: column !important; gap: 12px; }
  .para-illustration { flex: 0 0 auto; max-width: 100%; width: 100%; }
  .story-line { font-size: 1rem; }
}
