﻿:root {
  --bg: #f6f7fb; --card: #ffffff; --text: #1d2433; --muted: #5b6579; --line: #e3e7f0;
  --brand: #1f3a5f; --brand-2: #2b6cb0;
  --def-bg: #fff8dc; --def-bd: #e0b400;
  --formula-bg: #e8f1ff; --formula-bd: #2b6cb0;
  --note-bg: #eaf7ec; --note-bd: #3fa34d;
  --warn-bg: #fdecea; --warn-bd: #d64545;
  --ex-bg: #f3f0ff; --ex-bd: #6a5acd;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 6px 18px rgba(20, 30, 60, .05);
}
:root[data-theme="dark"] {
  --bg: #12161f; --card: #1a202c; --text: #e6eaf2; --muted: #9aa5ba; --line: #2b3446;
  --brand: #8fb4e8; --brand-2: #7fb0ff;
  --def-bg: #2b2610; --def-bd: #c9a400;
  --formula-bg: #14263f; --formula-bd: #4a86d6;
  --note-bg: #14301b; --note-bd: #3fa34d;
  --warn-bg: #3a1a1a; --warn-bd: #e06060;
  --ex-bg: #221d3d; --ex-bd: #8a7be0;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.65 "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Thanh trên */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--card);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.topbar .in {
  max-width: 980px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--brand); font-size: 18px; }
.crumbs { color: var(--muted); font-size: 14px; flex: 1; min-width: 0; }
.crumbs a { color: var(--muted); }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 14px;
}
.btn:hover { border-color: var(--brand-2); }

main { max-width: 980px; margin: 0 auto; padding: 24px 16px 60px; }
h1 { font-size: 28px; line-height: 1.25; margin: 6px 0 4px; color: var(--brand); }
h2 {
  font-size: 21px; margin: 32px 0 10px; padding-left: 12px;
  border-left: 5px solid var(--brand-2); color: var(--brand);
}
h3 { font-size: 18px; margin: 20px 0 6px; }
main h2[id] { scroll-margin-top: 72px; }

