/* ============================================================
   Guangbo Yu — personal site
   Plain CSS, no framework, no build step.

   Design language follows PRISM (github.com/xyjoey/PRISM):
   deep navy and gold, Georgia headings over Inter body,
   slate neutrals, card-based content, avatar sidebar.
   ============================================================ */

/* ---------- 1. Tokens ---------- */

:root {
  --bg:      #fefffe;
  --fg:      #0f172a;
  --card:    #ffffff;

  --accent:      #d4a562;
  --accent-deep: #b8914d;

  --n50:  #f8fafc;
  --n100: #f1f5f9;
  --n200: #e2e8f0;
  --n300: #cbd5e1;
  --n400: #94a3b8;
  --n500: #64748b;
  --n600: #475569;
  --n700: #334155;
  --n800: #1e293b;
  --n900: #0f172a;

  --font-sans:  Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
                "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-mono:  "SF Mono", ui-monospace, Monaco, "Cascadia Code", Consolas, monospace;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow:    0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

  --radius:    0.75rem;
  --radius-lg: 1rem;

  --shell:  76rem;   /* page container */
  --rail:   17.5rem; /* sidebar width */
  --gutter: clamp(1.25rem, 4vw, 2.5rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --fg: #f8fafc; --card: #1e293b;
    --accent: #e4b976; --accent-deep: #d4a562;
    --n50: #0f172a; --n100: #1e293b; --n200: #334155; --n300: #475569;
    --n400: #64748b; --n500: #94a3b8; --n600: #cbd5e1; --n700: #e2e8f0;
    --n800: #f1f5f9; --n900: #f8fafc;
  }
}

:root[data-theme="light"] {
  --bg: #fefffe; --fg: #0f172a; --card: #ffffff;
  --accent: #d4a562; --accent-deep: #b8914d;
  --n50: #f8fafc; --n100: #f1f5f9; --n200: #e2e8f0; --n300: #cbd5e1;
  --n400: #94a3b8; --n500: #64748b; --n600: #475569; --n700: #334155;
  --n800: #1e293b; --n900: #0f172a;
}
:root[data-theme="dark"] {
  --bg: #0f172a; --fg: #f8fafc; --card: #1e293b;
  --accent: #e4b976; --accent-deep: #d4a562;
  --n50: #0f172a; --n100: #1e293b; --n200: #334155; --n300: #475569;
  --n400: #64748b; --n500: #94a3b8; --n600: #cbd5e1; --n700: #e2e8f0;
  --n800: #f1f5f9; --n900: #f8fafc;
}

/* ---------- 2. Reset ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.625;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img { max-width: 100%; height: auto; display: block; }
ul { margin: 0; padding: 0; list-style: none; }
dl, dd { margin: 0; }

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.25;
  margin: 0;
  color: var(--n900);
  text-wrap: balance;
}

p { margin: 0 0 1em; text-wrap: pretty; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent-deep); text-decoration: none; transition: color 140ms ease; }
a:hover { color: var(--accent); }

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.skip-link { position: absolute; left: -9999px; top: 0; background: var(--card);
  padding: .6rem 1rem; z-index: 100; border-radius: .5rem; }
.skip-link:focus { left: 1rem; top: .75rem; }

/* ---------- 3. Shell ---------- */

.shell { max-width: var(--shell); margin-inline: auto; padding-inline: var(--gutter); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--n200);
}
.topbar__in {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding-block: .9rem;
}
.wordmark {
  font-family: var(--font-serif); font-weight: 700; font-size: 1.3rem;
  color: var(--n900); white-space: nowrap;
}
.wordmark:hover { color: var(--n900); }

