/* ==========================================================================
   Peter Lu — portfolio
   Tokens first, components second. Nothing below sets a colour literal:
   every colour comes from a token so all three theme states resolve.
   ========================================================================== */

/* --- reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, p, ul, figure { margin: 0; }
ul { padding: 0; }
img { max-width: 100%; display: block; }
button { font: inherit; }

/* --- tokens: light (default, and the un-stamped baseline) ----------------- */
:root {
  --paper: #F4F5F1;
  --surface: #FFFFFF;
  --surface-2: #EDEFE9;
  --ink: #151F1D;
  --ink-2: #33413E;
  --muted: #5F6D69;
  --line: #DBDFD6;
  --line-strong: #C3C9BE;
  --accent: #0E6A5E;
  --brass: #8C6725;
  --shadow: 0 1px 2px rgba(21,31,29,.05), 0 8px 24px -16px rgba(21,31,29,.28);

  --measure: 66ch;
  --page: 1000px;
  --gutter: 28px;
}

/* --- tokens: dark by OS preference, unless light was explicitly chosen ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0D1312;
    --surface: #141B1A;
    --surface-2: #1A2220;
    --ink: #E7EBE7;
    --ink-2: #C3CCC8;
    --muted: #8E9C97;
    --line: #243230;
    --line-strong: #33433F;
    --accent: #54C2AD;
    --brass: #C69A50;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -18px rgba(0,0,0,.8);
  }
}

/* --- tokens: dark chosen explicitly (beats a light OS) -------------------- */
:root[data-theme="dark"] {
  --paper: #0D1312;
  --surface: #141B1A;
  --surface-2: #1A2220;
  --ink: #E7EBE7;
  --ink-2: #C3CCC8;
  --muted: #8E9C97;
  --line: #243230;
  --line-strong: #33433F;
  --accent: #54C2AD;
  --brass: #C69A50;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -18px rgba(0,0,0,.8);
}

/* --- base ----------------------------------------------------------------- */
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }

.wrap { max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter); }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--paper);
  padding: 10px 16px; text-decoration: none; border-radius: 0 0 3px 0;
}
.skip:focus { left: 0; }

a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px;
}

/* --- type ----------------------------------------------------------------- */
.mono, .eyebrow, .brand, .btn, .metric .val, .job-when, .tag, .clist a, footer, .stage .num, .outcome .where, .loop-note {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

.eyebrow {
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}

h1, h2, h3 { text-wrap: balance; }

h1 {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 400; font-size: clamp(2.9rem, 7vw, 4.4rem);
  line-height: 1.02; letter-spacing: -.02em; margin-top: 18px;
}
/* --- optional CJK classes -------------------------------------------------
   Only rendered when content.json supplies `person.nameCjk` or a trait `cjk`.
   Both are empty right now, so these rules are inert — kept so restoring the
   Chinese name is a content edit, not a CSS edit. */
h1 .cjk {
  display: block; font-size: .34em; letter-spacing: .22em; color: var(--muted);
  font-family: "IBM Plex Sans", "Noto Sans TC", sans-serif; font-weight: 400; margin-top: .9rem;
}
h2 {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 400; font-size: clamp(1.7rem, 3.4vw, 2.2rem);
  line-height: 1.15; letter-spacing: -.015em;
}
h3 { font-size: 1.02rem; font-weight: 600; letter-spacing: -.005em; }

/* --- top bar -------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; height: 56px;
}
.brand {
  font-size: .8rem; letter-spacing: .1em; text-transform: uppercase;
  text-decoration: none; white-space: nowrap;
}
.brand b { font-weight: 500; }
.brand span { color: var(--muted); }

.navlinks {
  display: flex; gap: 22px; margin-left: auto; min-width: 0;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.navlinks::-webkit-scrollbar { display: none; }
.navlinks a {
  /* --muted measures 4.95:1 on paper and 6.57:1 in dark, so it clears AA as
     secondary navigation should. The vertical padding is what matters here:
     it takes the hit area to 38px, past the 24px WCAG 2.2 minimum. */
  font-size: .83rem; text-decoration: none; color: var(--muted); white-space: nowrap;
  padding: 8px 0; border-bottom: 1px solid transparent;
  transition: color .18s, border-color .18s;
}
.navlinks a:hover { color: var(--ink); border-bottom-color: var(--accent); }

