/* davidcwei.com — the site's only stylesheet.
   Pages carry no inline CSS: every page links this file and inherits the
   responsive behaviour below, so anything new is mobile-ready by default. */

/* --- Newsreader, self-hosted (variable: weight 300-500, optical size
   6-72). Self-hosting keeps the site loading in mainland China, removes
   the only third-party request, and lets the CSP lock to 'self'. */

@font-face {
  font-family: 'Newsreader';
  font-style: italic;
  font-weight: 300 500;
  font-display: swap;
  src: url('/fonts/newsreader-italic-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Newsreader';
  font-style: italic;
  font-weight: 300 500;
  font-display: swap;
  src: url('/fonts/newsreader-italic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url('/fonts/newsreader-normal-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url('/fonts/newsreader-normal-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --paper:    #f7f7f5;
  --ink:      #17181b;
  --ink-soft: #6a6d73;
  --rule:     #e2e2de;
  --accent:   #2f4f7f;
  --measure:  34rem;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  /* Size of every small mono label — dates, group headings, captions,
     footer links. Defined once so it can be raised for phones in one
     place; anything new should use var(--micro) rather than a literal. */
  --micro: 0.7rem;
}

@media (max-width: 30rem) {
  :root { --micro: 0.78rem; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:    #111214;
    --ink:      #e7e7e3;
    --ink-soft: #8b8f95;
    --rule:     #272a2d;
    --accent:   #97b4dd;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-size: clamp(1rem, 0.97rem + 0.2vw, 1.125rem);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- responsive foundations -------------------------------------
   These four rules are why new content stays mobile-safe. Media can
   never exceed the column, long unbroken strings (URLs, code) wrap
   instead of forcing a horizontal scrollbar, and anything genuinely
   wide scrolls inside itself rather than widening the page. */

img, svg, video, iframe, embed, object {
  max-width: 100%;
  height: auto;
}

p, li, h1, h2, h3, h4, blockquote, figcaption, td, th {
  overflow-wrap: break-word;
}

pre, table { max-width: 100%; overflow-x: auto; }

table { display: block; border-collapse: collapse; }

/* The reading column. Width is capped in rem and padded in rem, so it
   fluidly fills any screen narrower than the cap without media queries. */

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(3.5rem, 11vh, 8rem) clamp(1.25rem, 4vw, 1.5rem) clamp(4rem, 12vh, 8rem);
}

/* --- navigation ------------------------------------------------ */

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.4rem;
  margin-bottom: clamp(3rem, 8vh, 5rem);
  font-style: italic;
  font-size: 0.95em;
}

.nav a {
  display: inline-block;
  padding: 0.35rem 0;
  color: var(--ink-soft);
  text-decoration: none;
  transition: color 120ms ease;
}

.nav a:hover,
.nav a:focus-visible { color: var(--ink); }

.nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 0.05em;
  text-underline-offset: 0.28em;
}

/* --- base type -------------------------------------------------- */

h1 {
  margin: 0 0 1.5rem;
  font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.35rem);
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

/* text-wrap: pretty lets the browser avoid single-word last lines and
   poor rag; balance keeps multi-line headings visually even. Both are
   progressive enhancements — older browsers simply ignore them. */

p { margin: 0 0 1.35rem; text-wrap: pretty; }

h1, h2, h3 { text-wrap: balance; }

p a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 0.055em;
  text-underline-offset: 0.18em;
  transition: text-decoration-color 120ms ease;
}

p a:hover { text-decoration-color: transparent; }

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: clamp(2.5rem, 7vh, 4rem) 0;
}

/* Placeholder line on pages that have no content yet. */
.soon { color: var(--ink-soft); font-style: italic; }

/* --- footer links ---------------------------------------------- */

