/* Tokens */
:root {
  --paper: #edf1f2;
  --ink: #12242f;
  --ink-2: #4b5d69;
  --rule: #c4ced3;
  --accent: #5f2a8c;
  --accent-soft: #cbb8dc;
  --warm: #8a5a12;

  --serif: "Source Serif 4", "Songti TC", Georgia, serif;
  --sans: "Archivo", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;

  --label-w: 10rem;
  --gap: 2.5rem;
  --prose-w: 40rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1b23;
    --ink: #e3eaed;
    --ink-2: #9bacb6;
    --rule: #2a3a45;
    --accent: #c9a7ec;
    --accent-soft: #56406f;
    --warm: #e9b872;
  }
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.6;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }

a {
  color: var(--warm);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover { text-decoration-thickness: 2px; }
a:focus-visible {
  outline: 2px solid var(--warm);
  outline-offset: 3px;
  border-radius: 2px;
}

.wrap {
  max-width: 76rem;
  margin-inline: auto;
  padding-inline: clamp(1.25rem, 5vw, 4rem);
}

/* Top bar */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
}
/* Let the aurora show through the bar */
.js .top {
  background: color-mix(in srgb, var(--paper) 72%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.top-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 2rem;
  padding-block: 0.85rem;
}
.name {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
}
.name a {
  color: var(--ink);
  text-decoration: none;
}
.name-zh {
  margin-left: 0.55rem;
  font-weight: 400;
  color: var(--ink-2);
}
.top nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 1.5rem;
}
.top nav a {
  color: var(--ink);
  font-size: 0.95rem;
  font-stretch: 92%;
  text-decoration: none;
}
.top nav a:hover { text-decoration: underline; }
.top nav a[aria-current="true"] {
  color: var(--warm);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.45em;
}

/* Opening statement, set as two staggered lines */
.hero {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  row-gap: clamp(0.5rem, 1.6vw, 1.25rem);
  align-items: start;
  padding-block: clamp(3rem, 9vw, 7rem) clamp(2.5rem, 6vw, 4.5rem);
}
.statement {
  font-size: clamp(1.9rem, 1rem + 3.6vw, 3.75rem);
  font-weight: 320;
  line-height: 1.13;
  letter-spacing: -0.012em;
  text-wrap: balance;
}
.s1 { grid-column: 1 / span 9; }
.s2 { grid-column: 4 / span 9; }

.intro {
  padding-left: calc(var(--label-w) + var(--gap));
  padding-bottom: clamp(3rem, 7vw, 5rem);
}
.intro p {
  max-width: 37rem;
  font-size: 1.3rem;
  line-height: 1.5;
}

/* One page-load moment: the opening words come into focus in turn.
   Without script the two lines simply rise. */
@media (prefers-reduced-motion: no-preference) {
  .statement, .intro p {
    animation: rise 700ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
  }
  .s2 { animation-delay: 90ms; }
  .intro p { animation-delay: 620ms; }
  @keyframes rise {
    from { opacity: 0; transform: translateY(0.5em); }
  }

  /* script.js splits the lines into words; hold them until it has */
  .js .statement:not(.split) {
    opacity: 0;
    animation: reveal 1ms 1500ms forwards;
  }
  .statement.split { animation: none; }
  .word {
    display: inline-block;
    animation: word-in 900ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
    animation-delay: calc(var(--i) * 65ms);
  }
  @keyframes reveal { to { opacity: 1; } }
  @keyframes word-in {
    from { opacity: 0; filter: blur(14px); transform: translateY(0.3em); }
  }
}

