/* ============================================================
   Yi (Jasper) Zhao — personal academic homepage
   Layered blue palette, IBM Plex family, light + dark themes
   ------------------------------------------------------------
   THEMING
   The page is LIGHT by default for everyone — it deliberately
   does not follow the visitor's OS setting. Dark is opt-in via
   the toggle, which sets data-theme="dark" on <html>.

   Every colour is a token. Light values are the defaults on
   :root; each token's dark counterpart is defined ONCE as a
   --d-* token and remapped in the single :root[data-theme="dark"]
   block. To change a colour, edit the value in ONE place: the
   light value on :root, or the matching --d-* token.
   ============================================================ */

:root {
  /* ---- light palette (defaults) ---- */
  --page-bg: #ffffff;
  --wash: #eaf4fe;                    /* soft blue wash behind the header */
  --wash-fade: rgba(234, 244, 254, 0);
  --card-bg: #ffffff;
  --logo-tile: #ffffff;               /* stays light in both themes: the seals are dark line art */

  --ink: #10233c;          /* dark navy body text */
  --heading: #0c1e38;
  --navy: #1e3a8a;         /* emphasis / <strong> */
  --accent: #1d4ed8;       /* primary blue — links */
  --accent-hover: #1e3a8a;
  --sky: #0284c7;          /* sky blue — secondary text */
  --lake: #0e7490;         /* lake blue — tertiary text */
  --pub-tldr: #1e40af;     /* publication abstracts */

  --sky-soft: #e8f4fd;
  --accent-soft: #eef4ff;
  --border-blue: #d6e6f7;
  --dash-border: #c9e2f7;
  --stem-color: #cbe3f9;   /* NB: not --stem — .timeline uses that for the stem WIDTH */
  --dot-ring: #eaf4fe;
  --pub-hover-border: #93c5fd;
  --rule-end: #38bdf8;     /* end stop of the h2 underline + timeline dot */

  --icon-bg-a: #eef4ff;
  --icon-bg-b: #e3f3fd;
  --icon-border: #c4dcf5;
  --icon-hover-a: #1d4ed8;
  --icon-hover-b: #0284c7;
  --icon-hover-text: #ffffff;

  --chip-a: #1d4ed8;       /* news date chip */
  --chip-b: #0284c7;
  --chip-text: #ffffff;
  --venue-a: #0284c7;      /* publication venue chip */
  --venue-b: #0e7490;
  --venue-text: #ffffff;

  --sel-bg: #1d4ed8;
  --sel-fg: #ffffff;

  --shadow-chip: rgba(2, 132, 199, 0.25);
  --shadow-venue: rgba(14, 116, 144, 0.22);
  --shadow-card: rgba(30, 58, 138, 0.05);
  --shadow-card-hover: rgba(29, 78, 216, 0.13);
  --shadow-logo: rgba(30, 58, 138, 0.08);
  --shadow-icon-hover: rgba(29, 78, 216, 0.25);
  --shadow-portrait: rgba(29, 78, 216, 0.22);

  /* ---- dark counterparts (values live here only) ---- */
  --d-page-bg: #0b1220;
  --d-wash: #0f1c30;
  --d-wash-fade: rgba(15, 28, 48, 0);
  --d-card-bg: #101c2f;
  --d-logo-tile: #eef3f9;

  --d-ink: #d7e3f2;
  --d-heading: #eef5fd;
  --d-navy: #9dc2fb;
  --d-accent: #6aa6fb;
  --d-accent-hover: #a5c9ff;
  --d-sky: #74c8f0;
  --d-lake: #67d3e8;
  --d-pub-tldr: #a9c9ff;

  --d-sky-soft: #16283e;
  --d-accent-soft: #16233a;
  --d-border-blue: #22344e;
  --d-dash-border: #1f3550;
  --d-stem-color: #2b4160;
  --d-dot-ring: #16263c;
  --d-pub-hover-border: #3f6fa8;

  --d-icon-bg-a: #16243c;
  --d-icon-bg-b: #14293f;
  --d-icon-border: #2b4160;
  --d-icon-hover-a: #2563eb;
  --d-icon-hover-b: #0284c7;

  --d-chip-a: #2563eb;
  --d-chip-b: #0369a1;
  --d-chip-text: #f2f8ff;
  --d-venue-a: #0369a1;
  --d-venue-b: #155e75;
  --d-venue-text: #f2f8ff;

  --d-sel-bg: #2f5fb8;

  --d-shadow-soft: rgba(0, 0, 0, 0.35);
  --d-shadow-strong: rgba(0, 0, 0, 0.5);

  --serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;

  color-scheme: light;
}

