/* ================================================================
   Kean Shi — Academic Homepage
   Institutional / editorial direction: near-monochrome surfaces,
   a single red accent, square corners, no decoration for its own
   sake. Hierarchy comes from weight, case, size and tracking.
   Type: Open Sans — one family, no second face.
   ================================================================ */

:root {
  --font-sans: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;

  /* Light: white + light grey surfaces, black type, one red accent */
  --color-bg: #ffffff;
  --color-surface: #f2f2f2;
  --color-fg: #000000;
  --color-muted: #575757;
  --color-border: #d9d9d9;
  --color-rule: #e5e5e5;
  --color-accent: #c41230;
  --color-accent-bg: #c41230;
  --color-on-accent: #ffffff;
  --color-dark: #000000;
  --color-on-dark: #ffffff;
  --color-ring: #c41230;

  /* Type scale. One family means the scale has to carry everything,
     so sizes are set and weights pushed apart deliberately. */
  --h1: 700 clamp(2.5rem, 6.5vw, 3.5rem) / 1.05 var(--font-sans);
  --h2: 700 clamp(1.75rem, 4vw, 2.5rem) / 1.15 var(--font-sans);
  --h3: 650 1.125rem / 1.4 var(--font-sans);
  --body: 400 1rem / 1.7 var(--font-sans);
  --body-lead: 400 1.0625rem / 1.75 var(--font-sans);
  --lede: 400 clamp(1.125rem, 2.1vw, 1.375rem) / 1.55 var(--font-sans);
  --eyebrow: 700 0.8125rem / 1.2 var(--font-sans);
  --meta: 600 0.8125rem / 1.4 var(--font-sans);
  --button: 700 0.8125rem / 1 var(--font-sans);
  --small: 400 0.875rem / 1.6 var(--font-sans);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  --space-7: 4.5rem;

  --container-max: 72rem;
  --gutter: clamp(1.5rem, 5vw, 3.5rem);
  --panel: clamp(3.5rem, 9vw, 5rem);
  --duration: 200ms;

  /* Brand: a circular avatar and the name, living in the navbar. */
  --header-h: 3.75rem;
  --brand-avatar: 1.75rem;
  --hero-portrait: 12rem;
}

@media (min-width: 768px) {
  :root {
    --hero-portrait: 14rem;
  }
}

[data-theme="dark"] {
  --color-bg: #111111;
  --color-surface: #1b1b1b;
  --color-fg: #f5f5f5;
  --color-muted: #b3b3b3;
  --color-border: #333333;
  --color-rule: #2a2a2a;
  /* Links need a light red here; the deep red stays for filled blocks */
  --color-accent: #ff6b7d;
  --color-accent-bg: #8f0f24;
  --color-on-accent: #ffffff;
  --color-ring: #ff6b7d;
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
  overflow-x: hidden;
  overflow-x: clip;
}

body {
  margin: 0;
  font: var(--body);
  color: var(--color-fg);
  background: var(--color-bg);
  overflow-x: hidden;
  overflow-x: clip;
  transition: background-color var(--duration) ease, color var(--duration) ease;
}

h1,
h2,
h3 {
  font-family: var(--font-sans);
  letter-spacing: -0.015em;
  margin: 0 0 var(--space-3);
}

h1 { font: var(--h1); letter-spacing: -0.025em; }
h2 { font: var(--h2); }
h3 { font: var(--h3); }

p { margin: 0 0 var(--space-3); }

a {
  color: var(--color-accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.18em;
  transition: color var(--duration) ease, background-color var(--duration) ease;
  cursor: pointer;
}

a:hover {
  text-decoration-color: currentColor;
}

sup {
  font-size: 0.7em;
  line-height: 0;
}

:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: 0;
}

::selection {
  background: color-mix(in srgb, var(--color-accent) 25%, transparent);
}