.nav { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; }
.nav a {
  padding: .45rem .85rem; border-radius: .5rem; font-size: .9375rem;
  color: var(--n500); font-weight: 500;
}
.nav a:hover { color: var(--n900); background: var(--n100); }
.nav a[aria-current="page"] {
  color: var(--n900);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

/* Narrow screens: name and theme button on one row, the nav as a single row
   under them (scrolling sideways if it ever runs out of room) instead of wrapping. */
@media (max-width: 48em) {
  .topbar__in { flex-wrap: wrap; row-gap: .35rem; padding-block: .6rem .45rem; }
  .wordmark { order: 1; font-size: 1.2rem; }
  .icon-btn { order: 2; }
  .nav {
    order: 3; flex: 1 0 100%; flex-wrap: nowrap; gap: 0;
    overflow-x: auto; scrollbar-width: none; margin-inline: -.5rem;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: .35rem .55rem; font-size: .875rem; white-space: nowrap; }
}
@media (max-width: 30em) {
  .nav { justify-content: space-between; }
  .nav a { padding: .35rem .4rem; font-size: .8125rem; }
}

.icon-btn {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border: 1px solid var(--n200); border-radius: .5rem; background: var(--card);
  color: var(--n500); cursor: pointer; padding: 0; flex: none;
}
.icon-btn:hover { color: var(--n900); border-color: var(--n300); }
.icon-btn svg { width: 1.05rem; height: 1.05rem; }

/* Two-column body */
.layout {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 3.5rem);
  padding-block: clamp(2rem, 5vw, 3.25rem) 4rem;
  align-items: start;
}
@media (max-width: 60em) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 2.5rem; }
}

/* ---------- 4. Sidebar ---------- */

.rail { position: sticky; top: 5.5rem; }
@media (max-width: 60em) { .rail { position: static; } }

.avatar {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  background: var(--n200);
}
@media (max-width: 60em) {
  .avatar { width: 11rem; margin-inline: auto; }
}

.rail__name {
  margin: 1.15rem 0 0; text-align: center;
  font-family: var(--font-serif); font-weight: 700; color: var(--n900);
  font-size: 1.6rem; line-height: 1.25; letter-spacing: -0.01em;
}
.rail__role { margin: .35rem 0 0; text-align: center; color: var(--accent-deep); font-weight: 500; }
.rail__org  { margin: .1rem 0 0; text-align: center; color: var(--n500); font-size: .9375rem; }

.rail__links {
  display: flex; justify-content: center; flex-wrap: wrap;
  gap: .35rem; margin-top: 1.1rem;
}
.rail__links a {
  display: grid; place-items: center; width: 2.2rem; height: 2.2rem;
  border-radius: .5rem; color: var(--n500);
}
.rail__links a:hover { color: var(--accent-deep); background: var(--n100); }
.rail__links svg { width: 1.15rem; height: 1.15rem; fill: none;
  stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rail__links svg.is-solid { fill: currentColor; stroke: none; }

.panel {
  margin-top: 1.5rem; padding: 1.1rem 1.25rem;
  background: var(--n100); border-radius: var(--radius);
}
.panel h2 { font-size: 1rem; font-family: var(--font-sans); font-weight: 600; color: var(--n800); }
.panel ul { margin-top: .6rem; display: flex; flex-direction: column; gap: .35rem; }
.panel li { color: var(--n600); font-size: .9375rem; }

/* ---------- 5. Main content ---------- */

.section + .section { margin-top: clamp(2.5rem, 5vw, 3.5rem); }

.section__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.15rem;
}
.section__head h2 { font-size: 1.75rem; letter-spacing: -0.015em; }
.section__head a { font-size: .875rem; font-weight: 500; white-space: nowrap; }

.page-title { font-size: 2rem; letter-spacing: -0.02em; }
.page-title + .section { margin-top: 1.5rem; }
.lede { margin-top: .6rem; color: var(--n500); max-width: 44rem; }

.prose { color: var(--n600); }
.prose p { max-width: 46rem; }

/* Cards */
.card {
  background: var(--n50);
  border: 1px solid var(--n200);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.card + .card { margin-top: .9rem; }
.card:hover { border-color: var(--n300); box-shadow: var(--shadow-sm); }

.card__title { font-size: 1.0625rem; font-family: var(--font-sans); font-weight: 600;
  color: var(--n900); line-height: 1.45; }
.card__title a { color: inherit; }
.card__title a:hover { color: var(--accent-deep); }

.card__meta { margin: .3rem 0 0; font-size: .9375rem; color: var(--n500); }
.card__meta .me { color: var(--accent-deep); font-weight: 500; }
.card__venue { margin: .15rem 0 0; font-size: .9375rem; color: var(--n600); }
.card__body { margin: .65rem 0 0; font-size: .9375rem; color: var(--n500); }

.stamp {
  display: inline-block; font-size: .6875rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent-deep); vertical-align: .12em;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-radius: .3rem; padding: .12rem .45rem; white-space: nowrap;
}

