/* =========================================================================
   Yue Li — personal academic site
   al-folio-inspired clean academic. Warm paper + ink + teal.
   Light/dark via [data-theme] + prefers-color-scheme.
   ========================================================================= */

/* ---- Design tokens ---------------------------------------------------- */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-serif: Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Code", "Segoe UI Mono", Menlo, Consolas, monospace;

  --bg: #faf8f3;
  --bg-soft: #f1ede3;
  --surface: #fffdf8;
  --border: #e7e0d2;
  --border-strong: #d6cdba;
  --text: #211e19;
  --text-soft: #5b564c;
  --text-faint: #8d8675;
  --accent: #1f6357;
  --accent-hover: #154a41;
  --accent-tint: #e3efe9;
  --tag-bg: #efe7d6;
  --tag-text: #6c6453;
  --code-bg: #f4efe2;
  --thumb-fill: transparent;
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.05), 0 8px 28px rgba(60, 50, 30, 0.07);
  --shadow-lg: 0 10px 40px rgba(40, 30, 15, 0.18);

  --measure: 54rem;
  --measure-wide: 54rem;
  --radius: 10px;
  --radius-sm: 6px;
  --pad: clamp(1.1rem, 4vw, 2rem);
}

:root[data-theme="dark"] {
  --bg: #15130e;
  --bg-soft: #1e1a13;
  --surface: #1b1812;
  --border: #322c22;
  --border-strong: #463e30;
  --text: #ece6da;
  --text-soft: #b2aa98;
  --text-faint: #7e7666;
  --accent: #6cba9f;
  --accent-hover: #88ccb4;
  --accent-tint: #18261f;
  --tag-bg: #2a241b;
  --tag-text: #b2aa98;
  --code-bg: #201c14;
  --thumb-fill: #fff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 44px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130e;
    --bg-soft: #1e1a13;
    --surface: #1b1812;
    --border: #322c22;
    --border-strong: #463e30;
    --text: #ece6da;
    --text-soft: #b2aa98;
    --text-faint: #7e7666;
    --accent: #6cba9f;
    --accent-hover: #88ccb4;
    --accent-tint: #18261f;
    --tag-bg: #2a241b;
    --tag-text: #b2aa98;
    --code-bg: #201c14;
    --thumb-fill: #fff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 44px rgba(0, 0, 0, 0.6);
  }
}

/* ---- Reset / base ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16.5px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1, h2, h3, h4 { line-height: 1.22; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
img { max-width: 100%; height: auto; }
hr { border: none; border-top: 1px solid var(--border); margin: 2.4rem 0; }
::selection { background: var(--accent-tint); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--accent); color: #fff; padding: 0.6rem 1rem; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---- Layout ----------------------------------------------------------- */
.wrap { width: 100%; max-width: var(--measure); margin: 0 auto; padding: 0 var(--pad); }
.wrap--wide { max-width: var(--measure-wide); }

#main { padding-top: clamp(2.6rem, 4vw, 3.6rem); padding-bottom: 1.5rem; }
.section { margin: clamp(2.4rem, 6vw, 3.6rem) 0; }

.kicker {
  font-family: var(--font-mono);
  font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 1rem; font-weight: 500;
  display: flex; align-items: center; gap: 0.75rem;
}
.kicker::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---- Header / nav ----------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(150%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.nav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; height: 58px; }
.brand { display: inline-flex; align-items: baseline; gap: 0.5rem; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; color: var(--accent); }

.nav-right { display: flex; align-items: center; gap: 0.2rem; }
.navlink {
  color: var(--text-soft); padding: 0.4rem 0.65rem; border-radius: var(--radius-sm);
  font-size: 0.92rem; font-weight: 450;
}
.navlink:hover { color: var(--text); text-decoration: none; }
.navlink[aria-current="page"] { color: var(--accent); }

.search-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: none; background: none; color: var(--text-faint);
  font: inherit; font-size: 0.85rem; cursor: pointer; padding: 0.4rem 0.55rem; margin-left: 0.1rem;
}
.search-btn:hover { color: var(--accent); }
.search-btn svg { width: 15px; height: 15px; }
.kbd {
  font-family: var(--font-mono); font-size: 0.68rem; line-height: 1;
  border: 1px solid var(--border-strong); border-radius: 4px; padding: 0.18rem 0.32rem;
  color: var(--text-faint); background: var(--bg-soft);
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text-soft); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--bg-soft); }
.icon-btn svg { width: 17px; height: 17px; }

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