.container {
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.icon {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
  vertical-align: -0.15em;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -100%;
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  background: var(--color-dark);
  color: var(--color-on-dark);
  font: var(--button);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.skip-link:focus {
  top: 0;
  color: var(--color-on-dark);
}

/* ---------- Header ---------- */

/* No border here: the ticker parks at exactly --header-h, so a bottom border
   would add a pixel the ticker doesn't know about and leave a hairline seam. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-dark);
  color: var(--color-on-dark);
}

.header-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-4);
  min-height: var(--header-h);
}

/* ---- Brand ----
   Circle avatar plus the name, on an accent tab in the navbar. Nothing here
   moves or folds — it is the same at every scroll position. `stretch` makes
   the accent fill the navbar's full height, so no dark edge shows above or
   below it. */
.brand-block {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: var(--space-2);
  margin-right: auto;
  padding-inline: 0.5rem 0.85rem;
  background: var(--color-accent-bg);
  color: var(--color-on-accent);
  text-decoration: none;
  overflow: hidden;
}

.brand-block:hover {
  background: color-mix(in srgb, var(--color-accent-bg) 88%, #000000);
}

.brand-block__avatar {
  order: -1;
  display: block;
  width: var(--brand-avatar);
  height: var(--brand-avatar);
  flex-shrink: 0;
  object-fit: cover;
  border: 1px solid var(--color-fg);
  border-radius: 50%;
}

.brand-block__name {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
}


.nav-list {
  display: flex;
  gap: var(--space-4);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-list a {
  position: relative;
  display: inline-block;
  padding: var(--space-2) 0;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--color-on-dark);
}

/* Flat accent rule instead of a highlighter swipe */
.nav-list a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.25rem;
  height: 2px;
  background: var(--color-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--duration) ease;
}

.nav-list a:hover::after,
.nav-list a:focus-visible::after {
  transform: scaleX(1);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--color-on-dark) 40%, transparent);
  border-radius: 0;
  background: transparent;
  color: var(--color-on-dark);
  cursor: pointer;
  transition: background-color var(--duration) ease, color var(--duration) ease;
}

.theme-toggle:hover {
  background: var(--color-on-dark);
  color: var(--color-dark);
}

.theme-toggle .icon {
  width: 1.15rem;
  height: 1.15rem;
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-moon { display: block; }
[data-theme="dark"] .icon-sun { display: none; }

/* ---------- Hero ---------- */

.hero {
  position: relative;
  padding-block: var(--space-7) var(--space-6);
}

/* Mobile-first: statement, portrait, then the contact row */
.bento {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.tile {
  min-width: 0;
}

.hero-portrait {
  max-width: var(--hero-portrait);
}

.hero-portrait img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--color-border);
}

@media (min-width: 768px) {
  .bento {
    grid-template-columns: minmax(0, 1fr) var(--hero-portrait);
    gap: var(--space-5) var(--space-6);
  }

  .tile { grid-column: 1; grid-row: 1; }
  .hero-portrait { grid-column: 2; grid-row: 1; justify-self: end; }
  .tile-links { grid-column: 1; grid-row: 2; }
}

.lede {
  font: var(--lede);
  color: var(--color-fg);
  margin-bottom: 0;
  max-width: 34em;
}

/* Key terms get a ruled underline, not a highlighter swatch */
.lede em {
  font-style: normal;
  font-weight: 600;
  border-bottom: 2px solid var(--color-accent);
  padding-bottom: 0.05em;
}

/* ---------- Contact chips ---------- */

.tile-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  align-content: start;
}

@media (min-width: 768px) {
  /* One row across the text column, capped so the buttons stay button-sized */
  .tile-links {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: 36rem;
  }
}

.chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-fg);
  border-radius: 0;
  text-decoration: none;
  font: var(--button);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-fg);
  background: transparent;
  transition: background-color var(--duration) ease, color var(--duration) ease,
    border-color var(--duration) ease;
}

/* One primary action; the rest stay subordinate */
.chip-primary {
  background: var(--color-accent-bg);
  border-color: var(--color-accent-bg);
  color: var(--color-on-accent);
}

.chip:hover {
  background: var(--color-fg);
  border-color: var(--color-fg);
  color: var(--color-bg);
}

/* ---------- Interests ticker ---------- */

.ticker {
  overflow: hidden;
  background: var(--color-dark);
  color: var(--color-on-dark);
  padding-block: 0.65rem;
}

/* Parks directly under the sticky header and stays there. The hairline rule
   separates two black bands that would otherwise read as one. Only where the
   header is a single row — on mobile it wraps and would be taller than
   --header-h, which would tuck the ticker behind it. */
@media (min-width: 768px) {
  .ticker {
    position: sticky;
    top: var(--header-h);
    z-index: 40;
    border-top: 2px solid var(--color-accent);
  }
}

.ticker-track {
  display: flex;
  width: max-content;
}

.js .ticker-track {
  animation: ticker 32s linear infinite;
}

.ticker-group {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-right: var(--space-4);
  white-space: nowrap;
  font: var(--eyebrow);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

/* Square separator, drawn rather than declared in markup */
.ticker-group span::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: var(--space-4);
  background: var(--color-accent);
  vertical-align: middle;
}

