/* ============================================
   Ruihua Guo — Personal Site
   Rigorous, quiet, scholarly
   Palatino throughout, dual institutional accents
   ============================================ */

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

/* --- Tokens --- */
:root {
  /* Neutrals */
  --color-bg:              #fafaf8;
  --color-text:            #1a1a1a;
  --color-text-secondary:  #55534f;
  --color-text-muted:      #8a8681;
  --color-border:          #e8e6e2;
  --color-border-strong:   #d6d3cd;

  /* Institutional accents — each has one structural role */
  --color-nus-blue:        #003D7C;   /* primary: links, focus, hero rule */
  --color-nus-blue-hover:  #002a58;
  --color-cornell-red:     #B31B1B;   /* reserved: awards, signature moment */

  /* Typography */
  --font-serif:         "Palatino Linotype", Palatino, "Book Antiqua", "TeX Gyre Pagella", Georgia, serif;
  --font-display-sans:  "Helvetica Neue", Helvetica, Arial, sans-serif;  /* name only — NYC-subway register */
  --font-label:         -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --text-micro:     0.75rem;   /* 12px */
  --text-small:     0.875rem;  /* 14px */
  --text-body:      1.0625rem; /* 17px — generous for long reads in Palatino */
  --text-subtitle:  1.2rem;
  --text-section:   1.55rem;
  --text-display:   2.625rem;

  /* Spacing */
  --space-xs:   0.25rem;
  --space-sm:   0.5rem;
  --space-md:   1rem;
  --space-lg:   1.5rem;
  --space-xl:   2.5rem;
  --space-2xl:  3.5rem;
  --space-3xl:  5rem;

  /* Other */
  --radius-sm:  4px;
  --radius-md:  8px;
  --transition: 180ms ease;
}

/* --- Base --- */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-serif);
  font-size: var(--text-body);
  color: var(--color-text);
  background-color: var(--color-bg);
  line-height: 1.7;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

/* Headings — one family, hierarchy by size/italic/weight */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  line-height: 1.2;
  font-weight: 400;
  text-wrap: balance;
  color: var(--color-text);
}

h2 { font-size: var(--text-section); font-style: italic; }
h3 { font-size: var(--text-subtitle); font-weight: 500; }

p {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

p + p { margin-top: var(--space-sm); }

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

/* Links — NUS blue, primary accent, one role */
a {
  color: var(--color-nus-blue);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: rgba(0, 61, 124, 0.35);
  transition: color var(--transition), text-decoration-color var(--transition);
}

a:hover {
  color: var(--color-nus-blue-hover);
  text-decoration-color: var(--color-nus-blue-hover);
}

a:focus-visible {
  outline: 2px solid var(--color-nus-blue);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

ul, ol { list-style: none; }

/* Skip link — hidden until focused */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.5rem 1rem;
  background: var(--color-text);
  color: var(--color-bg);
  text-decoration: none;
  z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* --- Layout container --- */
.container {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--space-3xl) var(--space-lg) var(--space-2xl);
}

/* --- Hero --- */
.hero {
  display: flex;
  align-items: flex-start;
  gap: var(--space-xl);
  padding-bottom: var(--space-2xl);
  border-bottom: 1px solid var(--color-border);
}

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

.name {
  font-family: var(--font-display-sans);
  font-size: var(--text-display);
  font-weight: 700;
  font-style: normal;
  letter-spacing: -0.025em;
  line-height: 1.02;
  margin-bottom: var(--space-md);
  color: #000;
}

.name-typed {
  white-space: pre;
}

/* Blinking caret while typing. Removed once typing finishes. */
.name-caret {
  display: inline-block;
  width: 0.06em;
  height: 0.9em;
  background: #000;
  margin-left: 0.06em;
  transform: translateY(0.05em);
  animation: name-caret-blink 1s steps(2, end) infinite;
}
.name-caret--done {
  animation: none;
  opacity: 0;
  transition: opacity 280ms ease;
}
@keyframes name-caret-blink {
  0%, 50%   { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* Signature moment: Cornell red period after the name. Visible by default;
   the typed-name script hides it during typing then fades it back in. */
.name .mark {
  color: var(--color-cornell-red);
  font-style: normal;
  font-weight: 700;
  margin-left: 0.02em;
  transition: opacity 280ms ease;
}
.name .mark--hidden  { opacity: 0; }
.name .mark--visible { opacity: 1; }

/* Thin NUS rule under the hero bio */
.hero-rule {
  width: 3rem;
  height: 2px;
  background: var(--color-nus-blue);
  margin: var(--space-md) 0 var(--space-lg);
  border: 0;
}

.bio {
  font-size: var(--text-body);
  line-height: 1.75;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-lg);
  max-width: 60ch;
}

.info-list li {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  padding: 0.25rem 0;
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
}

.info-label {
  font-family: var(--font-label);
  font-size: var(--text-micro);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  min-width: 4.5rem;
  flex-shrink: 0;
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin-top: var(--space-lg);
  font-style: italic;
  font-size: var(--text-body);
}

.hero-photo {
  flex-shrink: 0;
  width: 170px;
}

.profile-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-md);
  filter: grayscale(8%);
  background: var(--color-border-strong);
}

