/* ---------- Tokens ---------- */
:root {
  --bg: #fbfaf7;
  --bg-soft: #f3f1ec;
  --surface: #ffffff;
  --text: #1c1b19;
  --text-soft: #4a4843;
  --muted: #8a867d;
  --border: #e4e0d7;
  --accent: #b4452a;
  --accent-soft: #f6e6df;
  --green: #2f7a4f;
  --green-soft: #e1f0e6;
  --code-bg: #f0ede6;
  --shadow: 0 1px 2px rgba(28, 27, 25, 0.04), 0 4px 16px rgba(28, 27, 25, 0.04);

  /* System UI font, same stack as guangyiliu.com — no web fonts to load. */
  --sans: ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;

  --wrap: 896px; /* 848px content + 24px gutters, same as guangyiliu.com */
  --measure: 680px;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #141412;
    --bg-soft: #1c1b19;
    --surface: #1e1d1b;
    --text: #ecebe6;
    --text-soft: #c4c1b8;
    --muted: #8f8b82;
    --border: #2e2c28;
    --accent: #e67b5c;
    --accent-soft: #3a2620;
    --green: #6cc08f;
    --green-soft: #1d3326;
    --code-bg: #24231f;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #141412;
  --bg-soft: #1c1b19;
  --surface: #1e1d1b;
  --text: #ecebe6;
  --text-soft: #c4c1b8;
  --muted: #8f8b82;
  --border: #2e2c28;
  --accent: #e67b5c;
  --accent-soft: #3a2620;
  --green: #6cc08f;
  --green-soft: #1d3326;
  --code-bg: #24231f;
  --shadow: none;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration-color: var(--border); text-underline-offset: 3px; }