/* --- dark is opt-in: only the toggle sets this attribute --- */
:root[data-theme="dark"] {
  --page-bg: var(--d-page-bg);
  --wash: var(--d-wash);
  --wash-fade: var(--d-wash-fade);
  --card-bg: var(--d-card-bg);
  --logo-tile: var(--d-logo-tile);
  --ink: var(--d-ink);
  --heading: var(--d-heading);
  --navy: var(--d-navy);
  --accent: var(--d-accent);
  --accent-hover: var(--d-accent-hover);
  --sky: var(--d-sky);
  --lake: var(--d-lake);
  --pub-tldr: var(--d-pub-tldr);
  --sky-soft: var(--d-sky-soft);
  --accent-soft: var(--d-accent-soft);
  --border-blue: var(--d-border-blue);
  --dash-border: var(--d-dash-border);
  --stem-color: var(--d-stem-color);
  --dot-ring: var(--d-dot-ring);
  --pub-hover-border: var(--d-pub-hover-border);
  --icon-bg-a: var(--d-icon-bg-a);
  --icon-bg-b: var(--d-icon-bg-b);
  --icon-border: var(--d-icon-border);
  --icon-hover-a: var(--d-icon-hover-a);
  --icon-hover-b: var(--d-icon-hover-b);
  --chip-a: var(--d-chip-a);
  --chip-b: var(--d-chip-b);
  --chip-text: var(--d-chip-text);
  --venue-a: var(--d-venue-a);
  --venue-b: var(--d-venue-b);
  --venue-text: var(--d-venue-text);
  --sel-bg: var(--d-sel-bg);
  --shadow-chip: var(--d-shadow-soft);
  --shadow-venue: var(--d-shadow-soft);
  --shadow-card: var(--d-shadow-soft);
  --shadow-card-hover: var(--d-shadow-strong);
  --shadow-logo: var(--d-shadow-soft);
  --shadow-icon-hover: var(--d-shadow-soft);
  --shadow-portrait: var(--d-shadow-strong);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    linear-gradient(180deg, var(--wash) 0%, var(--wash-fade) 480px),
    var(--page-bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* brand bar across the very top */
body::before {
  content: "";
  display: block;
  height: 5px;
  background: linear-gradient(90deg, #1e3a8a 0%, #1d4ed8 40%, #0284c7 75%, #22d3ee 100%);
}

::selection {
  background: var(--sel-bg);
  color: var(--sel-fg);
}

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 54px 24px 40px;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
}

/* ---------- theme toggle ----------
   Fixed in the top-right corner. The icon shows the theme you
   would switch TO: a moon while light, a sun while dark.
   ---------------------------------------------------------- */

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--accent);
  background: linear-gradient(135deg, var(--icon-bg-a), var(--icon-bg-b));
  border: 1px solid var(--icon-border);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease,
              color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.theme-toggle svg {
  width: 20px;
  height: 20px;
}
.theme-toggle:hover {
  background: linear-gradient(135deg, var(--icon-hover-a), var(--icon-hover-b));
  border-color: var(--icon-hover-a);
  color: var(--icon-hover-text);
  box-shadow: 0 4px 12px var(--shadow-icon-hover);
  transform: translateY(-1px);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* show the moon in light mode, the sun in dark mode */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- header ---------- */

.header-grid {
  display: flex;
  gap: 46px;
  align-items: flex-start;
}

.header-text { flex: 1; min-width: 0; }

h1 {
  font-family: var(--serif);
  font-size: 2.8rem;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.015em;
  line-height: 1.12;
  color: var(--heading);
}
h1 .alt-name {
  color: var(--sky);
  font-weight: 500;
}

.subtitle {
  margin: 0 0 16px;
  color: var(--lake);
  font-size: 1.1rem;
  font-weight: 500;
}
.subtitle a { font-weight: 500; }

.links {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.links a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  color: var(--accent);
  background: linear-gradient(135deg, var(--icon-bg-a), var(--icon-bg-b));
  border: 1px solid var(--icon-border);
  border-radius: 50%;
  transition: all 0.18s ease;
}
.links a svg {
  width: 20px;
  height: 20px;
}
.links a:hover {
  background: linear-gradient(135deg, var(--icon-hover-a), var(--icon-hover-b));
  border-color: var(--icon-hover-a);
  color: var(--icon-hover-text);
  text-decoration: none;
  box-shadow: 0 4px 12px var(--shadow-icon-hover);
  transform: translateY(-1px);
}

.bio p {
  margin: 0 0 15px;
  font-size: 1.02rem;
}
.bio .interests {
  color: var(--ink);
  font-size: 1.05rem;
  background: transparent;
  border: none;
  border-left: 4px solid var(--accent);
  border-radius: 0;
  padding: 2px 0 2px 14px;
  box-shadow: none;
}
.bio .interests strong { color: var(--navy); font-weight: 700; }
.bio .interest-topics {
  color: var(--navy);
  font-weight: 600;
}

.portrait {
  margin: 8px 0 0;
  flex: 0 0 235px;
}
.portrait img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}
.portrait .frame {
  padding: 4px;
  border-radius: 16px;
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8 45%, #0ea5e9 80%, #67e8f9);
  box-shadow: 0 6px 20px var(--shadow-portrait);
}
.portrait figcaption {
  text-align: center;
  color: var(--sky);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  margin-top: 12px;
}

/* ---------- sections ---------- */

section { margin-top: 52px; }

section::before {
  content: "";
  display: block;
  border-top: 1px solid var(--border-blue);
  margin-bottom: 34px;
}

h2 {
  font-family: var(--serif);
  font-size: 1.72rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 24px;
  color: var(--heading);
}
h2::after {
  content: "";
  display: block;
  width: 52px;
  height: 4px;
  margin-top: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--rule-end));
}

