/* Giao diện theo tinh thần Medium: một cột đọc, chữ serif lớn, nhiều khoảng trắng, ít chữ quanh bài. */

/* ---------- Bảng màu ---------- */

:root {
  --bg: #ffffff;
  --bg-soft: #f9f9f9;
  --bg-muted: #f2f2f2;
  --ink: #242424;
  --ink-soft: #6b6b6b;
  --ink-faint: #a8a8a8;
  --line: #f2f2f2;
  --line-strong: #e5e5e5;
  --accent: #1a8917;
  --header-bg: rgba(255, 255, 255, 0.97);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.12);

  --code-bg: #f9f9f9;
  --hl-comment: #6e7781;
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-number: #0550ae;
  --hl-title: #8250df;
  --hl-type: #953800;
  --hl-attr: #0550ae;
  --hl-meta: #6e7781;

  --c-summary: #242424;
  --c-note: #2f6fb0;
  --c-tip: #1a8917;
  --c-important: #7a4fc2;
  --c-warning: #b26b00;
  --c-caution: #c4372b;
  --c-example: #6b6b6b;

  --tile-co-so-du-lieu-bg: #e6f2ea;
  --tile-co-so-du-lieu-ink: #1e5c38;
  --tile-he-thong-bg: #e6eefa;
  --tile-he-thong-ink: #1f4f8f;
  --tile-bai-toan-kinh-dien-bg: #fbf3dc;
  --tile-bai-toan-kinh-dien-ink: #7a5800;
  --tile-ai-bg: #eeeaf8;
  --tile-ai-ink: #4b3a8f;
  --tile-bao-mat-bg: #fbe9e7;
  --tile-bao-mat-ink: #9a2b1f;
  --tile-mang-bg: #e3f4f6;
  --tile-mang-ink: #145e69;
  --tile-cong-nghe-moi-bg: #fbe8f1;
  --tile-cong-nghe-moi-ink: #8f2a5c;
  --tile-nghien-cuu-bg: #eceff3;
  --tile-nghien-cuu-ink: #3d4a5c;
  --tile-thuc-chien-bg: #fbeee3;
  --tile-thuc-chien-ink: #94440f;
  --font-sans: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-serif: "Source Serif 4", Charter, Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --bg-soft: #1a1a1a;
    --bg-muted: #242424;
    --ink: #e6e6e6;
    --ink-soft: #a8a8a8;
    --ink-faint: #6b6b6b;
    --line: #242424;
    --line-strong: #333333;
    --accent: #4caf50;
    --header-bg: rgba(18, 18, 18, 0.97);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
    --code-bg: #1a1a1a;
    --hl-comment: #8b949e;
    --hl-keyword: #ff7b72;
    --hl-string: #a5d6ff;
    --hl-number: #79c0ff;
    --hl-title: #d2a8ff;
    --hl-type: #ffa657;
    --hl-attr: #79c0ff;
    --hl-meta: #8b949e;
    --c-summary: #e6e6e6;
    --c-note: #79b0ea;
    --c-tip: #6fcf73;
    --c-important: #b89cf0;
    --c-warning: #e3a649;
    --c-caution: #f0857a;
    --c-example: #a8a8a8;
    --tile-co-so-du-lieu-bg: #1b2e22;
    --tile-co-so-du-lieu-ink: #8fd1a6;
    --tile-he-thong-bg: #17243a;
    --tile-he-thong-ink: #8db7ee;
    --tile-bai-toan-kinh-dien-bg: #312813;
    --tile-bai-toan-kinh-dien-ink: #e8c66a;
    --tile-ai-bg: #231f38;
    --tile-ai-ink: #b9a9f0;
    --tile-bao-mat-bg: #351c19;
    --tile-bao-mat-ink: #f0958a;
    --tile-mang-bg: #14292c;
    --tile-mang-ink: #7fd0db;
    --tile-cong-nghe-moi-bg: #331a27;
    --tile-cong-nghe-moi-ink: #f09ac4;
    --tile-nghien-cuu-bg: #20252c;
    --tile-nghien-cuu-ink: #a9b6c8;
    --tile-thuc-chien-bg: #33231a;
    --tile-thuc-chien-ink: #f2b385;    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121212;
  --bg-soft: #1a1a1a;
  --bg-muted: #242424;
  --ink: #e6e6e6;
  --ink-soft: #a8a8a8;
  --ink-faint: #6b6b6b;
  --line: #242424;
  --line-strong: #333333;
  --accent: #4caf50;
  --header-bg: rgba(18, 18, 18, 0.97);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  --code-bg: #1a1a1a;
  --hl-comment: #8b949e;
  --hl-keyword: #ff7b72;
  --hl-string: #a5d6ff;
  --hl-number: #79c0ff;
  --hl-title: #d2a8ff;
  --hl-type: #ffa657;
  --hl-attr: #79c0ff;
  --hl-meta: #8b949e;
  --c-summary: #e6e6e6;
  --c-note: #79b0ea;
  --c-tip: #6fcf73;
  --c-important: #b89cf0;
  --c-warning: #e3a649;
  --c-caution: #f0857a;
  --c-example: #a8a8a8;
  --tile-co-so-du-lieu-bg: #1b2e22;
  --tile-co-so-du-lieu-ink: #8fd1a6;
  --tile-he-thong-bg: #17243a;
  --tile-he-thong-ink: #8db7ee;
  --tile-bai-toan-kinh-dien-bg: #312813;
  --tile-bai-toan-kinh-dien-ink: #e8c66a;
  --tile-ai-bg: #231f38;
  --tile-ai-ink: #b9a9f0;
  --tile-bao-mat-bg: #351c19;
  --tile-bao-mat-ink: #f0958a;
  --tile-mang-bg: #14292c;
  --tile-mang-ink: #7fd0db;
  --tile-cong-nghe-moi-bg: #331a27;
  --tile-cong-nghe-moi-ink: #f09ac4;
  --tile-nghien-cuu-bg: #20252c;
  --tile-nghien-cuu-ink: #a9b6c8;
  --tile-thuc-chien-bg: #33231a;
  --tile-thuc-chien-ink: #f2b385;  color-scheme: dark;
}