/* Mục thu gọn được (trang bài học) */
.sec > h2 { cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sec > h2::after { content: "▾"; font-size: 18px; color: var(--muted); transition: transform .2s; }
.sec.closed > h2::after { transform: rotate(-90deg); }
.sec > h2:hover { background: var(--formula-bg); border-radius: 0 8px 8px 0; }
.sec > h2:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.sec.closed > .sec-body { display: none; }
.toolbar { margin: 4px 0 0; }
@media print { .sec.closed > .sec-body { display: block; } .sec > h2::after, .toolbar { display: none; } }
.sub { color: var(--muted); margin: 0 0 18px; }
p { margin: 8px 0; }
ul, ol { margin: 8px 0; padding-left: 24px; }
li { margin: 4px 0; }

/* Khối nội dung */
.box { border-radius: 10px; padding: 12px 16px; margin: 14px 0; border-left: 5px solid; }
.box > .t { font-weight: 700; margin-bottom: 4px; display: block; }
.def { background: var(--def-bg); border-color: var(--def-bd); }
.formula { background: var(--formula-bg); border-color: var(--formula-bd); }
.note { background: var(--note-bg); border-color: var(--note-bd); }
.warn { background: var(--warn-bg); border-color: var(--warn-bd); }
.ex { background: var(--ex-bg); border-color: var(--ex-bd); }
.box p:first-of-type { margin-top: 0; }
.box > :last-child { margin-bottom: 0; }
.center { text-align: center; font-size: 19px; margin: 8px 0; }
.sol { margin-left: 4px; color: var(--muted); }
.ok { color: var(--note-bd); font-weight: 600; }

/* Công thức / kí hiệu */
.m { font-family: "Cambria Math", "Times New Roman", serif; font-size: 1.08em; white-space: nowrap; }
.ov { text-decoration: overline; }
.figs { display: flex; flex-wrap: wrap; gap: 14px 22px; justify-content: center; margin: 12px 0; }
.figs figure { margin: 0; text-align: center; font-size: 14px; color: var(--muted); }
.figs svg { width: min(100%, 280px); height: auto; display: block; margin: 0 auto 2px; color: var(--text); }
.figs svg .lbl { font-size: 17px; font-weight: 600; fill: #2b93b8; font-style: italic; stroke: none; }
.figs svg .dim { font-size: 12px; fill: var(--muted); stroke: none; }
.figs svg .fillc { fill: rgba(43, 147, 184, .16); }
.ndiv { text-decoration: line-through; }   /* kí hiệu "không chia hết": ⋮ gạch ngang */
.frac { display: inline-block; vertical-align: middle; text-align: center; line-height: 1.25; margin: 0 2px; }
.frac > span { display: block; padding: 0 4px; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; }
.hl { background: rgba(224, 180, 0, .25); padding: 0 3px; border-radius: 3px; }

/* Bảng */
.tw { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; background: var(--card); min-width: 280px; }
th, td { border: 1px solid var(--line); padding: 6px 12px; text-align: center; }
th { background: var(--formula-bg); }
.tbl-compact td, .tbl-compact th { padding: 4px 10px; }

/* Sơ đồ tư duy */
.mm { margin-top: 10px; }
.mm figure { margin: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; box-shadow: var(--shadow); }
.mm img { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto; }
.mm figcaption { font-size: 13px; color: #5b6579; text-align: right; padding: 4px 6px 0; }

/* Điều hướng bài */
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 36px; flex-wrap: wrap; }
.pager a {
  flex: 1; min-width: 200px; padding: 12px 16px; border: 1px solid var(--line);
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow); color: var(--text);
}
.pager a:hover { border-color: var(--brand-2); text-decoration: none; }
.pager small { display: block; color: var(--muted); }
.pager .next { text-align: right; }

/* Trang mục lục */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow); color: var(--text); display: block;
}
a.card:hover { border-color: var(--brand-2); text-decoration: none; transform: translateY(-1px); }
.card h3 { margin: 0 0 4px; color: var(--brand); }
.card p { margin: 0; color: var(--muted); font-size: 15px; }
.card.soon { opacity: .55; }
.tag { font-size: 12px; background: var(--formula-bg); color: var(--brand); padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.chap { margin: 28px 0 8px; }
.chap h2 { margin-top: 0; }
.lessons { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.lessons li { margin: 0; border-bottom: 1px solid var(--line); }
.lessons li:last-child { border-bottom: 0; }
.lessons a { display: flex; gap: 10px; padding: 10px 14px; color: var(--text); }
.lessons a:hover { background: var(--formula-bg); text-decoration: none; }
.lessons .n { min-width: 64px; color: var(--muted); font-weight: 600; }
.lessons .off { padding: 10px 14px; display: flex; gap: 10px; color: var(--muted); }
.lessons .off .n { min-width: 64px; }

/* Mục lục: chương sổ ra bài, bài sổ ra các mục */
details.chap { margin: 18px 0 8px; }
details.chap > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 2px 4px; border-radius: 8px; }
details.chap > summary::-webkit-details-marker, details.lesson > summary::-webkit-details-marker { display: none; }
details.chap > summary h3 { margin: 6px 0; font-size: 18px; }
details.chap > summary::after, details.lesson > summary::after {
  content: "▾"; margin-left: auto; padding-left: 10px; color: var(--muted); font-size: 18px; transition: transform .2s;
}
details.chap:not([open]) > summary::after, details.lesson:not([open]) > summary::after { transform: rotate(-90deg); }
details.chap > summary:hover { background: var(--formula-bg); }
details.chap > summary:focus-visible, details.lesson > summary:focus-visible { outline: 2px solid var(--brand-2); outline-offset: -2px; }
details.lesson > summary { list-style: none; cursor: pointer; display: flex; align-items: center; padding: 10px 14px; }
details.lesson > summary:hover { background: var(--formula-bg); }
details.lesson > summary .n { min-width: 64px; color: var(--muted); font-weight: 600; margin-right: 10px; }
.lessons li > details.lesson { display: block; }
details.lesson[open] > summary { background: var(--formula-bg); font-weight: 600; }
.lesson-body { position: relative; padding: 8px 14px 14px; background: var(--bg); border-top: 1px dashed var(--line); }
.lesson-body iframe { display: block; width: 100%; height: 320px; border: 0; background: transparent; }
.lesson-body .open-full { display: inline-block; padding: 2px 0 6px; font-size: 14px; color: var(--brand-2); }

/* Trang bài khi được nhúng trong mục lục */
html.embed body { background: transparent; }
html.embed .topbar, html.embed footer, html.embed .pager, html.embed main > h1, html.embed main > .sub { display: none; }
html.embed main { padding: 0 2px 8px; max-width: none; }
html.embed main h2:first-of-type, html.embed .sec:first-of-type > h2 { margin-top: 6px; }

/* Trang chủ: chọn lớp, lọc môn, lưới bìa sách */
.home { max-width: 1180px; }
.grades-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.grades-row .lbl { font-size: 22px; font-weight: 600; color: var(--muted); margin-right: 6px; }
/* Máy tính: 13 nút (Tất cả + lớp 1–12) chia đều hết chiều rộng hàng; điện thoại: xếp 2 dòng */
.grades { flex: 1; min-width: 0; display: grid; grid-template-columns: 1.7fr repeat(12, 1fr); gap: 10px; }
.grades .pill { min-width: 0; width: 100%; padding: 0; }
.pill { min-width: 46px; height: 46px; padding: 0 16px; border-radius: 14px; border: 2px solid transparent; font: inherit; font-size: 17px; font-weight: 700; cursor: pointer; }
.pill.all { background: #ece6ff; color: #6741d9; }
.pill.th { background: #ffe3d6; color: #e8590c; }
.pill.thcs { background: #d3f9e3; color: #0b7a56; }
.pill.thpt { background: #dbe4ff; color: #3b5bdb; }
.pill:hover { filter: brightness(.97); }
.pill.on { border-color: #5c4de5; box-shadow: 0 0 0 2px var(--card), 0 0 0 4px #5c4de5; }
:root[data-theme="dark"] .pill.all { background: #2e2650; color: #c4b5fd; }
:root[data-theme="dark"] .pill.th { background: #4a2a1b; color: #ffa06b; }
:root[data-theme="dark"] .pill.thcs { background: #12372b; color: #6ee7b7; }
:root[data-theme="dark"] .pill.thpt { background: #1f2a55; color: #a5b4fc; }
.home-layout { display: grid; grid-template-columns: 250px 1fr; gap: 24px; margin-top: 20px; align-items: start; }
.filter { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); position: sticky; top: 76px; }
.filter h2 { margin: 0; padding: 12px 16px; font-size: 17px; border: 0; border-bottom: 1px solid var(--line); color: var(--text); }
.filter .subjects { max-height: 60vh; overflow: auto; padding: 8px 6px; }
.chk { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; }
.chk:hover { background: var(--formula-bg); }
.chk input { width: 18px; height: 18px; accent-color: #5c4de5; }
.chk.none { color: var(--muted); font-weight: 500; cursor: default; }
.chk.none:hover { background: transparent; }
.chk em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); }
.filter .btn { margin: 4px 12px 12px; }
.count { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 18px; }
.book { position: relative; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); color: var(--text); }
a.book:hover { border-color: #5c4de5; transform: translateY(-2px); text-decoration: none; }
.book img { display: block; width: 100%; height: auto; aspect-ratio: 320 / 450; object-fit: cover; background: var(--line); }
.book .bt { padding: 10px 12px 12px; text-align: center; font-weight: 700; font-size: 15px; }
.book.off img { filter: grayscale(.6); opacity: .65; }
.book.off .bt { color: var(--muted); }
.book .soon { position: absolute; top: 10px; right: 10px; background: rgba(31, 58, 95, .88); color: #fff; font-size: 12px; padding: 3px 9px; border-radius: 999px; }
.empty { grid-column: 1 / -1; color: var(--muted); padding: 24px 4px; }
@media (max-width: 760px) {
  .home-layout { grid-template-columns: 1fr; }
  .filter { position: static; }
  .filter .subjects { max-height: none; display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; }   /* 2 cột thẳng hàng */
  .chk { padding: 8px 8px; gap: 8px; font-size: 14px; align-items: flex-start; }
  .chk input { flex: none; margin-top: 2px; }
  .grades-row .lbl { width: 100%; font-size: 18px; }
  .grades { flex-basis: 100%; grid-template-columns: repeat(7, 1fr); gap: 8px; }   /* dòng 1: Tất cả + lớp 1–6; dòng 2: lớp 7–12 */
  .grades .pill { height: 42px; font-size: 16px; }
  .grades .pill.all { font-size: 13px; }
}

.search { width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; margin: 6px 0 4px; }
.hidden { display: none !important; }

footer { text-align: center; color: var(--muted); font-size: 13px; padding: 20px; }

@media (max-width: 600px) {
  body { font-size: 16px; }
  h1 { font-size: 23px; }
  .crumbs { order: 3; flex-basis: 100%; }
}
@media print {
  .topbar, .pager, .btn, footer { display: none; }
  body { background: #fff; color: #000; }
}

/* Logo trên thanh đầu trang */
.brand { display: inline-flex; align-items: center; line-height: 0; }
.brand .lg { height: 34px; width: auto; display: block; }
.brand .dk { display: none; }
:root[data-theme="dark"] .brand .lt { display: none; }
:root[data-theme="dark"] .brand .dk { display: block; }
@media (max-width: 560px) { .brand .lg { height: 28px; } }

/* Bảng biến thiên (Toán 12) */
.bbt { margin: 0 auto; text-align: center; }
.bbt th { text-align: center; border-right: 2px solid var(--text); font-style: italic; }
.bbt td { min-width: 34px; padding: 4px 8px; }
.bbt td.ar { font-size: 20px; line-height: 1; }
.bbt tr:nth-child(1), .bbt tr:nth-child(2) { border-bottom: 1px solid var(--line); }

/* Vectơ: mũi tên phía trên chữ */
.vec { position: relative; display: inline-block; padding: 0 1px; }
.vec::before { content: "\2192"; position: absolute; left: 0; right: 0; top: -0.78em; text-align: center; font-size: .72em; font-style: normal; line-height: 1; }

/* Biến cố đối: gạch ngang trên */
.ov { text-decoration: overline; text-decoration-thickness: 1px; }
