/* ==========================================================================
   Sheng Zha — Personal Homepage
   Modern Minimal. Warm cream, Didone serif, editorial precision.
   Inspired by: The Essential Man style direction.
   ========================================================================== */

/* --- Custom Properties --- */
:root {
  --bg: #F5F0E8;
  --text: #2B2B2B;
  --text-heading: #0A0A0A;
  --text-secondary: #6B6660;
  --accent: #1B2838;
  --accent-hover: #C23C3C;
  --accent-red: #C23C3C;
  --border: #0A0A0A;
  --border-light: #D8D3CB;
  --nav-bg: rgba(245, 240, 232, 0.92);
  --code-bg: rgba(27, 40, 56, 0.06);
  --selection-bg: #1B2838;
  --selection-text: #F5F0E8;
  --font-heading: 'Bodoni Moda', 'Didot', 'Georgia', serif;
  --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  --bg: #0C0C0C;
  --text: #D8D2C8;
  --text-heading: #F0EBE2;
  --text-secondary: #8A857D;
  --accent: #C8BAA4;
  --accent-hover: #D94848;
  --accent-red: #D94848;
  --border: #3A3530;
  --border-light: #2A2724;
  --nav-bg: rgba(12, 12, 12, 0.92);
  --code-bg: rgba(200, 186, 164, 0.1);
  --selection-bg: #C8BAA4;
  --selection-text: #0C0C0C;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
  background-color: var(--bg);
  overflow-x: hidden;
  transition: background-color 0.4s ease, color 0.4s ease;
  font-weight: 400;
}

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

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

/* --- Typography --- */
h1, h2, h3 {
  font-family: var(--font-heading);
  color: var(--text-heading);
  line-height: 1.15;
}

h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  letter-spacing: -0.02em;
  font-weight: 400;
  font-style: italic;
}

h2 {
  font-size: clamp(1.1rem, 2vw, 1.25rem);
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 2.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

h3 {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  font-family: var(--font-body);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--accent-hover);
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

p {
  margin-bottom: 1rem;
}

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

code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  background: var(--code-bg);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  color: var(--text-heading);
}

/* --- Layout --- */
.section {
  max-width: 48rem;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}

.section-rule {
  max-width: 48rem;
  margin: 0 auto;
  border: none;
  height: 2px;
  background: var(--border);
}

/* --- Navigation --- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  transition: background 0.4s ease;
}

.nav-inner {
  max-width: 48rem;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-name {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 1.15rem;
  color: var(--text-heading);
  letter-spacing: -0.01em;
  font-style: italic;
}

.nav-name:hover {
  color: var(--text-heading);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

.nav-links a {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: color 0.2s ease;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.nav-links a:hover {
  color: var(--text-heading);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.nav-toggle.active span:nth-child(1) {
  transform: translateY(6.5px) rotate(45deg);
}

.nav-toggle.active span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
  transform: translateY(-6.5px) rotate(-45deg);
}

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.nav-backdrop.visible {
  opacity: 1;
}

/* --- Theme Toggle --- */
.theme-toggle {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 5px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, border-color 0.2s ease;
  min-width: 32px;
  min-height: 32px;
}

.theme-toggle:hover {
  color: var(--text-heading);
  border-color: var(--text-secondary);
}

.icon-sun, .icon-moon, .icon-auto { display: none; }
[data-mode="light"] .icon-sun { display: block; }
[data-mode="dark"] .icon-moon { display: block; }
[data-mode="auto"] .icon-auto { display: block; }

/* --- Hero --- */
.hero {
  max-width: 48rem;
  margin: 0 auto;
  padding: 6rem 1.5rem 4rem;
}