a:hover { color: var(--accent); text-decoration-color: currentColor; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { font-weight: 500; line-height: 1.3; margin: 0; }
h1 { font-weight: 600; letter-spacing: -0.02em; }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 16px; background: var(--surface); padding: 8px 12px; z-index: 10; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Header / footer ---------- */
.site-header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { font-weight: 600; font-size: 16px; text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 22px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { font-size: 15px; color: var(--text-soft); text-decoration: none; white-space: nowrap; }
.nav a:hover, .nav a[aria-current='page'] { color: var(--text); }
.nav a[aria-current='page'] { box-shadow: inset 0 -2px 0 var(--accent); }
.theme-toggle {
  border: 1px solid var(--border); background: transparent; color: var(--text-soft);
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }

.site-footer { border-top: 1px solid var(--border); margin-top: 96px; padding: 32px 0 48px; color: var(--muted); font-size: 14px; }
.footer-inner { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; }
.footer-links a { text-decoration: none; }

main { padding-top: 56px; }
section { margin-top: 64px; }

/* ---------- Home hero ---------- */
/* Text left, 3:4 portrait right — same proportions as guangyiliu.com */
.hero { display: flex; gap: 40px; align-items: flex-start; margin-top: 8px; }
.hero-text { flex: 1; min-width: 0; max-width: 628px; }
.portrait { flex: none; width: 180px; height: 240px; border-radius: 12px; object-fit: cover; background: var(--bg-soft); }
:root[data-theme='dark'] .portrait { filter: brightness(0.88); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .portrait { filter: brightness(0.88); } }
.hero h1 { font-size: 30px; }
.tagline { font-size: 17px; color: var(--accent); margin: 4px 0 18px; }
.intro { font-size: 16px; color: var(--text-soft); line-height: 1.5; }
.intro p { margin: 0 0 14px; }
.intro strong { color: var(--text); }
.hero-links { display: flex; gap: 18px; flex-wrap: wrap; font-size: 15px; margin-top: 8px; }
.hero-links a { color: var(--text-soft); }

/* ---------- Section heads & lists ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 8px; }
.section-head h2 { font-size: 15px; font-family: var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.section-head a { font-size: 14px; color: var(--muted); text-decoration: none; }
.section-head a:hover { color: var(--accent); }

.post-list, .research-list { list-style: none; margin: 0; padding: 0; }
.post-row { display: grid; grid-template-columns: 96px 1fr; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.post-row:last-child { border-bottom: 0; }
.post-row time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; padding-top: 3px; }
.post-link { font-size: 17px; font-weight: 500; text-decoration: none; line-height: 1.4; }
.post-summary { margin: 4px 0 0; color: var(--text-soft); font-size: 15px; }
.row-section { font-size: 12px; color: var(--muted); margin-left: 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.year-group { margin-top: 40px; }
.year { font-size: 15px; font-family: var(--sans); color: var(--muted); font-weight: 600; margin-bottom: 4px; }

.research-row { padding: 20px 0; border-bottom: 1px solid var(--border); }
.research-meta { color: var(--muted); font-size: 14px; margin-top: 4px; }
.research-links { display: flex; gap: 14px; font-size: 14px; margin-top: 8px; }
.research-links a { color: var(--accent); }

.empty { color: var(--muted); font-style: italic; }

/* ---------- Badges & tags ---------- */
.badge {
  display: inline-block; font-family: var(--sans); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle; background: var(--bg-soft); color: var(--text-soft);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.muted { background: var(--bg-soft); color: var(--muted); }
.card-top .badge, .badges .badge:first-child { margin-left: 0; }
.tags, .topic-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { font-size: 13.5px; text-decoration: none; padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-soft); }
.tag:hover { border-color: var(--accent); }
.tag small { color: var(--muted); margin-left: 2px; }

/* ---------- Cards & tiles ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.card {
  display: flex; flex-direction: column; gap: 8px; padding: 20px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); text-decoration: none; box-shadow: var(--shadow); transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); color: inherit; transform: translateY(-1px); }
.card h3 { font-size: 17px; }
.card p { margin: 0; color: var(--text-soft); font-size: 15px; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; }
.card-top time { color: var(--muted); font-size: 13px; }
.card-meta { margin-top: auto; padding-top: 6px; color: var(--muted); font-size: 13px; }
.logo { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; }
.logo-fallback { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 17px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; }
.tile {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; min-height: 180px; padding: 20px;
  border-radius: var(--radius); text-decoration: none; color: #fff; overflow: hidden; isolation: isolate;
  background: linear-gradient(135deg, #2b2a27, #5b3a2e);
}
.tile::before { content: ''; position: absolute; inset: 0; z-index: -2; background: var(--cover, none) center / cover; }
.tile::after { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.1)); }
.tile:nth-child(3n + 2) { background: linear-gradient(135deg, #1f2f3a, #2f5a5c); }
.tile:nth-child(3n + 3) { background: linear-gradient(135deg, #2c2540, #6a4a3a); }
.tile:hover { color: #fff; }
.tile:hover .tile-title { text-decoration: underline; text-underline-offset: 4px; }
.tile-kind { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; font-weight: 600; }
.tile-title { font-size: 18px; font-weight: 600; line-height: 1.3; }
.tile-summary { font-size: 14px; opacity: 0.85; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Page heads ---------- */
.page-head { max-width: var(--measure); margin-bottom: 24px; }
.page-head h1 { font-size: 30px; }
.lede { font-size: 17px; color: var(--text-soft); margin: 10px 0 0; line-height: 1.55; }
.crumb { display: inline-block; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); text-decoration: none; margin-bottom: 12px; font-weight: 600; }
.cta { margin-top: 40px; color: var(--text-soft); font-size: 16px; }
.cta a { color: var(--accent); }

/* ---------- Entry (article) ---------- */
.entry { max-width: var(--measure); }
.entry.wide { max-width: none; }
.entry-head { margin-bottom: 40px; }
.entry-head h1 { font-size: 34px; line-height: 1.2; }
.entry-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; margin-top: 18px; color: var(--muted); font-size: 14.5px; }
.entry-meta .dot { margin: 0 10px; }
.entry-meta .badges { margin-left: 12px; display: inline-flex; gap: 6px; }
.entry-meta .badges .badge { margin-left: 0; }
.actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.btn { font-size: 14px; padding: 7px 14px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; background: var(--surface); }
.btn:hover { border-color: var(--accent); }

.toc { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; margin-bottom: 36px; background: var(--bg-soft); font-size: 15px; }
.toc summary { cursor: pointer; font-weight: 600; color: var(--text-soft); }
.toc ol { margin: 10px 0 0; padding-left: 20px; }
.toc li { margin: 4px 0; }
.toc .toc-3 { margin-left: 18px; list-style: circle; }
.toc a { text-decoration: none; color: var(--text-soft); }