@media (max-width: 540px) {
  .navlink { padding: 0.4rem 0.45rem; }
  .search-btn { padding: 0.34rem; }
}

/* ---- About head (centered, al-folio style) ---------------------------- */
.about-head { padding-top: 0.5rem; }
.about-head h1 { font-size: clamp(2rem, 5vw, 2.6rem); margin: 0 0 1.2rem; }
.about-cols::after { content: ""; display: block; clear: both; }
.about-text .bio p:first-child { margin-top: 0; }
.about-side { float: right; width: 190px; margin: 0.3rem 0 1.2rem 2rem; }
.portrait {
  width: 190px; aspect-ratio: 4 / 5; object-fit: cover; object-position: center 18%;
  border-radius: 12px; border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); background: var(--bg-soft); display: block;
}
.contact { font-size: 0.82rem; color: var(--text-faint); margin-top: 0.75rem; line-height: 1.65; word-break: break-word; }
.contact a { color: var(--text-soft); }
.contact a:hover { color: var(--accent); }

.social {
  display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 0.4rem; margin: 1rem 0 0.2rem;
}
.social a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-soft); background: var(--surface);
}
.social a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.social svg { width: 18px; height: 18px; }
.social a .label { display: none; }

/* ---- Prose (bio + blog body) ------------------------------------------ */
.prose { font-size: 1.04rem; line-height: 1.72; color: var(--text); }
.prose p { margin: 0 0 1.1rem; }
.prose a { text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.bio { max-width: 40rem; }

.post-prose { font-size: 1.12rem; line-height: 1.75; }
.post-prose h2 { font-family: var(--font-sans); font-size: 1.42rem; margin: 2.2rem 0 0.85rem; scroll-margin-top: 72px; }
.post-prose h3 { font-family: var(--font-sans); font-size: 1.15rem; margin: 1.7rem 0 0.55rem; scroll-margin-top: 72px; }
.post-prose ul, .post-prose ol { padding-left: 1.3rem; margin: 0 0 1.1rem; }
.post-prose li { margin: 0.3rem 0; }
.post-prose img { border-radius: var(--radius-sm); display: block; margin: 1.6rem auto; border: 1px solid var(--border); background: var(--surface); padding: 0.6rem; }
.post-prose blockquote { margin: 1.4rem 0; padding: 0.2rem 0 0.2rem 1.2rem; border-left: 3px solid var(--accent); color: var(--text-soft); font-style: italic; }

code { font-family: var(--font-mono); font-size: 0.85em; }
.post-prose :not(pre) > code { background: var(--code-bg); border: 1px solid var(--border); padding: 0.1em 0.36em; border-radius: 5px; font-style: normal; }
pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1rem 1.1rem; overflow-x: auto; margin: 1.5rem 0; line-height: 1.55;
}
pre code { font-size: 0.82rem; color: var(--text); }

