/* ============================================================
   Tingyu Dai — Sociology of AI
   Layout & typesetting adapted from xuanyouliu.com's academic
   structure (round portrait hero, animated section-title
   underline, 2-col about+news, 3-col research grid, badge
   publication cards, simple teaching list, 2-col contact),
   while preserving the "重写 Future" visual identity:
   electric blue + fluorescent green, interactive dot field,
   custom cursor blob, expandable pub abstracts.
   ============================================================ */

:root {
  /* surfaces */
  --color-bg:        #f7f7f9;
  --color-bg-alt:    #eef0fa;
  --color-surface:   #ffffff;

  /* ink — blue-black family */
  --color-text:       #0a0d2c;
  --color-text-muted: #555a78;
  --color-text-light: #8b8fa7;

  /* hairlines */
  --color-border:       #d6d8e6;
  --color-border-light: #e8e9f2;

  /* electric blue (replaces purple accent) */
  --color-accent:        #1b30ff;
  --color-accent-hover:  #0014dd;
  --color-accent-deep:   #0a18b8;
  --color-accent-light:  rgba(27, 48, 255, 0.10);
  --color-on-accent:     #ffffff;

  /* fluorescent green — highlight & hover pop */
  --color-green:       #d2ff3d;
  --color-green-soft:  #e6ff80;
  /* text color that always reads on the green chip — same in both themes */
  --color-on-green:    #0a0d2c;

  /* type */
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", Arial, sans-serif;
  --font-display: "Space Grotesk", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-serif:   var(--font-display);   /* xuanyouliu uses Merriweather for the academic feel —
                                            we substitute Space Grotesk for the poster look */

  /* spacing scale */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2.5rem;
  --space-2xl: 4rem;
  --space-3xl: 6rem;

  /* layout */
  --max-width:    min(92vw, 1320px);
  --content-width: 800px;
  --border-radius: 4px;

  /* easings & transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
  --theme-transition-duration: 0.65s;
  --theme-transition-ease: cubic-bezier(.4, 0, .2, 1);
  --ease:        cubic-bezier(.4, 0, .2, 1);
  --ease-out:    cubic-bezier(.16, 1, .3, 1);
  --ease-press:  cubic-bezier(.4, 0, .6, 1);

  /* elevation */
  --shadow-soft: 0 1px 2px rgba(10, 13, 44, 0.04), 0 12px 32px -16px rgba(10, 13, 44, 0.12);
  --shadow-lift: 0 2px 6px rgba(10, 13, 44, 0.06), 0 26px 56px -22px rgba(10, 13, 44, 0.20);
  --shadow-blue: 0 1px 2px rgba(10, 13, 44, 0.08), 0 14px 32px -10px rgba(27, 48, 255, 0.45);

  /* nav surface — overridden per theme */
  --nav-bg: rgba(247, 247, 249, 0.92);
  --nav-menu-overlay-bg: rgba(247, 247, 249, 0.65);
}

/* ============================================
   Dark mode — applied when [data-theme="dark"]
   is set on <html>, OR via prefers-color-scheme
   when no explicit override.
   ============================================ */
:root[data-theme="dark"],
:root:not([data-theme]) {
  /* default: light (the :root block above) */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg:        #0c0f24;
    --color-bg-alt:    #161a3a;
    --color-surface:   #1f2347;

    --color-text:       #f4f5fb;
    --color-text-muted: #c3c7e0;
    --color-text-light: #8b90b2;

    --color-border:       #3a3f70;
    --color-border-light: #262a52;

    --color-accent:        #8a96ff;
    --color-accent-hover:  #a8b1ff;
    --color-accent-deep:   #6c7bff;
    --color-accent-light:  rgba(138, 150, 255, 0.20);

    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.40), 0 12px 32px -16px rgba(0, 0, 0, 0.65);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.45), 0 26px 56px -22px rgba(0, 0, 0, 0.75);
    --shadow-blue: 0 1px 2px rgba(0, 0, 0, 0.40), 0 14px 32px -10px rgba(138, 150, 255, 0.55);

    --nav-bg: rgba(12, 15, 36, 0.88);
    --nav-menu-overlay-bg: rgba(12, 15, 36, 0.78);
  }
}

[data-theme="dark"] {
  --color-bg:        #0c0f24;
  --color-bg-alt:    #161a3a;
  --color-surface:   #1f2347;

  --color-text:       #f4f5fb;
  --color-text-muted: #c3c7e0;
  --color-text-light: #8b90b2;

  --color-border:       #3a3f70;
  --color-border-light: #262a52;

  --color-accent:        #8a96ff;
  --color-accent-hover:  #a8b1ff;
  --color-accent-deep:   #6c7bff;
  --color-accent-light:  rgba(138, 150, 255, 0.20);

  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.40), 0 12px 32px -16px rgba(0, 0, 0, 0.65);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.45), 0 26px 56px -22px rgba(0, 0, 0, 0.75);
  --shadow-blue: 0 1px 2px rgba(0, 0, 0, 0.40), 0 14px 32px -10px rgba(138, 150, 255, 0.55);

  --nav-bg: rgba(12, 15, 36, 0.88);
  --nav-menu-overlay-bg: rgba(12, 15, 36, 0.78);
}

/* dark-mode component overrides */
[data-theme="dark"] .hero-text::before,
[data-theme="dark"] .hero::before { background: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .hero-text::before,
  :root:not([data-theme="light"]) .hero::before { background: none; }
}

/* Cursor blob: multiply blend disappears on dark bg → use screen so the
   solid dot lightens the dark canvas instead of being absorbed. The
   merged-state tint also swaps to green for clearer contrast on dark. */
/* dark mode: brighter translucent green so it pops on dark bg without
   any mix-blend-mode (which was Safari's primary cursor-lag cause) */
[data-theme="dark"] .cursor-blob::before { background: rgba(210, 255, 61, 0.55); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cursor-blob::before { background: rgba(210, 255, 61, 0.55); }
}

/* In dark mode, partial green highlighters become full green chips with
   dark text — light text was unreadable on the bright green band. */
[data-theme="dark"] .contact-note h3 {
  background-image: none;
  background-color: var(--color-green);
  color: var(--color-on-green);
  padding: 0.05em 0.4em;
  border-radius: 2px;
}
[data-theme="dark"] .pub-cue {
  background-image: linear-gradient(var(--color-green), var(--color-green));
  padding: 2px 8px;
  border-radius: 2px;
}
[data-theme="dark"] .pub.open .pub-cue {
  color: var(--color-on-green);
}
@media (hover: hover) {
  @media (hover: hover) {
[data-theme="dark"] .pub:hover .pub-cue{
    color: var(--color-on-green);
  }
}
}
/* Section-title highlight: push the green band entirely BELOW the text
   in dark mode so it reads as a chunky underline accent instead of
   overlapping the white letters. */
