/* =========================================================================
   jonathanchien.com — design system
   Plain CSS. No build step, no framework, no resets from elsewhere.
   Sections: 1 tokens · 2 reset · 3 base type · 4 layout · 5 header/footer
             6 components · 7 prose · 8 utilities · 9 motion & print
   ========================================================================= */

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

:root {
  color-scheme: light dark;

  /* Surfaces */
  --bg:            light-dark(#fcfcfb, #0f0f0e);
  --bg-subtle:     light-dark(#f5f5f1, #171716);
  --bg-inset:      light-dark(#efefea, #1d1d1b);

  /* Ink */
  --text:          light-dark(#1b1b19, #e8e7e2);
  --text-muted:    light-dark(#67675f, #9a998f);
  --text-faint:    light-dark(#8d8d84, #74736b);

  /* Lines */
  --border:        light-dark(#e4e4dd, #272724);
  --border-strong: light-dark(#cbcbc2, #383834);

  /* Accent — used sparingly, on purpose */
  --accent:        light-dark(#a84a26, #e08a5f);
  --accent-soft:   light-dark(#f3e7e0, #2a1f18);

  /* Type */
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter,
                "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono",
               "Roboto Mono", Menlo, Consolas, monospace;

  --step--1: clamp(0.82rem, 0.79rem + 0.14vw, 0.89rem);
  --step-0:  clamp(1rem,    0.96rem + 0.20vw, 1.09rem);
  --step-1:  clamp(1.18rem, 1.10rem + 0.38vw, 1.38rem);
  --step-2:  clamp(1.42rem, 1.28rem + 0.68vw, 1.80rem);
  --step-3:  clamp(1.72rem, 1.48rem + 1.15vw, 2.40rem);
  --step-4:  clamp(2.05rem, 1.66rem + 1.90vw, 3.10rem);

  /* Rhythm */
  --space-2xs: 0.25rem;
  --space-xs:  0.5rem;
  --space-s:   0.75rem;
  --space-m:   1.25rem;
  --space-l:   2rem;
  --space-xl:  3.25rem;
  --space-2xl: 5rem;

  /* Measure */
  --measure: 40rem;   /* reading column */
  --wide:    58rem;   /* header, footer, listings */

  --radius: 6px;
  --ring: light-dark(#a84a26, #e08a5f);
}

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

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd, ul, ol, pre {
  margin: 0;
}

/* Strip list styling only where the design supplies its own. A blanket
   ul[class] reset out-specifics later class rules — this stays explicit. */
.entries, .tags, .social, .site-nav ul {
  list-style: none;
  padding: 0;
}

img, svg, video { display: block; max-width: 100%; height: auto; }

button, input, textarea, select { font: inherit; color: inherit; }

/* ---- 3. Base typography ------------------------------------------------- */

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.65;
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
h4 { font-size: var(--step-0); }

p { text-wrap: pretty; }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--border-strong);
  transition: color 120ms ease, text-decoration-color 120ms ease;
}
a:hover { color: var(--accent); text-decoration-color: currentColor; }

:where(a, button, input, textarea, summary):focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 3px;
  border-radius: 2px;
}

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.9em; }

::selection { background: var(--accent-soft); color: var(--text); }

/* ---- 4. Layout ---------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: var(--wide);
  margin-inline: auto;
  padding-inline: clamp(1.15rem, 5vw, 2.5rem);
}

main.wrap {
  flex: 1 0 auto;
  padding-block: var(--space-xl) var(--space-2xl);
}

/* Narrow reading column for text-heavy pages */
.measure { max-width: var(--measure); }

/* Vertical rhythm between top-level sections, whatever they are called. */
main > section + section,
.section + .section { margin-top: var(--space-xl); }

.stack > * + * { margin-top: var(--space-m); }

/* ---- 5. Header & footer ------------------------------------------------- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--bg);
  color: var(--text);
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  text-decoration: none;
}
.skip-link:focus { left: 0.75rem; top: 0.75rem; }

.site-header {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-m);
  min-height: 4rem;
  flex-wrap: wrap;
}

.wordmark {
  font-family: var(--font-serif);
  font-size: var(--step-0);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  margin-right: auto;
  white-space: nowrap;
}
.wordmark:hover { color: var(--accent); }

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.85rem, 2.4vw, 1.6rem);
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  font-size: var(--step--1);
  color: var(--text-muted);
  text-decoration: none;
  padding-block: 0.35rem;
  border-bottom: 1px solid transparent;
}
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle svg {
  width: 15px; height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  grid-area: 1 / 1;
}
.icon-moon { fill: currentColor; stroke: none; }
:root[data-theme="dark"] .icon-sun,
:root:not([data-theme="light"]) .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
:root[data-theme="light"] .icon-sun { display: block; }
:root[data-theme="light"] .icon-moon { display: none; }
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] .icon-sun  { display: block; }
  :root[data-theme="auto"] .icon-moon { display: none; }
}

.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-l);
  font-size: var(--step--1);
  color: var(--text-muted);
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-s) var(--space-l);
  align-items: baseline;
  justify-content: space-between;
}
.social {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-m);
  list-style: none;
  margin: 0;
  padding: 0;
}
.social a { text-decoration: none; }
.social a:hover { text-decoration: underline; text-underline-offset: 0.2em; }

/* ---- 6. Components ------------------------------------------------------ */

/* Page intro */
.intro { max-width: var(--measure); }
.intro h1 { margin-bottom: var(--space-s); }
.intro .lede {
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--text-muted);
  text-wrap: pretty;
}
.intro .lede + p { margin-top: var(--space-m); }

.page-title { margin-bottom: var(--space-s); }
.page-intro {
  max-width: var(--measure);
  color: var(--text-muted);
  margin-bottom: var(--space-xl);
}

/* Small caps section label */
.label {
  font-size: 0.72rem;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--space-m);
}

/* Divided list — the workhorse for projects, roles, and posts */
.entries { list-style: none; margin: 0; padding: 0; }
.entries > li { border-top: 1px solid var(--border); }
.entries > li:last-child { border-bottom: 1px solid var(--border); }

.entry {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: var(--space-m);
  padding-block: var(--space-m);
  align-items: baseline;
}
.entry-meta {
  font-size: var(--step--1);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.entry-title {
  font-family: var(--font-serif);
  font-size: var(--step-1);
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
}
.entry-title a { text-decoration: none; }
.entry-title a:hover { color: var(--accent); text-decoration: underline; }
.entry-sub {
  font-size: var(--step--1);
  color: var(--text-muted);
  margin-top: var(--space-2xs);
}
.entry-body { margin-top: var(--space-xs); color: var(--text-muted); }
.entry-body p + p { margin-top: var(--space-xs); }

/* Bullet list used inside an entry (opts back out of the ul[class] reset) */
.bullets {
  list-style: disc;
  margin: var(--space-xs) 0 0;
  padding-left: 1.1em;
  color: var(--text-muted);
}
.bullets li { margin-top: var(--space-2xs); }
.bullets li::marker { color: var(--text-faint); }

/* Tags */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  list-style: none;
  margin: var(--space-s) 0 0;
  padding: 0;
}
.tag {
  font-size: 0.74rem;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.14rem 0.6rem;
  white-space: nowrap;
}

/* Inline arrow link */
.more {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: var(--step--1);
  text-decoration: none;
  color: var(--text-muted);
}
.more::after { content: "\2192"; transition: transform 140ms ease; }
.more:hover { color: var(--accent); }
.more:hover::after { transform: translateX(3px); }

/* Callout */
.note {
  border-left: 2px solid var(--accent);
  background: var(--bg-subtle);
  padding: var(--space-m);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: var(--step--1);
  color: var(--text-muted);
}

/* Post header + meta */
.post-header { max-width: var(--measure); margin-bottom: var(--space-l); }
.post-header h1 { font-size: var(--step-3); margin-bottom: var(--space-s); }
.post-meta {
  font-size: var(--step--1);
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.post-meta .dot { color: var(--border-strong); }

.post-nav {
  max-width: var(--measure);
  margin-top: var(--space-xl);
  padding-top: var(--space-m);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: var(--space-m);
  font-size: var(--step--1);
}

/* ---- 7. Prose (article body) -------------------------------------------- */

.prose {
  max-width: var(--measure);
  font-size: var(--step-0);
  line-height: 1.72;
}
.prose > * + * { margin-top: var(--space-m); }
.prose h2 {
  font-size: var(--step-2);
  margin-top: var(--space-xl);
  padding-top: var(--space-xs);
}
.prose h3 { font-size: var(--step-1); margin-top: var(--space-l); }
.prose h2 + *, .prose h3 + * { margin-top: var(--space-s); }

.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: var(--space-xs); }
.prose li::marker { color: var(--text-faint); }

.prose blockquote {
  border-left: 2px solid var(--border-strong);
  padding-left: var(--space-m);
  color: var(--text-muted);
  font-style: italic;
}
.prose blockquote p + p { margin-top: var(--space-s); }

.prose :not(pre) > code {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.prose pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-m);
  overflow-x: auto;
  line-height: 1.55;
  font-size: 0.86rem;
}
.prose pre code { background: none; border: 0; padding: 0; }

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin-block: var(--space-l);
}

.prose img { border-radius: var(--radius); margin-inline: auto; }
.prose figure figcaption {
  font-size: var(--step--1);
  color: var(--text-faint);
  text-align: center;
  margin-top: var(--space-xs);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
}
.prose th, .prose td {
  text-align: left;
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.prose th { color: var(--text-faint); font-weight: 600; }

/* Anchored headings */
.prose :is(h2, h3) { scroll-margin-top: 5.5rem; }

/* ---- 8. Utilities ------------------------------------------------------- */

.muted  { color: var(--text-muted); }
.faint  { color: var(--text-faint); }
.small  { font-size: var(--step--1); }
.center { text-align: center; }
.mt-l   { margin-top: var(--space-l); }
.mt-xl  { margin-top: var(--space-xl); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- 9. Responsive, motion, print --------------------------------------- */

@media (max-width: 34rem) {
  .entry { grid-template-columns: 1fr; gap: var(--space-2xs); }
  .entry-meta { order: -1; }

  /* Wordmark and toggle share the first row; nav drops to its own. */
  .header-inner {
    min-height: 0;
    padding-block: var(--space-s);
    row-gap: var(--space-xs);
  }
  .theme-toggle { order: 2; }
  .site-nav { order: 3; flex-basis: 100%; }
  .site-nav ul { gap: 0.9rem; }

  .page-intro { margin-bottom: var(--space-l); }
  .post-nav { flex-direction: column; gap: var(--space-xs); }
}

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

@media print {
  .site-header, .site-footer, .theme-toggle, .skip-link, .post-nav { display: none; }
  body { background: #fff; color: #000; }
  .wrap { max-width: none; padding: 0; }
  a { text-decoration: none; }
  .prose a::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }
}