/* syntax tokens (highlight.js), theme-aware */
.hljs-comment, .hljs-quote { color: var(--text-faint); font-style: italic; }
.hljs-keyword, .hljs-built_in, .hljs-literal { color: var(--accent); }
.hljs-string { color: #3f7d4f; }
:root[data-theme="dark"] .hljs-string { color: #9bc99b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hljs-string { color: #9bc99b; } }
.hljs-number, .hljs-symbol { color: #a9651f; }
:root[data-theme="dark"] .hljs-number { color: #d8a657; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hljs-number { color: #d8a657; } }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--accent-hover); font-weight: 600; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-params { color: var(--text); }

/* ---- News ------------------------------------------------------------- */
.news-item { display: flex; gap: 1.1rem; padding: 0.5rem 0; font-size: 0.96rem; border-bottom: 1px dotted var(--border); }
.news-item:last-child { border-bottom: none; }
.news-item .date { font-family: var(--font-mono); font-size: 0.76rem; color: var(--text-faint); flex: none; width: 4.7rem; padding-top: 0.2rem; }
.news-item .body { color: var(--text-soft); }
.news-item .body em { color: var(--text); font-style: italic; }

/* ---- Interests (editorial list, no cards) ----------------------------- */
.interests { margin: 0; }
.interest { display: grid; grid-template-columns: 2.4rem 1fr; gap: 0 0.4rem; padding: 0.85rem 0; border-bottom: 1px solid var(--border); }
.interest:last-child { border-bottom: none; }
.interest .num { font-family: var(--font-mono); font-size: 0.8rem; color: var(--accent); padding-top: 0.18rem; }
.interest h3 { font-size: 1.02rem; margin: 0 0 0.2rem; }
.interest p { margin: 0; color: var(--text-soft); font-size: 0.94rem; line-height: 1.55; }

/* ---- Publications (al-folio entry style) ------------------------------ */
.year-head { font-family: var(--font-mono); font-size: 0.92rem; color: var(--text-faint); font-weight: 500; margin: 1.9rem 0 0.6rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--border); }
.pub { display: flex; gap: 1.1rem; align-items: flex-start; padding: 0.95rem 0; border-bottom: 1px solid var(--border); }
.pub:last-child { border-bottom: none; }
.pub-main { flex: 1; min-width: 0; order: 1; }
.pub-thumb {
  flex: none; width: 215px; order: 2; align-self: flex-start;
  padding: 8px; border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border: 1px solid color-mix(in srgb, var(--border-strong) 60%, transparent);
  box-shadow: 0 1px 2px rgba(40, 32, 16, 0.05), 0 8px 22px rgba(40, 32, 16, 0.10);
  -webkit-backdrop-filter: blur(8px) saturate(115%); backdrop-filter: blur(8px) saturate(115%);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.pub:hover .pub-thumb { transform: translateY(-3px); box-shadow: 0 6px 12px rgba(40, 32, 16, 0.08), 0 16px 34px rgba(40, 32, 16, 0.16); }
.pub-thumb img { width: 100%; height: 150px; object-fit: contain; display: block; border-radius: 6px; background: var(--thumb-fill); }
.pub-title { font-weight: 600; font-size: 1.03rem; margin: 0 0 0.25rem; line-height: 1.4; }
.pub-title a { color: var(--text); }
.pub-title a:hover { color: var(--accent); }
.pub-star { color: var(--accent); margin-right: 0.15rem; }
.pub-authors { color: var(--text-soft); font-size: 0.92rem; margin: 0 0 0.22rem; }
.pub-authors .me { color: var(--accent); font-weight: 600; }
.pub-authors sup.role, .role-legend sup.role { color: var(--accent); font-weight: 600; font-size: 0.7em; }
.role-legend { font-size: 0.82rem; color: var(--text-faint); margin: -0.6rem 0 1.3rem; }
.pub-authors strong { font-weight: 700; color: var(--text); }
.pub-venue { font-style: italic; color: var(--text-soft); font-size: 0.92rem; margin: 0 0 0.5rem; }
.pub-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.ab-btn {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 0.16rem 0.52rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  color: var(--text-soft); background: var(--surface); cursor: pointer; line-height: 1.5;
}
.ab-btn:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.ab-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }
.pub-cite { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-faint); margin-left: 0.1rem; }
.af-badge { font-family: var(--font-mono); font-size: 0.66rem; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 999px; padding: 0.06rem 0.5rem; margin-left: 0.5rem; white-space: nowrap; }
.cf-note { color: var(--text-faint); font-size: 0.92em; margin-left: 0.4rem; }
.award-badge { font-family: var(--font-mono); font-style: normal; font-size: 0.66rem; color: var(--accent); background: var(--accent-tint); border-radius: 999px; padding: 0.06rem 0.5rem; margin-left: 0.5rem; white-space: nowrap; }
.bibtex {
  margin: 0.7rem 0 0.2rem; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.85rem 0.95rem; overflow-x: auto; position: relative;
}
.bibtex pre { margin: 0; border: none; padding: 0; background: none; }
.bibtex pre code { font-size: 0.76rem; line-height: 1.5; white-space: pre; }
.bibtex .copy { position: absolute; top: 0.5rem; right: 0.5rem; }
.bibtex[hidden] { display: none; }

/* tag filter */
.tagbar { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.4rem 0 1.5rem; }
.tagbtn {
  font-family: var(--font-mono); font-size: 0.74rem; padding: 0.26rem 0.62rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft); cursor: pointer;
}
.tagbtn:hover { border-color: var(--accent); color: var(--accent); }
.tagbtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Tags ------------------------------------------------------------- */
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag { font-family: var(--font-mono); font-size: 0.7rem; color: var(--tag-text); background: var(--tag-bg); border-radius: 4px; padding: 0.1rem 0.45rem; }

/* ---- Post list -------------------------------------------------------- */
.post-list { display: flex; flex-direction: column; }
.post-row { display: block; padding: 1.05rem 0; border-bottom: 1px solid var(--border); }
.post-row:last-child { border-bottom: none; }
.post-row .date { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-faint); }
.post-row h3 { font-size: 1.14rem; margin: 0.2rem 0 0.3rem; }
.post-row h3 a { color: var(--text); }
.post-row h3 a:hover { color: var(--accent); }
.post-row p { margin: 0; color: var(--text-soft); font-size: 0.95rem; }
.post-row .tags { margin-top: 0.5rem; }

