/* Source Sans 3, the site's original typeface, for every page that links this file: the weights in use
   (400, 600, 700) and the italic for venue names. Loaded here so pages need no font link of their own. */
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,400;0,600;0,700;1,400&display=swap');

/* =====================================================================
   Site design system — shared by every page.
   A page links this first, then its own stylesheet (home.css, …), which only
   adds layout for that page. See DESIGN.md for how to build a new page.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  /* Colour */
  --bg: #ffffff;
  --text: #22262b;            /* body copy */
  --ink: #101317;             /* headings and emphasis */
  --muted: #626a75;           /* secondary text: role, authors, captions, footer */
  --faint: #a3a8b0;           /* inactive navigation */
  --accent: #1a5fb4;          /* links */
  --alert: #b3261e;           /* highlights and calls to action (awards, "looking for internships") */
  --surface: #fafafa;         /* cards: Apple Newsroom's tile grey, barely there on white */
  --tile: #ffffff;            /* image slots inside cards */
  --glass: rgb(0 0 0 / 0.05); /* nav pill tint, over a blur */
  --solid: #111111;           /* hover pill and tooltip */

  /* Type. Source Sans 3 (loaded at the top of this file), the typeface the site was designed in;
     Helvetica / Arial while it loads or if blocked, PingFang / YaHei for Chinese.
     The brush face for 王琛 (Ma Shan Zheng) is loaded per page from Google Fonts, subset to its two
     characters; the rest are fallbacks while it loads or if it is blocked. */
  --font: "Source Sans 3", "Source Sans Pro", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-cn: "Ma Shan Zheng", "STXingkai", "Xingkai SC", "KaiTi", cursive;

  /* Type scale: the original site's sizes (only the name is larger). Size / line height / tracking for
     each step; tracking is Source Sans 3's own (normal), headings in its semibold (600). */
  --headline: 44px;  --headline-lh: 50px;  --headline-ls: normal;    /* page title (the name), the one step larger than the original site */
  --section: 21.12px; --section-lh: 33.8px; --section-ls: normal;    /* section headings */
  --body: 17px;      --body-lh: 25.5px;    --body-ls: normal;        /* everything else, subheads in bold */
  --meta: 15.2px;                                                    /* paper authors, venue and links */
  --small: 14.4px;   --small-lh: 23px;     --small-ls: normal;       /* footnotes, dates, tooltips */
  --fine: 13.6px;    --fine-lh: 21.8px;                              /* footer */

  /* Space. One blank line (the body line height) is the basic gap. */
  --sp-line: 25.5px;      /* one body line: between paragraphs; between a heading and what follows it */
  --sp-section: 64px;   /* between sections */
  --sp-page-top: 96px;  /* below the fixed nav, before the first thing on a page (56px on phones): generous, so the page opens with air under the nav */
  --gutter: 20px;       /* page side padding */
  --column: 860px;      /* content column width; wide enough for the longest one-line paper title (Seated VR) */
  --nav-width: 234px;   /* the top nav pill: 6 buttons of 36px, 2px apart, 4px padding; pages line up with its edges */
  --card-pad: 14px;     /* card padding; cards also bleed this far past the column */
  --tile-pad: 8px;      /* image padding inside a tile */

  /* Radius. Nested corners differ by the padding between them, so the curves run parallel. */
  --r-card: 12px;       /* cards, nav pill */
  --r-control: 8px;     /* buttons, tiles, avatar (12px card - 4px padding) */
  --r-tip: 6px;         /* tooltips */
  --r-image: 3px;       /* pictures inside a tile */

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);   /* things sliding into place */
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1); /* longer, gentler moves */
  --dur-fast: 0.15s;    /* colour and opacity changes */
  --dur: 0.24s;         /* short moves */

  /* Fixed nav clearance: 16px from the window top + 44px pill + 4px */
  --nav-clear: 64px;
}
/* Narrow screens: the headline steps down a little (the homepage puts 王琛 on its own line there) */
@media (max-width: 640px) {
  :root { --headline: 36px; --headline-lh: 42px; --sp-page-top: 56px; }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* scrollbar-gutter: the page keeps the same width whether it scrolls or not, so the centred nav and
   column sit in the same place on long and short pages (with always-visible scrollbars) */
html { font-size: var(--body); scroll-behavior: smooth; scrollbar-gutter: stable; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--body)/var(--body-lh) var(--font);
  letter-spacing: var(--body-ls);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3, p, ul { margin: 0; }
/* No orphans: a heading or paragraph never ends on a line holding a single word or a single Chinese
   character; the browser rebalances the last lines only when that would happen, otherwise wraps as usual */
h1, h2, h3, p, li, figcaption, .posttitle { text-wrap: pretty; }
ul { padding: 0; list-style: none; }
img { max-width: 100%; }

/* ---------- Type styles ---------- */
/* Headline: the page title, one per page */
.t-headline { color: var(--ink); font-size: var(--headline); font-weight: 600; line-height: var(--headline-lh); letter-spacing: var(--headline-ls); }
/* Section heading: every h2 */
h2, .t-section { margin-bottom: var(--sp-line); color: var(--ink); font-size: var(--section); font-weight: 600; line-height: var(--section-lh); letter-spacing: var(--section-ls); }
/* Subhead: body size, semibold (paper titles, post titles in lists); 700 read too heavy in Source Sans 3 */
.t-subhead { color: var(--ink); font-size: var(--body); font-weight: 600; line-height: var(--body-lh); }
/* Small: footnotes and captions */
.t-small { font-size: var(--small); line-height: var(--small-lh); letter-spacing: var(--small-ls); }
.t-muted { color: var(--muted); }
.t-alert { color: var(--alert); }
/* Running text: paragraphs one blank line apart */
.prose p + p { margin-top: var(--sp-line); }

/* ---------- Layout ---------- */
/* The content column, with room at the top for the fixed nav */
.wrap { max-width: calc(var(--column) + 2 * var(--gutter)); margin-inline: auto; padding: var(--nav-clear) var(--gutter) 44px; }
/* In-page links land below the fixed nav, with 18px to spare */
section { scroll-margin-top: calc(var(--nav-clear) + 14px); }
section + section { margin-top: var(--sp-section); }

/* ---------- Component: top nav ---------- */
/* One glass pill fixed at the top centre of the window, holding icon buttons. Markup:
   <nav class="dock"><div class="dock-seg"> <a class="dock-icon" data-label="…">icons</a> …
   <span class="dock-glow"></span><span class="dock-tip"></span></div></nav>
   site.js slides one shared black pill (.dock-glow) and tooltip (.dock-tip) to the hovered button. */
.dock {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
}
/* The pill: the glass tint over blurred content, with a faint white inner stroke like a glass edge.
   The glass is drawn on ::before at z-index -1 so the black hover pill paints over it. */
.dock-seg { position: relative; display: flex; gap: 2px; padding: 4px; border-radius: var(--r-card); }
.dock-seg::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px) saturate(1.15);
  backdrop-filter: blur(10px) saturate(1.15);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25);
}
.dock a {
  display: grid;
  place-items: center;
  height: 36px;
  border-radius: var(--r-control);
  color: var(--solid);
  white-space: nowrap;
  transition: color var(--dur-fast) ease, scale var(--dur-fast) ease;
}
.dock a:hover { text-decoration: none; }
/* Buttons sit above the shared black pill */
.dock-icon { position: relative; z-index: 1; width: 36px; flex: none; }
/* Icons: Tabler line icons (24px grid), 1.5 stroke, to match the line-drawn cat. Hovered or focused
   (.is-lit), each swaps to the filled version of the same icon. Each button sets --s so all icons
   look the same size (measured from the drawn ink). The filled one is drawn at --f (default 94%) of
   --s: a solid shape reads bigger than an outline of the same size. */