/* ---------- news ---------- */

.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.news-list li {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 10px 0;
}
.news-list li + li {
  border-top: 1px dashed var(--dash-border);
}
.news-list .date {
  flex: 0 0 92px;
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--chip-text);
  background: linear-gradient(135deg, var(--chip-a), var(--chip-b));
  border-radius: 7px;
  text-align: center;
  padding: 2.5px 4px;
  white-space: nowrap;
  box-shadow: 0 2px 6px var(--shadow-chip);
}
.news-list .news-text {
  flex: 1;
  min-width: 0;
  font-size: 1.02rem;
}
.news-list .news-text strong { color: var(--navy); }

/* ---------- education ---------- */

.item.edu {
  display: flex;
  gap: 20px;
  align-items: center;
}
.edu-logo {
  flex: 0 0 76px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--logo-tile);
  border: 1px solid var(--border-blue);
  border-radius: 18px;
  box-shadow: 0 3px 10px var(--shadow-logo);
}
.edu-logo img {
  max-width: 56px;
  max-height: 56px;
}
.edu-body { flex: 1; min-width: 0; }

/* ---------- experience timeline ----------
   Structure:
     <ol class="timeline">
       <li class="timeline-item">
         <div class="timeline-rail">
           <span class="timeline-dot"></span>
           <span class="timeline-stem"></span>   <!-- auto-hidden on last item -->
         </div>
         <div class="timeline-body">…</div>
       </li>
     </ol>
   The stem starts at the center of this item's dot and ends at the
   center of the next item's dot — never above the first or below the last.
   To add an entry: insert another <li class="timeline-item"> (newest first).
   ---------------------------------------------------------- */

.timeline {
  --dot: 12px;
  --line-gap: calc((1.22rem * 1.7 - var(--dot)) / 2); /* centers dot on first heading line */
  --stem: 2px;
  --rail-w: 12px;
  --gap: 16px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline-item {
  display: flex;
  align-items: stretch;
  gap: var(--gap);
  margin: 0;
  padding: 0 0 26px;
}
.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 var(--rail-w);
  width: var(--rail-w);
}

.timeline-dot {
  flex: 0 0 var(--dot);
  width: var(--dot);
  height: var(--dot);
  margin-top: var(--line-gap);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--rule-end));
  box-shadow: 0 0 0 3.5px var(--dot-ring);
  z-index: 1;
}

