/* ============================================================
   base.css — reset, nền giấy, typography gốc, khung trang, masthead
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--leading);
  color: var(--ink);
  background-color: var(--bg);
  /* Vân giấy cực nhẹ — KHÔNG dùng lưới blueprint phủ toàn trang nữa */
  background-image:
    radial-gradient(110% 60% at 50% -10%, rgba(36,65,104,.05), transparent 60%),
    radial-gradient(rgba(28,26,20,.018) 1px, transparent 1px);
  background-size: auto, 4px 4px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---- Typography gốc ---- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: 1.12; font-weight: 700; color: var(--ink);
  letter-spacing: -0.02em; text-wrap: balance;
}
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); font-weight: 600; letter-spacing: -0.01em; }
p  { color: var(--ink-soft); text-wrap: pretty; }
strong { color: var(--ink); font-weight: 600; }
em { font-style: italic; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }
:not(pre) > code {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 0.05em 0.4em; font-size: 0.85em; color: var(--ink);
}
sub, sup { font-family: var(--font-mono); font-size: .72em; }

::selection { background: var(--accent); color: #fff; }

/* nhãn mono dạng eyebrow / "kỹ thuật" */
.eyebrow {
  font-family: var(--font-mono); text-transform: uppercase;
  letter-spacing: var(--eyebrow-ls); font-size: var(--fs-tiny);
  font-weight: 600; color: var(--accent);
}

/* icon line dùng chung */
.ic { width: 1.25em; height: 1.25em; display: inline-block; vertical-align: -0.18em;
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Khung trang ---- */
.wrap { width: 100%; max-width: var(--content-w); margin-inline: auto; padding-inline: var(--s-5); }

/* ---- Thanh tiến trình cuộn ---- */
#progress {
  position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 100;
  background: var(--accent);
  transform-origin: 0 50%; transform: scaleX(0);
}

/* ---- Masthead (thanh điều hướng trên cùng) ---- */
.topbar {
  position: sticky; top: 0; z-index: 90;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 2px 0 var(--brand-900);
}
.topbar .wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 6px var(--s-4); min-height: 62px; padding-block: 8px; }
.brand { display: flex; align-items: center; gap: var(--s-3); font-family: var(--font-display);
  font-weight: 600; font-size: 1.06rem; color: var(--ink); letter-spacing: -0.01em; flex: 0 1 auto; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--brand-900); color: var(--surface); flex: none;
}
.brand .logo .ic { width: 21px; height: 21px; stroke-width: 1.7; }
.topbar nav { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 4px var(--s-5);
  font-family: var(--font-mono); font-size: var(--fs-tiny); text-transform: uppercase; letter-spacing: .08em; min-width: 0; }
.topbar nav a { color: var(--ink-soft); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.topbar nav a:hover { color: var(--accent); text-decoration: none; }
/* Nav nhiều mục: ở màn hẹp giảm khoảng cách; rất hẹp thì chỉ giữ link "về" (mục đầu), ẩn các neo phần */
@media (max-width: 720px) {
  .topbar nav { gap: 4px var(--s-3); letter-spacing: .05em; }
}
@media (max-width: 520px) {
  .topbar nav a:not(:first-child) { display: none; }
}

/* ---- Bố cục topic: nội dung + mục lục dính ---- */
.topic-layout { display: grid; grid-template-columns: 1fr; gap: var(--s-8); padding-block: var(--s-8) var(--s-12); }
@media (min-width: 1040px) {
  .topic-layout { grid-template-columns: 250px minmax(0,1fr); gap: var(--s-10); }
  .toc { order: 1; }
  .topic-main { order: 2; min-width: 0; max-width: var(--reading-w); }
}

.topic-main > section { scroll-margin-top: 84px; margin-bottom: var(--s-10); }
.topic-main > section > h2 {
  display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: var(--s-3);
  margin-bottom: var(--s-5); padding-bottom: var(--s-3); border-bottom: 2px solid var(--ink);
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
}
.topic-main > section > h2 .n {
  font-size: var(--fs-tiny); color: var(--accent); font-family: var(--font-mono); font-weight: 600;
  letter-spacing: .1em; align-self: center;
}

/* tiêu đề phụ trong section */
.topic-main h3.sub {
  display: flex; align-items: center; gap: var(--s-3); margin: var(--s-8) 0 var(--s-4);
  font-size: 1.18rem; letter-spacing: -0.01em;
}
.topic-main h3.sub .ic { color: var(--accent); width: 1.15em; height: 1.15em; }
.topic-main h3.sub:first-child { margin-top: 0; }

/* ---- Mục lục dính (rail trái) ---- */
.toc { position: sticky; top: 84px; align-self: start; font-size: var(--fs-small); display: none; }
@media (min-width: 1040px) { .toc { display: block; } }
.toc .toc-title { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .14em;
  font-size: var(--fs-tiny); color: var(--muted); margin-bottom: var(--s-4); font-weight: 600; }
.toc ol { list-style: none; padding: 0; counter-reset: toc; }
.toc li { counter-increment: toc; }
.toc a { display: grid; grid-template-columns: auto 1fr; gap: var(--s-3); align-items: baseline;
  padding: 7px 0; color: var(--ink-soft); border-bottom: 1px solid var(--line-soft); }
.toc a::before { content: counter(toc, decimal-leading-zero); font-family: var(--font-mono);
  font-size: var(--fs-tiny); color: var(--muted); font-weight: 600; }
.toc a:hover { color: var(--accent); text-decoration: none; }
.toc a.active { color: var(--accent); font-weight: 600; }
.toc a.active::before { color: var(--accent); }

/* ---- Footer ---- */
.site-foot { border-top: 1px solid var(--line); background: var(--surface); margin-top: var(--s-10); }
.site-foot .wrap { padding-block: var(--s-6); color: var(--muted); font-size: var(--fs-small);
  display: flex; flex-wrap: wrap; gap: var(--s-4); justify-content: space-between; }

/* ---- Tiện ích ---- */
.center { text-align: center; }
.muted { color: var(--muted); }
.rule { flex: 1; height: 1px; background: var(--line-strong); }
section[id^="part-"] { scroll-margin-top: 84px; }