[data-theme="dark"] .section-title::after {
  bottom: -10px;
  height: 6px;
  z-index: 0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .contact-note h3 {
    background-image: none;
    background-color: var(--color-green);
    color: var(--color-on-green);
    padding: 0.05em 0.4em;
    border-radius: 2px;
  }
  :root:not([data-theme="light"]) .pub-cue {
    background-image: linear-gradient(var(--color-green), var(--color-green));
    padding: 2px 8px;
    border-radius: 2px;
  }
  :root:not([data-theme="light"]) .pub.open .pub-cue {
    color: var(--color-on-green);
  }
  :root:not([data-theme="light"]) .section-title::after {
    bottom: -10px;
    height: 6px;
    z-index: 0;
  }
}
@media (prefers-color-scheme: dark) and (hover: hover) {
  @media (hover: hover) {
:root:not([data-theme="light"]) .pub:hover .pub-cue{
    color: var(--color-on-green);
  }
}
}

/* smooth theme transitions on the colors that flip */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition:
    background-color var(--theme-transition-duration) var(--theme-transition-ease),
    background var(--theme-transition-duration) var(--theme-transition-ease),
    border-color var(--theme-transition-duration) var(--theme-transition-ease),
    color var(--theme-transition-duration) var(--theme-transition-ease),
    fill var(--theme-transition-duration) var(--theme-transition-ease),
    stroke var(--theme-transition-duration) var(--theme-transition-ease),
    box-shadow var(--theme-transition-duration) var(--theme-transition-ease),
    outline-color var(--theme-transition-duration) var(--theme-transition-ease),
    text-decoration-color var(--theme-transition-duration) var(--theme-transition-ease) !important;
}

@supports (view-transition-name: none) {
  html.theme-view-transition::view-transition-old(root),
  html.theme-view-transition::view-transition-new(root) {
    animation-duration: var(--theme-transition-duration);
    animation-timing-function: var(--theme-transition-ease);
  }

  html.theme-view-transition::view-transition-old(root) {
    z-index: 1;
  }

  html.theme-view-transition::view-transition-new(root) {
    z-index: 2;
    animation: theme-circle-reveal var(--theme-transition-duration) var(--theme-transition-ease) both;
  }

  @keyframes theme-circle-reveal {
    from {
      clip-path: circle(0 at var(--theme-origin-x, 50vw) var(--theme-origin-y, 2rem));
    }
    to {
      clip-path: circle(var(--theme-reveal-radius, 150vmax) at var(--theme-origin-x, 50vw) var(--theme-origin-y, 2rem));
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  html.theme-transition,
  html.theme-transition *,
  html.theme-transition *::before,
  html.theme-transition *::after {
    transition-duration: 0.01ms !important;
  }

  html.theme-view-transition::view-transition-old(root),
  html.theme-view-transition::view-transition-new(root) {
    animation: none !important;
  }
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--nav-scroll-offset, 5.5rem);
  font-size: 16px;
  scrollbar-gutter: stable;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  cursor: none;
}

/* hide OS cursor on interactive elements too, otherwise the hand
   cursor overrides our blob the moment you reach a link/button */
a, button, [role="button"], [data-cursor="grow"],
.pub, .project-card {
  cursor: none;
}

/* Also include touchscreens with stylus that report hover:hover but pointer:coarse. */
@media (hover: none), (pointer: coarse), (max-width: 880px) {
  body, a, button, [role="button"], [data-cursor="grow"],
  .pub, .project-card { cursor: auto; }
  .cursor-blob { display: none !important; }
}

::selection {
  background: var(--color-green);
  color: var(--color-on-green);
}
::-moz-selection {
  background: var(--color-green);
  color: var(--color-on-green);
}

/* suppress Safari's default focus ring after a mouse click — that's
   what was painting the dark rectangle around the EMAIL button. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 4px;
  border-radius: var(--border-radius);
}
/* also kill iOS / Safari tap highlight flashes */
* { -webkit-tap-highlight-color: transparent; }

.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--color-text);
  color: #fff;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--border-radius);
  z-index: 10000;
  font-weight: 500;
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: var(--space-md); color: #fff; }

/* ============================================
   Typography
   ============================================ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.03em;
  color: var(--color-text);
}

h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); }
h2 { font-size: clamp(1.75rem, 3vw, 2.4rem); }
h3 { font-size: clamp(1.2rem, 2vw, 1.5rem); }

p { margin-bottom: 1em; }
p:last-child { margin-bottom: 0; }

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
@media (hover: hover) {
a:hover{ color: var(--color-accent-hover); }
}

strong { font-weight: 600; }
em { font-style: italic; color: var(--color-text); }

/* Body copy — sparing marker highlight; plain strong for the rest */
.about-text strong {
  font-weight: 600;
}
.about-text .hl,
#research .section-subtitle .hl {
  font-weight: 600;
  background-image: linear-gradient(transparent 72%, rgba(210, 255, 61, 0.65) 72%, rgba(210, 255, 61, 0.65) 94%, transparent 94%);
  padding: 0 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
[data-theme="dark"] .about-text .hl,
[data-theme="dark"] #research .section-subtitle .hl {
  background-image: linear-gradient(transparent 72%, rgba(210, 255, 61, 0.35) 72%, rgba(210, 255, 61, 0.35) 94%, transparent 94%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .about-text .hl,
  :root:not([data-theme="light"]) #research .section-subtitle .hl {
    background-image: linear-gradient(transparent 72%, rgba(210, 255, 61, 0.35) 72%, rgba(210, 255, 61, 0.35) 94%, transparent 94%);
  }
}

/* ============================================
   Cursor blob (preserved from Tami's identity)
   ============================================ */
.cursor-blob {
  position: fixed;
  top: 0;
  left: 0;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  overflow: visible;
  background: transparent;
  transform: translate3d(0, 0, 0);
  transition: opacity 0.22s var(--ease);
}
.cursor-blob::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(27, 48, 255, 0.55);
  transform: scale(1);
  transform-origin: center;
  opacity: 1;
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1),
              background 0.28s var(--ease-out),
              opacity 0.2s var(--ease-out);
}
.cursor-blob.visible { opacity: 1; }

/* Grow: links / cards — large cursor stays visible */
.cursor-blob.grow::before {
  transform: scale(3.142857);
  background: rgba(210, 255, 61, 0.6);
}

/* Merge: fade out while the control fills from center (no swell-then-vanish) */
.cursor-blob.merge::before {
  opacity: 0;
  transform: scale(1);
  transition: opacity 0.14s var(--ease-out);
}

/* ============================================
   Hover-wipe overlay — INCITE-style.
   Two colored layers + a clone of the thumbnail
   image cascade in from the top-left after a dwell.
   The final (image) layer reveals the picture from
   the corner. Shared by .pub-thumb and .project-image.
   ============================================ */