.hero.visible h1,
.hero.visible .hero-subtitle,
.hero.visible .hero-tagline,
.hero.visible .hero-projects,
.hero.visible .hero-links,
.hero.visible .hero-photo {
  animation: hero-enter 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.hero.visible h1             { animation-delay: 0s; }
.hero.visible .hero-subtitle { animation-delay: 0.06s; }
.hero.visible .hero-tagline  { animation-delay: 0.12s; }
.hero.visible .hero-projects { animation-delay: 0.18s; }
.hero.visible .hero-links    { animation-delay: 0.24s; }
.hero.visible .hero-photo    { animation-delay: 0.08s; }

@keyframes hero-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-content {
  display: flex;
  align-items: flex-start;
  gap: 3.5rem;
}

.hero-text {
  flex: 1;
}

.hero-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin: 1rem 0 0.25rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero-tagline {
  font-family: var(--font-heading);
  font-size: clamp(1.15rem, 2.5vw, 1.35rem);
  color: var(--text);
  margin: 0.75rem 0 1.5rem;
  line-height: 1.6;
  font-weight: 400;
  font-style: italic;
}

.hero-projects {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0;
}

.hero-projects li {
  font-size: 0.9rem;
}

.hero-projects li a {
  color: var(--accent);
  font-weight: 500;
}

.hero-projects li a:hover {
  color: var(--accent-hover);
}

.hero-projects li:not(:last-child)::after {
  content: '\00b7';
  margin: 0 0.5rem;
  color: var(--text-secondary);
  opacity: 0.4;
}

.hero-links {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.hero-links a {
  color: var(--text-secondary);
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  padding: 6px;
}

.hero-links a:hover {
  color: var(--accent-hover);
}

.hero-photo {
  flex-shrink: 0;
}

.hero-photo img {
  width: 200px;
  height: 200px;
  border-radius: 6px;
  object-fit: cover;
  filter: grayscale(15%);
  transition: filter 0.3s ease;
}

.hero-photo img:hover {
  filter: grayscale(0%);
}

/* --- About --- */
.about-content p {
  color: var(--text);
  font-size: 0.975rem;
}

.about-content p:first-child {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--text-heading);
  font-weight: 400;
}

/* --- What I've Built --- */
.built-grid {
  display: grid;
  gap: 0;
}

.built-item {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border-light);
}

.built-item:first-child {
  padding-top: 0;
}

.built-item:last-child {
  border-bottom: none;
}

.built-item h3 {
  color: var(--text-heading);
}

.built-item h3 a {
  color: inherit;
  transition: color 0.2s ease;
}

.built-item h3 a:hover {
  color: var(--accent-hover);
}

.built-role {
  font-size: 0.78rem;
  color: var(--accent-red);
  font-weight: 600;
  margin-bottom: 0.4rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.built-item p:last-of-type {
  color: var(--text-secondary);
  font-size: 0.925rem;
  line-height: 1.65;
}

.built-stars {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.built-stars::before {
  content: '\2605';
  color: var(--accent-red);
  font-size: 0.85rem;
}

/* --- Publications --- */
.publications-list {
  display: grid;
  gap: 0;
}

.pub-item {
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--border-light);
}

.pub-item:first-child {
  padding-top: 0;
}

.pub-item:last-child {
  border-bottom: none;
}

.pub-item h3 {
  font-size: 1rem;
  font-weight: 500;
}

.pub-item h3 a {
  color: var(--text-heading);
  transition: color 0.2s ease;
}

.pub-item h3 a:hover {
  color: var(--accent-hover);
}

.pub-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  line-height: 1.5;
}

.pub-award {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15em 0.55em;
  border-radius: 3px;
  background: var(--accent-red);
  color: var(--selection-text);
  vertical-align: middle;
  margin-left: 0.3rem;
  position: relative;
  top: -1px;
}

.section-link {
  margin-top: 2rem;
}

.section-link a {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.section-note {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* --- Talks --- */
.talks-list {
  display: grid;
  gap: 0;
}

.talk-item {
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--border-light);
}

.talk-item:first-child {
  padding-top: 0;
}

.talk-item:last-child {
  border-bottom: none;
}

.talk-item h3 {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-heading);
}

.talk-item h3 a {
  color: var(--text-heading);
  transition: color 0.2s ease;
}

.talk-item h3 a:hover {
  color: var(--accent-hover);
}

