:root {
  --bg: #f8f5f0;
  --bg-card: #ffffff;
  --text: #2c2c2c;
  --text-muted: #5a5a5a;
  --primary: #1a5276;
  --primary-light: #2980b9;
  --accent: #c0392b;
  --border: #e0dcd4;
  --success: #27ae60;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --font: 'Sarabun', 'Kanit', system-ui, sans-serif;
}

/* Eye-care / Dark mode */
[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --text: #e8e8e8;
  --text-muted: #a0a0b0;
  --primary: #5dade2;
  --primary-light: #85c1e9;
  --accent: #e74c3c;
  --border: #2a2a4a;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

[data-theme="soft"] {
  --bg: #f0ebe3;
  --bg-card: #faf7f2;
  --text: #3d3d3d;
  --text-muted: #6b6b6b;
  --primary: #5d4e37;
  --primary-light: #8b7355;
  --accent: #a0522d;
  --border: #d4cfc4;
}

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

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

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

/* Header */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

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

.logo span {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  display: block;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
}

/* Nav */
.nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
}

.nav a {
  padding: 0.4rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s;
}

.nav a:hover, .nav a.active {
  background: var(--primary);
  color: #fff;
}

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

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

.card h2 {
  font-size: 1.25rem;
  color: var(--primary);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary);
}

.card h3 {
  font-size: 1.1rem;
  color: var(--primary);
  margin: 1.25rem 0 0.5rem;
}

.card h4 {
  font-size: 1rem;
  margin: 1rem 0 0.4rem;
  color: var(--text);
}

.card p, .card li {
  margin-bottom: 0.6rem;
  color: var(--text);
}

.card ul, .card ol {
  padding-left: 1.4rem;
  margin-bottom: 0.8rem;
}

.card li {
  margin-bottom: 0.35rem;
}

/* Chapter list */
.chapter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 600px) {
  .chapter-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.chapter-item:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.chapter-num {
  width: 42px;
  height: 42px;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.chapter-item strong {
  display: block;
  font-size: 0.95rem;
}

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

/* Video box */
.video-box {
  background: linear-gradient(135deg, #1a5276, #2980b9);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1rem 0;
  text-align: center;
}

.video-box a {
  color: #fff;
  font-weight: 600;
  text-decoration: underline;
}

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

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

.question-card .q-num {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

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

.options label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.4rem;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}

.options label:hover {
  border-color: var(--primary);
  background: rgba(26, 82, 118, 0.05);
}

.options input {
  margin-top: 0.2rem;
  accent-color: var(--primary);
}

.options label.correct {
  border-color: var(--success);
  background: rgba(39, 174, 96, 0.1);
}

.options label.wrong {
  border-color: var(--accent);
  background: rgba(192, 57, 43, 0.1);
}

.score-box {
  text-align: center;
  padding: 1.5rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 2px solid var(--primary);
  margin: 1.5rem 0;
}

.score-box .score {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
}

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

/* Print */
@media print {
  .header, .nav, .header-actions, .btn, .no-print, .footer, .rest-overlay {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
  }
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }
  a {
    color: #000;
    text-decoration: none;
  }
  .main {
    max-width: 100%;
    padding: 0;
  }
}

/* Utilities */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.highlight {
  background: rgba(41, 128, 185, 0.12);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
}

.tip-box {
  background: rgba(39, 174, 96, 0.1);
  border-left: 4px solid var(--success);
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  border-radius: 0 8px 8px 0;
}

.warning-box {
  background: rgba(192, 57, 43, 0.08);
  border-left: 4px solid var(--accent);
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  border-radius: 0 8px 8px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

th {
  background: var(--primary);
  color: #fff;
}

/* Responsive */
@media (max-width: 480px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* โน้ตเน้นสอบ */
.note-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: #c0392b;
  color: #fff;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  margin-right: 0.35rem;
  vertical-align: middle;
}

.note-list li {
  margin-bottom: 0.45rem;
}

/* ตัวเตือนพัก 30 นาที */
.rest-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(12, 18, 32, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
}

.rest-overlay[hidden] {
  display: none !important;
}

.rest-card {
  width: min(520px, 100%);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 16px;
  padding: 1.25rem 1.2rem 1.1rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  max-height: min(90vh, 640px);
  overflow: auto;
}

.rest-card h2 {
  font-size: 1.15rem;
  margin: 0 0 0.6rem;
  color: var(--primary);
  border: none;
  padding: 0;
}

.dhikr {
  font-size: 1.35rem;
  text-align: center;
  line-height: 1.8;
  margin: 0.4rem 0 0.2rem;
  color: var(--primary);
}

.dhikr-th {
  text-align: center;
  color: var(--text-muted);
  margin: 0 0 0.8rem;
  font-size: 0.92rem;
}

.rest-card .src {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}

.rest-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