/* ---------- Nền ---------- */

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main { flex: 1 0 auto; }

a { color: inherit; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 20;
  background: var(--ink);
  color: var(--bg);
  padding: 0.4rem 0.7rem;
}
.skip:focus { top: 0.5rem; }

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.muted { color: var(--ink-soft); }

/* ---------- Thanh trên cùng ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar-inner {
  height: 57px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.search-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  width: 240px;
  padding: 0 16px;
  border-radius: 20px;
  background: var(--bg-soft);
  color: var(--ink-soft);
}
.search-pill:focus-within { box-shadow: 0 0 0 1px var(--line-strong); }
.search-pill input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.search-pill input::placeholder { color: var(--ink-soft); }
.search-pill input::-webkit-search-cancel-button { display: none; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); }

.search-icon { display: none; }

.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1;
}
.avatar-xs { width: 20px; height: 20px; font-size: 11px; }
.avatar-sm { width: 32px; height: 32px; font-size: 15px; }
.avatar-md { width: 44px; height: 44px; font-size: 20px; }
.avatar-lg { width: 64px; height: 64px; font-size: 28px; }
.avatar-link { text-decoration: none; display: inline-flex; }

/* ---------- Tab series ---------- */

.tabs {
  display: flex;
  gap: 32px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none;
  padding: 16px 0 15px;
  font-size: 14px;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- Danh sách bài ---------- */

.feed-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 48px;
  align-items: center;
  padding: 28px 0;
  border-bottom: 1px solid var(--line);
}

.feed-source {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 13px;
}
.feed-source a { text-decoration: none; }
.feed-source a:hover { text-decoration: underline; }
.feed-author { font-weight: 500; }