/* Aurora layer behind the top of the page; script.js starts it */
.fx {
  position: absolute;
  inset: 0 0 auto 0;
  height: 46rem;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(#000 55%, transparent);
  mask-image: linear-gradient(#000 55%, transparent);
}
.fx canvas {
  display: block;
  width: 100%;
  height: 100%;
}
main { position: relative; z-index: 1; }

/* Sections: label in the left column, content on the right */
.band {
  display: grid;
  grid-template-columns: var(--label-w) minmax(0, 1fr);
  column-gap: var(--gap);
  border-top: 1px solid var(--rule);
  padding-block: 2.25rem 3.5rem;
  position: relative;
}
/* A short warm tab marks where each section starts */
.band::before {
  content: "";
  position: absolute;
  top: -2px;
  left: 0;
  width: 2.25rem;
  height: 3px;
  background: var(--warm);
}
.band h2 {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  font-stretch: 92%;
  line-height: 1.9;
}

.entry + .entry { margin-top: 2.75rem; }
.entry.has-fig + .entry.has-fig { margin-top: 3.75rem; }
.entry-body { max-width: var(--prose-w); }
.entry.has-fig {
  display: grid;
  grid-template-columns: minmax(0, var(--prose-w)) minmax(14rem, 18rem);
  justify-content: space-between;
  column-gap: 3rem;
  align-items: start;
}

.entry h3 {
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.005em;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 1.5rem;
  margin-block: 0.4rem 0.9rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-stretch: 92%;
  line-height: 1.5;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.entry-body p + p:not(.meta) { margin-top: 0.85rem; }
.meta + p { margin-top: 0; }
.meta:last-child { margin-bottom: 0; }
.entry h3 a { color: inherit; text-decoration-color: var(--warm); }
cite { font-style: italic; }

/* Experience: logo, role, and a strip showing when on a shared time axis */
.timeline {
  --strip-w: 16rem;
  --months: 23;
  position: relative;
}
.axis { display: none; }
.entry.role {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  column-gap: 1.1rem;
  align-items: start;
}
.entry.role .entry-body { max-width: calc(var(--prose-w) - 3.85rem); }
.logo {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0.4rem;
  margin-top: 0.1rem;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.logo img, .logo svg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.logo-text {
  padding: 0;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 0.66rem;
  font-weight: 700;
  font-stretch: 85%;
  letter-spacing: 0.02em;
}
.strip {
  grid-column: 2;
  position: relative;
  z-index: 1;
  height: 14px;
  max-width: 22rem;
  margin-top: 0.8rem;
  background-image:
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule));
  background-size: 1px 100%;
  background-repeat: no-repeat;
  background-position: 0 0, 52.17% 0, 100% 0;
}
.strip span {
  position: absolute;
  top: 4px;
  height: 6px;
  left: calc(var(--s) / var(--months) * 100%);
  width: calc((var(--e) - var(--s)) / var(--months) * 100%);
  background: var(--accent);
  border-radius: 3px;
  transition: background-color 150ms;
}
@media (hover: hover) {
  .timeline:has(.entry.role:hover) .strip span { background: var(--accent-soft); }
  .timeline .entry.role:hover .strip span { background: var(--accent); }
}

/* Two columns of entries where there is room */
@media (min-width: 60rem) {
  .entries.cols-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2.5rem 3.5rem;
  }
  .entries.cols-2 .entry + .entry { margin-top: 0; }
}

@media (min-width: 68.01rem) {
  .timeline { padding-top: 2.1rem; }
  .axis {
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: var(--strip-w);
    font-family: var(--sans);
    font-size: 0.75rem;
    line-height: 1.2;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
  }
  .tick {
    position: absolute;
    top: 0;
    bottom: 0;
    padding-left: 0.35rem;
    border-left: 1px solid var(--rule);
  }
  .tick-end {
    right: 0;
    padding: 0 0.35rem 0 0;
    border-left: 0;
    border-right: 1px solid var(--warm);
  }
  .entry.role {
    grid-template-columns: 2.75rem minmax(0, 1fr) var(--strip-w);
  }
  .strip {
    grid-column: 3;
    max-width: none;
    margin-top: 0.55rem;
    background: none;
  }
}

/* Short fact lists */
.facts {
  list-style: disc;
  padding-left: 1.1em;
}
.facts li + li { margin-top: 0.2rem; }
.facts li::marker { color: var(--ink-2); }


/* Figures */
.fig {
  margin-top: 0.35rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.4;
}
.nb { white-space: nowrap; }

.fig-title {
  text-wrap: balance;
  font-weight: 600;
  margin-bottom: 1.1rem;
}
.row-label { color: var(--ink-2); }
.fig figcaption {
  margin-top: 1rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 0.8rem;
}

.dumbbell + .dumbbell { margin-top: 0.6rem; }
.track {
  --y: 1.95rem;
  position: relative;
  height: 2.6rem;
  margin-inline: 0.9rem;
}
.track::before {
  content: "";
  position: absolute;
  inset-inline: -0.9rem;
  top: var(--y);
  height: 1px;
  background: var(--rule);
}
.link {
  position: absolute;
  top: calc(var(--y) - 0.5px);
  left: calc(min(var(--a), var(--b)) * 1%);
  width: calc((max(var(--a), var(--b)) - min(var(--a), var(--b))) * 1%);
  height: 2px;
  background: var(--accent-soft);
}
.dot {
  position: absolute;
  top: calc(var(--y) - 4.5px);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translateX(-50%);
}
.dot-a {
  left: calc(var(--a) * 1%);
  background: var(--paper);
  border: 2px solid var(--accent);
}
.dot-b {
  left: calc(var(--b) * 1%);
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--paper);
}
.val {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dot-a .val { bottom: 12px; }

.legend {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.9rem;
  color: var(--ink-2);
}
.key {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.key-a { border: 2px solid var(--accent); }
.key-b { background: var(--accent); margin-left: 0.9rem; }

.meter + .meter { margin-top: 0.9rem; }
.meter .row-label {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}
.meter .num {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.bar {
  height: 10px;
  background: var(--accent-soft);
  border-radius: 0 4px 4px 0;
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-right: 2px solid var(--paper);
}

/* Contact */
.contact-mail { font-size: 1.375rem; line-height: 1.3; }
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.75rem;
  margin-top: 0.9rem;
  font-family: var(--sans);
  font-size: 0.95rem;
}

.foot {
  padding-block: 1.5rem 3rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-2);
}
.foot p {
  border-top: 1px solid var(--rule);
  padding-top: 1.25rem;
}

/* Narrower screens: figures move under the prose */
@media (max-width: 68rem) {
  .entry.has-fig { display: block; }
  .fig { margin-top: 1.75rem; max-width: 22rem; }
}

/* Phones: one column */
@media (max-width: 45rem) {
  body { font-size: 1.0625rem; }
  .top { position: static; }
  html { scroll-padding-top: 1rem; }
  .s1, .s2 { grid-column: 1 / -1; }
  .intro p { font-size: 1.15rem; }
  .intro { padding-left: 0; }
  .band {
    display: block;
    padding-block: 1.5rem 2.75rem;
  }
  .band h2 { margin-bottom: 1rem; }
  .fig { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

@media print {
  .top { position: static; }
  .top nav { display: none; }
}