.links { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin-top: .8rem; font-size: .875rem; }
.links a { font-weight: 500; }

/* Publication list grouped by year */
.year-head {
  font-family: var(--font-mono); font-size: .8125rem; color: var(--n400);
  letter-spacing: .04em; margin: 1.75rem 0 .7rem;
}
.year-head:first-child { margin-top: 0; }

/* ---------- 6. Diagrams ---------- */

.diagram { margin: 1.15rem 0 0; overflow-x: auto; padding: 1px; }  /* room for edge strokes */
.diagram svg {
  width: 100%; min-width: 30rem; height: auto; display: block; color: var(--n700);
  overflow: visible;   /* keeps the outer box strokes at the viewBox edge */
}
.diagram figcaption { margin-top: .6rem; font-size: .8125rem; color: var(--n500); }

.dg-box  { fill: none; stroke: currentColor; stroke-opacity: .3; }
.dg-line { stroke: currentColor; stroke-opacity: .3; fill: none; }
.dg-dash { stroke-dasharray: 3 4; }
.dg-fill { fill: var(--accent); fill-opacity: .1; stroke: none; }
.dg-bar  { fill: var(--accent); fill-opacity: .75; stroke: none; }
.dg-t    { fill: currentColor; font-family: var(--font-sans); font-size: 12px; }
.dg-s    { fill: currentColor; fill-opacity: .62; font-family: var(--font-sans); font-size: 10.5px; }

/* Screenshots and screen recordings */
.media { margin: 1.15rem 0 0; }
.media img {
  width: 100%; border-radius: var(--radius); border: 1px solid var(--n200);
  background: var(--n100);
}
.media figcaption { margin-top: .6rem; font-size: .8125rem; color: var(--n500); }

