/* วิทยาศาสตร์ประถม - Eye-friendly Design + Day/Night Mode */
:root {
  /* Day Mode - Soft, eye-friendly */
  --bg-primary: #f7f5f0;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-soft: #eef6f0;
  --text-primary: #2c3e50;
  --text-secondary: #5a6a7a;
  --text-muted: #7f8c8d;
  --accent: #27ae60;
  --accent-hover: #219a52;
  --accent-soft: #d5f5e3;
  --border: #e0e6ed;
  --shadow: 0 4px 20px rgba(0,0,0,0.06);
  --shadow-hover: 0 8px 30px rgba(0,0,0,0.1);
  --success: #27ae60;
  --danger: #e74c3c;
  --warning: #f39c12;
  --info: #3498db;
  --nav-bg: #ffffff;
  --quiz-correct: #d4edda;
  --quiz-wrong: #f8d7da;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Sarabun', 'Kanit', system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg-primary: #1a1f2e;
  --bg-secondary: #242b3d;
  --bg-card: #2a3142;
  --bg-soft: #1e2535;
  --text-primary: #e8ecf1;
  --text-secondary: #a8b3c4;
  --text-muted: #7a8699;
  --accent: #2ecc71;
  --accent-hover: #27ae60;
  --accent-soft: #1a3d2e;
  --border: #3a4558;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --shadow-hover: 0 8px 30px rgba(0,0,0,0.4);
  --nav-bg: #242b3d;
  --quiz-correct: #1e3a2f;
  --quiz-wrong: #3d1f1f;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* Typography */
h1, h2, h3, h4, h5 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

h1 { font-size: 1.8rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

p { margin-bottom: 1rem; color: var(--text-secondary); }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}
a:hover { color: var(--accent-hover); }

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Navbar */
.navbar {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-primary);
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #27ae60, #2ecc71);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.3rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1.2rem;
}

.btn-icon:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Mobile Menu */
.menu-toggle {
  display: none;
}

.nav-links {
  display: flex;
  gap: 6px;
  list-style: none;
}

.nav-links a {
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
}

.nav-links a:hover,
.nav-links a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

/* Grade Cards */
.grade-card {
  text-align: center;
  padding: 28px 20px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.grade-card .grade-num {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.grade-card .grade-label {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.grade-card .grade-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.grade-card.completed::after {
  content: '✓';
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--success);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

/* Topic Cards */
.topic-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  cursor: pointer;
}

.topic-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.topic-info h3 {
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.topic-info p {
  font-size: 0.88rem;
  margin: 0;
  color: var(--text-muted);
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #2ecc71);
  border-radius: 3px;
  transition: width 0.4s;
}

/* Lesson Content */
.lesson-header {
  background: linear-gradient(135deg, var(--accent), #2ecc71);
  color: white;
  padding: 32px 20px;
  border-radius: 0 0 var(--radius) var(--radius);
  margin-bottom: 24px;
}

.lesson-header h1 {
  color: white;
  margin-bottom: 8px;
}

.lesson-header p {
  color: rgba(255,255,255,0.9);
  margin: 0;
}

.lesson-body {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

.lesson-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
}

.lesson-section h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent-soft);
}

.example-box {
  background: var(--bg-soft);
  border-left: 4px solid var(--accent);
  padding: 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 16px 0;
}

.example-box h4 {
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 1rem;
}

.img-placeholder {
  width: 100%;
  max-width: 400px;
  height: 200px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  margin: 16px auto;
  border: 2px dashed var(--border);
}

/* Quiz */
.quiz-container {
  max-width: 700px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.quiz-question {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 16px;
}

.quiz-question h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-secondary);
}

.quiz-option:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

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

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

.quiz-option input {
  display: none;
}

.option-letter {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}

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

.explanation {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  display: none;
}

.explanation.show {
  display: block;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

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

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

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1.1rem;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.stat-card {
  text-align: center;
  padding: 20px 12px;
}

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

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Certificate */
.certificate {
  background: white;
  color: #2c3e50;
  max-width: 800px;
  margin: 20px auto;
  padding: 40px;
  border: 8px double #27ae60;
  border-radius: 8px;
  text-align: center;
  position: relative;
}

.certificate h1 {
  color: #27ae60;
  font-size: 2rem;
  margin-bottom: 8px;
}

.certificate .score {
  font-size: 3rem;
  font-weight: 700;
  color: #27ae60;
  margin: 20px 0;
}

/* Games */
.game-card {
  text-align: center;
  padding: 24px;
}

.game-card .game-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 16px 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--text-secondary);
}

.breadcrumb span {
  color: var(--text-muted);
}

/* Hero */
.hero {
  text-align: center;
  padding: 40px 16px 30px;
}

.hero h1 {
  font-size: 1.9rem;
  margin-bottom: 12px;
}

.hero p {
  font-size: 1.05rem;
  max-width: 600px;
  margin: 0 auto 24px;
}

/* Responsive */
@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    flex-direction: column;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    padding: 12px 16px;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.3rem; }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .lesson-header {
    padding: 24px 16px;
  }

  .certificate {
    padding: 24px 16px;
    margin: 12px;
  }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.4s ease;
}

/* True/False specific */
.tf-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tf-options .quiz-option {
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* Badge */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-success {
  background: #d4edda;
  color: #155724;
}

[data-theme="dark"] .badge-success {
  background: #1e3a2f;
  color: #2ecc71;
}