.pub-thumb, .project-image { overflow: hidden; }
.pub-thumb > picture,
.project-image > picture,
.hero-image > picture { display: contents; }

.wipe-layer {
  position: absolute;
  inset: 0;
  transform-origin: top left;
  transform: scale3d(0.001, 0.001, 1);
  opacity: 1;
  transition:
    transform 0.55s cubic-bezier(0.5, 0, 0.2, 1),
    opacity 0.36s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  backface-visibility: hidden;
}
.wipe-layer.in {
  transform: scale3d(1, 1, 1);
  will-change: transform;
}
.wipe-layer.out {
  opacity: 0;
}
.wipe-layer.color-1 { background: var(--color-accent); z-index: 2; }
.wipe-layer.color-2 { background: var(--color-green);  z-index: 3; }
.wipe-layer.image {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wipe-layer.image.wipe-layer-photo {
  display: block;
}
.wipe-layer.image .wipe-clone-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* ============================================
   Dot canvas — fixed full-page backdrop.
   Visible behind transparent sections (About,
   Publications, Contact); covered by section-alt
   (Research, Teaching) for an alternating rhythm.
   ============================================ */
.dot-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  /* dvh matches window.innerHeight while iOS URL bar animates, keeping the
     canvas backing store (W/H from JS) in sync with the CSS box. */
  height: 100vh;
  height: 100dvh;
  z-index: 0;
  pointer-events: none;
  contain: strict;
  transform: translate3d(0, 0, 0);
}

/* ============================================
   Scroll progress
   ============================================ */
.scroll-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: var(--color-accent);
  z-index: 1001;
  transition: width .08s linear;
}

/* ============================================
   Navigation
   ============================================ */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background var(--transition-base),
              border-color var(--transition-base);
}

/* Solid translucent bg instead of backdrop-filter blur — the blur is
   Safari's #1 performance killer on fixed bars (full-width compositing
   pass every frame). The visual cost is tiny, the perf win is big. */
.nav.scrolled,
body.no-scroll .nav {
  background: var(--color-bg);
  border-bottom-color: var(--color-border-light);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  display: block;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  color: var(--color-accent);
  transition: transform 0.5s var(--ease-press), color 0.25s var(--ease);
}
.nav-logo-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.nav-logo-bg { fill: currentColor; transition: fill 0.25s var(--ease); }
.nav-logo-mark,
.nav-logo-dot { fill: #fff; transition: fill 0.25s var(--ease); }
@media (hover: hover) {
.nav-logo:hover{
    transform: rotate(-90deg);
    color: var(--color-green);
  }
.nav-logo:hover .nav-logo-mark, .nav-logo:hover .nav-logo-dot{ fill: #0a0d2c; }
}

/* Click/tap burst — works on touch and desktop. */
.nav-logo.is-tapped {
  animation: nav-logo-spin 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nav-logo.is-tapped .nav-logo-bg {
  animation: nav-logo-flash 0.7s ease-out;
}
.nav-logo.is-tapped .nav-logo-dot {
  transform-box: fill-box;
  transform-origin: center;
  animation: nav-logo-dot-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nav-logo.is-tapped .nav-logo-mark {
  transform-box: fill-box;
  transform-origin: center;
  animation: nav-logo-mark-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes nav-logo-spin {
  0%   { transform: rotate(0)        scale(1); }
  35%  { transform: rotate(-140deg)  scale(1.18); }
  70%  { transform: rotate(-300deg)  scale(0.92); }
  100% { transform: rotate(-360deg)  scale(1); }
}
@keyframes nav-logo-flash {
  0%   { fill: var(--color-accent); }
  30%  { fill: var(--color-green); }
  100% { fill: var(--color-accent); }
}
@keyframes nav-logo-dot-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(2.2); }
  100% { transform: scale(1); }
}
@keyframes nav-logo-mark-pop {
  0%, 100% { transform: scale(1); }
  40%      { transform: scale(0.78); }
}

@media (prefers-reduced-motion: reduce) {
  .nav-logo.is-tapped,
  .nav-logo.is-tapped .nav-logo-bg,
  .nav-logo.is-tapped .nav-logo-dot,
  .nav-logo.is-tapped .nav-logo-mark { animation: none; }
}

.nav-links {
  display: flex;
  gap: var(--space-lg);
  margin-left: auto;
  margin-right: var(--space-lg);
  list-style: none;
}
.nav-links li { display: flex; align-items: center; }

.nav-link {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
  position: relative;
  padding: 4px 0;
}

.nav-link::after {
  content: '';
  position: absolute;
  /* Default = thin (hover state). .active explicitly overrides to the
     chunky bar. Keeping the thin geometry in the base means width is the
     only thing that animates on hover-out, so the bar shrinks at the
     thin weight instead of snapping back to chunky mid-retract. */
  bottom: -3px;
  left: 0;
  width: 0;
  height: 2px;
  background-color: var(--color-accent);
  transition: width var(--transition-base);
}
[data-theme="dark"] .nav-link::after { background-color: var(--color-green); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .nav-link::after { background-color: var(--color-green); }
}
@media (hover: hover) {
.nav-link:hover{
  color: var(--color-text);
}
}
/* Hover inherits the thin base geometry; only width grows. */
@media (hover: hover) {
.nav-link:hover::after{ width: 100%; }
}

.nav-link.active {
  color: var(--color-text);
  font-weight: 600;
}
/* Active = chunky highlighter bar. Overrides the thin base height/bottom. */
.nav-link.active::after {
  width: 100%;
  height: 5px;
  bottom: -6px;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-xs);
  margin-right: -8px;
  color: var(--color-text);
}
.nav-toggle span {
  width: 24px;
  height: 2px;
  background-color: currentColor;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}
.nav-toggle.active span:first-child {
  transform: rotate(45deg) translate(5px, 5px);
}
.nav-toggle.active span:last-child {
  transform: rotate(-45deg) translate(5px, -5px);
}

body.no-scroll {
  overflow: hidden;
}

/* circular icon button for theme toggle */
.theme-toggle {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  border: 1.5px solid var(--color-border);
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 0.32s cubic-bezier(0.16, 1, 0.3, 1),
              color var(--transition-base),
              transform 0.15s var(--ease-press);
  overflow: hidden;
}
.theme-toggle::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--color-accent-light);
  transform: scale(0);
  transform-origin: center;
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (hover: hover) {
.theme-toggle:hover{
  border-color: var(--color-accent);
}
}
@media (hover: hover) {
.theme-toggle:hover::before{
  transform: scale(1);
}
}
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle.is-switching {
  transform: scale(0.94);
  border-color: var(--color-accent);
}

/* theme-toggle: crossfade sun/moon icons */
.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  transition:
    opacity var(--theme-transition-duration) var(--theme-transition-ease),
    transform var(--theme-transition-duration) var(--theme-transition-ease);
}
.theme-toggle .sun-icon {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-60deg) scale(0.55);
}
.theme-toggle .moon-icon {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
}
.theme-toggle.is-switching .sun-icon,
.theme-toggle.is-switching .moon-icon {
  transition-duration: calc(var(--theme-transition-duration) * 0.85);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun-icon {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
  }
  :root:not([data-theme="light"]) .theme-toggle .moon-icon {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(60deg) scale(0.55);
  }
}
[data-theme="dark"] .theme-toggle .sun-icon {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
}
[data-theme="dark"] .theme-toggle .moon-icon {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(60deg) scale(0.55);
}
[data-theme="light"] .theme-toggle .sun-icon {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-60deg) scale(0.55);
}
[data-theme="light"] .theme-toggle .moon-icon {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
}

