/* ---------- tokens ---------- */
:root {
  --bg: #f7f5f0;
  --surface: #fdfcf9;
  --text: #1d2126;
  --muted: #555d68;
  --faint: #6b737e;
  --line: #e2ddd2;
  --line-strong: #cfc8ba;
  --accent: #2f5d8a;
  --accent-soft: #e4ecf4;
  --note: #855510;
  --note-soft: #f4e8d2;
  --code-bg: #eeebe3;
  --selection: #cfdff0;
  --shadow: 0 1px 2px rgba(29, 33, 38, .05), 0 6px 18px -6px rgba(29, 33, 38, .08);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --measure: 56rem;
  --gutter: 1.25rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a; --surface: #1a1d22; --text: #e8e5de; --muted: #a8aeb7; --faint: #8b929c;
    --line: #2a2e35; --line-strong: #3a3f47; --accent: #93bce6; --accent-soft: #1d2936;
    --note: #e3b46e; --note-soft: #2d2517; --code-bg: #21252b; --selection: #2c4560;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a; --surface: #1a1d22; --text: #e8e5de; --muted: #a8aeb7; --faint: #8b929c;
  --line: #2a2e35; --line-strong: #3a3f47; --accent: #93bce6; --accent-soft: #1d2936;
  --note: #e3b46e; --note-soft: #2d2517; --code-bg: #21252b; --selection: #2c4560;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5rem; scrollbar-color: var(--line-strong) var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 1.0625rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  caret-color: var(--accent);
}
::selection { background: var(--selection); color: var(--text); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: .2em; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); transition: text-decoration-color .15s; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; letter-spacing: -.015em; text-wrap: balance; }
h3 { font-size: 1.2rem; margin: 0 0 .35rem; }
p { text-wrap: pretty; }
img { max-width: 100%; height: auto; }
code, pre { font-family: var(--mono); font-size: .88em; }
:not(pre) > code { background: var(--code-bg); padding: .1em .35em; border-radius: 4px; }
pre { background: var(--code-bg); padding: 1rem; border-radius: 8px; overflow-x: auto; line-height: 1.5; }
time, .entry-num, .dates { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: .5rem; background: var(--surface); padding: .5rem .75rem; z-index: 10; }
.skip:focus { left: .5rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: var(--measure); margin: 0 auto; padding: .65rem var(--gutter); display: flex; align-items: center; gap: 1rem; }
.brand { font: 600 1.05rem var(--serif); letter-spacing: -.01em; color: var(--text); text-decoration: none; margin-right: auto; }
.topbar nav { display: flex; gap: .15rem; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: .95rem; padding: .35rem .65rem; border-radius: 6px; transition: color .15s, background-color .15s; }
.topbar nav a:hover { color: var(--text); background: var(--accent-soft); }
.topbar nav a[aria-current="page"] { color: var(--text); font-weight: 500; box-shadow: inset 0 -2px 0 var(--accent); border-radius: 6px 6px 0 0; }
.theme-toggle {
  display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; padding: 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--line-strong); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: inline; }
}

/* ---------- layout ---------- */
.page { max-width: var(--measure); margin: 0 auto; padding: 3.5rem var(--gutter) 4.5rem; }
.block { margin-top: 3.5rem; }
.section-head { font-size: 1.6rem; margin: 0 0 1.25rem; padding-bottom: .6rem; border-bottom: 1px solid var(--line); }
.prose p { margin: 0 0 1rem; }
.prose ul { padding-left: 1.2rem; }
.prose li { margin: .35rem 0; }
.prose li::marker { color: var(--faint); }
.empty { color: var(--muted); margin: 0; }

/* ---------- page header (shared by every page) ---------- */
.page-header { margin-bottom: 2.5rem; }
.page-header h1 { font-size: clamp(2.25rem, 5.5vw, 3rem); margin: 0; letter-spacing: -.025em; }
.page-header .lede { margin: .6rem 0 0; font-size: 1.15rem; color: var(--muted); max-width: 40rem; }
.page-header.has-photo { display: flex; align-items: center; gap: 2rem; }
.portrait { width: 160px; height: 160px; border-radius: 12px; object-fit: cover; flex: none; background: var(--surface); box-shadow: var(--shadow); }
.social { list-style: none; display: flex; gap: .5rem; padding: 0; margin: 1.1rem 0 0; }
.social a {
  display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: 8px;
  color: var(--muted); border: 1px solid var(--line); background: var(--surface); transition: color .15s, border-color .15s;
}
.social a:hover { color: var(--accent); border-color: var(--accent); }
.social svg { width: 1.1rem; height: 1.1rem; }
.toc { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--accent); }
.toc + .block { margin-top: 2.5rem; }