/* Phones keep the nav — the page has eight sections, so dropping it means
   thumb-scrolling the whole thing. It becomes a scrollable strip, and the
   brand sheds its CJK half to make room. */
@media (max-width: 760px) {
  .topbar-inner { gap: 12px; }
  .brand span { display: none; }
  .navlinks {
    gap: 18px; padding-right: 12px;
    /* Fades the last item instead of letting it collide with the theme
       toggle mid-word, which also signals that the strip scrolls. */
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent);
            mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent);
  }
}

.theme-toggle {
  display: grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line-strong); border-radius: 2px;
  cursor: pointer; transition: color .18s, border-color .18s;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { width: 15px; height: 15px; display: block; }
.theme-toggle .icon-dark { display: none; }
.theme-toggle .icon-light { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-dark { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-light { display: none; }
}
:root[data-theme="dark"] .theme-toggle .icon-dark { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: none; }

/* --- section frame -------------------------------------------------------- */
section { padding: 76px 0; }
section + section { border-top: 1px solid var(--line); }

.sec-head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-bottom: 38px; }
.sec-head .rule { height: 1px; background: var(--line-strong); margin-top: 6px; }
.sec-head p:not(.eyebrow) { color: var(--muted); margin-top: .7rem; max-width: 58ch; font-size: .97rem; }
@media (min-width: 860px) {
  .sec-head { grid-template-columns: 150px minmax(0, 1fr); gap: 0 40px; align-items: baseline; }
  .sec-head .eyebrow { padding-top: .55rem; }
  .sec-head .rule { grid-column: 1 / -1; margin-top: 22px; }
}

/* --- hero ----------------------------------------------------------------- */
.hero { padding: 64px 0 62px; }
.hero-grid { display: grid; gap: 38px; }

@media (min-width: 820px) {
  .hero-grid { grid-template-columns: minmax(0, 1fr) 264px; gap: 56px; align-items: start; }
}

/* 4:5 headshot frame. The image file is already cropped to 4:5, so `cover`
   never has to make a cropping decision of its own. */
.portrait {
  width: 264px; max-width: 100%; margin-top: 4px;
  aspect-ratio: 4 / 5; overflow: hidden;
  border: 1px solid var(--line-strong); border-radius: 3px;
  background: var(--surface-2); box-shadow: var(--shadow);
}
.portrait img { width: 100%; height: 100%; object-fit: cover; }

/* Single-column hero: the headshot leads instead of trailing the whole block,
   at a size that introduces him without pushing the name below the fold.
   Must sit AFTER the .portrait base rule — same specificity, later wins. */
@media (max-width: 819px) {
  .hero { padding: 40px 0 48px; }
  .hero-grid { gap: 24px; }
  .portrait { order: -1; width: 132px; margin-top: 0; }
}

.hero-role {
  font-family: "Newsreader", Georgia, serif;
  font-size: clamp(1.25rem, 2.6vw, 1.55rem); font-weight: 400; line-height: 1.35;
  margin-top: 26px; color: var(--ink-2);
}
.hero-role em { font-style: italic; color: var(--accent); }
.hero-lede { margin-top: 20px; color: var(--ink-2); font-size: 1.02rem; max-width: 56ch; }

.hero-meta {
  display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 24px;
  font-family: "IBM Plex Mono", monospace; font-size: .78rem; color: var(--muted);
}
.hero-meta span { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex: none; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 30px; }

/* Shortcut to the side project, kept off the contact-button row so it reads as
   a different kind of link rather than a fourth way to reach him. Opens in a
   new tab, so the portfolio stays put. */