@keyframes ticker {
  to { transform: translateX(-50%); }
}

/* ---------- Sections ---------- */

.section {
  position: relative;
  padding-block: var(--panel);
}

.section-title {
  display: block;
  font: var(--h2);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-5);
}

/* Short accent rule under each heading — the only repeated ornament */
.section-title::after {
  content: "";
  display: block;
  width: 2.5rem;
  height: 3px;
  margin-top: var(--space-3);
  background: var(--color-accent);
}

.band {
  background: var(--color-surface);
}

/* ---------- Scroll reveal (classes added by JS only) ---------- */

.js .reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  transition-delay: var(--reveal-delay, 0s);
}

.js .reveal.revealed {
  opacity: 1;
  transform: none;
}

/* After the reveal finishes, restore snappy hover transitions */
.js .reveal.settled {
  transition: background-color var(--duration) ease,
    border-color var(--duration) ease, color var(--duration) ease;
  transition-delay: 0s;
}

/* ---------- About + Recent News ----------
   Two sibling blocks sharing one row. About is a <section>; the news column is
   its own block, not nested inside it. The row owns the vertical rhythm that
   .section normally provides, since neither block is a full-width section. */

.about-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
  padding-block: var(--panel);
  align-items: start;
}

@media (min-width: 1024px) {
  .about-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 26rem);
    gap: var(--space-6) var(--space-7);
  }

  /* Too narrow for a date gutter, so the date sits above the item */
  .news-block .news-list li {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-1);
  }
}

/* The only paneled block on the page: a grey ground plus a hairline, so it
   reads as a card sitting on the page rather than as another page section. */
.news-block {
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

/* Card scale, not section scale — and a shorter rule to match */
.news-block .section-title {
  font-size: 1.25rem;
  letter-spacing: -0.015em;
  margin-bottom: var(--space-4);
}

.news-block .section-title::after {
  width: 1.75rem;
}

.news-block .news-list li:first-child {
  padding-top: 0;
}

.about-body {
  max-width: 42rem;
  font: var(--body-lead);
}

.inline-logo {
  height: 1.15em;
  width: auto;
  vertical-align: -0.2em;
}

.contact-cta {
  font-size: 1.0625rem;
  font-weight: 600;
  margin-bottom: 0;
}

/* ---------- News ---------- */

.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.news-list li {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: var(--space-3);
  padding-block: var(--space-3);
  font: var(--small);
}

.news-list li + li {
  border-top: 1px solid var(--color-rule);
}

.news-date {
  font: var(--eyebrow);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
  padding-top: 0.15em;
}

/* ---------- Research ---------- */

.pub-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-4);
}

.pub {
  display: grid;
  grid-template-columns: minmax(0, 16rem) minmax(0, 1fr);
  gap: var(--space-5);
  padding: var(--space-5);
  background: var(--color-surface);
  border-radius: 0;
  transition: background-color var(--duration) ease;
}

/* Figure always leads, so the eye lands on the same column every time */
.pub-img {
  width: 100%;
  height: auto;
  /* --color-fg rather than a literal black, so the rule stays visible when the
     page flips to dark */
  border: 1px solid var(--color-fg);
  background: #ffffff;
  align-self: start;
}

.pub-body {
  min-width: 0;
}

.pub-title {
  font-size: 1.125rem;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
}

.pub-authors {
  margin-bottom: var(--space-1);
  font: var(--small);
  color: var(--color-muted);
}

.pub-authors strong {
  color: var(--color-fg);
  font-weight: 700;
}

.pub-venue {
  font: var(--meta);
  margin-bottom: var(--space-3);
}

.badge {
  display: inline-block;
  padding: 0.15em 0.5em;
  margin-left: 0.35em;
  border-radius: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-variant-numeric: tabular-nums;
}

.pub-links {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-height: 2.25rem;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-fg);
  border-radius: 0;
  font: var(--button);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-fg);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration) ease, color var(--duration) ease,
    border-color var(--duration) ease;
}

.link-btn:hover {
  background: var(--color-fg);
  color: var(--color-surface);
}

.abs-toggle[aria-expanded="true"] {
  background: var(--color-fg);
  color: var(--color-surface);
}

/* Grid-rows accordion: animates open/closed without fixed heights */
.abstract {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 320ms cubic-bezier(0.16, 1, 0.3, 1);
}