.elsewhere {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.6rem;
  font-family: var(--mono);
  font-size: var(--micro);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.elsewhere a {
  display: inline-block;
  padding: 0.35rem 0;
  color: var(--ink-soft);
  text-decoration: none;
  transition: color 120ms ease;
}

.elsewhere a:hover,
.elsewhere a:focus-visible { color: var(--ink); }

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

/* --- writing index ---------------------------------------------- */

.group {
  margin: 3rem 0 0.85rem;
  font-family: var(--mono);
  font-size: var(--micro);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.group:first-of-type { margin-top: 0; }

.posts {
  margin-top: 1rem;
  border-top: 1px solid var(--rule);
}

.group + .posts { margin-top: 0; }

.post {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: inherit;
}

.post time {
  flex: 0 0 5.5rem;
  font-family: var(--mono);
  font-size: var(--micro);
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.post .title {
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 0.055em;
  text-underline-offset: 0.18em;
  transition: text-decoration-color 140ms ease;
}

.post:hover .title,
.post:focus-visible .title { text-decoration-color: var(--accent); }

/* Narrow screens: stack the date above the title and give the whole
   row a taller touch target. */
@media (max-width: 30rem) {
  .post {
    flex-direction: column;
    gap: 0.3rem;
    padding: 1.1rem 0;
  }
  .post time { flex: none; }
}

/* --- project list ------------------------------------------------ */

.projects { border-top: 1px solid var(--rule); }

.project {
  padding: 1.35rem 0;
  border-bottom: 1px solid var(--rule);
}

.project-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.project-head a {
  display: inline-block;
  padding: 0.2rem 0;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 0.055em;
  text-underline-offset: 0.18em;
  transition: text-decoration-color 140ms ease;
}

.project-head a:hover,
.project-head a:focus-visible { text-decoration-color: var(--accent); }

.project .meta {
  flex: none;
  font-family: var(--mono);
  font-size: var(--micro);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.project p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.97em;
  line-height: 1.55;
  text-wrap: pretty;
}

@media (max-width: 30rem) {
  .project-head { flex-direction: column; gap: 0.1rem; }
}

/* --- essay pages ------------------------------------------------ */

.essay h1 { margin: 0 0 0.85rem; }

.essay-meta {
  display: block;
  margin: 0 0 clamp(2.5rem, 6vh, 3.5rem);
  font-family: var(--mono);
  font-size: var(--micro);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.essay h2 {
  margin: 2.6rem 0 1rem;
  font-size: 1.2em;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.essay h3 {
  margin: 2.2rem 0 0.9rem;
  font-size: 1.05em;
  font-weight: 500;
  letter-spacing: -0.005em;
  line-height: 1.3;
}

.essay blockquote {
  margin: 2.2rem 0;
  padding-left: clamp(1rem, 3vw, 1.3rem);
  border-left: 1px solid var(--rule);
  font-style: italic;
  font-size: 1.03em;
  line-height: 1.6;
  text-wrap: pretty;
}

.essay blockquote em { font-style: normal; }

.essay .center { text-align: center; }

.essay .indent { padding-left: clamp(1rem, 3vw, 1.3rem); }

.essay img {
  display: block;
  margin: 2.2rem auto;
}

.essay .lead {
  display: block;
  width: 100%;
  margin: 0 0 clamp(2.5rem, 6vh, 3.5rem);
}

.essay-meta:has(+ .lead) { margin-bottom: 1.6rem; }

.essay figure { margin: 2.2rem 0; }

.essay figure img { margin: 0 auto; }

.essay figcaption {
  margin-top: 0.7rem;
  font-family: var(--mono);
  font-size: var(--micro);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: center;
}

.essay ol,
.essay ul { margin: 0 0 1.35rem; padding-left: 1.3rem; }

.essay li { margin-bottom: 0.45rem; }

.editors-note {
  font-size: 0.88em;
  font-style: italic;
  color: var(--ink-soft);
  padding-bottom: 1.75rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--rule);
}

/* --- quiet entrance --------------------------------------------- */

.reveal {
  opacity: 0;
  transform: translateY(0.5rem);
  animation: rise 700ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.reveal:nth-child(1) { animation-delay: 40ms; }
.reveal:nth-child(2) { animation-delay: 140ms; }
.reveal:nth-child(3) { animation-delay: 240ms; }
.reveal:nth-child(4) { animation-delay: 340ms; }
.reveal:nth-child(5) { animation-delay: 420ms; }
.reveal:nth-child(6) { animation-delay: 500ms; }

@keyframes rise {
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; opacity: 1; transform: none; }
  * { transition-duration: 0.01ms !important; }
}