/* Paper figures are drawn on white; keep them on a white plate in both themes. */
.media--plate img { background: #fff; padding: .5rem; }
.media--narrow img { max-width: 34rem; margin-inline: auto; }

.card__takeaway {
  margin: 1.15rem 0 0; padding: .7rem 1rem; font-size: .9375rem; color: var(--n700);
  border-left: 3px solid var(--accent); border-radius: 0 .5rem .5rem 0;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* ---------- 7. Tables ---------- */

.table-scroll { overflow-x: auto; margin-top: 1rem; }
table.results {
  border-collapse: collapse; font-size: .875rem;
  font-variant-numeric: tabular-nums; min-width: 22rem;
}
table.results th, table.results td {
  text-align: right; padding: .45rem 0 .45rem 1.25rem; white-space: nowrap;
}
table.results th:first-child, table.results td:first-child { text-align: left; padding-left: 0; }
table.results thead th {
  font-weight: 600; color: var(--n400); font-size: .75rem;
  letter-spacing: .06em; text-transform: uppercase; border-bottom: 1px solid var(--n200);
}
table.results tbody td { color: var(--n500); border-bottom: 1px solid var(--n200); }
table.results tbody tr:last-child td { border-bottom: 0; }
table.results tbody tr.is-key td { color: var(--n900); }
table.results tbody tr.is-key td:first-child { font-weight: 600; }
.table-note { margin-top: .5rem; font-size: .8125rem; color: var(--n400); }
table.results--wide { width: 100%; min-width: 0; }
table.results--wide th + th, table.results--wide td + td { padding-left: .9rem; }
table.results--wide td:first-child, table.results--wide th { white-space: normal; }
table.results td small { display: block; margin-top: .1rem; font-size: .75rem; font-weight: 400; color: var(--n400); }

/* ---------- 8. Photography ---------- */

/* Each place is a <details>, so folding is native: keyboard and screen readers
   get it for free, and collapsed sections never download their thumbnails. */
.fold + .fold { margin-top: .35rem; }

.gallery-group {
  display: flex; align-items: center; gap: .6rem;
  font-family: var(--font-serif); font-weight: 700; font-size: 1.25rem;
  color: var(--n900); cursor: pointer; list-style: none;
  margin-top: 1.75rem; padding-bottom: .6rem;
  border-bottom: 1px solid var(--n200);
}
.gallery-group::-webkit-details-marker { display: none; }
.gallery-group:hover { color: var(--accent-deep); }

/* Disclosure chevron, drawn rather than loaded. */
.gallery-group::before {
  content: ""; flex: none; width: .5rem; height: .5rem;
  border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg) translate(-2px, -2px);
  transition: transform 160ms ease;
}
.fold[open] > .gallery-group::before { transform: rotate(45deg) translate(-1px, -3px); }

.fold__count {
  margin-left: auto; font-family: var(--font-sans); font-weight: 500;
  font-size: .8125rem; color: var(--n400); font-variant-numeric: tabular-nums;
}

.gallery { columns: 2; column-gap: 1rem; margin-top: 1.5rem; }
@media (max-width: 46em) { .gallery { columns: 1; } }

.shot { break-inside: avoid; margin-bottom: 1rem; }
.shot--feature { column-span: all; }
.shot button {
  display: block; width: 100%; padding: 0; border: 0; background: none;
  cursor: zoom-in; font: inherit; color: inherit; text-align: left;
}
.shot img { width: 100%; border-radius: var(--radius); background: var(--n100);
  transition: opacity 200ms ease; }
.shot button:hover img { opacity: .9; }
.shot figcaption {
  margin-top: .5rem; font-size: .8125rem; color: var(--n400);
  display: flex; flex-wrap: wrap; gap: .2rem .6rem;
}
.shot figcaption b { font-weight: 600; color: var(--n600); }

.gallery-empty {
  margin-top: 2rem; padding: 2.5rem; border: 1px dashed var(--n300);
  border-radius: var(--radius); color: var(--n500); font-size: .9375rem; text-align: center;
}

.lightbox {
  position: fixed; inset: 0; z-index: 50; display: none; place-items: center;
  padding: clamp(.75rem, 3vw, 2.5rem);
  background: color-mix(in srgb, var(--n900) 92%, #000);
  backdrop-filter: blur(6px);
}
.lightbox.is-open { display: grid; }
.lightbox img { max-width: 100%; max-height: 82vh; width: auto; object-fit: contain;
  border-radius: var(--radius); }
.lightbox__cap { margin-top: .9rem; text-align: center; font-size: .875rem; color: var(--n400); }
.lightbox__close, .lightbox__nav {
  position: absolute; background: none; border: 0; color: var(--n400);
  font-family: var(--font-sans); font-size: 1.5rem; line-height: 1; padding: .75rem; cursor: pointer;
}
.lightbox__close:hover, .lightbox__nav:hover { color: #fff; }
.lightbox__close { top: .5rem; right: .75rem; }
.lightbox__nav--prev { left: .25rem; top: 50%; transform: translateY(-50%); }
.lightbox__nav--next { right: .25rem; top: 50%; transform: translateY(-50%); }

/* ---------- 9. Blog posts ---------- */

/* One reading column, no sidebar: posts carry code, math and wide tables. */
.post { max-width: 46rem; margin-inline: auto; padding-block: clamp(2rem, 5vw, 3.25rem) 4rem; }

.post-back { font-size: .875rem; font-weight: 500; margin-bottom: 1.5rem; }
.post-kicker {
  font-size: .75rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-deep); margin-bottom: .6rem;
}
.post-title { font-size: clamp(1.75rem, 4.5vw, 2.4rem); letter-spacing: -0.02em; line-height: 1.18; }
.post-dek { margin-top: .9rem; font-size: 1.125rem; color: var(--n500); }
.post-meta { margin-top: .9rem; font-size: .875rem; color: var(--n400); }
.post-head { padding-bottom: 1.75rem; border-bottom: 1px solid var(--n200); }

.post-toc {
  margin-top: 1.75rem; padding: 1rem 1.25rem;
  background: var(--n100); border-radius: var(--radius); font-size: .9375rem;
}
.post-toc p { font-weight: 600; color: var(--n800); margin-bottom: .4rem; }
.post-toc ol { margin: 0; padding-left: 1.25rem; columns: 2; column-gap: 2rem; color: var(--n400); }
.post-toc li { padding: .1rem 0; break-inside: avoid; }
@media (max-width: 36em) { .post-toc ol { columns: 1; } }

.post-body { margin-top: 2rem; font-size: 1.0625rem; line-height: 1.75; color: var(--n700); }
.post-body p { margin-bottom: 1.1em; }
.post-body h2 { font-size: 1.6rem; letter-spacing: -0.015em; margin: 2.75rem 0 .9rem;
  scroll-margin-top: 5rem; }
.post-body h3 { font-family: var(--font-sans); font-weight: 600; font-size: 1.0625rem;
  margin: 2.1rem 0 .5rem; scroll-margin-top: 5rem; }
.post-body strong { color: var(--n900); font-weight: 600; }
.post-body a {
  text-decoration: underline; text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.post-body a:hover { text-decoration-color: currentColor; }
.post-body ul, .post-body ol { margin: 0 0 1.1em; padding-left: 1.35rem; }
.post-body ul { list-style: disc; }
.post-body ol { list-style: decimal; }
.post-body li { margin: .35rem 0; }
.post-body li::marker { color: var(--n400); }

.post-body code {
  font-family: var(--font-mono); font-size: .84em;
  background: var(--n100); border-radius: .3rem; padding: .1em .35em;
}
.post-body pre {
  margin: 1.1rem 0 1.4rem; padding: .95rem 1.1rem; overflow-x: auto;
  background: var(--n100); border: 1px solid var(--n200); border-radius: var(--radius);
  font-size: .8125rem; line-height: 1.6;
}
.post-body pre code { background: none; padding: 0; font-size: inherit; color: var(--n800); }

.post-body math { font-family: "Noto Sans Math", "STIX Two Math", "Cambria Math", math; }
.post-body math[display="block"] {
  display: block; margin: 1.3rem 0; font-size: 1.1em;
  overflow-x: auto; overflow-y: hidden; padding-block: .25rem;
}

/* Figures are drawn on white, so they sit on a white plate in both themes. */
.post-fig { margin: 1.75rem 0; }
.post-fig img {
  width: 100%; background: #fff; padding: .6rem;
  border: 1px solid var(--n200); border-radius: var(--radius);
}
.post-fig figcaption { margin-top: .65rem; font-size: .875rem; line-height: 1.55; color: var(--n500); }

.post-body .table-scroll { margin: 1.5rem 0; }
table.post-table {
  border-collapse: collapse; min-width: 44rem;
  font-size: .8125rem; line-height: 1.5;
}
table.post-table th, table.post-table td {
  text-align: left; vertical-align: top; padding: .55rem .9rem .55rem 0;
  border-bottom: 1px solid var(--n200);
}
table.post-table th {
  font-weight: 600; color: var(--n400); font-size: .72rem;
  letter-spacing: .06em; text-transform: uppercase;
}
table.post-table td { color: var(--n600); }
table.post-table td:first-child { color: var(--n900); font-weight: 500; }

.post-body .takeaway {
  margin: 1.4rem 0 1.6rem; padding: .85rem 1.1rem;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-radius: 0 .5rem .5rem 0;
}

.post-body hr { border: 0; border-top: 1px solid var(--n200); margin: 2.5rem 0 1.25rem; }
.post-body hr.post-end ~ p { font-size: .875rem; color: var(--n500); }

/* ---------- 10. Footer ---------- */

.site-foot {
  border-top: 1px solid var(--n200);
  padding-block: 1.5rem 2.5rem;
  font-size: .875rem; color: var(--n400);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1.5rem;
}

/* ---------- 11. Print ---------- */

@media print {
  .topbar, .rail, .site-foot, .lightbox, .post-toc, .post-back { display: none; }
  .layout { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  .card { break-inside: avoid; border-color: #ddd; }
}
