/* ===== MathLearn - Eye-friendly Math Learning Platform ===== */
/* Soft colors for prolonged reading, mobile-first */

:root {
  /* Light mode - warm soft tones */
  --bg-primary: #f7f3eb;
  --bg-secondary: #fffdf8;
  --bg-card: #ffffff;
  --bg-sidebar: #f0ebe0;
  --text-primary: #2c3e50;
  --text-secondary: #5a6a7a;
  --text-muted: #8a9aa8;
  --accent: #4a7c59;
  --accent-hover: #3d6b4a;
  --accent-light: #e8f0ea;
  --border: #e0d8c8;
  --shadow: rgba(44, 62, 80, 0.08);
  --success: #2e7d32;
  --error: #c62828;
  --warning: #f9a825;
  --quiz-correct: #e8f5e9;
  --quiz-wrong: #ffebee;
  --header-bg: #4a7c59;
  --header-text: #ffffff;
  --progress-bg: #e0d8c8;
  --progress-fill: #4a7c59;
}

[data-theme="dark"] {
  --bg-primary: #1a1f2e;
  --bg-secondary: #232a3b;
  --bg-card: #2a3142;
  --bg-sidebar: #1e2433;
  --text-primary: #e8ecf0;
  --text-secondary: #a8b4c0;
  --text-muted: #7a8a98;
  --accent: #6bbf8a;
  --accent-hover: #5aaf78;
  --accent-light: #2a3d35;
  --border: #3a4255;
  --shadow: rgba(0, 0, 0, 0.3);
  --success: #66bb6a;
  --error: #ef5350;
  --warning: #ffca28;
  --quiz-correct: #1b3a2a;
  --quiz-wrong: #3a1f1f;
  --header-bg: #2a3d35;
  --header-text: #e8ecf0;
  --progress-bg: #3a4255;
  --progress-fill: #6bbf8a;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Sarabun', 'Kanit', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ===== Header ===== */
.header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 12px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: inherit;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-icon {
  background: rgba(255,255,255,0.15);
  border: none;
  color: inherit;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.25);
}

/* ===== Layout ===== */
.app-container {
  display: flex;
  min-height: calc(100vh - 56px);
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  overflow-y: auto;
  position: fixed;
  top: 56px;
  left: 0;
  bottom: 0;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 900;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 850;
  top: 56px;
}

.sidebar-overlay.show {
  display: block;
}

.nav-section {
  margin-bottom: 0.5rem;
}

.nav-section-title {
  padding: 0.6rem 1.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.nav-section-title:hover {
  color: var(--accent);
}

.nav-section-title .chevron {
  transition: transform 0.2s;
}

.nav-section-title.collapsed .chevron {
  transform: rotate(-90deg);
}

.nav-list {
  list-style: none;
}

.nav-list.collapsed {
  display: none;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1.25rem 0.65rem 1.75rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-item a:hover,
.nav-item a.active {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: var(--accent);
}

.nav-item .progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.nav-item .progress-dot.done {
  background: var(--success);
}

.nav-item .progress-dot.in-progress {
  background: var(--warning);
}

/* Main content */
.main-content {
  flex: 1;
  padding: 1.25rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 4px 16px var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

/* ===== Home ===== */
.hero {
  text-align: center;
  padding: 2rem 1rem;
}

.hero h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.hero p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 520px;
  margin: 0 auto 1.5rem;
}

.grade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.grade-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  text-decoration: none;
  color: inherit;
  display: block;
}

.grade-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 20px var(--shadow);
}

.grade-card .grade-num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.grade-card .grade-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.grade-card .grade-progress {
  margin-top: 0.75rem;
  height: 6px;
  background: var(--progress-bg);
  border-radius: 3px;
  overflow: hidden;
}

.grade-card .grade-progress-bar {
  height: 100%;
  background: var(--progress-fill);
  border-radius: 3px;
  transition: width 0.4s;
}

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: 1.5rem 0;
}

.stat-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1.25rem;
  text-align: center;
  min-width: 100px;
}