.dock-icon .i-line { width: var(--s, 20px); height: var(--s, 20px); fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.dock-icon .i-fill { width: calc(var(--s, 20px) * var(--f, 0.94)); height: calc(var(--s, 20px) * var(--f, 0.94)); fill: currentColor; }
.dock-icon .i-fill, .dock-icon.is-lit .i-line { display: none; }
.dock-icon.is-lit .i-fill { display: block; }
/* .line-only buttons (X) keep their line icon when lit, just turned white; no filled version */
.dock-icon.line-only.is-lit .i-line { display: block; }
/* Image icons (the cat) */
.dock-icon img.i-line, .dock-icon img.i-fill { width: 20px; height: 20px; }
.dock-icon img { display: block; }
/* Shared black pill and tooltip, hidden at rest */
.dock-glow, .dock-tip {
  position: absolute;
  top: 4px;
  left: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-fast) ease, transform var(--dur) var(--ease-out);
}
.dock-glow { width: 36px; height: 36px; border-radius: var(--r-control); background: var(--solid); }
.dock-icon.is-lit { color: #fff; }
/* Tooltip below the pill, since the nav sits at the top edge of the window */
.dock-tip {
  top: calc(100% + 8px);
  padding: 6px 10px;
  border-radius: var(--r-tip);
  background: var(--solid);
  color: #fff;
  font: 400 var(--small)/1 var(--font);
  white-space: nowrap;
}
.dock-seg.is-lit .dock-glow, .dock-seg.is-lit .dock-tip { opacity: 1; }
/* Placing the pill or tooltip for the first time (or after leaving): jump there, do not slide */
.dock-seg.is-placing .dock-glow, .dock-seg.is-placing .dock-tip, .dock-seg.tip-placing .dock-tip { transition: opacity var(--dur-fast) ease; }
.dock-seg.no-tip .dock-tip { opacity: 0; }
/* Resting on the current page's (or section's) button (aria-current): pill and filled icon, no tooltip */
.dock-seg.at-rest .dock-tip { opacity: 0; }
.dock a:focus-visible { outline: none; }
.dock a:active { scale: 0.94; }
@media (prefers-reduced-motion: reduce) {
  .dock a, .dock-glow, .dock-tip { transition: none; }
}

/* ---------- Component: card ---------- */
/* A light grey panel with 12px corners. It bleeds its padding past the column on both sides, so
   its contents still line up with the section heading above it. */
.card {
  margin-inline: calc(-1 * var(--card-pad));
  padding: var(--card-pad);
  border-radius: var(--r-card);
  background: var(--surface);
}

/* ---------- Component: tile ---------- */
/* A white 2:1 image slot with 8px corners, so pictures of different shapes and backgrounds read as
   one set: white-backed figures melt into it, full-bleed ones get an even margin. Pictures keep their
   own ratio, centred inside the padding (their width/height attributes give the ratio before they
   load), so the slight rounding lands on the picture's own corners. A 3D model fills the padded area.
   A new thumbnail should be about 720x360. */
.tile { position: relative; aspect-ratio: 2 / 1; border-radius: var(--r-control); background: var(--tile); }
.tile img, .tile video, .tile model-viewer {
  position: absolute;
  inset: var(--tile-pad);
  display: block;
  border-radius: var(--r-image);
}
.tile img, .tile video { width: auto; height: auto; max-width: calc(100% - 2 * var(--tile-pad)); max-height: calc(100% - 2 * var(--tile-pad)); margin: auto; }
.tile model-viewer { width: calc(100% - 2 * var(--tile-pad)); height: calc(100% - 2 * var(--tile-pad)); }

/* ---------- Component: link row ---------- */
/* A row of links separated by space alone (no divider lines) */
.link-row { display: flex; flex-wrap: wrap; column-gap: 1em; }

/* ---------- Component: back link ---------- */
/* A left arrow back to the parent page (a post back to Posts), after charlsyang.com/blog, on the
   title's line just outside the content column, so the title keeps the column edge. It shows its
   light grey box from the start (the nav pill's grey), so it reads as a button before any hover.
   It sits right after <nav class="dock"> in the markup and is placed against the page: the title's
   first line starts at --nav-clear + --sp-page-top, and the button is as tall as the title's letters (its font size, --section), centred on that line.
   Where the margin left of the column is too narrow for it (under ~850px, phones included), it moves
   above the title instead, flush with the column edge. Same tab, since it is going back. */
.back-link {
  position: absolute;
  top: calc(var(--nav-clear) + var(--sp-page-top) + (var(--section-lh) - var(--section)) / 2);
  left: calc(max(var(--gutter), 50% - var(--column) / 2) - var(--section) - 24px);
  display: grid;
  place-items: center;
  width: var(--section);
  height: var(--section);
  border-radius: var(--r-tip);
  /* A light touch: 3.5% black, lighter than the nav pill, so it does not weigh on the title */
  background: rgb(0 0 0 / 0.035);
  color: var(--muted);
  transition: color var(--dur-fast) ease, background-color var(--dur-fast) ease, scale var(--dur-fast) ease;
}
.back-link svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.back-link:hover { text-decoration: none; }
@media (hover: hover) { .back-link:hover { color: var(--ink); background: rgb(0 0 0 / 0.06); } }
.back-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; color: var(--ink); }
.back-link:active { scale: 0.94; }
@media (prefers-reduced-motion: reduce) { .back-link { transition: none; } }
@media (max-width: 849px) {
  /* The box is visible, so its own left edge lines up with the column (and the title) */
  .back-link { top: calc(var(--nav-clear) + var(--sp-page-top) - var(--section) - 12px); left: max(var(--gutter), 50% - var(--column) / 2); }
}

/* ---------- Component: footer ---------- */
.foot { margin-top: 56px; color: var(--muted); font-size: var(--fine); line-height: var(--fine-lh); }