/* ---------- projects / publications ---------- */
.cards { list-style: none; padding: 0; margin: 0; }
.card { display: grid; grid-template-columns: 15rem 1fr; gap: 1.75rem; align-items: start; padding: 1.5rem 0; border-top: 1px solid var(--line); }
.card:first-child { border-top: 0; padding-top: .25rem; }
.card.no-img { grid-template-columns: 1fr; }
.card-img-link { display: block; border-radius: 8px; }
.card-img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; object-position: top; border-radius: 8px; border: 1px solid var(--line); display: block; box-shadow: var(--shadow); transition: transform .25s cubic-bezier(.2, .7, .2, 1); }
.card-img-link:hover .card-img { transform: translateY(-2px); }
.card-body h3 { font-size: 1.3rem; margin: 0 0 .4rem; }
.card-body p { margin: 0 0 .6rem; }
.card-meta { font: 400 .82rem var(--mono); color: var(--faint); margin: 0 0 .25rem !important; font-variant-numeric: tabular-nums; }
.role { color: var(--muted); }
.label { font-weight: 600; color: var(--text); }
.card-links { display: flex; flex-wrap: wrap; gap: .5rem; margin: .9rem 0 0 !important; }
.card-links a {
  font-size: .88rem; font-weight: 500; text-decoration: none; padding: .3rem .75rem; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent); transition: background-color .15s, color .15s;
}
.card-links a::after { content: " ↗"; font-size: .85em; }
.card-links a:hover { background: var(--accent); color: var(--bg); }
.authors { color: var(--muted); }

/* ---------- experience ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline > li { padding: 1.4rem 0; border-top: 1px solid var(--line); }
.timeline > li:first-child { border-top: 0; padding-top: .25rem; }
.tl-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .2rem 1rem; }
.tl-head h3 { margin: 0; font-size: 1.3rem; }
.role-name { display: block; font-family: var(--sans); font-weight: 400; font-size: 1rem; letter-spacing: 0; color: var(--muted); margin-top: .15rem; }
.dates { font: 400 .82rem var(--mono); color: var(--faint); white-space: nowrap; }
.timeline ul { margin: .7rem 0 0; padding-left: 1.1rem; }
.timeline ul li { margin: .35rem 0; }
.timeline ul li::marker { color: var(--faint); }

/* ---------- misc ---------- */
.hobbies { display: grid; grid-template-columns: repeat(2, 1fr); column-gap: 2.5rem; margin: 0; }
.hobbies > div { padding: 1.1rem 0; border-top: 1px solid var(--line); }
.hobbies > div:nth-child(-n+2) { border-top: 0; padding-top: .25rem; }
.hobbies dt { font: 600 1.2rem var(--serif); margin-bottom: .25rem; }
.hobbies dd { margin: 0; color: var(--muted); }

/* ---------- blog feed ---------- */
.blog-tools { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.filters { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.filters button { font: 500 .88rem var(--sans); border: 0; border-radius: 6px; background: none; color: var(--muted); padding: .35rem .8rem; cursor: pointer; transition: background-color .15s, color .15s; }
.filters button:hover { color: var(--text); }
.filters button span { font: 400 .8rem var(--mono); color: var(--faint); margin-left: .3rem; }
.filters button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.filters button[aria-pressed="true"] span { color: inherit; }
.blog-links { display: inline-flex; align-items: center; gap: 1.25rem; font-size: .92rem; }
.rss { display: inline-flex; align-items: center; gap: .35rem; }
.rss svg { width: .85em; height: .85em; }
.feed { list-style: none; padding: 0; margin: 0; }
.entry { padding: 1.6rem 0; border-bottom: 1px solid var(--line); }
.entry[hidden] { display: none; }
.entry-meta { display: flex; align-items: center; gap: .65rem; font: 400 .82rem var(--mono); color: var(--faint); margin: 0 0 .5rem; }
.entry-num { min-width: 1.5rem; }
.badge { font: 600 .7rem var(--sans); text-transform: uppercase; letter-spacing: .07em; padding: .15rem .5rem; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }
.badge-note { background: var(--note-soft); color: var(--note); }
.entry-title { font-size: 1.5rem; margin: .2rem 0 .45rem; }
.entry-title a { color: var(--text); text-decoration: none; }
.entry-title a:hover { color: var(--accent); }
.entry-excerpt { margin: 0 0 .7rem; color: var(--muted); }
.entry-body { font-size: 1.1rem; }
.entry-body p:last-child { margin-bottom: .6rem; }
.entry-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.1rem; margin: 0; font-size: .88rem; }
.permalink { color: var(--faint); text-decoration: none; }
.permalink:hover { color: var(--accent); }
.entry-title .permalink { font-size: .85em; opacity: 0; transition: opacity .15s; }
.entry:hover .entry-title .permalink, .entry-title .permalink:focus-visible { opacity: 1; }
.tags { display: inline-flex; flex-wrap: wrap; gap: .6rem; }
.tags a { color: var(--muted); text-decoration: none; }
.tags a:hover { color: var(--accent); }
.share { font: 500 .88rem var(--sans); background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; }
.share:hover { color: var(--accent); }
.feed-empty { color: var(--muted); padding: 1.6rem 0; margin: 0; border-bottom: 1px solid var(--line); }
.end-of-feed { text-align: center; font-size: .85rem; color: var(--faint); margin-top: 2rem; }
.tag-cloud { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 2.5rem; }
.tag-cloud a { font-size: .92rem; text-decoration: none; padding: .3rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); transition: border-color .15s, color .15s; }
.tag-cloud a:hover { border-color: var(--accent); color: var(--accent); }
.tag-cloud span { font: 400 .8rem var(--mono); color: var(--faint); margin-left: .2rem; }
.tag-group h2 { font-size: 1.35rem; border-bottom: 1px solid var(--line); padding-bottom: .5rem; margin: 2rem 0 .75rem; }
.tag-group ul { list-style: none; padding: 0; margin: 0; }
.tag-group li { margin: .6rem 0; display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; }
.tag-group time { font: 400 .82rem var(--mono); color: var(--faint); }