.abstract > div {
  overflow: hidden;
}

.abstract p {
  margin: var(--space-3) 0 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  font: var(--small);
  color: var(--color-muted);
}

.abstract.open {
  grid-template-rows: 1fr;
}

.pub-more {
  margin: var(--space-5) 0 0;
  font: var(--small);
  color: var(--color-muted);
}

/* ---------- Path: two outlined panels ---------- */

.path-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  align-items: stretch;
}

.path-block {
  padding: var(--space-5);
  background: var(--color-bg);
  border: 1px solid var(--color-accent);
}

/* Panel heading. Sentence case, not the uppercase eyebrow used elsewhere —
   these name a block, they aren't labels sitting beside one. */
.side-heading {
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-4);
}

.path-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-4);
}

.path-item {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

/* Brand marks are drawn for light grounds. A white tile is invisible against
   the white panel but keeps them legible once the panel goes dark. */
.path-logo {
  width: 3rem;
  height: 3rem;
  flex-shrink: 0;
  object-fit: contain;
  background: #ffffff;
  padding: 0.3rem;
}

.path-body {
  min-width: 0;
}

.path-org {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  font-weight: 700;
  margin-bottom: 0.1rem;
}

.path-date {
  font: var(--eyebrow);
  letter-spacing: 0;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

.path-desc {
  margin: 0;
  font: var(--small);
  color: var(--color-muted);
}

/* ---------- Awards & services ---------- */

.tile-duo {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--space-4);
  align-items: stretch;
}

.mini-tile {
  padding: var(--space-5);
  background: var(--color-surface);
  border-radius: 0;
}

.mini-tile .section-title {
  font-size: 1.375rem;
  letter-spacing: -0.015em;
  margin-bottom: var(--space-4);
}

.mini-tile .section-title::after {
  margin-top: var(--space-2);
}

.award-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.award-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding-block: var(--space-2);
  font: var(--small);
}

.award-list li + li {
  border-top: 1px solid var(--color-border);
}

.award-date {
  flex-shrink: 0;
  font: var(--eyebrow);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

.award-highlight {
  font-style: normal;
  font-weight: 700;
}

/* ---------- Contact / Footer ---------- */

.contact-band {
  background: var(--color-accent-bg);
  color: var(--color-on-accent);
}

.contact-band a {
  color: var(--color-on-accent);
  text-decoration-color: color-mix(in srgb, var(--color-on-accent) 55%, transparent);
  font-weight: 700;
}

.contact-band a:hover {
  text-decoration-color: currentColor;
}

.contact-layout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  flex-wrap: wrap;
}

.contact-lede {
  font: var(--lede);
  max-width: 34rem;
  margin-bottom: 0;
}

.section-title-contact {
  color: var(--color-on-accent);
}

.section-title-contact::after {
  background: var(--color-on-accent);
}

.visitor-map {
  display: inline-block;
  flex-shrink: 0;
  padding: var(--space-3);
  background: #ffffff;
  border: 1px solid var(--color-on-accent);
  border-radius: 0;
  line-height: 0;
}

.visitor-map-caption {
  margin: 0 0 var(--space-2);
  font: var(--meta);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.3;
  color: #000000;
}

/* The widget inline-styles its "Total Pageviews" label dark; it sits on the
   dark map, so force it readable */
.visitor-map div div {
  color: #ffffff !important;
}

/* The contact section's own bottom padding already separates the rule */
.site-footer {
  border-top: 1px solid color-mix(in srgb, var(--color-on-accent) 35%, transparent);
  padding-block: var(--space-4);
}

.footer-inner p {
  margin: 0;
  font: var(--small);
  color: color-mix(in srgb, var(--color-on-accent) 85%, transparent);
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .pub {
    grid-template-columns: 1fr;
  }

  .pub-img {
    max-width: 32rem;
  }
}

@media (max-width: 767px) {
  /* No vertical padding: the accent tab stretches to its row, so it sits flush
     with the top of the navbar instead of leaving a dark sliver above it. */
  .header-inner {
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
  }

  .header-inner nav {
    order: 3;
    width: 100%;
  }

  .nav-list {
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  .hero {
    padding-block: var(--space-6) var(--space-5);
  }

  .news-list li {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .path-grid,
  .tile-duo {
    grid-template-columns: 1fr;
    gap: var(--space-5);
  }

  .award-list li {
    flex-direction: column;
    gap: var(--space-1);
  }
}

/* ---------- Motion preferences ---------- */

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

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
