/* ========================================
   Design Tokens
   ======================================== */

:root {
  /* Colors */
  --bg: #FAF9F6;
  --bg-warm: #F5F3EF;
  --text: #1A1A1A;
  --text-light: #6B6B6B;
  --text-lighter: #999;
  --accent: #C67D5B;
  --accent-light: #D4977A;
  --border: #E0DCD5;
  --border-light: #EBE8E3;

  /* Gallery placeholders */
  --gallery-placeholder-1: #E8E4DE;
  --gallery-placeholder-2: #DDD8D0;
  --gallery-placeholder-3: #D3CEC5;

  /* Favorites covers */
  --fav-cover-1: #E8E4DE;
  --fav-cover-2: #DDD8D0;
  --fav-cover-3: #D3CEC5;

  /* Typography */
  --font-serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --font-sans: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  /* Spacing */
  --nav-height: 60px;
  --page-pad: clamp(1.5rem, 5vw, 4rem);
  --content-max: 860px;
  --content-wide: 1080px;

  /* Animation */
  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-page: 400ms;
  --duration-element: 500ms;
  --stagger-delay: 80ms;
}


/* ========================================
   Reset & Base
   ======================================== */

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

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

body {
  font-family: var(--font-sans);
  font-weight: 400;
  color: var(--text);
  background-color: var(--bg);
  line-height: 1.7;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}


/* ========================================
   Scroll Background (Guohua)
   ======================================== */

.scroll-viewport {
  position: relative;
  overflow: hidden;
  height: calc(100vh - var(--nav-height));
  margin-top: var(--nav-height);
  background: url('boat.png') no-repeat left center / auto 100%;
  background-position-x: 0%;
  transition: background-position-x 500ms var(--ease-out);
}

.scroll-track {
  display: flex;
  width: max-content;
  height: 100%;
  transition: transform 500ms var(--ease-out);
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.3;
}


/* ========================================
   Utility
   ======================================== */

.text-link {
  color: var(--text);
  position: relative;
  display: inline-block;
}

.text-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 400ms var(--ease-out);
}

.text-link:hover::after,
.text-link:focus-visible::after {
  transform: scaleX(1);
}

.link-sep {
  color: var(--text-lighter);
  margin: 0 0.5rem;
  font-weight: 300;
}

.hand-drawn-divider {
  display: block;
  margin: 0.75rem 0 1.5rem;
  opacity: 0.6;
}


/* ========================================
   Navigation
   ======================================== */

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(250, 249, 246, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-light);
  z-index: 100;
  transition: box-shadow 300ms var(--ease-smooth);
}

.nav.scrolled {
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
}

.nav-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: 0 var(--page-pad);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text);
  flex-shrink: 0;
}

.nav-logo-sketch {
  opacity: 0.7;
  transition: opacity 300ms var(--ease-out);
}

.nav-logo:hover .nav-logo-sketch {
  opacity: 1;
}

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

.nav-link {
  font-size: 0.82rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  padding: 0.4rem 0.75rem;
  color: var(--text-light);
  position: relative;
  transition: color 300ms var(--ease-out);
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0.15rem;
  left: 0.75rem;
  right: 0.75rem;
  height: 1.5px;
  background: var(--accent);
  border-radius: 1px;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 350ms var(--ease-out);
}

.nav-link:hover,
.nav-link:focus-visible {
  color: var(--text);
}

.nav-link.active {
  color: var(--text);
  font-weight: 500;
}

.nav-link.active::after {
  transform: scaleX(1);
}

.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  color: var(--text);
}


/* ========================================
   Pages
   ======================================== */

.page {
  flex: 0 0 100vw;
  width: 100vw;
  height: 100%;
  overflow-y: auto;
  background: rgba(250, 249, 246, 0.65);
}

.page-content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: clamp(3rem, 8vh, 6rem) var(--page-pad) 4rem;
}

.page-header {
  margin-bottom: 3rem;
}

.page-title {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}


/* ========================================
   Stagger Animation
   ======================================== */

.stagger {
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity var(--duration-element) var(--ease-out),
    transform var(--duration-element) var(--ease-out);
}

.stagger.animate-in {
  opacity: 1;
  transform: translateY(0);
}


/* ========================================
   About Page
   ======================================== */

.about-hero {
  display: flex;
  align-items: center;
  gap: clamp(3rem, 6vw, 5rem);
  min-height: 70%;
}

.about-portrait {
  flex-shrink: 0;
}

.portrait-sketch {
  color: var(--text);
  opacity: 0.85;
}

.about-text {
  flex: 1;
  max-width: 480px;
}

.about-name {
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 0.4rem;
}

.about-tagline {
  font-family: var(--font-serif);
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-style: italic;
  color: var(--text-light);
  letter-spacing: 0.02em;
}

.about-bio {
  font-size: 0.95rem;
  color: var(--text-light);
  line-height: 1.8;
  margin-bottom: 1.5rem;
}

.about-links {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
}


