:root {
  --bg: #13243a;
  --bg2: #172b44;
  --panel: #1c3350;
  --line: #2e4866;
  --text: #e9eef3;
  --muted: #a3b4c6;
  --copper: #e0995a;
  --flow: #6cc9b4;
  --rose: #d47a7a;
  --off: #4a6380;
  --measure: 64ch;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}
a { color: var(--copper); text-underline-offset: 3px; }
a:hover { color: #f2b77f; }
:focus-visible { outline: 2px solid var(--flow); outline-offset: 3px; border-radius: 3px; }
canvas { display: block; width: 100%; }

/* scroll progress */
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 30; }
.progress span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--flow), var(--copper)); transform-origin: 0 50%; transform: scaleX(0); }

/* header */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.9rem max(1.5rem, calc((100vw - 1120px) / 2));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
  transition: border-color .3s;
}
.top.scrolled { border-bottom-color: var(--line); }
.name { color: var(--text); text-decoration: none; font-weight: 750; font-variation-settings: "wdth" 115; }
.top nav { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.top nav a { color: var(--muted); text-decoration: none; font-size: 0.92rem; position: relative; }
.top nav a::after { content: ""; position: absolute; left: 0; right: 0; bottom: -4px; height: 2px; background: var(--copper); transform: scaleX(0); transition: transform .25s; transform-origin: left; }
.top nav a:hover, .top nav a.on { color: var(--text); }
.top nav a.on::after, .top nav a:hover::after { transform: scaleX(1); }

main { overflow-x: clip; }

/* hero */
.hero { position: relative; min-height: calc(100vh - 60px); display: flex; align-items: center; }
.waves { position: absolute; inset: 0; height: 100%; opacity: 0.9; }
.hero-inner { position: relative; max-width: 1120px; margin: 0 auto; padding: 4rem 1.5rem 5rem; width: 100%; }
.hero-who { color: var(--muted); margin: 0 0 1.25rem; }
.hero-title {
  font-size: clamp(2.8rem, 7.6vw, 6.4rem);
  line-height: 0.96;
  font-weight: 800;
  font-variation-settings: "wdth" 66;
  letter-spacing: -0.015em;
  margin: 0 0 1.75rem;
  max-width: 11em;
}
.hero-title .line { display: block; overflow: hidden; }
.lede { font-size: clamp(1.1rem, 1.6vw, 1.3rem); max-width: 36em; margin: 0 0 2rem; }
.hero-meta { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 2.25rem; }
.hero-meta p { color: var(--muted); max-width: 30em; margin: 0; }
.freq {
  display: flex; align-items: baseline; gap: 0.3rem;
  padding: 0.5rem 0.9rem; border: 1px solid var(--line); border-radius: 8px; background: color-mix(in srgb, var(--panel) 70%, transparent);
}
.freq-val { font-size: 1.9rem; font-weight: 700; font-variation-settings: "wdth" 80; color: var(--flow); min-width: 4.2ch; }
.freq-unit { color: var(--muted); }
.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.btn {
  display: inline-block; padding: 0.75rem 1.2rem; border: 1px solid var(--line); border-radius: 6px;
  color: var(--text); text-decoration: none; font: inherit; font-weight: 600; background: transparent; cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s;
}
.btn:hover { border-color: var(--muted); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--copper); border-color: var(--copper); color: #1b1309; }
.btn.primary:hover { background: #f0ab6c; color: #1b1309; }

/* hero entrance: the one orchestrated sequence */
.js .hero-who, .js .hero-title .line > *, .js .lede, .js .hero-meta, .js .actions { opacity: 0; }
.js .ready .hero-who { animation: rise .7s .05s both cubic-bezier(.2,.7,.2,1); }
.js .hero-title .line { opacity: 1; }
.js .hero-title .line .w { display: inline-block; }
.js .ready .hero-title .line .w { animation: rise .8s both cubic-bezier(.2,.7,.2,1); }
.js .ready .lede { animation: rise .8s .55s both cubic-bezier(.2,.7,.2,1); }
.js .ready .hero-meta { animation: rise .8s .7s both cubic-bezier(.2,.7,.2,1); }
.js .ready .actions { animation: rise .8s .85s both cubic-bezier(.2,.7,.2,1); }
@keyframes rise { from { opacity: 0; transform: translateY(0.6em); } to { opacity: 1; transform: none; } }

/* sections */
.block { max-width: 1120px; margin: 0 auto; padding: 5.5rem 1.5rem; }
.alt { position: relative; }
.alt::before { content: ""; position: absolute; inset: 0 calc(50% - 50vw); background: var(--bg2); z-index: -1; }
.head { max-width: 46rem; margin-bottom: 2.5rem; }
h2 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.02;
  font-weight: 780;
  font-variation-settings: "wdth" 70;
  margin: 0 0 1rem;
}
.head p { color: var(--muted); font-size: 1.1rem; margin: 0; }
h3 { font-size: 1.15rem; margin: 0 0 0.25rem; }
.sub-h { font-size: 1.4rem; font-variation-settings: "wdth" 80; margin: 3rem 0 1rem; }
.fine { color: var(--muted); font-size: 0.85rem; max-width: var(--measure); margin-top: 1.25rem; }

/* reveal on scroll (sections only) */
.js .reveal { opacity: 0; transform: translateY(24px); transition: opacity .8s cubic-bezier(.2,.7,.2,1), transform .8s cubic-bezier(.2,.7,.2,1); }
.js .reveal.in { opacity: 1; transform: none; }

/* day simulator */
.sim { display: grid; grid-template-columns: 1.25fr 1fr; gap: 1.5rem; align-items: start; }
.sim-chart, .sim-diagram, .lab-controls, .lab-plot {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem;
}
.sim-diagram { margin: 0; }
#day-chart { height: 280px; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; color: var(--muted); font-size: 0.85rem; margin-top: 0.6rem; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 0.4rem; }
.sw.load { background: var(--text); }
.sw.pv { background: var(--copper); height: 8px; opacity: .8; }
.sw.soc { background: var(--flow); }
.sw.out { background: var(--rose); height: 8px; opacity: .45; }
.sw.base { background: var(--muted); }
.sw.gfm { background: var(--flow); }
.sw.dg { background: var(--rose); height: 5px; }
.sw.ufls { background: var(--rose); height: 2px; }
.scrub { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.9rem; }
.scrub output { font-weight: 700; font-size: 1.2rem; min-width: 3.5em; text-align: right; }
.play { font: inherit; font-weight: 600; color: var(--bg); background: var(--flow); border: 0; border-radius: 999px; padding: 0.45rem 1rem; cursor: pointer; min-width: 5em; }
input[type=range] { flex: 1; accent-color: var(--copper); }

.diagram { width: 100%; height: auto; display: block; }
.diagram .bus { stroke: var(--line); stroke-width: 6; stroke-linecap: round; }
.diagram .bus-label { fill: var(--muted); font-size: 12px; text-anchor: middle; }
.diagram .node rect { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; transition: opacity .35s, stroke .35s; }
.diagram .node.key rect { stroke: var(--copper); }
.diagram .node.live rect { stroke: var(--flow); }
.diagram .node text { fill: var(--text); font-size: 14px; font-weight: 600; text-anchor: middle; }
.diagram .node text.sub { fill: var(--muted); font-size: 11.5px; font-weight: 400; }
.diagram .node.dead { opacity: 0.32; }
.diagram .path { stroke: var(--off); stroke-width: 3; stroke-dasharray: 2 6; transition: stroke .3s; }
.diagram .path.fwd, .diagram .path.rev { stroke: var(--flow); stroke-width: 4; stroke-dasharray: 8 7; stroke-linecap: round; }
.diagram .path.fwd { animation: flow .9s linear infinite; }
.diagram .path.rev { animation: flow .9s linear infinite reverse; }
.diagram .path.dg.fwd { stroke: var(--rose); }
@keyframes flow { to { stroke-dashoffset: -15; } }
.sim-diagram figcaption { color: var(--muted); font-size: 0.95rem; margin-top: 0.6rem; min-height: 3.2em; }
.sim-diagram figcaption.flash { animation: flash .6s; }
@keyframes flash { from { color: var(--text); } to { color: var(--muted); } }

.tally { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin: 1.5rem 0 0; }
.tally div { border-top: 2px solid var(--line); padding-top: 0.6rem; }
.tally dt { color: var(--muted); font-size: 0.88rem; }
.tally dd { margin: 0; font-size: 1.6rem; font-weight: 700; font-variation-settings: "wdth" 80; }

/* frequency lab */
.lab { display: grid; grid-template-columns: 0.8fr 1.4fr; gap: 1.5rem; align-items: stretch; }
.lab-controls { display: flex; flex-direction: column; gap: 1.1rem; }
.lab-controls label { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 1rem; font-size: 0.95rem; }
.lab-controls label input { grid-column: 1 / -1; }
.lab-controls output { font-weight: 700; color: var(--flow); }
.readout { margin: 0.4rem 0 0; display: grid; gap: 0.6rem; }
.readout div { display: flex; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--line); padding-top: 0.5rem; }
.readout dt { color: var(--muted); font-size: 0.9rem; }
.readout dd { margin: 0; font-weight: 700; }
.readout dd.bad { color: var(--rose); }
.readout dd.good { color: var(--flow); }
#freq-chart { height: 340px; }