/* ============================================
   Hero
   ============================================ */
.hero {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-3xl) var(--space-lg) var(--space-2xl);
  isolation: isolate;
  z-index: 2;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(135deg, transparent 0%, var(--color-bg-alt) 100%);
  opacity: 0.45;
  z-index: -1;
}

.hero-content {
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: calc(var(--space-xl) + 1rem);
  align-items: center;
}

/* round portrait — adopted from xuanyouliu */
.hero-image-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.hero-image-accent {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--color-accent);
  opacity: 0.4;
  transform: translate(14px, 14px) scale(0.94);
  pointer-events: none;
  transition: transform 0.5s var(--ease-out), opacity 0.4s ease, border-color 0.4s ease;
}
@media (hover: hover) {
  @media (hover: hover) {
.hero-image-wrapper:hover .hero-image-accent{
    transform: translate(18px, 18px) scale(0.94);
    opacity: 0.6;
  }
}
}

.hero-image {
  width: 280px;
  height: 280px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--color-text);
  box-shadow: var(--shadow-blue);
  position: relative;
  isolation: isolate;
  transition: transform 0.5s var(--ease-out), box-shadow 0.4s ease;
}
@media (hover: hover) {
  @media (hover: hover) {
.hero-image:hover{
    transform: translateY(-4px) scale(1.02);
    box-shadow:
      0 2px 4px rgba(10, 13, 44, 0.06),
      0 30px 60px -15px rgba(27, 48, 255, 0.55);
  }
}
}

/* Safari: percentage-sized img + object-fit inside overflow:hidden often mis-crops;
   absolute fill is reliable across browsers. */
.hero-image img,
.hero-image .profile-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: 50% 42%;
  display: block;
}

.hero-image-corner {
  position: absolute;
  bottom: 10px; right: 10px;
  width: 24px; height: 24px;
  background: var(--color-green);
  border: 2px solid var(--color-text);
  border-radius: 50%;
  z-index: 3;
}

/* hero text */
.hero-text {
  max-width: 620px;
  position: relative;
  isolation: isolate;
}
.hero-text::before {
  content: '';
  position: absolute;
  inset: -1.1rem -1.4rem;
  z-index: -1;
  background: radial-gradient(ellipse at center, rgba(247,247,249,0.92) 0%, transparent 72%);
  pointer-events: none;
}

.hero-greeting {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.hero-greeting::before {
  content: '';
  width: 32px;
  height: 8px;
  background-color: var(--color-green);
  display: inline-block;
  flex-shrink: 0;
}

.hero-name {
  margin-bottom: var(--space-md);
  color: var(--color-text);
  display: inline-block;
  font-weight: 700;
  letter-spacing: -0.035em;
  transition: color 0.4s ease, transform 0.4s ease;
}
@media (hover: hover) {
  @media (hover: hover) {
.hero-name:hover{
    color: var(--color-accent);
    transform: scale(1.01);
  }
}
}
.hero-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: var(--space-xs);
  letter-spacing: -0.012em;
}

.hero-affiliation {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.65;
  margin-bottom: var(--space-md);
}
.hero-affiliation a {
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  transition: color 0.25s ease, border-color 0.25s ease;
}
@media (hover: hover) {
.hero-affiliation a:hover{
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}
}

/* interest chips — preserved Tami style (border + green hover) */
.hero-interests {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: var(--space-lg);
}
.hero-interests .interest-chip {
  position: relative;
  isolation: isolate;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.85rem;
  border: 1.5px solid var(--color-text);
  border-radius: 999px;
  color: var(--color-text);
  background: var(--color-surface);
  overflow: hidden;
  transition: color 0.32s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.32s cubic-bezier(0.16, 1, 0.3, 1),
              transform var(--transition-fast);
}
.hero-interests .interest-chip::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--color-green);
  transform: scale(0);
  transform-origin: center;
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (hover: hover) {
  @media (hover: hover) {
.hero-interests .interest-chip:hover{
    color: var(--color-on-green);
    border-color: var(--color-on-green);
  }
}
  @media (hover: hover) {
.hero-interests .interest-chip:hover::before{
    transform: scale(1);
  }
}
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--border-radius);
  overflow: hidden;
  /* explicit list — `transition: all` was making Safari re-evaluate
     background-color / box-shadow / color every paint, contributing to
     the EMAIL button's flicker on hover */
  transition: color 0.32s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.32s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow var(--transition-fast);
  border: 1.5px solid transparent;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  text-decoration: none;
}
.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  transform: scale(0);
  transform-origin: center;
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-primary, .btn-primary:focus, .btn-primary:focus-visible{
  color: var(--color-on-accent);
  border-color: var(--color-accent);
  box-shadow: none;
  opacity: 1;
}
@media (hover: hover) {
.btn-primary:hover{
  color: var(--color-on-accent);
  border-color: var(--color-accent);
  box-shadow: none;
  opacity: 1;
}
}
.btn-primary {
  background-color: var(--color-accent);
}
.btn-primary::before {
  background-color: var(--color-accent);
}
.btn-primary:focus::before, .btn-primary:focus-visible::before{
  transform: scale(1);
}
@media (hover: hover) {
.btn-primary:hover::before{
  transform: scale(1);
}
}
.btn-primary:active { transform: translateY(2px) scale(0.97); }

.btn-secondary {
  background-color: transparent;
  color: var(--color-text);
  border-color: var(--color-text);
}
.btn-secondary::before {
  background-color: var(--color-bg-alt);
}
@media (hover: hover) {
.btn-secondary:hover{
  color: var(--color-text);
  border-color: var(--color-text);
}
}
@media (hover: hover) {
.btn-secondary:hover::before{
  transform: scale(1);
}
}

.btn-icon {
  padding: var(--space-sm);
  background-color: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
}
@media (hover: hover) {
.btn-icon:hover{
  color: var(--color-accent);
  background-color: var(--color-accent-light);
}
}
.btn-icon:active { transform: scale(0.9); }

/* ============================================
   Sections
   ============================================ */