.feed-link { display: block; text-decoration: none; }
.feed-link h2 {
  margin: 0;
  font-size: 22px;
  line-height: 28px;
  font-weight: 700;
  letter-spacing: -0.016em;
}
.feed-sub {
  margin: 8px 0 0;
  font-size: 16px;
  line-height: 24px;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* Ô màu thay ảnh bìa: tên series và số thứ tự trong series. */
.tile {
  --tile-bg: var(--bg-muted);
  --tile-ink: var(--ink-soft);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 112px;
  height: 112px;
  padding: 12px;
  border-radius: 4px;
  background: var(--tile-bg);
  color: var(--tile-ink);
  text-decoration: none;
  overflow: hidden;
}
.tile-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.3;
}
.tile-num {
  align-self: flex-end;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 44px;
  line-height: 0.9;
  letter-spacing: -0.03em;
}
.tile-wide {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  padding: 16px 18px;
}
.tile-wide .tile-num { font-size: 64px; }
.tile-co-so-du-lieu { --tile-bg: var(--tile-co-so-du-lieu-bg); --tile-ink: var(--tile-co-so-du-lieu-ink); }
.tile-he-thong { --tile-bg: var(--tile-he-thong-bg); --tile-ink: var(--tile-he-thong-ink); }
.tile-bai-toan-kinh-dien { --tile-bg: var(--tile-bai-toan-kinh-dien-bg); --tile-ink: var(--tile-bai-toan-kinh-dien-ink); }
.tile-ai { --tile-bg: var(--tile-ai-bg); --tile-ink: var(--tile-ai-ink); }
.tile-bao-mat { --tile-bg: var(--tile-bao-mat-bg); --tile-ink: var(--tile-bao-mat-ink); }
.tile-mang { --tile-bg: var(--tile-mang-bg); --tile-ink: var(--tile-mang-ink); }
.tile-cong-nghe-moi { --tile-bg: var(--tile-cong-nghe-moi-bg); --tile-ink: var(--tile-cong-nghe-moi-ink); }
.tile-nghien-cuu { --tile-bg: var(--tile-nghien-cuu-bg); --tile-ink: var(--tile-nghien-cuu-ink); }
.tile-thuc-chien { --tile-bg: var(--tile-thuc-chien-bg); --tile-ink: var(--tile-thuc-chien-ink); }

.series-pills { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; margin: 0 0 16px; }
.series-pills > span { font-size: 13px; color: var(--ink-soft); }
.story-series .crumb-series { font-weight: 400; color: var(--ink-soft); }
.pills { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; }
.pills a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 100px;
  background: var(--bg-muted);
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
}
.pills a:hover { background: var(--line-strong); }
.pills span { color: var(--ink-soft); font-size: 12px; }

/* ---------- Trang chủ ---------- */

.home {
  width: 100%;
  max-width: 1192px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 64px;
}
.home-feed { max-width: 728px; width: 100%; margin: 0 auto; padding-top: 24px; }

