:root {
  --bg: #fafaf8; --card: #ffffff; --text: #22221f; --muted: #6b6a64; --line: #c9c7bd;
  --root-bg: #2c2c2a; --root-text: #ffffff;
  --mod-bg: #eeedfe; --mod-line: #7f77dd; --mod-text: #3c3489;
  --topic-bg: #ffffff; --topic-line: #d3d1c7;
  --tag-bg: #e1f5ee; --tag-text: #085041;
  --todo-bg: #f1efe8; --todo-text: #5f5e5a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a; --card: #262624; --text: #ecebe6; --muted: #a3a29b; --line: #55544f;
    --root-bg: #ecebe6; --root-text: #1c1c1a;
    --mod-bg: #3c3489; --mod-line: #afa9ec; --mod-text: #eeedfe;
    --topic-bg: #262624; --topic-line: #44443f;
    --tag-bg: #085041; --tag-text: #e1f5ee;
    --todo-bg: #33332f; --todo-text: #b4b2a9;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; }
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; padding: 24px 28px 8px; }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--topic-line); border-radius: 8px; padding: 6px 12px; font-size: 13px; color: var(--muted); }
.stat b { color: var(--text); font-size: 16px; margin-right: 4px; }
main { padding: 8px 28px 40px; display: grid; gap: 28px; }

.tree-wrap { overflow-x: auto; padding-bottom: 8px; }
.tree ul { list-style: none; margin: 0; padding: 0 0 0 24px; display: flex; flex-direction: column; position: relative; }
.tree li { display: flex; align-items: center; position: relative; padding: 6px 0 6px 24px; }
.tree li::before { content: ""; position: absolute; left: 0; top: 50%; width: 24px; border-top: 1.5px solid var(--line); }
.tree li::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; border-left: 1.5px solid var(--line); }
.tree li:first-child::after { top: 50%; }
.tree li:last-child::after { bottom: 50%; }
.tree li:only-child::after { display: none; }
.tree li > ul::before { content: ""; position: absolute; left: 0; top: 50%; width: 24px; border-top: 1.5px solid var(--line); }
.tree > ul { padding-left: 0; }
.tree > ul > li { padding-left: 0; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }

.node { border-radius: 10px; padding: 10px 14px; flex-shrink: 0; }
.node.root { background: var(--root-bg); color: var(--root-text); font-weight: 600; font-size: 16px; }
.node.module { background: var(--mod-bg); border: 1px solid var(--mod-line); color: var(--mod-text); max-width: 240px; }
.node.module .en { font-weight: 600; font-size: 14px; }
.node.module .vi { font-size: 12.5px; opacity: .85; }
.node.topic { background: var(--topic-bg); border: 1px solid var(--topic-line); width: 330px; }
.node.topic .t { font-weight: 600; font-size: 14px; }
.node.topic .t small { font-weight: 400; color: var(--muted); }
.node.topic ul.points { list-style: disc; display: block; padding: 4px 0 0 18px; margin: 0; }
.node.topic ul.points li { display: list-item; padding: 1px 0; font-size: 13px; }
.node.topic ul.points li::before, .node.topic ul.points li::after { display: none; }
.node.topic ul.points li.acc { list-style: none; margin-left: -18px; }
.node.topic details summary { cursor: pointer; list-style: none; position: relative; padding-left: 18px; }
.node.topic details summary::-webkit-details-marker { display: none; }
.node.topic details summary::before { content: ""; position: absolute; left: 3px; top: 7px; width: 6px; height: 6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
.node.topic details[open] summary::before { transform: rotate(45deg); top: 5px; }
.node.topic details summary:hover { color: var(--mod-text); }
.node.topic .more { margin: 4px 0 6px 18px; padding: 8px 10px; background: var(--bg); border-left: 3px solid var(--mod-line); border-radius: 0 6px 6px 0; font-size: 12.5px; color: var(--text); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bar h2 { margin: 0; }
.btns button { font: inherit; font-size: 13px; padding: 5px 12px; margin-left: 6px; border-radius: 8px; border: 1px solid var(--topic-line); background: var(--card); color: var(--text); cursor: pointer; }
.btns button:hover { border-color: var(--mod-line); }
.hint { margin: 6px 0 12px; font-size: 12.5px; color: var(--muted); }
.node.topic .toggle { cursor: pointer; position: relative; padding-left: 18px; }
.node.topic .toggle::before { content: ""; position: absolute; left: 2px; top: 8px; width: 7px; height: 7px; border-right: 2px solid var(--mod-line); border-bottom: 2px solid var(--mod-line); transform: rotate(45deg); transition: transform .15s; }
.col.collapsed > .node .toggle::before { transform: rotate(-45deg); top: 7px; }
.node.topic .toggle:hover { color: var(--mod-text); }
.node.topic .count { font-weight: 400; font-size: 11.5px; color: var(--muted); background: var(--bg); border: 1px solid var(--topic-line); border-radius: 10px; padding: 0 7px; margin-left: 2px; white-space: nowrap; }
.col.collapsed > .node .body { display: none; }
.col.collapsed > ul { display: none; }
.node.topic.section { width: 330px; border: 1px solid var(--mod-line); }
.tag { display: inline-block; background: var(--tag-bg); color: var(--tag-text); border-radius: 6px; font-size: 11.5px; padding: 1px 8px; margin-top: 6px; margin-right: 4px; }

.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.job { background: var(--card); border: 1px solid var(--topic-line); border-radius: 10px; padding: 12px 14px; }
.job .h { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.job p { margin: 0; font-size: 13px; }
.job.todo { background: var(--todo-bg); color: var(--todo-text); }
.badge { float: right; font-size: 11.5px; border-radius: 6px; padding: 1px 8px; background: var(--tag-bg); color: var(--tag-text); }
.job.todo .badge { background: transparent; border: 1px solid var(--line); color: var(--todo-text); }

.terms { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; font-size: 13.5px; }
.terms th, .terms td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--topic-line); vertical-align: top; }
.terms th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.terms td:first-child { font-weight: 600; white-space: nowrap; }
body { font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif; }
.terms-wrap { overflow-x: auto; }
.terms td:nth-child(3) { white-space: nowrap; }
#vi-only:empty { display: none; }
/* Cột lưới không bị nội dung rộng (sơ đồ, bảng) kéo giãn → không tràn ngang trên mobile */
main > * { min-width: 0; }
/* Mobile: lề 2 bên 20px, khớp với header/footer dùng chung */
@media (max-width: 760px) {
  .top { padding: 20px 20px 8px; }
  main { padding: 8px 20px 32px; }
}
/* Nút tới bảng từ vựng chuyên ngành */
.top-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
a.stat { text-decoration: none; }
a.stat:hover { border-color: var(--mod-line); }
.glossary-btn { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-size: 14px; font-weight: 600; padding: 8px 14px; border-radius: 10px; background: var(--mod-bg); color: var(--mod-text); border: 1px solid var(--mod-line); }
.glossary-btn:hover { filter: brightness(0.97); }
.glossary-btn .langs { font-size: 11.5px; font-weight: 500; opacity: .8; }
.to-top { font-size: 13px; color: var(--muted); text-decoration: none; }
.to-top:hover { color: var(--text); }
#glossary .hint { margin-top: 0; }
/* Cuộn tới đúng chỗ, không bị header dính che mất */
html { scroll-behavior: smooth; }
#glossary, #top { scroll-margin-top: 100px; }
@media (max-width: 760px) {
  .top-right { align-items: flex-start; }
}