.section {
  position: relative;
  padding: var(--space-2xl) var(--space-lg);
  z-index: 2;
  /* skip rendering/layout when off-screen — huge scroll-perf win
     on Safari, especially while the dot canvas is repainting */
  content-visibility: auto;
  contain-intrinsic-size: auto 600px;
  scroll-margin-top: var(--nav-scroll-offset, 5.5rem);
}

.section-alt {
  background-color: var(--color-bg-alt);
}

.section-inner {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  position: relative;
}

/* section title — partial fluorescent-green highlighter band */
h2.section-title {
  font-size: clamp(1.75rem, 3vw, 2.4rem);
  margin-bottom: calc(var(--space-lg) + 10px);
  position: relative;
  display: inline-block;
  isolation: isolate;
  scroll-margin-top: var(--nav-scroll-offset, 5.5rem);
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  transform-origin: 0 50%;
  will-change: transform;
}
h2.section-title.active {
  transform: scale(1.06);
}
.section-title::after {
  content: '';
  position: absolute;
  bottom: 0.22em;
  left: -0.15em;
  width: 0;
  height: 0.42em;
  background-color: var(--color-green);
  z-index: -1;
  transition: width 0.7s var(--ease-out);
}
.section-title.active::after {
  width: 80%;
}

.section-subtitle {
  margin-top: calc(var(--space-md) * -1);
  margin-bottom: var(--space-xl);
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  max-width: 64ch;
  line-height: 1.6;
}

/* ============================================
   About
   ============================================ */
.about-content {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-xl);
  align-items: start;
}

.about-text .lead {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.32;
  color: var(--color-text);
  margin-bottom: var(--space-lg);
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.about-text p {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}
.about-text p:last-child { margin-bottom: 0; }
.about-text strong { color: var(--color-text); }

.about-text a {
  color: var(--color-accent);
  position: relative;
  transition: color 0.3s ease;
}
.about-text a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background-color: var(--color-accent);
  transition: width 0.3s ease;
}
@media (hover: hover) {
.about-text a:hover{ color: var(--color-accent-hover); }
}
@media (hover: hover) {
.about-text a:hover::after{ width: 100%; }
}

/* about-news sidebar */
.about-news {
  position: sticky;
  /* JS keeps --nav-scroll-offset in sync with the live nav height. */
  top: var(--nav-scroll-offset, 88px);
}
.about-news h3 {
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--color-accent);
  margin-bottom: var(--space-md);
}

.news-list {
  list-style: none;
}
.news-list li {
  padding: var(--space-sm) var(--space-sm);
  margin: 0 calc(var(--space-sm) * -1);
  border-bottom: 1px solid var(--color-border-light);
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  transition: background-color 0.2s ease, transform 0.2s ease,
              color 0.2s ease, box-shadow 0.2s ease;
  border-radius: var(--border-radius);
  position: relative;
}
.news-list li:last-child { border-bottom: none; }
.news-list li a {
  color: var(--color-text);
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition-fast);
}
@media (hover: hover) {
.news-list li a:hover{ border-bottom-color: var(--color-accent); }
}

@media (hover: hover) {
  @media (hover: hover) {
.news-list li:hover{
    background-color: var(--color-surface);
    transform: translateX(4px);
    color: var(--color-text);
    border-bottom-color: transparent;
    box-shadow: 0 2px 8px rgba(10,13,44,0.06);
  }
}
  .news-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px;
    height: 70%;
    background-color: var(--color-green);
    border-radius: 2px;
    transition: transform 0.2s ease;
    opacity: 0;
  }
  @media (hover: hover) {
.news-list li:hover::before{
    transform: translateY(-50%) scaleY(1);
    opacity: 1;
  }
}
}

.news-date {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--color-accent);
  margin-right: var(--space-sm);
  letter-spacing: 0.04em;
}

/* ============================================
   Research (projects-grid)
   ============================================ */
#research.section-alt {
  /* Gaps and margins show the dot field at full strength */
  background-color: transparent;
}

#research .project-card {
  background-color: transparent;
}

#research .project-content {
  background-color: transparent;
}

@media (hover: hover) {
  @media (hover: hover) {
#research .project-card:hover .project-content{
    background-color: transparent;
  }
}
  @media (hover: hover) {
#research .project-card:hover .project-desc::after{
    background: linear-gradient(transparent, var(--color-bg));
  }
}
}

#research .project-desc::after {
  background: linear-gradient(transparent, var(--color-bg));
}

/* Research cards: bold + highlight animate in when expanded */
#research .project-desc strong {
  font-weight: inherit;
  color: var(--color-text-muted);
  transition: font-weight 0.01s, color 0.42s var(--ease-out) 0.12s;
}
#research .project-desc .hl {
  --hl-band: rgba(210, 255, 61, 0.65);
  font-weight: inherit;
  color: var(--color-text-muted);
  background-image: linear-gradient(transparent 72%, var(--hl-band) 72%, var(--hl-band) 94%, transparent 94%);
  background-size: 0% 100%;
  background-repeat: no-repeat;
  padding: 0 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: font-weight 0.01s,
              background-size 0.48s cubic-bezier(0.16, 1, 0.3, 1) 0.18s,
              color 0.42s var(--ease-out) 0.22s;
}
#research .project-desc a {
  color: var(--color-text-muted);
  border-bottom: 1px solid transparent;
  transition: color 0.42s var(--ease-out) 0.14s,
              border-color 0.42s var(--ease-out) 0.14s;
}
[data-theme="dark"] #research .project-desc .hl {
  --hl-band: rgba(210, 255, 61, 0.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #research .project-desc .hl {
    --hl-band: rgba(210, 255, 61, 0.35);
  }
}
@media (hover: hover) {
  #research .project-card.open .project-desc strong{
    font-weight: 600;
    color: var(--color-text);
  }
@media (hover: hover) {
#research .project-card:hover .project-desc strong{
    font-weight: 600;
    color: var(--color-text);
  }
}
  #research .project-card.open .project-desc .hl{
    font-weight: 600;
    background-size: 100% 100%;
    color: var(--color-text);
  }
@media (hover: hover) {
#research .project-card:hover .project-desc .hl{
    font-weight: 600;
    background-size: 100% 100%;
    color: var(--color-text);
  }
}
  #research .project-card.open .project-desc a{
    color: var(--color-text);
    border-bottom-color: var(--color-border);
  }
@media (hover: hover) {
#research .project-card:hover .project-desc a{
    color: var(--color-text);
    border-bottom-color: var(--color-border);
  }
}
}
@media (hover: none) {
  #research .project-card.open .project-desc strong {
    font-weight: 600;
    color: var(--color-text);
  }
  #research .project-card.open .project-desc .hl {
    font-weight: 600;
    background-size: 100% 100%;
    color: var(--color-text);
  }
  #research .project-card.open .project-desc a {
    color: var(--color-text);
    border-bottom-color: var(--color-border);
  }
}