/* ---- Single post ------------------------------------------------------ */
.post-header { margin-bottom: 1.6rem; }
.post-header h1 { font-size: clamp(1.7rem, 4.2vw, 2.2rem); margin: 0.5rem 0 0.55rem; }
.post-header .meta { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-faint); display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: center; }
.back-link { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-soft); display: inline-flex; align-items: center; gap: 0.35rem; }

.toc { margin: 1.6rem 0 2rem; padding: 0.9rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft); }
.toc .toc-label { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-faint); margin: 0 0 0.5rem; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0.22rem 0; font-size: 0.92rem; }
.toc li.lvl-3 { padding-left: 1.1rem; }
.toc a { color: var(--text-soft); }
.toc a:hover { color: var(--accent); }

/* ---- Projects --------------------------------------------------------- */
.proj { padding: 0.8rem 0; border-bottom: 1px solid var(--border); }
.proj:last-child { border-bottom: none; }
.proj .top { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.proj .name { font-weight: 600; }
.proj .lang { font-family: var(--font-mono); font-size: 0.73rem; color: var(--text-faint); }
.proj p { margin: 0.3rem 0 0; color: var(--text-soft); font-size: 0.92rem; }

/* ---- Misc ------------------------------------------------------------- */
.more-link { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.88rem; font-weight: 500; margin-top: 1.1rem; }
.more-link:hover { gap: 0.55rem; text-decoration: none; }
.muted { color: var(--text-faint); }
.loading { color: var(--text-faint); font-family: var(--font-mono); font-size: 0.84rem; padding: 1rem 0; }

/* ---- Footer ----------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 3rem; padding: 1.8rem 0 2.4rem; color: var(--text-faint); font-size: 0.84rem; }
.site-footer .row { display: flex; flex-wrap: wrap; gap: 0.8rem 1.4rem; justify-content: space-between; align-items: center; }
.site-footer a { color: var(--text-soft); }
.site-footer .social-mini { display: flex; gap: 0.3rem; }
.site-footer .social-mini a { width: 30px; height: 30px; border: none; }
.site-footer .social-mini { margin: 0; }

/* ---- Command palette (⌘K) --------------------------------------------- */
.cmdk-overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: color-mix(in srgb, var(--text) 22%, transparent);
  backdrop-filter: blur(2px); padding: 12vh 1rem 1rem; justify-content: center; align-items: flex-start;
}
.cmdk-overlay.open { display: flex; }
.cmdk {
  width: min(640px, 100%); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden;
  display: flex; flex-direction: column; max-height: 70vh;
}
.cmdk-input-wrap { display: flex; align-items: center; gap: 0.6rem; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border); }
.cmdk-input-wrap svg { width: 17px; height: 17px; color: var(--text-faint); flex: none; }
.cmdk-input { flex: 1; border: none; background: none; color: var(--text); font: inherit; font-size: 1.02rem; outline: none; }
.cmdk-input::placeholder { color: var(--text-faint); }
.cmdk-results { overflow-y: auto; padding: 0.4rem; }
.cmdk-group { font-family: var(--font-mono); font-size: 0.64rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-faint); padding: 0.6rem 0.7rem 0.3rem; }
.cmdk-item { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.5rem 0.7rem; border-radius: var(--radius-sm); cursor: pointer; }
.cmdk-item[aria-selected="true"] { background: var(--accent-tint); }
.cmdk-item .t { color: var(--text); font-size: 0.94rem; }
.cmdk-item .s { color: var(--text-faint); font-size: 0.78rem; }
.cmdk-item mark { background: none; color: var(--accent); font-weight: 600; }
.cmdk-empty { color: var(--text-faint); padding: 1.4rem 0.7rem; text-align: center; font-size: 0.9rem; }
.cmdk-foot { display: flex; gap: 1rem; padding: 0.55rem 0.9rem; border-top: 1px solid var(--border); font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-faint); }
.cmdk-foot span { display: inline-flex; align-items: center; gap: 0.35rem; }

/* ---- Responsive ------------------------------------------------------- */
@media (max-width: 560px) {
  .about-side { float: none; width: 100%; max-width: 210px; margin: 0 0 1.2rem; }
  .portrait { width: 100%; }
  .pub { flex-direction: column; gap: 0.8rem; }
  .pub-thumb { order: -1; width: 100%; }
  .pub-thumb img { height: 210px; }
}
