/* ===== CSS Variables ===== */
:root {
  --color-bg: #fafaf8;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-secondary: #6b6b6b;
  --color-text-muted: #999;
  --color-border: #e8e6e2;
  --color-accent: #2a2a2a;
  --color-hover: #f5f3ef;
  --color-overlay: rgba(0,0,0,0.85);

  --font-serif: Georgia, "Songti SC", "STSong", "Noto Serif SC", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;

  --header-height: 68px;
  --max-width: 1600px;
  --gallery-gap: 40px;
  --transition: 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-slow: 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
  --radius: 2px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

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

img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

.hidden { display: none !important; }

/* ===== Page Loader ===== */
.page-loader {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.page-loader.loaded { opacity: 0; visibility: hidden; }
.loader-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Header ===== */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(250, 250, 248, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  z-index: 1000;
  transition: var(--transition);
}
.site-header.scrolled {
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  height: 100%;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

/* Logo */
.logo {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: opacity var(--transition);
}
.logo:hover { opacity: 0.7; }

/* Navigation */
.main-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.nav-link {
  position: relative;
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-secondary);
  letter-spacing: 0.03em;
  transition: color var(--transition);
  white-space: nowrap;
}
.nav-link:hover, .nav-link.active {
  color: var(--color-text);
}
.nav-link::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 14px;
  right: 14px;
  height: 1px;
  background: var(--color-text);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition);
}
.nav-link:hover::after, .nav-link.active::after {
  transform: scaleX(1);
}

/* Dropdown */
.dropdown { position: relative; }
.dropdown-toggle { display: flex; align-items: center; gap: 6px; }
.dropdown-arrow { transition: transform var(--transition); }
.dropdown.open .dropdown-arrow { transform: rotate(180deg); }

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  min-width: 240px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 8px 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
  z-index: 100;
}
.dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 20px;
  font-size: 0.85rem;
  text-align: left;
  color: var(--color-text-secondary);
  transition: all var(--transition);
  border-left: 2px solid transparent;
}
.dropdown-item:hover {
  color: var(--color-text);
  background: var(--color-hover);
  border-left-color: var(--color-text);
}
.dropdown-item.active {
  color: var(--color-text);
  font-weight: 500;
  border-left-color: var(--color-text);
}
.dropdown-item-tag {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin-left: 6px;
  font-style: italic;
}

/* Mobile Menu Button */
.mobile-menu-btn {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
}
.mobile-menu-btn span {
  width: 20px;
  height: 1.5px;
  background: var(--color-text);
  transition: var(--transition);
}

/* ===== Main Content ===== */
.main-content {
  min-height: calc(100vh - var(--header-height) - 60px);
  padding-top: var(--header-height);
}

.view {
  display: none;
  opacity: 0;
  animation: fadeInUp 0.5s ease forwards;
}
.view.active {
  display: block;
}

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

/* ===== Gallery View ===== */
.gallery-view {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 48px 32px 64px;
}

.project-header {
  margin-bottom: 40px;
  max-width: 800px;
}
.project-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  margin-bottom: 12px;
  color: var(--color-text);
}
.project-description {
  font-size: 0.875rem;
  line-height: 1.8;
  color: var(--color-text-secondary);
  max-width: 600px;
}

/* Gallery — Masonry (waterfall) layout.
   Items are absolutely positioned & translated by app.js layoutMasonry().
   Column count / widths / offsets are computed from the container width. */
.gallery {
  position: relative;
  min-height: 240px;
}

.gallery-item {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  opacity: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--color-hover);
  cursor: pointer;
  will-change: transform, opacity;
  transition: opacity 0.6s ease, transform 0.45s cubic-bezier(0.22, 0.61, 0.36, 1), box-shadow var(--transition);
}
.gallery-item.positioned {
  opacity: 1;
}
.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform var(--transition-slow), filter var(--transition);
}
.gallery-item:hover {
  box-shadow: var(--shadow-md);
}
.gallery-item:hover img {
  transform: scale(1.02);
}
.gallery-item::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--color-overlay);
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}
.gallery-item:hover::after { opacity: 0.08; }

/* Image size semantics (masonry):
   full   → spans all columns (hero row)
   large  → spans two columns
   medium / small / third / half → single column
   Actual widths & positions are set by JS. */

.gallery-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ===== Cover (homepage full-width waterfall) =====
   3-column waterfall that fills the entire container width.
   Items are absolutely positioned by layoutCover() in app.js.
   Each item's width varies (65%–100% of column) for visual rhythm;
   heights follow natural aspect ratios. */
.cover {
  position: relative;
  width: 100%;
  margin: 0 auto;
  padding: 40px 0 80px;
}

.cover-item {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  cursor: pointer;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--color-hover);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transition: opacity 0.6s ease, box-shadow var(--transition);
}
.cover-item.positioned { opacity: 1; }
.cover-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.cover-item:hover { box-shadow: var(--shadow-md); }
.cover-item:hover img { transform: scale(1.02); }