/* Large monogram variant for the hero profile placeholder */
.profile-img--mono {
  font-size: 2.5rem;
  aspect-ratio: 1;
}

/* --- Sections --- */
.section { padding: var(--space-2xl) 0 0; }

.section-title {
  font-family: var(--font-display-sans);
  font-size: 1.25rem;
  font-style: normal;
  font-weight: 700;
  letter-spacing: -0.005em;
  margin-bottom: var(--space-lg);
  color: var(--color-text);
}

.section-intro {
  font-size: var(--text-body);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-lg);
  max-width: 60ch;
  line-height: 1.75;
}

/* Research Interests — vertical-line dividers between phrases. */
.interests-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  max-width: none;
}
.interests-list .sep {
  display: inline-block;
  width: 1px;
  height: 0.95em;
  background: var(--color-border-strong);
  margin: 0 0.75rem;
  flex-shrink: 0;
}

/* --- News list --- */
.news-list li {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--color-border);
  line-height: 1.55;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--space-sm);
}

.news-list li:last-child { border-bottom: 0; }

.news-list time {
  font-family: var(--font-label);
  font-size: var(--text-micro);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  flex-shrink: 0;
}

/* --- Teaching groups (no logo/date columns — just title + list) --- */
.teaching-group {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border);
}
.teaching-group:last-child { border-bottom: 0; }
.teaching-group h3 {
  margin-bottom: 0.5rem;
  color: var(--color-text);
}
.teaching-group .timeline-sub { margin-top: 0; }

/* --- Timeline (Education, Experience) --- */
.timeline { display: flex; flex-direction: column; }

.timeline-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-lg);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border);
}

.timeline-item:last-child { border-bottom: 0; }

.timeline-logo {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  object-fit: contain;
  margin-top: 0.2rem;
}

/* Monogram fallback when no logo image */
.timeline-logo--mono {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-style: italic;
  color: var(--color-text-secondary);
}

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

.timeline-content h3 {
  margin-bottom: 0.1rem;
  color: var(--color-text);
}

.timeline-role {
  font-size: var(--text-body);
  color: var(--color-text-secondary);
  margin-bottom: 0.1rem;
}

.timeline-detail {
  font-size: var(--text-small);
  color: var(--color-text-muted);
  font-style: italic;
}

.timeline-date {
  font-family: var(--font-label);
  font-size: var(--text-micro);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  letter-spacing: 0.04em;
  padding-top: 0.3rem;
}

.timeline-sub {
  margin-top: 0.35rem;
  padding-left: 0;
}
.timeline-sub li {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  line-height: 1.55;
  padding: 0.1rem 0;
}

/* --- Works in progress (zzzdavid-style "pub" block) --- */
.pub-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.pub {
  display: flex;
  align-items: flex-start;        /* image pins to top; content grows down */
  gap: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}
.pub:last-child { border-bottom: 0; }

.pub-image {
  flex-shrink: 0;
  align-self: flex-start;         /* stay at top when abstract expands */
  width: 320px;
  height: auto;                   /* natural aspect ratio — entire figure shown */
  max-height: 380px;
  object-fit: contain;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  padding: 4px;
  margin-top: 0.3rem;
}

