/* ==========================================================================
   Sheng Zha — Personal Homepage
   Modern Minimal design. Navy, white, camel, black, gray, olive palette.
   ========================================================================== */

/* --- Custom Properties --- */
:root {
  --bg: #FAFAFA;
  --bg-card: #FFFFFF;
  --text: #1C2541;
  --text-heading: #111111;
  --text-secondary: #6B7280;
  --accent: #C4A77D;
  --accent-hover: #A8895F;
  --accent-secondary: #5B6B4A;
  --border: #E5E5E5;
  --rule: #1C2541;
  --nav-bg: rgba(250, 250, 250, 0.85);
  --font-heading: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0D1B2A;
  --bg-card: #162638;
  --text: #F5F5F5;
  --text-heading: #FFFFFF;
  --text-secondary: #9CA3AF;
  --accent: #D4B896;
  --accent-hover: #E0CAA8;
  --accent-secondary: #8FA87E;
  --border: #2A3F55;
  --rule: #3B5068;
  --nav-bg: rgba(13, 27, 42, 0.85);
}

/* --- 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.7;
  color: var(--text);
  background-color: var(--bg);
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

@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.2;
  font-weight: 700;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.25rem);
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  margin-bottom: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

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

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

p {
  margin-bottom: 1rem;
}

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

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

.section-rule {
  max-width: 48rem;
  margin: 0 auto;
  border: none;
  border-top: 2px solid var(--rule);
  opacity: 0.2;
}

/* --- Navigation --- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s 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: 700;
  font-size: 1.05rem;
  color: var(--text-heading);
  letter-spacing: -0.01em;
}

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

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

.nav-links a {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: color 0.2s ease;
}

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

.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(7px) rotate(45deg);
}

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

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

/* --- Theme Toggle --- */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  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: 34px;
  min-height: 34px;
}

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

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

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

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

.hero-text {
  flex: 1;
}

.hero-tagline {
  font-size: clamp(1.05rem, 2.5vw, 1.2rem);
  color: var(--text);
  margin: 0.75rem 0 1rem;
  line-height: 1.6;
  font-weight: 500;
}

.hero-roles {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 1.5rem;
}

.hero-roles li {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

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

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

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

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

.hero-photo img {
  width: 200px;
  height: 200px;
  border-radius: 12px;
  object-fit: cover;
}

.photo-placeholder {
  width: 200px;
  height: 200px;
  border-radius: 12px;
  background: var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FAFAFA;
  font-family: var(--font-heading);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

[data-theme="dark"] .photo-placeholder {
  background: #2A3F55;
}

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

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

.built-item {
  padding: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s ease;
}

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

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

.built-role {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.built-item p:last-child {
  color: var(--text-secondary);
  font-size: 0.925rem;
}

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

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

.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);
}

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

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

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

.section-link a {
  font-size: 0.925rem;
  font-weight: 500;
}

.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: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.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-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

/* --- Open Source --- */
.os-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.os-card {
  display: block;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s ease;
  color: var(--text);
}

.os-card:hover {
  border-color: var(--accent);
  color: var(--text);
}

.os-card h3 {
  color: var(--text-heading);
  margin-bottom: 0.15rem;
}

.os-role {
  font-size: 0.8rem;
  color: var(--accent-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}

.os-card p:last-of-type {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.os-stars {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

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

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

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

.footer-links a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

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

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

/* --- Scroll Animations --- */
.section, .hero {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

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

/* --- 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
   ========================================================================== */

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

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

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

  .nav-links a {
    font-size: 1rem;
  }

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

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

  .photo-placeholder,
  .hero-photo img {
    width: 120px;
    height: 120px;
    font-size: 1.75rem;
  }

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

  .section {
    padding: 2rem 1.5rem;
  }

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

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

  .os-grid {
    grid-template-columns: 1fr;
  }
}

/* Tablet */
@media (min-width: 640px) and (max-width: 1023px) {
  .os-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .photo-placeholder,
  .hero-photo img {
    width: 160px;
    height: 160px;
  }
}

/* Desktop enhancements */
@media (min-width: 1024px) {
  .hero {
    padding-top: 5rem;
  }

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