.side {
  border-left: 1px solid var(--line);
  padding: 40px 0 40px 40px;
}
.side-block + .side-block { margin-top: 40px; }
.side-block h2 { margin: 0 0 16px; font-size: 16px; font-weight: 600; }
.side-about { margin: 0; font-size: 15px; line-height: 22px; color: var(--ink-soft); }
.side-more {
  display: inline-block;
  margin-top: 12px;
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
}
.side-more:hover { text-decoration: underline; }
.side-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 20px; }
.side-source { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 12px; color: var(--ink-soft); }
.side-list a {
  font-size: 16px;
  line-height: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.side-list a:hover { text-decoration: underline; }

/* ---------- Trang danh sách ---------- */

.page {
  width: 100%;
  max-width: 728px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}
.page-head { padding: 40px 0 24px; text-align: center; }
.page-head h1 {
  margin: 0;
  font-size: 42px;
  line-height: 52px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-kicker { margin: 0 0 8px; font-size: 14px; color: var(--ink-soft); }
.page-kicker a { text-decoration: none; }
.page-sub { max-width: 34rem; margin: 12px auto 0; font-size: 16px; line-height: 24px; color: var(--ink-soft); }
.page-count { margin: 12px 0 0; font-size: 14px; color: var(--ink-soft); }
.pills-large { display: flex; justify-content: center; }
.pills-large .pills { justify-content: center; max-width: 36rem; }

.archive-group { margin-top: 32px; }
.archive-group h2 {
  margin: 0 0 4px;
  padding-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-list li { padding: 16px 0; border-bottom: 1px solid var(--line); }
.archive-list a {
  display: block;
  font-size: 18px;
  line-height: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.archive-list a:hover { text-decoration: underline; }
.archive-list span { display: block; margin-top: 4px; font-size: 13px; color: var(--ink-soft); }

.missing { text-align: center; }
.missing-links { display: flex; justify-content: center; gap: 24px; font-size: 14px; color: var(--ink-soft); }

/* ---------- Bài viết ---------- */

.story-wrap { width: 100%; padding: 0 24px; }
.story { max-width: 680px; margin: 0 auto; padding: 48px 0 32px; }

.draft-banner {
  margin: 0 0 24px;
  padding: 8px 12px;
  border: 1px dashed var(--c-warning);
  color: var(--c-warning);
  font-size: 14px;
}

.story-series { margin: 0 0 16px; font-size: 14px; color: var(--ink-soft); }
.story-series a { color: var(--ink); text-decoration: none; font-weight: 500; }
.story-series a:hover { text-decoration: underline; }

.story-head h1 {
  margin: 0;
  font-size: 42px;
  line-height: 52px;
  font-weight: 700;
  letter-spacing: -0.016em;
}
.story-sub {
  margin: 12px 0 0;
  font-size: 22px;
  line-height: 30px;
  color: var(--ink-soft);
  letter-spacing: -0.01em;
}

.byline { display: flex; align-items: center; gap: 12px; margin-top: 32px; }
.byline p { margin: 0; }
.byline-name { font-size: 16px; font-weight: 500; }
.byline-meta { font-size: 14px; color: var(--ink-soft); }

.story-actions {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 32px;
  padding: 4px 4px 4px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.share-link { position: relative; }
.share-link[data-copied]::after {
  content: attr(data-tip);
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  padding: 6px 10px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  white-space: nowrap;
}

.toc-drop summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  list-style: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink-soft);
}
.toc-drop summary::-webkit-details-marker { display: none; }
.toc-drop summary:hover,
.toc-drop[open] summary { color: var(--ink); }
.toc-drop ol {
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 5;
  width: min(440px, calc(100vw - 48px));
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: 8px 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  box-shadow: var(--shadow);
}
.toc-drop li a {
  display: block;
  padding: 8px 20px;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink-soft);
  text-decoration: none;
}
.toc-drop li a:hover { background: var(--bg-soft); color: var(--ink); }

/* Mục lục dạng gạch mờ ở lề trái, chỉ hiện chữ khi rê chuột. Màn hình hẹp không có. */
.toc-rail {
  position: fixed;
  top: 140px;
  left: max(16px, calc(50% - 340px - 260px));
  z-index: 4;
  width: 210px;
  max-height: calc(100vh - 200px);
  overflow: auto;
  scrollbar-width: none;
  display: none;
}
.toc-rail::-webkit-scrollbar { display: none; }
.toc-rail ol { list-style: none; margin: 0; padding: 0; }
.toc-rail a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  text-decoration: none;
  color: var(--ink-soft);
}
.toc-rail a::before {
  content: "";
  flex: none;
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: var(--line-strong);
  transition: width 150ms, background 150ms;
}
.toc-rail a.active::before { width: 22px; background: var(--ink); }
.rail-label {
  font-size: 13px;
  line-height: 18px;
  opacity: 0;
  transition: opacity 150ms;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-rail:hover .rail-label,
.toc-rail:focus-within .rail-label { opacity: 1; }
.toc-rail a:hover,
.toc-rail a.active { color: var(--ink); }
@media (min-width: 1240px) {
  .toc-rail { display: block; }
}

/* Thân bài */

.story-body { margin-top: 40px; }
.story-body > * { margin-top: 0; margin-bottom: 0; }
.story-body > * + * { margin-top: 30px; }

.story-body p,
.story-body li {
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 32px;
  letter-spacing: -0.003em;
  overflow-wrap: break-word;
}

.story-body a { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.story-body strong { font-weight: 700; }

.story-body h2,
.story-body h3,
.story-body h4 {
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.016em;
}
.story-body > h2 { margin-top: 56px; font-size: 26px; line-height: 32px; }
.story-body > h3 { margin-top: 44px; font-size: 21px; line-height: 28px; }
.story-body > h4 { margin-top: 36px; font-size: 18px; line-height: 24px; }
.story-body > h2 + *,
.story-body > h3 + *,
.story-body > h4 + * { margin-top: 14px; }

.story-body .anchor {
  margin-left: 8px;
  color: var(--ink-faint);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
}
.story-body h2:hover .anchor,
.story-body h3:hover .anchor,
.story-body .anchor:focus { opacity: 1; }

.story-body ul,
.story-body ol { padding-left: 30px; }
.story-body li + li { margin-top: 12px; }
.story-body li > ul,
.story-body li > ol { margin-top: 12px; }

.story-body blockquote {
  margin-left: 0;
  margin-right: 0;
  padding-left: 20px;
  border-left: 3px solid var(--ink);
}
.story-body blockquote p { font-style: italic; }

.story-body hr {
  border: 0;
  height: 32px;
  margin: 48px 0;
  text-align: center;
}
.story-body hr::before {
  content: "...";
  font-family: var(--font-serif);
  font-size: 30px;
  letter-spacing: 0.6em;
  color: var(--ink);
}

/* Code */
.story-body code,
.story-body kbd {
  font-family: var(--font-mono);
  font-size: 0.78em;
  font-variant-ligatures: none;
  font-feature-settings: "calt" 0, "liga" 0;
  background: var(--bg-muted);
  padding: 2px 5px;
  border-radius: 3px;
}

.code-block {
  position: relative;
  background: var(--code-bg);
  border-radius: 4px;
}
.code-block pre {
  margin: 0;
  padding: 28px 22px 22px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 14.5px;
  line-height: 1.6;
  tab-size: 4;
}
.code-block pre code {
  font-size: inherit;
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: var(--ink);
}
.code-block[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  left: 22px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.code-block .copy {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink-soft);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms;
}
.code-block:hover .copy,
.code-block .copy:focus { opacity: 1; }

.hljs-comment,
.hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword,
.hljs-selector-tag,
.hljs-operator { color: var(--hl-keyword); }
.hljs-string,
.hljs-regexp,
.hljs-addition { color: var(--hl-string); }
.hljs-number,
.hljs-literal,
.hljs-symbol { color: var(--hl-number); }
.hljs-title,
.hljs-title.function_,
.hljs-section { color: var(--hl-title); }
.hljs-type,
.hljs-built_in,
.hljs-class .hljs-title { color: var(--hl-type); }
.hljs-variable,
.hljs-template-variable,
.hljs-attr,
.hljs-attribute,
.hljs-params { color: var(--hl-attr); }
.hljs-meta,
.hljs-meta .hljs-keyword { color: var(--hl-meta); }
.hljs-deletion { color: var(--c-caution); }

/* Bảng: chỉ kẻ ngang, chữ sans nhỏ hơn thân bài. */
.table-wrap { overflow-x: auto; }
.story-body table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 22px;
}
.story-body th,
.story-body td {
  padding: 10px 16px 10px 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
.story-body th {
  font-weight: 600;
  border-bottom-color: var(--line-strong);
  white-space: nowrap;
}
.story-body td code,
.story-body th code { font-size: 0.85em; }

/* Sơ đồ */
.diagram { overflow-x: auto; text-align: center; }
.diagram pre.mermaid {
  margin: 0;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 14px;
}
/* Mermaid vẽ nhãn bằng thẻ p, không để nó nhận cỡ chữ serif của đoạn văn. */
.story-body .diagram p,
.story-body .diagram span {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  letter-spacing: 0;
}

/* Khối nhấn mạnh: một vạch màu bên trái, không đóng khung. */
.callout {
  --c: var(--c-note);
  padding: 2px 0 2px 22px;
  border-left: 3px solid var(--c);
}
.callout-title,
.story-body .callout-title {
  margin: 0 0 6px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--c);
}
.story-body .callout p,
.story-body .callout li { font-size: 18px; line-height: 29px; }
.callout > p:not(.callout-title) { margin: 0; }
.callout > * + * { margin-top: 12px; }
.callout ul,
.callout ol { margin: 0; padding-left: 24px; }
.story-body .callout li + li { margin-top: 8px; }
.callout-summary {
  --c: var(--c-summary);
  border-left: 0;
  padding: 22px 26px;
  border-radius: 4px;
  background: var(--bg-soft);
}
.callout-note { --c: var(--c-note); }
.callout-tip { --c: var(--c-tip); }
.callout-important { --c: var(--c-important); }
.callout-warning { --c: var(--c-warning); }
.callout-caution { --c: var(--c-caution); }
.callout-example { --c: var(--c-example); }

/* Cuối bài */
.story-foot { margin-top: 56px; }
.author-card {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}
.author-card p { margin: 0; }
.author-label { font-size: 13px; color: var(--ink-soft); }
.author-name { font-size: 20px; line-height: 28px; font-weight: 700; letter-spacing: -0.01em; }
.author-bio { font-size: 14px; color: var(--ink-soft); }

.more { background: var(--bg-soft); padding: 48px 24px 64px; }
.more-inner { max-width: 728px; margin: 0 auto; }
.more h2 { margin: 0 0 24px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 40px 32px; }
.story-card p { margin: 0; }
.card-kicker { margin-top: 16px !important; font-size: 13px; color: var(--ink-soft); }
.story-card h3 { margin: 8px 0 0; font-size: 20px; line-height: 26px; font-weight: 700; letter-spacing: -0.016em; }
.story-card h3 a { text-decoration: none; }
.story-card h3 a:hover { text-decoration: underline; }
.card-sub {
  margin-top: 8px !important;
  font-size: 15px;
  line-height: 22px;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Tìm kiếm ---------- */

.search-box { margin: 40px 0 8px; }
.search-box input {
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.016em;
  outline: none;
}
.search-box input::placeholder { color: var(--ink-faint); font-weight: 400; }
.search-box input:focus { border-bottom-color: var(--ink); }
.search-status { min-height: 1.5em; margin: 12px 0 0; font-size: 14px; color: var(--ink-soft); }
.search-results { list-style: none; margin: 0; padding: 0; }
.search-results > li { padding: 28px 0; border-bottom: 1px solid var(--line); }
.search-results .card-meta { margin: 0 0 6px; font-size: 13px; color: var(--ink-soft); }
.search-results h2 { margin: 0; font-size: 22px; line-height: 28px; font-weight: 700; letter-spacing: -0.016em; }
.search-results h2 a { text-decoration: none; }
.search-results h2 a:hover { text-decoration: underline; }
.search-results ul { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 12px; }
.search-results ul a { font-size: 15px; font-weight: 600; text-decoration: none; }
.search-results ul a:hover { text-decoration: underline; }
.search-results ul p { margin: 2px 0 0; font-size: 15px; line-height: 22px; color: var(--ink-soft); }
.search-results mark { background: color-mix(in srgb, var(--c-warning) 25%, transparent); color: inherit; border-radius: 2px; }

/* ---------- Chân trang ---------- */

.site-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 24px;
  padding: 32px 24px calc(40px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-soft);
}
.site-foot p { margin: 0; }
.site-foot nav { display: flex; flex-wrap: wrap; gap: 20px; }
.site-foot a { text-decoration: none; }
.site-foot a:hover { color: var(--ink); }

/* ---------- Màn hình nhỏ ---------- */

@media (max-width: 1080px) {
  .home { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
}

@media (max-width: 720px) {
  .search-pill { display: none; }
  .search-icon { display: inline-grid; }
  .topbar-inner { padding: 0 16px; gap: 8px; }
  .logo { font-size: 20px; overflow: hidden; text-overflow: ellipsis; }
  .home, .page { padding-left: 16px; padding-right: 16px; }
  .story-wrap { padding: 0 16px; }
  .story { padding-top: 32px; }
  .feed-item { grid-template-columns: minmax(0, 1fr) 80px; gap: 20px; padding: 22px 0; }
  .tile:not(.tile-wide) { width: 80px; height: 80px; padding: 8px; }
  .tile:not(.tile-wide) .tile-label { font-size: 8px; }
  .tile:not(.tile-wide) .tile-num { font-size: 32px; }
  .feed-link h2 { font-size: 18px; line-height: 24px; }
  .feed-sub { font-size: 15px; line-height: 21px; }
  .story-head h1 { font-size: 32px; line-height: 40px; }
  .story-sub { font-size: 19px; line-height: 27px; }
  .story-body p,
  .story-body li { font-size: 18px; line-height: 29px; }
  .story-body > * + * { margin-top: 26px; }
  .story-body > h2 { margin-top: 44px; font-size: 22px; line-height: 28px; }
  .story-body > h3 { margin-top: 36px; font-size: 19px; line-height: 25px; }
  .code-block { margin-left: -16px; margin-right: -16px; border-radius: 0; }
  .story-body .callout p,
  .story-body .callout li { font-size: 17px; line-height: 27px; }
  .callout-summary { margin-left: -16px; margin-right: -16px; border-radius: 0; padding: 20px 16px; }
  .page-head h1 { font-size: 32px; line-height: 40px; }
  .more { padding: 40px 16px 48px; }
  .more-grid { grid-template-columns: minmax(0, 1fr); gap: 36px; }
  .search-box input { font-size: 22px; }
}

/* ---------- In ---------- */

@media print {
  .topbar,
  .site-foot,
  .toc-rail,
  .story-actions,
  .more,
  .code-block .copy,
  .story-body .anchor { display: none !important; }
  body { background: #fff; color: #000; }
  .story { padding-top: 0; }
  .code-block pre { white-space: pre-wrap; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