.projects-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-md);
  align-items: start;
}

.project-card {
  background-color: var(--color-surface);
  border-radius: var(--border-radius);
  overflow: hidden;
  border: 1px solid var(--color-border-light);
  transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1),
              box-shadow 0.6s cubic-bezier(0.165, 0.84, 0.44, 1),
              border-color 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
  position: relative;
  display: flex;
  flex-direction: column;
}

@media (hover: hover) {
  @media (hover: hover) {
.project-card:hover{
    box-shadow: var(--shadow-lift);
    transform: translateY(-6px) scale(1.01);
    border-color: var(--color-accent);
    z-index: 10;
  }
}
  .project-card:active {
    transform: translateY(2px) scale(0.97);
    box-shadow: var(--shadow-soft);
    transition: transform 0.05s var(--ease), box-shadow 0.05s var(--ease);
  }
}

.project-image {
  aspect-ratio: 16 / 10;
  overflow: hidden;
  position: relative;
  display: block;
  background: var(--color-bg-alt);
  isolation: isolate;
}
.project-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  opacity: 0;
  transition: opacity 0.45s ease;
}
.project-image.loaded img,
.project-image img.loaded {
  opacity: 1;
}
.project-image.is-wiping img {
  transition: opacity 0.45s ease;
}
.project-grad-1 { background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-deep) 100%); }
.project-grad-2 { background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-green) 130%); }
.project-grad-3 { background: linear-gradient(135deg, var(--color-text) 0%, var(--color-accent) 100%); }

.project-content {
  padding: var(--space-md) var(--space-md) var(--space-md);
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  transition: background-color 0.3s ease;
}
@media (hover: hover) {
  @media (hover: hover) {
.project-card:hover .project-content{ background: var(--color-bg); }
}
}

.project-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.022em;
  line-height: 1.25;
  margin-bottom: var(--space-sm);
  transition: color 0.3s ease;
}
@media (hover: hover) {
  @media (hover: hover) {
.project-card:hover .project-title{ color: var(--color-accent); }
}
}

.project-desc {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: 0;
  max-height: 4.6em;
  overflow: hidden;
  position: relative;
  transition: max-height 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.project-desc p {
  margin: 0 0 0.75em;
}
.project-desc p:last-child {
  margin-bottom: 0;
}
.project-desc a {
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  transition: color 0.25s ease, border-color 0.25s ease;
}
@media (hover: hover) {
.project-desc a:hover{
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}
}
.project-desc::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1.5em;
  background: linear-gradient(transparent, var(--color-surface));
  pointer-events: none;
  transition: opacity 0.5s ease;
}
@media (hover: hover) {
  @media (hover: hover) {
.project-card:hover .project-desc{ max-height: 1000px; }
}
  @media (hover: hover) {
.project-card:hover .project-desc::after{ opacity: 0; }
}
  @media (hover: hover) {
.project-card:hover .project-content{ background: var(--color-surface); }
}
  @media (hover: hover) {
.project-card:hover .project-desc::after{
    background: linear-gradient(transparent, var(--color-surface));
  }
}
}

/* ============================================
   Publications — original Tami expandable rows
   ============================================ */
.pub-list { list-style: none; padding: 0; margin: 0; }

.pub {
  border-top: 1px solid var(--color-border-light);
  cursor: pointer;
  transition: background .25s var(--ease);
}
.pub:first-child { border-top: 2px solid var(--color-text); }
.pub:last-child  { border-bottom: 2px solid var(--color-text); }

.pub:focus-visible, .pub.open {
  outline: none;
  background: rgba(27, 48, 255, 0.025);
}
@media (hover: hover) {
  @media (hover: hover) {
.pub:hover{
    outline: none;
    background: rgba(27, 48, 255, 0.025);
  }
}
}

.pub-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 24px;
  padding: 32px 16px;
  align-items: start;
}

.pub-thumb {
  position: relative;
  width: 96px;
  flex-shrink: 0;
  aspect-ratio: auto;
  overflow: hidden;
  isolation: isolate;
  background: none !important;
}

/* Sized to the number in JS; do not span the full 96px grid column */
.pub-thumb .wipe-layer.wipe-layer-pub {
  inset: auto;
  top: 0;
  left: 0;
}

.pub-thumb-num {
  position: relative;
  z-index: 5;
  display: inline-block;
  width: fit-content;
  padding-top: 2px;
  font-family: var(--font-display);
  font-size: 52px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--color-text-light);
  text-shadow: none;
  font-variant-numeric: tabular-nums;
  transition: color .25s var(--ease);
}
.pub.open .pub-thumb-num { color: var(--color-accent); }
@media (hover: hover) {
  @media (hover: hover) {
.pub:hover .pub-thumb-num{ color: var(--color-accent); }
}
}
/* Legacy gradient hooks — kept inert so existing HTML stays valid */
.pub-grad-1, .pub-grad-2, .pub-grad-3, .pub-grad-4 { background: none; }

.pub-body {
  min-width: 0;
  transition: transform .35s var(--ease);
}
.pub.open .pub-body { transform: translateX(8px); }
@media (hover: hover) {
  @media (hover: hover) {
.pub:hover .pub-body{ transform: translateX(8px); }
}
}

.pub-meta {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 10px;
}

/* Projects-only method tags — capsule pills */
.pub-topics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  font-family: var(--font-display);
  font-size: 0.75rem;
  line-height: 1;
}

.pub-topic {
  display: inline-flex;
  align-items: center;
  padding: 0.32rem 0.7rem;
  border: 1px solid color-mix(in srgb, var(--color-green) 55%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-green) 14%, transparent);
  color: var(--color-accent);
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: background-color .25s var(--ease),
              border-color .25s var(--ease),
              color .25s var(--ease);
}

.pub.open .pub-topic {
  background: color-mix(in srgb, var(--color-green) 22%, transparent);
  border-color: color-mix(in srgb, var(--color-green) 75%, transparent);
}
@media (hover: hover) {
  @media (hover: hover) {
.pub:hover .pub-topic{
    background: color-mix(in srgb, var(--color-green) 22%, transparent);
    border-color: color-mix(in srgb, var(--color-green) 75%, transparent);
  }
}
}