/* stem: from THIS dot center → NEXT dot center */
.timeline-stem {
  flex: 1 0 auto;
  width: var(--stem);
  margin-top: calc(var(--dot) / -2);          /* pull up into current dot center */
  margin-bottom: calc(-1 * (var(--line-gap) + var(--dot) / 2)); /* reach next center */
  background: var(--stem-color);
  z-index: 0;
}
.timeline-item:last-child .timeline-stem {
  display: none; /* no stub past the final node */
}

.timeline-body {
  flex: 1;
  min-width: 0;
}

.timeline-body .item-head { margin: 0; }
.timeline-body h3 {
  font-family: var(--serif);
  font-size: 1.22rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
  color: var(--heading);
}
.timeline-body .period {
  font-family: var(--mono);
  color: var(--sky);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--sky-soft);
  border-radius: 6px;
  padding: 1px 9px;
}
.timeline-body .role {
  margin: 3px 0 7px;
  font-size: 1rem;
  color: var(--accent);
  font-weight: 500;
}
.timeline-body p {
  margin: 0 0 6px;
  font-size: 1rem;
}

/* ---------- items (shared) ---------- */

.item { margin-bottom: 28px; }
.item:last-child { margin-bottom: 0; }

.item-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}
.item h3 {
  font-family: var(--serif);
  font-size: 1.22rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
  color: var(--heading);
}
.item .period {
  font-family: var(--mono);
  color: var(--sky);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--sky-soft);
  border-radius: 6px;
  padding: 1px 9px;
}
.item .role {
  margin: 3px 0 7px;
  font-size: 1rem;
  color: var(--accent);
  font-weight: 500;
}
.item p {
  margin: 0 0 6px;
  font-size: 1rem;
}

/* ---------- publications ---------- */

.pub {
  margin-bottom: 20px;
  padding: 18px 20px;
  background: var(--card-bg);
  border: 1px solid var(--border-blue);
  border-radius: 14px;
  box-shadow: 0 2px 8px var(--shadow-card);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease,
              background-color 0.25s ease;
}
.pub:last-child { margin-bottom: 0; }
.pub:hover {
  border-color: var(--pub-hover-border);
  box-shadow: 0 8px 22px var(--shadow-card-hover);
  transform: translateY(-2px);
}

.pub h3 {
  font-family: var(--serif);
  font-size: 1.16rem;
  font-weight: 600;
  margin: 0 0 6px;
  line-height: 1.45;
  color: var(--heading);
}
.pub .authors {
  margin: 0 0 5px;
  font-size: 0.98rem;
}
.pub .authors strong { color: var(--navy); }
.pub .venue {
  display: inline-block;
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--venue-text);
  background: linear-gradient(135deg, var(--venue-a), var(--venue-b));
  border-radius: 6px;
  padding: 2px 10px;
  box-shadow: 0 2px 5px var(--shadow-venue);
}
.pub .tldr {
  margin: 0;
  font-size: 0.98rem;
  color: var(--pub-tldr); /* deep blue for publication abstracts */
  line-height: 1.65;
}

/* ---------- footer ---------- */

footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border-blue);
  color: var(--sky);
  font-family: var(--mono);
  font-size: 0.8rem;
  text-align: center;
}

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  main { padding: 36px 20px 32px; }

  .theme-toggle {
    top: 12px;
    right: 12px;
  }

  .header-grid {
    flex-direction: column-reverse;
    gap: 28px;
  }
  .portrait {
    flex: none;
    width: 210px;
    margin: 0 auto;
  }
  h1 { font-size: 2.15rem; text-align: center; }
  .subtitle { text-align: center; }
  .links { justify-content: center; }

  .news-list li {
    flex-direction: column;
    gap: 5px;
  }
  .news-list .date { flex: none; align-self: flex-start; }

  .item-head { flex-direction: column; gap: 4px; align-items: flex-start; }

  .item.edu { gap: 14px; align-items: flex-start; }
  .edu-logo { flex-basis: 58px; height: 58px; border-radius: 14px; }
  .edu-logo img { max-width: 44px; max-height: 44px; }

  .timeline {
    --gap: 12px;
  }
}

/* ---------- motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