.talk-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* --- Footer --- */
.footer {
  border-top: 2px solid var(--border);
  margin-top: 2rem;
}

.footer-inner {
  max-width: 48rem;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.footer-links a {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--accent-hover);
}

.footer-copy {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- Scroll Animations --- */
.section, .hero {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1), transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.section.visible, .hero.visible {
  opacity: 1;
  transform: translateY(0);
}

.visible .built-item,
.visible .pub-item,
.visible .talk-item {
  animation: stagger-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes stagger-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.visible .built-item:nth-child(1) { animation-delay: 0.03s; }
.visible .built-item:nth-child(2) { animation-delay: 0.06s; }
.visible .built-item:nth-child(3) { animation-delay: 0.09s; }
.visible .built-item:nth-child(4) { animation-delay: 0.12s; }
.visible .built-item:nth-child(5) { animation-delay: 0.15s; }
.visible .built-item:nth-child(6) { animation-delay: 0.18s; }
.visible .built-item:nth-child(7) { animation-delay: 0.21s; }
.visible .built-item:nth-child(8) { animation-delay: 0.24s; }

.visible .pub-item:nth-child(1) { animation-delay: 0.03s; }
.visible .pub-item:nth-child(2) { animation-delay: 0.06s; }
.visible .pub-item:nth-child(3) { animation-delay: 0.09s; }
.visible .pub-item:nth-child(4) { animation-delay: 0.12s; }
.visible .pub-item:nth-child(5) { animation-delay: 0.15s; }
.visible .pub-item:nth-child(6) { animation-delay: 0.18s; }
.visible .pub-item:nth-child(7) { animation-delay: 0.21s; }
.visible .pub-item:nth-child(8) { animation-delay: 0.24s; }
.visible .pub-item:nth-child(9) { animation-delay: 0.27s; }
.visible .pub-item:nth-child(10) { animation-delay: 0.3s; }
.visible .pub-item:nth-child(11) { animation-delay: 0.33s; }

.visible .talk-item:nth-child(1) { animation-delay: 0.03s; }
.visible .talk-item:nth-child(2) { animation-delay: 0.06s; }
.visible .talk-item:nth-child(3) { animation-delay: 0.09s; }
.visible .talk-item:nth-child(4) { animation-delay: 0.12s; }
.visible .talk-item:nth-child(5) { animation-delay: 0.15s; }
.visible .talk-item:nth-child(6) { animation-delay: 0.18s; }
.visible .talk-item:nth-child(7) { animation-delay: 0.21s; }

/* --- Screen Reader Only --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 639px) {
  .nav-toggle {
    display: flex;
  }

  .nav-links {
    position: fixed;
    top: 0;
    right: -100%;
    width: 70%;
    max-width: 280px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    flex-direction: column;
    align-items: flex-start;
    padding: 4rem 1.5rem 2rem;
    gap: 1.25rem;
    border-left: 1px solid var(--border-light);
    transition: right 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 200;
  }

  .nav-links.open {
    right: 0;
  }

  .nav-links a {
    font-size: 0.9rem;
    text-transform: none;
    letter-spacing: 0.02em;
  }

  .hero-content {
    flex-direction: column-reverse;
    gap: 1.5rem;
  }

  .hero-photo {
    align-self: flex-start;
  }

  .hero-photo img {
    width: 110px;
    height: 110px;
    border-radius: 4px;
  }

  .hero {
    padding: 3rem 1.5rem 2.5rem;
  }

  .section {
    padding: 2.5rem 1.5rem;
  }

  .footer-inner {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  .footer-links {
    justify-content: center;
  }

  .hero-projects {
    flex-direction: column;
    gap: 0.25rem;
  }

  .hero-projects li:not(:last-child)::after {
    display: none;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .hero-photo img {
    width: 160px;
    height: 160px;
  }
}

@media (min-width: 1024px) {
  .hero {
    padding-top: 7rem;
  }

  .section {
    padding: 4.5rem 1.5rem;
  }
}