/* ---------- post ---------- */
.crumbs { font-size: .88rem; color: var(--faint); margin-bottom: 1.5rem; }
.crumbs a { color: var(--muted); }
.post-head { margin-bottom: 2.25rem; }
.byline { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .5rem; color: var(--muted); font-size: .95rem; margin: .8rem 0 0; }
.byline .share { font-size: .95rem; }
.post-body { font-size: 1.125rem; line-height: 1.7; }
.post-body h2 { font-size: 1.55rem; margin: 2.5rem 0 .8rem; }
.post-body h3 { margin-top: 1.8rem; }
.post-body blockquote { margin: 1.4rem 0; padding: .2rem 1.1rem; border-left: 1px solid var(--line-strong); color: var(--muted); font-style: italic; }
.post-body table { border-collapse: collapse; width: 100%; font-size: .95rem; display: block; overflow-x: auto; font-variant-numeric: tabular-nums; }
.post-body th, .post-body td { border: 1px solid var(--line); padding: .5rem .75rem; text-align: left; }
.post-body img { border-radius: 8px; }
.post-foot { margin-top: 3rem; border-top: 1px solid var(--line); padding-top: 1.5rem; }
.topics { display: flex; align-items: baseline; gap: .6rem; font-size: .92rem; margin: 0; }
.cite { margin: 1.5rem 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.cite summary { cursor: pointer; padding: .75rem 1rem; font-size: .92rem; font-weight: 500; color: var(--muted); border-radius: 10px; }
.cite summary:hover { color: var(--text); }
.cite[open] summary { border-bottom: 1px solid var(--line); border-radius: 10px 10px 0 0; }
.cite-tabs, .cite-formats { display: flex; gap: .25rem; align-items: center; }
.cite-tabs { padding: .7rem 1rem 0; }
.cite-tabs button { font: 500 .85rem var(--sans); background: none; border: 1px solid transparent; border-radius: 6px; padding: .25rem .65rem; color: var(--muted); cursor: pointer; }
.cite-tabs button:hover { color: var(--text); }
.cite-tabs button[aria-pressed="true"] { border-color: var(--line); color: var(--text); background: var(--bg); }
.cite-tabs .copy { margin-left: auto; color: var(--accent); }
.cite-panel { padding: .7rem 1rem 1rem; }
.cite-panel pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .82rem; }
.prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.5rem 0; }
.prevnext a { display: block; text-decoration: none; color: var(--text); padding: .9rem 1.1rem; border: 1px solid var(--line); border-radius: 10px; transition: border-color .15s; }
.prevnext a:hover { border-color: var(--accent); }
.prevnext span { display: block; font-size: .82rem; color: var(--faint); margin-bottom: .2rem; }
.prevnext .older { text-align: right; grid-column: 2; }
.related h2 { font-size: 1.2rem; margin: 2rem 0 .6rem; }
.related ul { padding-left: 1.1rem; margin: 0; }
.related time { font: 400 .8rem var(--mono); color: var(--faint); margin-left: .4rem; }
.back { font-size: .92rem; margin-top: 2rem; }
.notfound-links { font-size: 1.05rem; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, .5rem); background: var(--text); color: var(--bg); font-size: .88rem; padding: .55rem 1rem; border-radius: 8px; opacity: 0; transition: opacity .2s, transform .25s cubic-bezier(.2, .7, .2, 1); pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); }
.footer-inner { max-width: var(--measure); margin: 0 auto; padding: 1.75rem var(--gutter) 2.75rem; display: flex; flex-wrap: wrap; gap: .4rem .7rem; font-size: .88rem; color: var(--faint); }
.footer-inner a { color: var(--muted); }
.dot { color: var(--line-strong); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .card { grid-template-columns: 1fr; gap: 1rem; }
  .card-img { max-width: 26rem; }
}
@media (max-width: 640px) {
  :root { --gutter: 1rem; }
  body { font-size: 1rem; }
  .page { padding-top: 2.25rem; }
  .page-header.has-photo { flex-direction: column; align-items: flex-start; gap: 1.25rem; }
  .portrait { width: 112px; height: 112px; }
  .hobbies { grid-template-columns: 1fr; }
  .hobbies > div:nth-child(2) { border-top: 1px solid var(--line); padding-top: 1.1rem; }
  .prevnext { grid-template-columns: 1fr; }
  .prevnext .older { grid-column: 1; }
  .topbar nav a { padding: .35rem .45rem; }
  .brand { font-size: 1rem; }
  .blog-tools { align-items: flex-start; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