.pub-title {
  font-family: var(--font-display);
  font-size: clamp(20px, 2.2vw, 26px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.026em;
  color: var(--color-text);
  margin: 0 0 18px;
  text-wrap: balance;
  transition: color .25s var(--ease);
}
.pub.open .pub-title { color: var(--color-accent); }
@media (hover: hover) {
  @media (hover: hover) {
.pub:hover .pub-title{ color: var(--color-accent); }
}
}

.pub-authors {
  font-size: 15px;
  color: var(--color-text-muted);
  margin: 0 0 10px;
}
.pub-authors strong { color: var(--color-text); }

.pub-snip {
  font-size: 15px;
  color: var(--color-text-muted);
  line-height: 1.55;
  margin: 0;
  letter-spacing: -0.01em;
  text-wrap: pretty;
}

/* expand */
.pub-expand {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height .55s var(--ease-out), opacity .35s var(--ease),
              margin-top .35s var(--ease);
  margin-top: 0;
}
.pub.open .pub-expand {
  max-height: 1200px;
  opacity: 1;
  margin-top: 16px;
}
.pub-expand p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text-muted);
  margin: 0 0 12px;
  letter-spacing: -0.012em;
  max-width: none;
}

.pub-status {
  margin-top: 4px !important;
  padding-top: 14px;
  border-top: 1px solid var(--color-border-light);
  font-size: 14px;
  line-height: 1.55;
  color: var(--color-text-muted);
}
.pub-status-label {
  display: block;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-light);
  margin-bottom: 6px;
}

.pub-links {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 14px 0 0 !important;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
}
.pub-links a {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--color-accent);
  position: relative;
}
.pub-links a::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  bottom: -2px;
  height: 1px;
  background: var(--color-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .3s var(--ease);
}
@media (hover: hover) {
.pub-links a:hover::after{ transform: scaleX(1); }
}
.pub-links .arrow { transition: transform .3s var(--ease); }
@media (hover: hover) {
.pub-links a:hover .arrow{ transform: translateX(3px); }
}

/* read more / show less cue */
.pub-cue {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.005em;
  background-image: linear-gradient(transparent 58%, var(--color-green) 58%, var(--color-green) 95%, transparent 95%);
  padding: 0 6px;
  background-size: 0% 100%;
  background-repeat: no-repeat;
  transition: background-size .35s var(--ease-out), color .25s var(--ease);
}
.pub.open .pub-cue { background-size: 100% 100%; }
@media (hover: hover) {
  @media (hover: hover) {
.pub:hover .pub-cue{ background-size: 100% 100%; }
}
}
.pub-cue::after {
  content: " →";
  display: inline-block;
  transition: transform .35s var(--ease);
  margin-left: 2px;
}
.pub.open .pub-cue::after { transform: rotate(90deg); }
.pub-cue::before { content: attr(data-closed); }
.pub.open .pub-cue::before { content: attr(data-open); }

/* ============================================
   Teaching
   ============================================ */
.teaching-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.course-item {
  display: block;
  padding: var(--space-md) var(--space-lg);
  background-color: var(--color-surface);
  border-radius: var(--border-radius);
  border: 1px solid var(--color-border-light);
  /* Needed so the ::before image layer is clipped to the rounded card. */
  position: relative;
  overflow: hidden;
}

/* Hover image layer — sits behind the text, fades in on hover.
   Per-card bg-image is set via [data-hover-image] selectors below. */
.course-item::before {
  content: '';
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.4s ease-in-out;
  z-index: 0;
  pointer-events: none;
}

.course-item > .course-info {
  position: relative;
  z-index: 1;
}

@media (hover: hover) {
  @media (hover: hover) {
.course-item:hover::before{
    opacity: 0.18;
  }
}
  @media (hover: hover) {
.course-item:hover{
    border-color: var(--color-accent-light);
  }
}
}

/* Per-item images (webp with jpg fallback for older Safari). */
.course-item[data-hover-image="meeting"]::before {
  background-image: url('Asset/meeting.jpg');
  background-image: image-set(
    url('Asset/meeting.webp') type('image/webp'),
    url('Asset/meeting.jpg')  type('image/jpeg')
  );
}
.course-item[data-hover-image="ESL"]::before {
  background-image: url('Asset/ESL.jpg');
  background-image: image-set(
    url('Asset/ESL.webp') type('image/webp'),
    url('Asset/ESL.jpg')  type('image/jpeg')
  );
}

.course-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.course-title {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin-bottom: var(--space-xs);
  transition: color 0.25s ease;
}

.course-desc {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  max-width: none;
  margin: 0 0 var(--space-sm);
}

.course-meta {
  margin: 0;
  padding-top: var(--space-xs);
}
.course-term {
  font-family: var(--font-display);
  font-size: 0.8125rem;
  color: var(--color-text-light);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ============================================
   Contact
   ============================================ */
.contact-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xl);
  align-items: start;
}

.contact-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* contact items — blue line-icon + label + value, list style */
.contact-details {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

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

.contact-glyph {
  flex-shrink: 0;
  color: var(--color-accent);
  margin-top: 4px;
  transition: transform 0.3s var(--ease);
}
@media (hover: hover) {
  /* Only the inner <a> is interactive — scope the glyph lift to that, not
     the whole row (the SVG sits outside the link's hit area). */
  @media (hover: hover) {
.contact-item:has(a:hover) .contact-glyph{
    transform: translateY(-2px);
  }
}
}

.contact-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.contact-label {
  font-family: var(--font-display);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-light);
}

.contact-item a {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.012em;
  color: var(--color-text);
  border-bottom: 1px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  align-self: flex-start;
}
@media (hover: hover) {
.contact-item a:hover{
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}
}

.contact-note {
  padding: var(--space-lg);
  background-color: var(--color-surface);
  border-radius: var(--border-radius);
  border: 1px solid var(--color-border-light);
  transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1),
              box-shadow 0.6s cubic-bezier(0.165, 0.84, 0.44, 1),
              border-color 0.3s ease;
}
@media (hover: hover) {
  @media (hover: hover) {
.contact-note:hover{
    box-shadow: var(--shadow-lift);
    transform: translateY(-6px) scale(1.01);
    border-color: var(--color-accent);
    z-index: 1;
  }
}
  @media (hover: hover) {
.contact-note:hover h3{ color: var(--color-accent); }
}
  .contact-note:active {
    transform: translateY(2px) scale(0.97);
    box-shadow: var(--shadow-soft);
    transition: transform 0.05s var(--ease), box-shadow 0.05s var(--ease);
  }
}
@media (hover: none) {
  .contact-note:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-soft);
  }
}

.contact-note h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: var(--space-md);
  color: var(--color-text);
  display: inline-block;
  background-image: linear-gradient(transparent 55%, var(--color-green) 55%, var(--color-green) 95%, transparent 95%);
  padding: 0 8px;
}
.contact-note p {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.65;
}

/* ============================================
   Back to top
   ============================================ */