.stat-item .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-item .stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Lesson ===== */
.lesson-header {
  margin-bottom: 1.5rem;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.lesson-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.lesson-meta {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.lesson-content {
  font-size: 1.05rem;
}

.lesson-content h2 {
  font-size: 1.2rem;
  margin: 1.5rem 0 0.75rem;
  color: var(--accent);
  border-bottom: 2px solid var(--accent-light);
  padding-bottom: 0.35rem;
}

.lesson-content h3 {
  font-size: 1.1rem;
  margin: 1.25rem 0 0.5rem;
}

.lesson-content p {
  margin-bottom: 1rem;
}

.lesson-content ul, .lesson-content ol {
  margin: 0.75rem 0 1rem 1.5rem;
}

.lesson-content li {
  margin-bottom: 0.4rem;
}

.example-box {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: 0 12px 12px 0;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}

.example-box .example-title {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.tip-box {
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin: 1rem 0;
  font-size: 0.95rem;
}

/* ===== Quiz ===== */
.quiz-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.quiz-progress-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.question-card.correct {
  background: var(--quiz-correct);
  border-color: var(--success);
}

.question-card.wrong {
  background: var(--quiz-wrong);
  border-color: var(--error);
}

.question-num {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.question-text {
  font-weight: 600;
  margin-bottom: 1rem;
  font-size: 1.05rem;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-secondary);
}

.option:hover:not(.disabled) {
  border-color: var(--accent);
}

.option.selected {
  border-color: var(--accent);
  background: var(--accent-light);
}

.option.correct-answer {
  border-color: var(--success);
  background: var(--quiz-correct);
}

.option.wrong-answer {
  border-color: var(--error);
  background: var(--quiz-wrong);
}

.option input {
  display: none;
}

.option-label {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.option.selected .option-label {
  background: var(--accent);
  color: white;
}

.option.correct-answer .option-label {
  background: var(--success);
  color: white;
}

.option.wrong-answer .option-label {
  background: var(--error);
  color: white;
}

.explanation {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg-secondary);
  border-radius: 10px;
  font-size: 0.95rem;
  display: none;
}

.explanation.show {
  display: block;
}

.explanation.correct-exp {
  border-left: 3px solid var(--success);
}

.explanation.wrong-exp {
  border-left: 3px solid var(--error);
}

.quiz-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.btn {
  padding: 0.7rem 1.4rem;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.score-result {
  text-align: center;
  padding: 1.5rem;
  margin-top: 1rem;
}

.score-result .score-num {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
}

/* ===== Progress page ===== */
.progress-list {
  list-style: none;
}

.progress-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.progress-item:last-child {
  border-bottom: none;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* ===== Mobile ===== */
@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
  }

  .sidebar-overlay {
    display: none !important;
  }

  .app-container {
    margin-left: 0;
  }

  .main-content {
    padding: 1.75rem 2rem;
  }

  .menu-toggle {
    display: none !important;
  }

  .hero h1 {
    font-size: 2.1rem;
  }
}

@media (max-width: 767px) {
  .main-content {
    padding: 1rem;
  }

  .grade-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Placeholder for empty lessons */
.coming-soon {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
}

.coming-soon .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.6;
}

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

.text-center {
  text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ===== Games ===== */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.game-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
}
.game-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 20px var(--shadow);
}
.game-card .game-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}
.game-card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}
.game-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Visual diagrams in lessons ===== */
.visual-box {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 1.25rem;
  margin: 1.25rem 0;
  text-align: center;
  border: 1px solid var(--border);
}
.visual-box svg {
  max-width: 100%;
  height: auto;
}
.fraction-bar {
  display: flex;
  gap: 2px;
  max-width: 300px;
  margin: 0.75rem auto;
}
.fraction-bar .cell {
  flex: 1;
  height: 36px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.fraction-bar .cell.filled {
  background: var(--accent);
}
.fraction-bar .cell.empty {
  background: var(--bg-card);
}

/* Number line */
.number-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  max-width: 360px;
  margin: 1rem auto;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 0;
  position: relative;
}
.number-line .tick {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  position: relative;
}
.number-line .tick::before {
  content: '';
  display: block;
  width: 2px;
  height: 10px;
  background: var(--accent);
  margin: 0 auto 4px;
}

/* Place value blocks */
.pv-blocks {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin: 1rem 0;
}
.pv-block {
  text-align: center;
}
.pv-block .box {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: white;
  margin-bottom: 0.25rem;
}
.pv-block .label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Assessment grade select */
.assess-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.assess-btn {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 0.75rem;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  transition: all 0.2s;
}
.assess-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

/* Shape options hover */
.shape-opt:hover {
  border-color: var(--accent) !important;
  transform: scale(1.05);
}