/* Placeholder variant — muted block with a soft dashed border, zero content. */
.pub-image--placeholder {
  background: var(--color-border-light, #efede8);
  border: 1px dashed var(--color-border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-label);
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}

.pub-content {
  flex: 1;
  min-width: 0;
}

.pub-title {
  font-size: var(--text-subtitle);
  font-weight: 500;
  font-style: normal;
  line-height: 1.3;
  color: var(--color-text);
  margin-bottom: 0.35rem;
  /* Override the global h3 `text-wrap: balance` — long paper titles should
     fill the column width rather than balance into a narrow block. */
  text-wrap: pretty;
}

.pub-authors, .pub-venue {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  line-height: 1.55;
  margin-bottom: 0.2rem;
}

.pub-venue {
  font-style: italic;
  color: var(--color-text-muted);
}

.pub-note {
  color: var(--color-text-muted);
  font-size: var(--text-micro);
  margin-left: 0.4rem;
}

/* Award marker — Cornell red, reserved accent */
.pub-award, .award-mark {
  display: inline-block;
  font-family: var(--font-label);
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-cornell-red);
  border: 1px solid var(--color-cornell-red);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  margin-top: 0.35rem;
}

/* Disclosure (abstract toggle) */
.pub-toggle {
  margin-top: 0.4rem;
  font-size: var(--text-small);
}
.pub-toggle summary {
  cursor: pointer;
  color: var(--color-nus-blue);
  font-style: italic;
  width: fit-content;
}
.pub-toggle summary:hover { color: var(--color-nus-blue-hover); }
.pub-toggle[open] summary { margin-bottom: 0.4rem; }
.pub-toggle p {
  color: var(--color-text-secondary);
  line-height: 1.6;
  padding: 0.35rem 0 0.1rem 1rem;
  border-left: 2px solid var(--color-border);
}

/* --- Compact lists (Awards, Skills) --- */
.compact-list li {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  padding: 0.3rem 0;
  line-height: 1.55;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.compact-list .year {
  font-family: var(--font-label);
  font-size: var(--text-micro);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.kv-list {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.5rem 1rem;
  font-size: var(--text-small);
}
.kv-list dt {
  font-family: var(--font-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: var(--text-micro);
  color: var(--color-text-muted);
  padding-top: 0.15rem;
}
.kv-list dd { color: var(--color-text-secondary); }

/* --- Footer --- */
.site-footer {
  margin-top: var(--space-3xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-small);
  color: var(--color-text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-sm);
}
.site-footer a { color: var(--color-text-secondary); }
.site-footer a:hover { color: var(--color-nus-blue); }

/* --- Blog-specific (used on blog/index.html and post pages) --- */
.post-list li {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-md);
  align-items: baseline;
  flex-wrap: wrap;
}
.post-list li:last-child { border-bottom: 0; }
.post-list .post-title {
  font-size: var(--text-subtitle);
  font-style: italic;
  flex: 1;
}
.post-list .post-date {
  font-family: var(--font-label);
  font-size: var(--text-micro);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.post-list .post-summary {
  flex-basis: 100%;
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  margin-top: 0.15rem;
}

.post-article {
  max-width: 64ch;
  margin: 0 auto;
  padding: var(--space-2xl) 0;
}
.post-article h1 {
  font-style: italic;
  font-size: var(--text-display);
  line-height: 1.15;
  margin-bottom: var(--space-md);
}
.post-article .post-meta {
  font-family: var(--font-label);
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xl);
}
.post-article p { margin-bottom: var(--space-md); line-height: 1.75; }
.post-article h2 { margin: var(--space-xl) 0 var(--space-sm); }
.post-article h3 { margin: var(--space-lg) 0 var(--space-sm); font-style: italic; }
.post-article blockquote {
  margin: var(--space-lg) 0;
  padding-left: var(--space-md);
  border-left: 3px solid var(--color-nus-blue);
  color: var(--color-text-secondary);
  font-style: italic;
}

.back-home {
  display: inline-block;
  margin-top: var(--space-xl);
  font-size: var(--text-small);
  font-style: italic;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  :root { --text-display: 2.1rem; --text-section: 1.35rem; }
  .container { padding: var(--space-2xl) var(--space-md) var(--space-xl); }
  .hero { flex-direction: column-reverse; gap: var(--space-lg); }
  .hero-photo { width: 130px; }
  .timeline-item { flex-wrap: wrap; gap: var(--space-md); }
  .timeline-date { width: 100%; padding-top: 0; order: 3; }
  .kv-list { grid-template-columns: 1fr; gap: 0.25rem; }
  .pub { flex-direction: column; gap: var(--space-md); }
  .pub-image { width: 100%; height: auto; max-height: none; }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