.hero-project {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px 12px;
  margin-top: 20px; font-size: .9rem;
}
.hero-project a {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--accent); font-weight: 500; text-decoration: none;
  border-bottom: 1px solid var(--line-strong);
  padding: 3px 0 5px;   /* 24px is the bare WCAG minimum; this gives a thumb room */
  transition: border-color .18s;
}
.hero-project a:hover { border-bottom-color: var(--accent); }
.hero-project a svg { width: 12px; height: 12px; flex: none; }
.hero-project .note { color: var(--muted); font-size: .85rem; }
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: .79rem; letter-spacing: .03em; text-decoration: none;
  padding: 10px 16px; border-radius: 2px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  transition: border-color .18s, transform .18s, filter .18s;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.btn.primary:hover { filter: brightness(1.06); }
.btn svg { width: 14px; height: 14px; flex: none; }

/* --- metric band ---------------------------------------------------------- */
.band { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Cells are separated by rules, so they need padding on BOTH sides of the
   rule — otherwise the text of cells 2..n sits flush against the divider.
   Only the outer edges lose their padding, to keep the band flush with .wrap. */
.metric { padding: 26px 26px; border-right: 1px solid var(--line); }
.metric:first-child { padding-left: 0; }
.metric:last-child { border-right: 0; padding-right: 0; }
@media (max-width: 759px) {
  .metric { padding: 22px 20px; }
  .metric:nth-child(odd) { padding-left: 0; }
  .metric:nth-child(even) { border-right: 0; padding-right: 0; }
  .metric:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
}
.metric .val {
  font-family: "Newsreader", Georgia, serif; font-size: 2.05rem; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.metric .lab { font-size: .84rem; color: var(--muted); margin-top: 9px; line-height: 1.45; }

/* --- approach loop -------------------------------------------------------- */
.loop { display: grid; gap: 18px; }
@media (min-width: 800px) { .loop { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; } }

.stage {
  background: var(--surface); border: 1px solid var(--line); border-radius: 3px;
  padding: 22px 22px 24px;
}
.stage .num { font-size: .72rem; color: var(--accent); letter-spacing: .12em; }
.stage h3 { margin: 10px 0 12px; }
.stage ul { padding-left: 1.05em; color: var(--muted); font-size: .9rem; line-height: 1.65; }
.stage li { margin-bottom: 3px; }

.loop-note {
  margin-top: 20px; font-size: .76rem; color: var(--muted);
  display: flex; align-items: center; gap: 10px;
}
.loop-note .line { height: 1px; background: var(--line-strong); flex: 1; }

/* --- outcomes ------------------------------------------------------------- */
.outcomes {
  display: grid; gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 3px; overflow: hidden;
}
@media (min-width: 720px) { .outcomes { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.outcome { background: var(--surface); padding: 24px 22px 26px; }
.outcome .big {
  font-family: "Newsreader", Georgia, serif; font-size: 2.3rem; line-height: 1;
  letter-spacing: -.025em; font-variant-numeric: tabular-nums; color: var(--accent);
}
.outcome h3 { margin: 14px 0 7px; font-size: .95rem; }
.outcome p { font-size: .89rem; color: var(--muted); line-height: 1.6; }
.outcome .where {
  display: block; margin-top: 12px; font-size: .71rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--brass);
}

/* --- speaking band -------------------------------------------------------- */
.speaking { padding: 54px 0; }
.speaking-head { display: grid; gap: 10px; margin-bottom: 26px; }
@media (min-width: 860px) {
  .speaking-head { grid-template-columns: 150px minmax(0, 1fr); gap: 0 40px; align-items: baseline; }
  .speaking-head .eyebrow { padding-top: .45rem; }
}
.speaking-title {
  font-family: "Newsreader", Georgia, serif; font-weight: 400;
  font-size: clamp(1.3rem, 2.6vw, 1.65rem); line-height: 1.25; letter-spacing: -.01em;
}
.speaking-title em { font-style: italic; color: var(--accent); }

.shots { margin: 0; display: grid; gap: 14px; }
@media (min-width: 720px) { .shots { grid-template-columns: 1fr 1fr; gap: 16px; } }
.shots img {
  width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover;
  border: 1px solid var(--line-strong); border-radius: 3px;
  background: var(--surface); box-shadow: var(--shadow);
}
.shots figcaption {
  grid-column: 1 / -1; margin-top: 6px;
  font-size: .87rem; color: var(--muted); line-height: 1.6; max-width: 74ch;
}

/* --- side project --------------------------------------------------------- */
.project {
  display: grid; background: var(--surface);
  border: 1px solid var(--line); border-radius: 3px; overflow: hidden;
}
@media (min-width: 860px) { .project { grid-template-columns: minmax(0, 1fr) 296px; } }

.project-main { padding: 28px 26px 30px; }
.project-name {
  font-family: "Newsreader", Georgia, serif; font-weight: 400;
  font-size: 1.75rem; line-height: 1.1; letter-spacing: -.015em;
}
.project-tagline {
  font-family: "IBM Plex Mono", monospace; font-size: .74rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--brass); margin-top: 8px;
}
.project-body { margin-top: 16px; color: var(--ink-2); font-size: .95rem; line-height: 1.7; max-width: 62ch; }
.project-points {
  margin: 16px 0 0; padding-left: 1.1em; color: var(--muted);
  font-size: .9rem; line-height: 1.65; max-width: 64ch;
}
.project-points li { margin-bottom: 4px; }
.project-points li::marker { color: var(--line-strong); }

.project-side {
  padding: 28px 26px 30px; border-top: 1px solid var(--line);
  background: var(--surface-2); display: flex; flex-direction: column; gap: 20px;
}
@media (min-width: 860px) { .project-side { border-top: 0; border-left: 1px solid var(--line); } }

.project-scale { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.project-scale dt {
  font-family: "Newsreader", Georgia, serif; font-size: 1.6rem; line-height: 1;
  color: var(--accent); font-variant-numeric: tabular-nums;
}
.project-scale dd { margin: 5px 0 0; font-size: .76rem; color: var(--muted); line-height: 1.35; }

.project-link { justify-content: center; }
.project-url {
  font-family: "IBM Plex Mono", monospace; font-size: .7rem; color: var(--muted);
  margin-top: -12px; word-break: break-all;
}
.project-stack { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- experience timeline -------------------------------------------------- */
.tl { display: grid; }
.job { display: grid; padding: 30px 0; border-top: 1px solid var(--line); }
.job:first-child { border-top: 0; padding-top: 4px; }
@media (min-width: 860px) { .job { grid-template-columns: 150px minmax(0, 1fr); gap: 0 40px; } }

.job-when {
  font-size: .78rem; color: var(--muted);
  font-variant-numeric: tabular-nums; line-height: 1.5; padding-top: .35rem;
}
.job-when .now { color: var(--accent); }
.job-title {
  font-family: "Newsreader", Georgia, serif; font-size: 1.42rem; font-weight: 400;
  letter-spacing: -.01em; line-height: 1.2;
}
.job-org { margin-top: 6px; font-size: .9rem; color: var(--ink-2); }
.job-org b { font-weight: 600; }
.job-org span { color: var(--muted); }
/* Capped: the timeline's right column is ~810px, which runs bullets to ~98
   characters. Holding them near 70 keeps them readable. */
.job ul { margin-top: 14px; padding-left: 1.1em; color: var(--ink-2); font-size: .94rem; line-height: 1.7; max-width: 70ch; }
.job li { margin-bottom: 5px; }
.job li::marker { color: var(--line-strong); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 15px; }
.tag {
  font-size: .7rem; letter-spacing: .05em; padding: 3px 9px;
  border: 1px solid var(--line-strong); border-radius: 2px; color: var(--muted);
}

/* --- capabilities --------------------------------------------------------- */
.caps { display: grid; gap: 26px; }
@media (min-width: 760px) { .caps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 30px 44px; } }

.cap h3 {
  font-family: "IBM Plex Mono", monospace; font-size: .74rem; letter-spacing: .13em;
  text-transform: uppercase; color: var(--accent); font-weight: 500;
}
.cap .items { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font-size: .83rem; padding: 5px 11px; border-radius: 2px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
}

/* --- education ------------------------------------------------------------ */
.edu {
  display: grid; gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 3px; overflow: hidden;
}
@media (min-width: 760px) { .edu { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.edu-item { background: var(--surface); padding: 24px 22px; }
.edu-item .eyebrow { color: var(--brass); }
.edu-item h3 {
  margin: 9px 0 5px; font-family: "Newsreader", Georgia, serif;
  font-size: 1.2rem; font-weight: 400;
}
.edu-item p:not(.eyebrow) { font-size: .88rem; color: var(--muted); line-height: 1.6; }
.edu-item a { color: var(--accent); text-underline-offset: 3px; }

/* --- working style -------------------------------------------------------- */
.traits { display: grid; gap: 20px; }
@media (min-width: 820px) { .traits { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; } }

.trait { border-left: 2px solid var(--accent); padding: 2px 0 2px 20px; }
.trait h3 { font-family: "Newsreader", Georgia, serif; font-size: 1.3rem; font-weight: 400; }
.trait .zh {
  font-size: .8rem; color: var(--muted); margin-top: 2px;
  font-family: "IBM Plex Sans", "Noto Sans TC", sans-serif; letter-spacing: .06em;
}
.trait p:not(.zh) { margin-top: 11px; font-size: .92rem; color: var(--ink-2); line-height: 1.68; }

/* --- contact -------------------------------------------------------------- */
.contact { background: var(--surface-2); border-top: 1px solid var(--line); }
.contact-grid { display: grid; gap: 30px; align-items: end; }
@media (min-width: 800px) { .contact-grid { grid-template-columns: minmax(0, 1fr) auto; } }

.contact h2 { font-size: clamp(1.9rem, 4vw, 2.6rem); margin-top: 14px; }
.contact p:not(.eyebrow) { color: var(--muted); margin-top: 14px; max-width: 48ch; }

.clist { display: grid; gap: 12px; }
.clist a {
  display: flex; align-items: center; gap: 12px; text-decoration: none; font-size: .85rem;
  padding-bottom: 11px; border-bottom: 1px solid var(--line-strong); transition: color .18s;
}
.clist a:hover { color: var(--accent); }
.clist svg { width: 15px; height: 15px; flex: none; color: var(--accent); }

footer {
  padding: 26px 0 40px; font-size: .73rem; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between;
}

/* --- 404 ------------------------------------------------------------------ */
.notfound { padding: 96px 0 120px; max-width: 56ch; }
.notfound h1 { font-size: clamp(2.2rem, 5vw, 3rem); margin-top: 14px; }
.notfound-body { margin-top: 16px; color: var(--ink-2); }
.notfound .actions { margin-top: 28px; }

/* --- reveal on scroll ----------------------------------------------------- */
/* Scoped to .js (set by the inline head script) so the page stays fully
   readable when JavaScript is blocked — no fade means no blank page. */
.js .reveal { opacity: 0; transform: translateY(14px); transition: opacity .7s ease, transform .7s cubic-bezier(.2, .7, .3, 1); }
.js .reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .js .reveal { opacity: 1; transform: none; transition: none; }
  * { animation: none !important; }
}

/* --- print: the page doubles as a one-click résumé ------------------------ */
@media print {
  .topbar, .theme-toggle, .skip { position: static; }
  .topbar, .theme-toggle, .skip { display: none; }
  .js .reveal { opacity: 1; transform: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  section { padding: 18px 0; break-inside: avoid; }
  .job, .outcome, .stage, .edu-item, .trait, .project, .shots img { break-inside: avoid; }
  .shots { grid-template-columns: 1fr 1fr; gap: 10px; }
  .hero { padding: 0 0 18px; }
  .actions, .loop-note { display: none; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 8pt; color: #555; }
  .clist a::after, .btn::after { content: none; }
}