/* research */
.paper { border-left: 3px solid var(--copper); padding: 0.2rem 0 0.2rem 1.1rem; max-width: var(--measure); }
.cite { margin: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; border-bottom: 1px solid var(--line); }
.tabs button {
  font: inherit; font-size: 0.95rem; color: var(--muted); background: none; border: 0; padding: 0.7rem 1rem; cursor: pointer; position: relative;
}
.tabs button[aria-selected="true"] { color: var(--text); font-weight: 650; }
.tabs button::after { content: ""; position: absolute; left: 0.5rem; right: 0.5rem; bottom: -1px; height: 3px; background: var(--copper); transform: scaleX(0); transition: transform .3s; }
.tabs button[aria-selected="true"]::after { transform: scaleX(1); }
.panel { padding: 1.4rem 0 0; max-width: var(--measure); animation: panel .45s cubic-bezier(.2,.7,.2,1); }
@keyframes panel { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
.eq { font-size: 1.25rem; font-style: italic; color: var(--flow); background: var(--panel); border-radius: 8px; padding: 0.8rem 1rem; display: inline-block; margin: 0 0 1rem; }
.pc { color: var(--muted); }
.pc b { color: var(--text); }
.gaps { padding-left: 1.4rem; max-width: var(--measure); }
.gaps li { margin-bottom: 0.9rem; padding-left: 0.3rem; }
.gaps li::marker { color: var(--copper); font-weight: 700; }
.topic { max-width: var(--measure); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.2rem; margin-top: 2rem; }

/* field */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.cols p { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; margin: 3rem 0 0; }
.stats div { display: flex; flex-direction: column-reverse; gap: 0.3rem; }
.stats dd { margin: 0; font-size: clamp(2rem, 4vw, 3rem); font-weight: 780; font-variation-settings: "wdth" 70; color: var(--copper); line-height: 1; }
.stats dt { color: var(--muted); font-size: 0.92rem; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 0.5rem; bottom: 0.5rem; width: 2px; background: var(--line); }
.timeline::after { content: ""; position: absolute; left: 6px; top: 0.5rem; width: 2px; height: var(--fill, 0%); background: var(--copper); transition: height .2s linear; }
.timeline > li { position: relative; padding: 0 0 2.6rem 2.2rem; max-width: 52rem; }
.timeline > li::before {
  content: ""; position: absolute; left: 0; top: 0.45rem; width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--copper); z-index: 1;
}
.when { color: var(--copper); font-size: 0.9rem; margin: 0 0 0.1rem; }
.role { color: var(--muted); margin: 0 0 0.5rem; }
.timeline p:last-child { margin: 0; max-width: var(--measure); }