/* ===== Slider Layout (single image per project) ===== */
.slider-view { padding-bottom: 32px; }
.slider-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}
.slider-frame {
  position: relative;
  display: inline-flex;
  max-width: 100%;
}
.slider-img {
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: zoom-in;
  transition: opacity 0.35s ease;
}
/* Project text block pinned to the image's bottom-left corner */
.slider-text {
  position: absolute;
  left: 0;
  bottom: 0;
  max-width: 78%;
  padding: 56px 32px 24px 28px;
  border-radius: 0 0 0 var(--radius);
  background: linear-gradient(to top, rgba(0,0,0,0.62) 0%, rgba(0,0,0,0.28) 55%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}
.slider-text .project-title {
  color: #fff;
  font-size: 1.4rem;
  margin-bottom: 8px;
}
.slider-text .project-description {
  color: rgba(255,255,255,0.82);
  font-size: 0.8rem;
  line-height: 1.7;
  max-width: 460px;
}
.slider-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  line-height: 1;
  color: var(--color-text-secondary);
  border-radius: 50%;
  transition: color var(--transition), background var(--transition);
  z-index: 5;
}
.slider-arrow:hover {
  color: var(--color-text);
  background: var(--color-hover);
}
.slider-arrow-prev { left: 4px; }
.slider-arrow-next { right: 4px; }
.slider-meta {
  margin-top: 20px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* ===== About View ===== */
.about-view {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 64px 32px;
}

.about-container {
  display: flex;
  gap: 64px;
  align-items: flex-start;
  max-width: 1000px;
}

.avatar-frame {
  position: relative;
  flex-shrink: 0;
  width: 320px;
  height: 320px;
}
.avatar-ring {
  position: absolute;
  inset: -12px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  transition: transform var(--transition-slow);
}
.avatar-frame:hover .avatar-ring {
  transform: scale(1.03);
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  filter: grayscale(0.15);
  transition: filter var(--transition-slow);
}
.avatar-frame:hover .avatar-img {
  filter: grayscale(0);
}

.bio-content {
  flex: 1;
  padding-top: 20px;
}
.artist-name {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  margin-bottom: 4px;
}
.artist-title {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 24px;
}
.bio-text {
  font-size: 0.9375rem;
  line-height: 1.9;
  color: var(--color-text-secondary);
  max-width: 560px;
}

/* ===== Contact View ===== */
.contact-view {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 64px 32px;
}

.contact-container {
  max-width: 600px;
}

.contact-heading {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 400;
  margin-bottom: 40px;
}

.contact-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.contact-item {
  display: flex;
  align-items: baseline;
  gap: 24px;
  padding: 16px 0;
  border-bottom: 1px solid var(--color-border);
}
.contact-item:last-child { border-bottom: none; }

.contact-label {
  flex-shrink: 0;
  width: 100px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}
.contact-value {
  font-size: 0.9375rem;
  color: var(--color-text);
  word-break: break-all;
}
.contact-value a:hover { text-decoration: underline; }

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 20px 32px;
  background: var(--color-surface);
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  text-align: center;
}
.copyright {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  letter-spacing: 0.03em;
}

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.96);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.lightbox.open {
  display: flex;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.lightbox-content {
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.lightbox-img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 2px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: scaleIn 0.3s ease;
}
@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.lightbox-caption {
  color: rgba(255,255,255,0.6);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  color: rgba(255,255,255,0.7);
  font-size: 2rem;
  transition: color var(--transition), transform var(--transition);
  padding: 12px;
  z-index: 10;
}
.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  color: #fff;
}
.lightbox-close { top: 20px; right: 30px; font-size: 2.5rem; line-height: 1; }
.lightbox-prev { left: 20px; top: 50%; transform: translateY(-50%); font-size: 2.5rem; }
.lightbox-next { right: 20px; top: 50%; transform: translateY(-50%); font-size: 2.5rem; }
.lightbox-prev:hover { transform: translateY(-50%) scale(1.15); }
.lightbox-next:hover { transform: translateY(-50%) scale(1.15); }

/* ===== Responsive ===== */
/* Masonry column counts are computed in JS from container width:
   ≥1000px → 3 columns, 640–999px → 2 columns, <640px → 1 column. */
@media (max-width: 1024px) {
  .gallery-item { transition: opacity 0.6s ease, box-shadow var(--transition); }
}

@media (max-width: 768px) {
  :root { --header-height: 60px; }

  .header-inner { padding: 0 20px; }

  .main-nav {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 16px;
    gap: 0;
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
  }
  .main-nav.open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }
  .nav-link {
    width: 100%;
    text-align: left;
    padding: 14px 16px;
    font-size: 1rem;
    border-bottom: 1px solid var(--color-border);
  }
  .nav-link::after { display: none; }

  .dropdown-menu {
    position: static;
    transform: none;
    opacity: 1;
    visibility: visible;
    box-shadow: none;
    border: none;
    padding: 0 0 0 20px;
  }
  .dropdown.open .dropdown-menu {
    transform: none;
  }

  .mobile-menu-btn { display: flex; }
  .mobile-menu-btn.open span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
  .mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
  .mobile-menu-btn.open span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

  .gallery-view { padding: 32px 20px 48px; }

  /* Cover is JS-positioned; layoutCover() keeps 2 staggered columns on
     mobile with a full-width hero image every 3rd slot. */
  .cover { padding: 24px 0 56px; }

  .slider-img { max-height: 58vh; }
  .slider-arrow { width: 40px; height: 40px; font-size: 1.6rem; }
  .slider-text { padding: 44px 18px 16px 16px; max-width: 92%; }
  .slider-text .project-title { font-size: 1.15rem; }
  .slider-meta { margin-top: 20px; }

  .about-container {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 32px;
  }
  .avatar-frame { width: 200px; height: 200px; }
  .bio-content { padding-top: 0; }
  .bio-text { margin: 0 auto; }

  .contact-view { padding: 40px 20px; }

  .lightbox { padding: 20px; }
  .lightbox-close { top: 10px; right: 15px; font-size: 2rem; }
  .lightbox-prev, .lightbox-next { font-size: 1.8rem; }
}

@media (max-width: 480px) {
  .project-title { font-size: 1.4rem; }
}