/* ---------- Prose ---------- */
.prose { font-size: 17px; line-height: 1.7; color: var(--text); overflow-wrap: break-word; }
.prose > * { margin-block: 0; }
.prose > * + * { margin-top: 1.1em; }
.prose > :is(h2, h3, h4) + * { margin-top: 0.6em; }
.prose h2 { font-size: 22px; font-weight: 600; margin-top: 2em; }
.prose h3 { font-size: 19px; font-weight: 600; margin-top: 1.7em; }
.prose h4 { font-size: 17px; font-weight: 600; margin-top: 1.5em; }
.prose h2, .prose h3, .prose h4 { position: relative; }
.prose .anchor { position: absolute; left: -1.1em; color: var(--muted); text-decoration: none; opacity: 0; font-weight: 400; }
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.prose a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.prose blockquote { margin-left: 0; padding-left: 20px; border-left: 3px solid var(--accent); color: var(--text-soft); font-style: italic; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.35em; }
.prose hr { border: 0; text-align: center; margin: 2.4em 0; }
.prose hr::before { content: '· · ·'; color: var(--muted); letter-spacing: 0.6em; }
.prose code { font-family: var(--mono); font-size: 0.82em; background: var(--code-bg); padding: 0.15em 0.4em; border-radius: 5px; }
.prose pre { background: var(--code-bg); padding: 18px 20px; border-radius: var(--radius); overflow-x: auto; line-height: 1.5; }
.prose pre code { background: none; padding: 0; font-size: 14.5px; }
.prose figure { margin: 2em 0; }
.prose figure img { border-radius: 8px; display: block; margin: 0 auto; }
.prose figcaption { font-family: var(--sans); font-size: 14px; color: var(--muted); text-align: center; margin-top: 10px; }
.prose table { font-family: var(--sans); font-size: 15px; }
.prose .footnotes { margin-top: 3em; padding-top: 1.2em; border-top: 1px solid var(--border); font-size: 15px; color: var(--text-soft); }
.prose .footnotes h2 { font-size: 15px; font-family: var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 0; }
.prose .footnotes .anchor { display: none; }
.prose sup a { text-decoration: none; font-family: var(--sans); font-size: 0.75em; padding: 0 2px; }
.prose .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.entry-foot { margin-top: 56px; display: flex; flex-direction: column; gap: 24px; }
.prev-next { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; border-top: 1px solid var(--border); padding-top: 24px; }
.prev-next a { text-decoration: none; font-weight: 500; font-size: 16px; }
.prev-next span { display: block; font-family: var(--sans); font-size: 13px; color: var(--muted); font-weight: 400; margin-bottom: 4px; }
.prev-next .next { text-align: right; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table th button { all: unset; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.data-table th button::after { content: '↕'; color: var(--muted); font-size: 12px; }
.data-table th[aria-sort='ascending'] button::after { content: '↑'; color: var(--accent); }
.data-table th[aria-sort='descending'] button::after { content: '↓'; color: var(--accent); }
.data-table tbody tr:hover { background: var(--bg-soft); }
.table-tools { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.table-filter { font: inherit; font-size: 15px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); width: 280px; max-width: 100%; }
.table-count { color: var(--muted); font-size: 14px; }
.notes { margin-top: 32px; font-size: 16px; }

/* ---------- Hub ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 32px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; background: var(--surface); }
.stat:hover { border-color: var(--accent); }
.stat strong { display: block; font-size: 28px; font-weight: 600; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 14px; }
.directory { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 24px 32px; margin-top: 16px; }
.directory h3 { font-size: 16px; margin-bottom: 8px; }
.directory h3 a { text-decoration: none; }
.directory ul { list-style: none; padding: 0; margin: 0; font-size: 15px; }
.directory li { padding: 4px 0; }
.directory li a { text-decoration: none; color: var(--text-soft); }
.directory li a:hover { color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  .header-inner { flex-wrap: wrap; height: auto; gap: 0 14px; padding-top: 12px; }
  .theme-toggle { margin-left: auto; width: 30px; height: 30px; }
  .nav { order: 3; width: 100%; margin: 0 -16px; padding: 10px 16px 12px; gap: 16px; width: calc(100% + 32px); }
  .nav a[aria-current='page'] { box-shadow: none; color: var(--accent); }
  .nav a { font-size: 14px; }
  main { padding-top: 36px; }
  section { margin-top: 48px; }
  .hero { flex-direction: column-reverse; gap: 24px; }
  .portrait { width: 150px; height: 200px; }
  .hero h1, .page-head h1 { font-size: 26px; }
  .entry-head h1 { font-size: 28px; }
  .post-row { grid-template-columns: 1fr; gap: 2px; }
  .post-link { font-size: 16px; }
  .prose { font-size: 16px; }
  .prose .anchor { display: none; }
  .prev-next { grid-template-columns: 1fr; }
  .prev-next .next { text-align: left; }
  .table-filter { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  .site-header, .site-footer, .theme-toggle, .prev-next, .toc { display: none; }
  body { background: #fff; color: #000; }
}