/* projects */
.projects { display: grid; gap: 0.75rem; max-width: 52rem; }
.projects details { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 1.2rem; transition: border-color .25s; }
.projects details[open] { border-color: var(--copper); }
.projects summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.1rem 0; }
.projects summary::-webkit-details-marker { display: none; }
.p-title { font-weight: 700; font-size: 1.1rem; }
.p-tag { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.p-tag::after { content: "+"; display: inline-block; margin-left: 0.8rem; color: var(--copper); font-size: 1.2rem; transition: transform .25s; }
.projects details[open] .p-tag::after { transform: rotate(45deg); }
.projects details p { margin: 0 0 1.2rem; color: var(--muted); max-width: var(--measure); animation: panel .4s; }

/* map */
.map { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.map figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem; }
#china-map { width: 100%; height: auto; display: block; }
.grat line { stroke: var(--line); stroke-width: 1; opacity: .55; }
.grat text { fill: var(--off); font-size: 10px; }
.route { fill: none; stroke: var(--copper); stroke-width: 1.6; opacity: .75; }
.city circle.dot { fill: var(--flow); }
.city circle.ring { fill: none; stroke: var(--flow); stroke-width: 1.5; transform-box: fill-box; transform-origin: center; animation: ping 2.4s ease-out infinite; }
.city.home circle.dot { fill: var(--copper); }
.city.home circle.ring { stroke: var(--copper); }
.city text { fill: var(--text); font-size: 13px; font-weight: 600; }
.city text.prov { fill: var(--muted); font-size: 10.5px; font-weight: 400; }
.city { cursor: default; }
.city.hot text { fill: var(--flow); }
@keyframes ping { from { transform: scale(1); opacity: .9; } to { transform: scale(3.2); opacity: 0; } }

/* education */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; }
.two h2 { font-size: clamp(1.7rem, 3vw, 2.3rem); }
.prep { padding-left: 1.1rem; }
.prep li { margin-bottom: 0.45rem; }
.prep li::marker { color: var(--flow); }

/* contact */
.contact h2 { max-width: 14em; }
.links { list-style: none; padding: 0; margin: 2rem 0 0; display: flex; flex-wrap: wrap; gap: 0.8rem 2.2rem; font-size: 1.15rem; }
.links a { font-weight: 650; }

footer { max-width: 1120px; margin: 0 auto; padding: 2rem 1.5rem 3rem; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); }
footer p { margin: 0.2rem 0; }

/* responsive */
@media (max-width: 900px) {
  .sim, .lab, .cols, .two { grid-template-columns: 1fr; }
  .tally, .stats { grid-template-columns: 1fr 1fr; }
  .top nav { display: none; }
}
@media (max-width: 520px) {
  body { font-size: 1rem; }
  .block { padding: 4rem 1.1rem; }
  .hero-inner { padding: 3rem 1.1rem 4rem; }
  #day-chart { height: 220px; }
  #freq-chart { height: 260px; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .js .reveal, .js .hero-who, .js .lede, .js .hero-meta, .js .actions, .js .hero-title .line .w { opacity: 1 !important; transform: none !important; }
}
#china-map { max-width: 960px; margin: 0 auto; }
