/* Shell chung cho toàn bộ tài liệu học — 1 theme tối, không toggle. */
:root {
  --bg: #0e1117;
  --bg-soft: #161b24;
  --bg-code: #0a0d13;
  --line: #232a36;
  --fg: #d7dde7;
  --fg-dim: #8a94a6;
  --accent: #4da3ff;
  --accent-soft: rgba(77, 163, 255, .14);
  --good: #46d18a;
  --warn: #f0b429;
  --bad: #ff6b6b;
  --radius: 10px;
  --sidebar: 290px;
  --font: -apple-system, "Segoe UI", Roboto, "Noto Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 24px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.75 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- thanh tiến độ đọc ---------- */
#progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--good));
  z-index: 60; transition: width .1s linear;
}

/* ---------- bố cục ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); gap: 0; }

#toc {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  padding: 28px 18px 60px;
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
}
#toc .home {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--fg-dim); text-decoration: none; font-size: 13px;
  margin-bottom: 18px;
}
#toc .home:hover { color: var(--accent); }
#toc .label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-dim); margin: 0 0 10px; }
#toc a.item {
  display: block; padding: 5px 10px; margin: 1px 0;
  color: var(--fg-dim); text-decoration: none; font-size: 13.5px;
  border-left: 2px solid transparent; border-radius: 0 6px 6px 0;
  transition: color .15s, background .15s, border-color .15s;
}
#toc a.item.lvl3 { padding-left: 24px; font-size: 12.5px; }
#toc a.item:hover { color: var(--fg); background: var(--accent-soft); }
#toc a.item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }

main { padding: 48px 56px 140px; max-width: 900px; margin-inline: auto; }

/* ---------- chữ ---------- */
h1 { font-size: 34px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -.02em; }
h2 {
  font-size: 24px; margin: 56px 0 14px; padding-top: 18px;
  border-top: 1px solid var(--line); letter-spacing: -.01em;
}
h3 { font-size: 18.5px; margin: 34px 0 10px; color: #eaf0f8; }
h4 { font-size: 16px; margin: 24px 0 8px; color: var(--fg-dim); text-transform: none; }
h5 { font-size: 13px; margin: 22px 0 6px; color: var(--fg-dim); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
p, li { color: var(--fg); }
a { color: var(--accent); }
strong { color: #fff; }
hr { border: 0; border-top: 1px solid var(--line); margin: 40px 0; }

ul, ol { padding-left: 22px; }
li { margin: 5px 0; }
li::marker { color: var(--accent); }

/* ---------- code ---------- */
code {
  font: 13.5px/1.6 var(--mono);
  background: var(--bg-code); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px; color: #ffd9a0;
}
pre {
  position: relative;
  background: var(--bg-code); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; overflow-x: auto;
  margin: 18px 0;
}
pre code { background: none; border: 0; padding: 0; color: #cfe3ff; }
.copy {
  position: absolute; top: 8px; right: 8px;
  background: var(--bg-soft); color: var(--fg-dim);
  border: 1px solid var(--line); border-radius: 6px;
  font: 11px var(--font); padding: 3px 9px; cursor: pointer;
  opacity: 0; transition: opacity .15s, color .15s;
}
pre:hover .copy { opacity: 1; }
.copy:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- bảng ---------- */
.table-wrap { overflow-x: auto; margin: 20px 0; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg-soft); color: #fff; font-weight: 600; white-space: nowrap; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- blockquote thành callout ---------- */
blockquote {
  margin: 20px 0; padding: 12px 18px;
  border-left: 3px solid var(--warn);
  background: rgba(240, 180, 41, .07);
  border-radius: 0 var(--radius) var(--radius) 0;
}
blockquote p { margin: 6px 0; }

/* ---------- diagram ---------- */
.mermaid {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin: 24px 0;
  text-align: center; overflow-x: auto;
  font: 14px/1.5 var(--font);
}
.mermaid svg { max-width: 100%; height: auto; overflow: visible; }
/* vẽ đường nối dần khi diagram lọt vào màn hình */
.mermaid.draw .edgePath path, .mermaid.draw path.flowchart-link, .mermaid.draw .messageLine0 {
  stroke-dasharray: 1000; stroke-dashoffset: 1000;
  animation: draw 1.4s ease-out forwards;
}
.mermaid.draw .node, .mermaid.draw .actor, .mermaid.draw .label {
  animation: pop .5s ease-out backwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* ---------- hiện dần khi cuộn ---------- */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .5s ease, transform .5s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal, .reveal.in { opacity: 1; transform: none; transition: none; }
  .mermaid.draw * { animation: none !important; stroke-dashoffset: 0 !important; }
  html { scroll-behavior: auto; }
}

/* ---------- trang chủ ---------- */
.hero { padding: 70px 56px 30px; max-width: 1500px; margin-inline: auto; }
.hero h1 { font-size: 40px; }
.hero p { color: var(--fg-dim); max-width: 62ch; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 16px; padding: 20px 56px 120px; max-width: 1500px; margin-inline: auto; }
.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.card .tag { font: 11px var(--mono); color: var(--accent); letter-spacing: .1em; text-transform: uppercase; }
.card h3 { margin: 8px 0 6px; font-size: 17px; color: #fff; }
.card p { margin: 0; font-size: 14px; color: var(--fg-dim); line-height: 1.6; }

/* ---------- nút lên đầu trang ---------- */
#top {
  position: fixed; right: 24px; bottom: 24px; z-index: 50;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-soft); color: var(--fg); border: 1px solid var(--line);
  cursor: pointer; font-size: 16px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#top.show { opacity: 1; pointer-events: auto; }
#top:hover { transform: translateY(-2px); border-color: var(--accent); color: var(--accent); }

/* ---------- mobile ---------- */
#toc-toggle { display: none; }
@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  #toc {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 70;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  #toc.open { transform: none; }
  #toc-toggle {
    display: block; position: fixed; top: 12px; left: 12px; z-index: 80;
    background: var(--bg-soft); color: var(--fg); border: 1px solid var(--line);
    border-radius: 8px; padding: 7px 11px; cursor: pointer; font-size: 15px;
  }
  main { padding: 64px 20px 120px; }
  .hero, .cards { padding-left: 20px; padding-right: 20px; }
  .cards { grid-template-columns: 1fr; }
}

/* ---------- breadcrumb trên trang chi tiết ---------- */
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 0 0 18px; font-size: 13px; color: var(--fg-dim);
}
.crumbs a { color: var(--fg-dim); text-decoration: none; border-bottom: 1px solid transparent; }
.crumbs a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.crumbs > * + *::before { content: "/"; margin-right: 8px; color: var(--line); }
.crumbs [aria-current] { color: var(--fg); }

/* ---------- card nhóm ở trang chủ ---------- */
.group-card { border-left: 3px solid var(--accent); }
.group-card h3 { font-size: 19px; }
.group-card::after { content: "Xem danh sách \2192"; display: block; margin-top: 12px; font: 12px var(--mono); color: var(--accent); }

/* breadcrumb khi nằm trong .hero của trang nhóm */
.hero .crumbs { margin-bottom: 10px; }