.back-to-top {
  position: fixed;
  /* env() reserves room for the iOS home indicator in landscape. */
  bottom: max(30px, env(safe-area-inset-bottom));
  right: max(30px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity var(--transition-base),
              visibility var(--transition-base),
              transform var(--transition-base),
              background-color var(--transition-base),
              border-color var(--transition-base),
              color var(--transition-base);
  z-index: 999;
  box-shadow: var(--shadow-soft);
}
@media (hover: hover) {
.back-to-top:hover{
  background-color: var(--color-green);
  border-color: var(--color-on-green);
  color: var(--color-on-green);
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}
}
.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ============================================
   Footer
   ============================================ */
.footer {
  position: relative;
  padding: var(--space-lg) var(--space-lg);
  border-top: 1px solid var(--color-border);
  text-align: center;
  background: var(--color-bg);
  z-index: 2;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.footer p {
  font-family: var(--font-display);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}
.footer-note {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-top: var(--space-xs);
}

/* ============================================
   Reveal-on-scroll
   ============================================ */
.animate-on-scroll {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s var(--ease-out), transform 0.7s var(--ease-out);
}
.animate-on-scroll.is-visible {
  opacity: 1;
  transform: none;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
  .about-content {
    grid-template-columns: 1fr;
  }
  .about-news { position: static; }
}

@media (max-width: 900px) {
  .hero { padding: var(--space-2xl) var(--space-lg); }
  .hero-content {
    grid-template-columns: 1fr;
    text-align: center;
    gap: var(--space-xl);
  }
  .hero-image-wrapper { justify-self: center; }
  .hero-image { width: 220px; height: 220px; }
  .hero-greeting { justify-content: center; }
  .hero-interests { justify-content: center; }
  .hero-text { max-width: 100%; }
  .hero-text::before { display: none; }
  .hero-links { justify-content: center; }

  .nav-toggle { display: flex; }

  .nav-inner { flex-wrap: wrap; }
  .nav-inner .nav-logo { flex-shrink: 0; }
  .nav-inner .nav-controls {
    order: 2;
    margin-left: auto;
  }
  .nav-inner .nav-links {
    order: 3;
    width: 100%;
    flex-basis: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    margin-left: 0;
    margin-right: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height var(--transition-slow), opacity var(--transition-base);
  }
  .nav-inner .nav-links li { display: block; }
  .nav-inner .nav-links .nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 0;
    padding: 0.375rem 0;
    line-height: 1.3;
    width: fit-content;
  }
  .nav-inner .nav-links .nav-link::after { bottom: 2px; }
  .nav-inner .nav-links.active {
    max-height: 220px;
    opacity: 1;
    padding-top: var(--space-xs);
    padding-bottom: var(--space-sm);
  }

  body.no-scroll .nav {
    bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--nav-menu-overlay-bg);
  }

  .nav-inner {
    position: relative;
    z-index: 1;
  }

  .nav-inner::before {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 100vw;
    top: 0;
    bottom: 0;
    background: var(--color-bg);
    border-bottom: 1px solid transparent;
    z-index: -1;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base), border-color var(--transition-base);
  }

  body.no-scroll .nav-inner::before {
    opacity: 1;
    border-bottom-color: var(--color-border-light);
  }

  .nav-inner .nav-links.nav-links--instant {
    transition: none !important;
  }

  .section {
    content-visibility: visible;
    contain-intrinsic-size: auto;
  }

  .pub-row {
    grid-template-columns: 1fr;
    gap: 0;
    padding: var(--space-lg) var(--space-sm);
  }
  .pub-thumb { display: none; }
  .pub.open .pub-body{ transform: none; }
@media (hover: hover) {
.pub:hover .pub-body{ transform: none; }
}

  .contact-content { grid-template-columns: 1fr; }

  /* Research: stacked rows, compact horizontal cards (like xuanyouliu.com) */
  .projects-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  .project-card {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 0;
    min-height: 120px;
    align-items: stretch;
    cursor: pointer;
  }
  .project-image {
    width: 120px;
    min-width: 120px;
    /* Image grows with the card via grid row stretch — intentional. */
    height: 100%;
    aspect-ratio: auto;
    flex-shrink: 0;
  }
  .project-content {
    display: flex;
    flex-direction: column;
    /* flex-start instead of center: when closed the text group is shorter
       than the 120px min-height, so center pushed it down ~19px. As soon as
       the expand began and content passed 120px, justify-content stopped
       having slack and the title snapped upward — that was the "jump". */
    justify-content: flex-start;
    padding: var(--space-sm) var(--space-md);
    min-width: 0;
    overflow: hidden;
  }
  .project-title {
    font-size: 1.0625rem;
    margin-bottom: var(--space-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .project-desc {
    font-size: 0.9rem;
    /* 4.8em = 3 lines at line-height 1.6 (was 3.2em → 2 lines, felt empty). */
    max-height: 4.8em;
    margin-bottom: 0;
    /* Bumped from 0.5s. The open transition below now targets a realistic
       max-height instead of 1000px, so the curve plays out across the
       visible range rather than finishing in the first ~100ms. */
    transition: max-height 0.65s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  /* Compact: expand desc on tap (.open), not hover */
  @media (hover: hover) {
    @media (hover: hover) {
.project-card:hover .project-desc{
      max-height: 4.8em;
    }
}
    @media (hover: hover) {
.project-card:hover .project-desc::after{
      opacity: 1;
    }
}
  }
  .project-card.open .project-content {
    overflow: visible;
  }
  .project-card.open .project-desc {
    /* 30em ≈ 432px — comfortably above any real card's copy (~250-350px)
       while staying close enough that the max-height curve doesn't waste
       most of its duration overshooting beyond the content. */
    max-height: 30em;
  }
  .project-card.open .project-desc::after {
    opacity: 0;
  }
}

@media (max-width: 640px) {
  .section { padding: var(--space-xl) var(--space-md); }
  .hero { padding: var(--space-2xl) var(--space-md) var(--space-xl); }
  .nav-inner { padding: var(--space-sm) var(--space-md); }
}

/* ============================================
   Reduced motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .dot-canvas { display: none; }
  .cursor-blob { display: none !important; }
  body { cursor: auto; }
}

/* ============================================
   Print
   ============================================ */
@media print {
  body { font-size: 11pt; line-height: 1.45; color: #000; background: #fff; cursor: auto; }
  .scroll-progress, .nav, .footer, .dot-canvas, .cursor-blob, .back-to-top,
  .hero-image-wrapper, .pub-thumb, .project-image, .nav-toggle, .pub-cue { display: none !important; }
  .hero { padding: 0 0 12pt; border-bottom: 1px solid #aaa; }
  .hero-content { grid-template-columns: 1fr !important; padding: 0; gap: 8pt; }
  .section { padding: 12pt 0; break-inside: avoid; background: none; }
  .pub-row { grid-template-columns: 1fr !important; padding: 6pt 0 !important; }
  .pub-expand { max-height: none !important; opacity: 1 !important; margin-top: 6pt !important; }
  .about-content, .contact-content, .projects-grid { grid-template-columns: 1fr !important; gap: 8pt; }
  a { color: #000; text-decoration: underline; }
}
