/* ============================================================
   XSTK — Xác suất & Thống kê: từ Zero đến AI & Lượng tử
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f6f7fb;
  --paper: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --accent-soft: #eef2ff;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --cyan: #06b6d4;
  --side-bg: #141b2d;
  --side-bg2: #1c2540;
  --side-ink: #cbd5e1;
}

html { scroll-behavior: smooth; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
}

#app { display: flex; min-height: 100vh; }

/* ---------------- Sidebar ---------------- */
#sidebar {
  width: 320px;
  min-width: 320px;
  background: linear-gradient(180deg, var(--side-bg), var(--side-bg2));
  color: var(--side-ink);
  height: 100vh;
  overflow-y: auto;
  position: sticky;
  top: 0;
  padding: 18px 14px 40px;
  scrollbar-width: thin;
  scrollbar-color: #3b4663 transparent;
  z-index: 50;
}

.side-head a {
  display: block;
  color: #fff;
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 8px 10px 2px;
}
.side-head .tagline {
  display: block;
  font-size: 0.78rem;
  font-weight: 400;
  color: #8b96b3;
  padding: 0 10px 12px;
}

.side-links { border-bottom: 1px solid #2a344f; margin-bottom: 10px; padding-bottom: 10px; }
.side-links a {
  display: block;
  color: var(--side-ink);
  text-decoration: none;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.93rem;
}
.side-links a:hover { background: #232e4d; color: #fff; }

.phan-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7c89ab;
  margin: 18px 10px 6px;
  font-weight: 700;
}

details.mod { margin: 2px 0; border-radius: 10px; }
details.mod[open] { background: #1a2340; }
details.mod summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.93rem;
  font-weight: 600;
  color: #dbe2f0;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
details.mod summary::-webkit-details-marker { display: none; }
details.mod summary:hover { background: #232e4d; }
details.mod summary .mod-prog {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: #8b96b3;
  background: #101728;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
details.mod summary .mod-prog.full { color: #34d399; }

.lesson-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: #9aa7c7;
  text-decoration: none;
  font-size: 0.88rem;
  padding: 6px 10px 6px 16px;
  border-radius: 8px;
  margin: 1px 4px;
}
.lesson-link:hover { background: #232e4d; color: #fff; }
.lesson-link.active { background: linear-gradient(90deg, #4338ca, #6d28d9); color: #fff; }
.lesson-link .tick { font-size: 0.8rem; width: 1em; flex: none; }
.lesson-link.done .tick { color: #34d399; }

/* ---------------- Main content ---------------- */
#content { flex: 1; min-width: 0; padding: 34px 44px 90px; }
.page { max-width: 880px; margin: 0 auto; }

#menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 42px;
  height: 42px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

.crumbs { font-size: 0.85rem; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

.est-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 12px;
  margin-bottom: 6px;
}

/* Typography in lesson body */
.lesson-body h1, .page > h1 { font-size: 1.9rem; line-height: 1.3; margin: 4px 0 18px; }
.lesson-body h2 {
  font-size: 1.35rem;
  margin: 34px 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent-soft);
}
.lesson-body h3 { font-size: 1.12rem; margin: 24px 0 8px; }
.lesson-body p { margin: 12px 0; }
.lesson-body ul, .lesson-body ol { margin: 12px 0 12px 26px; }
.lesson-body li { margin: 6px 0; }
.lesson-body strong { color: #111827; }
.lesson-body code {
  background: #eef0f6;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9em;
  color: #4338ca;
}
.lesson-body pre {
  background: #10162b;
  color: #dbe4ff;
  padding: 14px 18px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 14px 0;
}
.lesson-body pre code { background: none; color: inherit; padding: 0; }

.term { font-weight: 700; color: var(--accent); }

/* Tables */
.lesson-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-size: 0.93rem;
  background: var(--paper);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(15,23,42,0.07);
}
.lesson-body th, .lesson-body td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
}
.lesson-body th { background: var(--accent-soft); color: #3730a3; }
.table-scroll { overflow-x: auto; }

/* Formulas */
.formula {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 16px 0;
  text-align: center;
  font-size: 1.13rem;
  overflow-x: auto;
  font-family: Georgia, "Times New Roman", serif;
}
.frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  margin: 0 3px;
  line-height: 1.25;
  font-size: 0.94em;
}
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 5px; }
.frac > span:last-child { padding: 0 5px; }

/* Callout boxes */
.box {
  border-radius: 12px;
  padding: 14px 18px 14px;
  margin: 18px 0;
  border: 1px solid var(--line);
  border-left-width: 5px;
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(15,23,42,0.05);
}
.box::before {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.box > p:first-of-type { margin-top: 4px; }
.box.def      { border-left-color: #3b82f6; background: #f5f9ff; }
.box.def::before      { content: "📖 Định nghĩa"; color: #1d4ed8; }
.box.tip      { border-left-color: var(--green); background: #f2fbf7; }
.box.tip::before      { content: "💡 Trực giác & mẹo nhớ"; color: #047857; }
.box.warn     { border-left-color: var(--amber); background: #fffaf0; }
.box.warn::before     { content: "⚠️ Cẩn thận nhầm lẫn"; color: #b45309; }
.box.ai       { border-left-color: var(--accent2); background: #faf7ff; }
.box.ai::before       { content: "🤖 Liên hệ AI / Machine Learning"; color: #6d28d9; }
.box.quantum  { border-left-color: var(--cyan); background: #f0fbfe; }
.box.quantum::before  { content: "⚛️ Liên hệ lượng tử"; color: #0e7490; }
.box.example  { border-left-color: #64748b; background: #f8fafc; }
.box.example::before  { content: "📝 Ví dụ cụ thể"; color: #334155; }

/* ---------------- Simulation (Lab) ---------------- */
.sim-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 26px 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(15,23,42,0.07);
}
.sim-head {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
  font-weight: 700;
  padding: 10px 18px;
  font-size: 1rem;
}
.sim-desc { padding: 10px 18px 0; color: var(--muted); font-size: 0.92rem; }
.sim-area { padding: 16px 18px 20px; }
.sim-area canvas {
  display: block;
  max-width: 100%;
  margin: 10px auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}
.sim-controls label { font-size: 0.88rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sim-stat {
  display: inline-block;
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 0.9rem;
  margin: 3px 4px 3px 0;
}
.sim-stat b { color: var(--accent); }
.sim-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.9rem;
}

.btn {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 8px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s, box-shadow 0.15s;
}
.btn:hover { box-shadow: 0 4px 14px rgba(99,102,241,0.35); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }
.btn.secondary:hover { background: var(--accent-soft); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

input[type="range"] { accent-color: var(--accent); }
select, input[type="number"], input[type="text"] {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

/* ---------------- Quiz ---------------- */
.quiz-section { margin-top: 40px; }
.quiz-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 4px;
  padding-top: 18px;
  border-top: 2px dashed var(--line);
}
.quiz-sub { color: var(--muted); font-size: 0.92rem; margin-bottom: 18px; }

.quiz-q {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  margin: 16px 0;
  box-shadow: 0 1px 4px rgba(15,23,42,0.06);
}
.quiz-q .q-text { font-weight: 600; margin-bottom: 12px; }
.quiz-q .q-num { color: var(--accent); font-weight: 800; margin-right: 6px; }

.quiz-opt {
  display: block;
  width: 100%;
  text-align: left;
  background: #f9fafb;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
  transition: border-color 0.12s, background 0.12s;
  line-height: 1.5;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.correct { border-color: var(--green); background: #ecfdf5; color: #065f46; font-weight: 600; }
.quiz-opt.wrong { border-color: var(--red); background: #fef2f2; color: #991b1b; }

.quiz-explain {
  margin-top: 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
}
.quiz-explain b { color: #92400e; }

.quiz-result {
  background: linear-gradient(120deg, #eef2ff, #f5f3ff);
  border: 1px solid #c7d2fe;
  border-radius: 14px;
  padding: 20px 24px;
  margin: 22px 0;
  text-align: center;
}
.quiz-result .score { font-size: 2rem; font-weight: 800; color: var(--accent); }
.quiz-result p { margin: 6px 0 12px; }

/* ---------------- Lesson nav ---------------- */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.lesson-nav a {
  text-decoration: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.93rem;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 12px 18px;
  border-radius: 12px;
  max-width: 48%;
}
.lesson-nav a:hover { border-color: var(--accent); background: var(--accent-soft); }
.lesson-nav a span { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 400; }
.lesson-nav .next { margin-left: auto; text-align: right; }

/* ---------------- Home ---------------- */
.hero {
  background:
    radial-gradient(1000px 400px at 90% -20%, rgba(139,92,246,0.55), transparent 60%),
    radial-gradient(700px 380px at -10% 120%, rgba(6,182,212,0.35), transparent 55%),
    linear-gradient(120deg, #1e1b4b, #312e81);
  color: #fff;
  border-radius: 20px;
  padding: 44px 40px;
  margin-bottom: 30px;
}
.hero h1 { font-size: 2.1rem; line-height: 1.25; margin-bottom: 12px; }
.hero p { color: #c7d2fe; max-width: 620px; font-size: 1.02rem; }
.hero .cta-row { margin-top: 22px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.cta-btn {
  display: inline-block;
  background: #fff;
  color: #4338ca;
  font-weight: 700;
  text-decoration: none;
  padding: 12px 26px;
  border-radius: 12px;
  font-size: 1rem;
}
.cta-btn:hover { background: #e0e7ff; }
.hero .overall { color: #a5b4fc; font-size: 0.92rem; }

.phan-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.phan-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: 0 1px 4px rgba(15,23,42,0.05);
}
.phan-card h2 { font-size: 1.2rem; margin-bottom: 2px; }
.phan-card .phan-desc { color: var(--muted); font-size: 0.92rem; margin-bottom: 12px; }
.prog-bar { background: #edf0f7; border-radius: 999px; height: 9px; overflow: hidden; margin: 8px 0 14px; }
.prog-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; transition: width 0.4s; }
.mod-row {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.94rem;
}
.mod-row:hover { background: var(--accent-soft); }
.mod-row .mod-icon { font-size: 1.15rem; width: 1.5em; text-align: center; flex: none; }
.mod-row .mod-name { font-weight: 600; }
.mod-row .mod-sub { color: var(--muted); font-size: 0.8rem; display: block; font-weight: 400; }
.mod-row .mod-count { margin-left: auto; font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.mod-row .mod-count.full { color: var(--green); font-weight: 700; }

/* ---------------- Glossary ---------------- */
.gloss-search { width: 100%; padding: 12px 16px; font-size: 1rem; margin: 14px 0 20px; }
.gloss-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  margin: 10px 0;
}
.gloss-item .g-term { font-weight: 700; color: var(--accent); }
.gloss-item .g-en { color: var(--muted); font-style: italic; font-size: 0.88rem; margin-left: 6px; }
.gloss-item .g-def { font-size: 0.94rem; margin-top: 4px; }

/* ---------------- Bài tập tự luyện + details ---------------- */
.box.practice { border-left-color: #14b8a6; background: #f0fdfa; }
.box.practice::before { content: "🏋️ Bài tập tự luyện"; color: #0f766e; }
.lesson-body details {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  margin: 10px 0;
  background: rgba(99, 102, 241, 0.04);
}
.lesson-body details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  user-select: none;
}
.lesson-body details[open] summary { margin-bottom: 8px; }

/* ---------------- Dark mode ---------------- */
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="dark"] body {
  --bg: #0e1320;
  --paper: #1a2234;
  --ink: #dbe2f0;
  --muted: #93a1bd;
  --line: #2b3650;
  --accent: #818cf8;
  --accent2: #a78bfa;
  --accent-soft: #232c4e;
}
html[data-theme="dark"] .lesson-body strong { color: #f1f5f9; }
html[data-theme="dark"] .lesson-body code { background: #252d45; color: #a5b4fc; }
html[data-theme="dark"] .lesson-body th { background: var(--accent-soft); color: #c7d2fe; }
html[data-theme="dark"] .formula { background: #141b2e; }
html[data-theme="dark"] .box { box-shadow: none; }
html[data-theme="dark"] .box.def      { background: #16233b; }
html[data-theme="dark"] .box.def::before      { color: #93c5fd; }
html[data-theme="dark"] .box.tip      { background: #122b22; }
html[data-theme="dark"] .box.tip::before      { color: #6ee7b7; }
html[data-theme="dark"] .box.warn     { background: #2b2113; }
html[data-theme="dark"] .box.warn::before     { color: #fcd34d; }
html[data-theme="dark"] .box.ai       { background: #241b38; }
html[data-theme="dark"] .box.ai::before       { color: #c4b5fd; }
html[data-theme="dark"] .box.quantum  { background: #0e2a33; }
html[data-theme="dark"] .box.quantum::before  { color: #67e8f9; }
html[data-theme="dark"] .box.example  { background: #1c2432; }
html[data-theme="dark"] .box.example::before  { color: #cbd5e1; }
html[data-theme="dark"] .box.practice { background: #102a26; }
html[data-theme="dark"] .box.practice::before { color: #5eead4; }
html[data-theme="dark"] .btn.secondary { background: var(--paper); }
html[data-theme="dark"] select,
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="text"] { background: var(--paper); color: var(--ink); }
html[data-theme="dark"] .quiz-opt { background: #202942; }
html[data-theme="dark"] .quiz-opt:hover:not(:disabled) { background: var(--accent-soft); }
html[data-theme="dark"] .quiz-opt.correct { background: #132e21; color: #6ee7b7; }
html[data-theme="dark"] .quiz-opt.wrong { background: #331a1c; color: #fca5a5; }
html[data-theme="dark"] .quiz-explain { background: #2a2410; border-color: #574a1a; }
html[data-theme="dark"] .quiz-explain b { color: #fcd34d; }
html[data-theme="dark"] .quiz-result { background: linear-gradient(120deg, #1e2445, #241e3f); border-color: #3b4680; }
html[data-theme="dark"] .prog-bar { background: #232c44; }
html[data-theme="dark"] .sim-error { background: #331a1c; border-color: #7f1d1d; color: #fca5a5; }
html[data-theme="dark"] .lesson-body details { background: rgba(129, 140, 248, 0.07); }
html[data-theme="dark"] .lesson-body table,
html[data-theme="dark"] .quiz-q,
html[data-theme="dark"] .phan-card,
html[data-theme="dark"] .sim-wrap { box-shadow: none; }
/* canvas giữ nền trắng như "tờ giấy thí nghiệm" để 34 sim luôn dễ đọc */
html[data-theme="dark"] .sim-area canvas { background: #fff; }

/* ---------------- Responsive ---------------- */
@media (max-width: 920px) {
  #menu-toggle { display: block; }
  #sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.4);
  }
  #sidebar.open { transform: translateX(0); }
  #content { padding: 66px 18px 70px; }
  .hero { padding: 30px 22px; }
  .hero h1 { font-size: 1.55rem; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav a { max-width: 100%; }
  .lesson-nav .next { margin-left: 0; }
}