/* ========================================
   Research Page
   ======================================== */

.research-entry {
  display: flex;
  gap: 2rem;
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--border-light);
}

.research-entry:first-child {
  padding-top: 0;
}

.research-entry:last-child {
  border-bottom: none;
}

.research-year {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-lighter);
  letter-spacing: 0.05em;
  flex-shrink: 0;
  width: 50px;
  padding-top: 0.15rem;
}

.research-body {
  flex: 1;
}

.research-title {
  font-size: 1.15rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  line-height: 1.4;
}

.research-venue {
  font-size: 0.85rem;
  color: var(--accent);
  font-style: italic;
  font-family: var(--font-serif);
  margin-bottom: 0.5rem;
}

.research-desc {
  font-size: 0.88rem;
  color: var(--text-light);
  line-height: 1.7;
}


/* ========================================
   Projects Page
   ======================================== */

.projects-page .page-content {
  max-width: var(--content-wide);
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.project-card {
  aspect-ratio: 1 / 1;
  padding: 2rem;
  border: 1px solid var(--border-light);
  background: rgba(250, 249, 246, 0.3);
  transition:
    border-color 400ms var(--ease-out),
    transform 400ms var(--ease-out),
    box-shadow 400ms var(--ease-out);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.project-card:hover {
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.project-icon {
  color: var(--text-light);
  margin-bottom: 1.25rem;
  transition: color 300ms var(--ease-out);
}

.project-card:hover .project-icon {
  color: var(--accent);
}

.project-title {
  font-size: 1.15rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.project-desc {
  font-size: 0.88rem;
  color: var(--text-light);
  line-height: 1.7;
}


/* ========================================
   Experience Page
   ======================================== */

.timeline {
  position: relative;
  padding-left: 2.5rem;
}

.timeline-line {
  position: absolute;
  top: 0.5rem;
  bottom: 0.5rem;
  left: 8px;
  width: 2px;
  background: var(--border-light);
}

.timeline-entry {
  position: relative;
  padding-bottom: 2.5rem;
}

.timeline-entry:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -2.5rem;
  top: 0.45rem;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  transform: translateX(-3px);
}

.timeline-dates {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-lighter);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.timeline-role {
  font-size: 1.15rem;
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.timeline-company {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.timeline-summary {
  font-size: 0.88rem;
  color: var(--text-light);
  line-height: 1.7;
}


/* ========================================
   Blog Page
   ======================================== */

.blog-entry {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border-light);
  transition: padding-left 300ms var(--ease-out);
}

.blog-entry:first-child {
  padding-top: 0;
}

.blog-entry:last-child {
  border-bottom: none;
}

.blog-entry:hover {
  padding-left: 0.5rem;
}

.blog-date {
  font-size: 0.8rem;
  color: var(--text-lighter);
  letter-spacing: 0.04em;
  flex-shrink: 0;
  width: 70px;
  padding-top: 0.2rem;
}

.blog-body {
  flex: 1;
}

.blog-title {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  line-height: 1.4;
  transition: color 300ms var(--ease-out);
}

.blog-entry:hover .blog-title {
  color: var(--accent);
}

.blog-excerpt {
  font-size: 0.88rem;
  color: var(--text-light);
  line-height: 1.7;
}

.blog-arrow {
  flex-shrink: 0;
  margin-top: 0.25rem;
  color: var(--text-lighter);
  transition: transform 300ms var(--ease-out), color 300ms var(--ease-out);
}

.blog-entry:hover .blog-arrow {
  transform: translateX(4px);
  color: var(--accent);
}


/* ========================================
   Gallery Page
   ======================================== */

.gallery-page .page-content {
  max-width: var(--content-wide);
}

.gallery-grid {
  columns: 3;
  column-gap: 1.25rem;
}

.gallery-item {
  break-inside: avoid;
  margin-bottom: 1.25rem;
  cursor: pointer;
  transition: transform 400ms var(--ease-out);
}

.gallery-item:hover {
  transform: scale(1.015);
}

.gallery-img {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.gallery-placeholder-svg {
  width: 50%;
  height: 50%;
  opacity: 0.3;
}

.gallery-caption {
  font-size: 0.78rem;
  color: var(--text-lighter);
  margin-top: 0.5rem;
  font-family: var(--font-serif);
  font-style: italic;
}


/* ========================================
   Lightbox
   ======================================== */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(26, 26, 26, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 300ms var(--ease-smooth);
  pointer-events: none;
}

.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  font-size: 2rem;
  color: rgba(255, 255, 255, 0.7);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 200ms;
  z-index: 10;
}

.lightbox-close:hover {
  color: #fff;
}

.lightbox-prev,
.lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.6);
  padding: 1rem;
  transition: color 200ms;
  z-index: 10;
}

.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

.lightbox-prev:hover,
.lightbox-next:hover {
  color: #fff;
}

.lightbox-content {
  max-width: 80vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lightbox-img {
  max-width: 100%;
  max-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-warm);
  min-width: 300px;
  min-height: 200px;
  padding: 2rem;
}

.lightbox-caption {
  color: rgba(255, 255, 255, 0.7);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.9rem;
  margin-top: 1rem;
}


/* ========================================
   Favorites Page
   ======================================== */

.favorites-section {
  margin-bottom: 3rem;
}

.favorites-section:last-child {
  margin-bottom: 0;
}

.favorites-category {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  letter-spacing: 0.01em;
}

.favorites-row {
  display: flex;
  gap: 1.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.favorites-row::-webkit-scrollbar {
  height: 4px;
}

.favorites-row::-webkit-scrollbar-track {
  background: transparent;
}

.favorites-row::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.favorite-item {
  flex-shrink: 0;
  width: 120px;
}

.favorite-cover {
  width: 120px;
  aspect-ratio: 2/3;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 400ms var(--ease-out);
  overflow: hidden;
}

.favorite-cover-landscape {
  aspect-ratio: 3/2;
}

.favorite-item:hover .favorite-cover {
  transform: translateY(-3px);
}

.favorite-placeholder-svg {
  width: 60%;
  height: 60%;
  opacity: 0.3;
}

.favorite-title {
  display: block;
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.5rem;
  line-height: 1.4;
}


/* ========================================
   Contact Page
   ======================================== */

.contact-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80%;
}

.contact-centered {
  text-align: center;
  max-width: 400px;
}

.contact-illustration {
  color: var(--text);
  opacity: 0.6;
  margin-bottom: 1.5rem;
}

.contact-centered .page-title {
  margin-bottom: 0;
}

.contact-centered .hand-drawn-divider {
  margin-left: auto;
  margin-right: auto;
}

.contact-text {
  font-size: 0.95rem;
  color: var(--text-light);
  line-height: 1.8;
  margin-bottom: 1.5rem;
}

.contact-links {
  margin-bottom: 1rem;
}

.contact-links .text-link {
  font-size: 1rem;
  font-weight: 500;
}

.contact-social {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-size: 0.85rem;
}

.social-link {
  color: var(--text-light);
  transition: color 300ms var(--ease-out);
}

.social-link:hover {
  color: var(--accent);
}


/* ========================================
   Footer
   ======================================== */

.footer {
  text-align: center;
  padding: 2rem var(--page-pad);
  font-size: 0.78rem;
  color: var(--text-lighter);
  letter-spacing: 0.03em;
  border-top: 1px solid var(--border-light);
}


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

@media (max-width: 768px) {
  :root {
    --nav-height: 56px;
  }

  .nav-toggle {
    display: flex;
  }

  .nav-links {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: rgba(250, 249, 246, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-direction: column;
    align-items: stretch;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition:
      transform 350ms var(--ease-out),
      opacity 350ms var(--ease-out);
  }

  .nav-links.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .nav-link {
    padding: 0.75rem var(--page-pad);
    font-size: 0.9rem;
  }

  .nav-link::after {
    left: var(--page-pad);
    right: auto;
    width: 24px;
    bottom: 0.5rem;
  }

  /* About */
  .about-hero {
    flex-direction: column;
    text-align: center;
    gap: 2rem;
    min-height: auto;
    padding-top: 2rem;
  }

  .about-text {
    max-width: 100%;
  }

  .about-text .hand-drawn-divider {
    margin-left: auto;
    margin-right: auto;
  }

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

  .portrait-sketch {
    width: 160px;
    height: auto;
  }

  /* Research */
  .research-entry {
    flex-direction: column;
    gap: 0.25rem;
  }

  .research-year {
    width: auto;
  }

  /* Projects */
  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Blog */
  .blog-entry {
    flex-direction: column;
    gap: 0.25rem;
  }

  .blog-date {
    width: auto;
  }

  .blog-arrow {
    display: none;
  }

  /* Gallery */
  .gallery-grid {
    columns: 2;
    column-gap: 0.75rem;
  }

  .gallery-item {
    margin-bottom: 0.75rem;
  }

  /* Favorites */
  .favorite-item {
    width: 100px;
  }

  .favorite-cover {
    width: 100px;
  }

  /* Lightbox */
  .lightbox-prev { left: 0.5rem; }
  .lightbox-next { right: 0.5rem; }
  .lightbox-content { max-width: 92vw; }
}

@media (max-width: 480px) {
  .gallery-grid {
    columns: 1;
  }

  .about-name {
    font-size: 2rem;
  }

  .project-card {
    padding: 1.5rem;
  }

  .timeline {
    padding-left: 2rem;
  }

  .timeline-dot {
    left: -2rem;
  }
}


/* ========================================
   Focus Styles
   ======================================== */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a:focus:not(:focus-visible),
button:focus:not(:focus-visible) {
  outline: none;
}


/* ========================================
   Reduced Motion
   ======================================== */

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

  .page {
    transform: none;
  }

  .stagger {
    opacity: 1;
    transform: none;
  }
}
