/* ============================================================
   Base
   ============================================================ */

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

:root {
  --color-bg: #ffffff;
  --color-text: #111111;
  --color-muted: #999999;
  --color-border: #e8e8e8;
  --font: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --header-height: 52px;
  --page-padding: 32px;
}

html {
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  line-height: 1.5;
}

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

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

/* ============================================================
   Header
   ============================================================ */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--page-padding);
}

.site-header__inner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-name {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-name a {
  opacity: 1;
  transition: opacity 0.2s;
}

.site-name a:hover {
  opacity: 0.5;
}

/* Nav links in header */
.site-nav {
  display: flex;
  gap: 20px;
  align-items: center;
}

.site-nav__link {
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  transition: color 0.2s;
}

.site-nav__link:hover,
.site-nav__link--active {
  color: var(--color-text);
}

/* Project header — title + back link */
.project-header-title {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 200px);
}

.back-link {
  font-size: 13px;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 1;
  transition: opacity 0.2s;
}

.back-link:hover {
  opacity: 0.5;
}

.back-link svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ============================================================
   Page wrapper
   ============================================================ */

.page-content {
  padding-top: var(--header-height);
}

/* ============================================================
   Home — Project Grid
   ============================================================ */

.grid-section {
  padding: 48px var(--page-padding) 80px;
}

/* Category grouping */
.category-section {
  margin-bottom: 64px;
}

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

.category-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-muted);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 28px;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 40px 24px;
}

.project-card {
  display: block;
  cursor: pointer;
}

.project-card__image-wrap {
  position: relative;
  overflow: hidden;
  background: #f2f2f2;
  aspect-ratio: 4 / 3;
}

.project-card__image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              opacity 0.4s ease;
  opacity: 0;
}

.project-card__image-wrap img.loaded {
  opacity: 1;
}

.project-card:hover .project-card__image-wrap img {
  transform: scale(1.03);
}

.project-card__meta {
  margin-top: 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.project-card__title {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.project-card__year {
  font-size: 12px;
  color: var(--color-muted);
  flex-shrink: 0;
}

/* ============================================================
   Project Detail Page — horizontal scroll
   ============================================================ */

/* Lock body scroll on project page */
body.project-page {
  overflow: hidden;
}

body.project-page .page-content {
  padding-top: 0;                             /* cancel base padding-top */
  margin-top: var(--header-height);           /* push below fixed header instead */
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* The horizontal scroll strip */
.project-images {
  display: flex;
  flex-direction: row;
  align-items: flex-start; /* all images hang from the same top line */
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  cursor: grab;
  user-select: none;
}

.project-images::-webkit-scrollbar {
  display: none;
}

.project-images.is-dragging {
  cursor: grabbing;
}

/* Intro text panel — first item in scroll */
.project-intro-panel {
  flex-shrink: 0;
  align-self: stretch;   /* fill full height even with align-items: flex-start on parent */
  width: 300px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 32px 44px 40px;
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  scrollbar-width: none;       /* Firefox */
  -ms-overflow-style: none;    /* IE/Edge */
}

.project-intro-panel::-webkit-scrollbar {
  display: none;               /* Chrome/Safari */
}

.project-intro-panel__title {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.project-intro-panel__description {
  font-size: 12px;
  color: var(--color-muted);
  line-height: 1.65;
}

.project-intro-panel__description + .project-intro-panel__description {
  margin-top: 0.8em;
}

.project-text-item__body + .project-text-item__body {
  margin-top: 0.8em;
}

.project-intro-panel__year {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 16px;
  letter-spacing: 0.03em;
}

/* Each image */
.project-image {
  flex-shrink: 0;
  padding: 44px 20px 32px;
  cursor: zoom-in;
}

/* Inner wrapper: width is set by JS to exactly the rendered image width */
.project-image__inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.project-image img {
  display: block;
  height: 65vh;
  width: auto;
  max-width: 80vw;
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none; /* prevent drag interference */
}

.project-image img.loaded {
  opacity: 1;
}

/* Caption sits directly below the photo, constrained to image width by the inner wrapper */
.project-image__caption {
  margin-top: 10px;
  font-size: 11px;
  color: var(--color-muted);
  line-height: 1.5;
  word-break: break-word;
}

/* Inline text / heading item */
.project-text-item {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 280px;
  padding: 44px 36px 32px;
  cursor: default;
}

.project-text-item__heading {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.project-text-item__body {
  font-size: 13px;
  color: var(--color-muted);
  line-height: 1.75;
}

/* End panel — prev/next project */
.project-end-panel {
  flex-shrink: 0;
  align-self: stretch;   /* fill full height */
  width: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 0 44px;
  border-left: 1px solid var(--color-border);
}

.project-end-panel__link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  transition: opacity 0.2s;
}

.project-end-panel__link:hover {
  opacity: 0.5;
}

.project-end-panel__label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.project-end-panel__title {
  font-size: 13px;
}

.project-end-panel__divider {
  width: 24px;
  height: 1px;
  background: var(--color-border);
  margin: 6px 0;
}

/* Back links at bottom of end panel */
.project-end-panel__links {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-end-panel__back {
  font-size: 12px;
  color: var(--color-muted);
  transition: opacity 0.2s;
  display: inline-block;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
}

.project-end-panel__back:hover {
  opacity: 0.5;
}

/* ============================================================
   Loading / Empty states
   ============================================================ */

.placeholder {
  background: #f2f2f2;
  width: 100%;
  aspect-ratio: 4 / 3;
}

.loading-state {
  padding: 80px var(--page-padding);
  text-align: center;
  font-size: 13px;
  color: var(--color-muted);
}

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

.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 20px var(--page-padding);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-footer__copy {
  font-size: 12px;
  color: var(--color-muted);
}

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

@media (max-width: 900px) {
  :root {
    --page-padding: 24px;
  }

  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 32px 20px;
  }
}

@media (max-width: 600px) {
  :root {
    --page-padding: 16px;
    --header-height: 48px;
  }

  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px 12px;
  }

  .grid-section {
    padding-top: 32px;
    padding-bottom: 60px;
  }

  /* On mobile, project title in header is hidden (too long/overlapping) */
  .project-header-title {
    display: none;
  }

  /* ── Project page: switch to vertical stack on mobile ── */
  body.project-page {
    overflow: auto;
  }

  body.project-page .page-content {
    height: auto;
    overflow: visible;
  }

  .project-images {
    flex-direction: column;
    height: auto;
    overflow: visible;
    cursor: default;
  }

  .project-intro-panel {
    width: 100%;
    align-self: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    justify-content: flex-start;
    padding: 32px var(--page-padding) 28px;
  }

  /* Prevent overly wide titles from wrapping awkwardly */
  .project-intro-panel__title {
    font-size: 12px;
    letter-spacing: 0.04em;
    word-break: break-word;
    hyphens: auto;
  }

  .project-image {
    padding: 20px 0 24px;
    cursor: default;
  }

  .project-image__inner {
    width: 100% !important;
  }

  /* Subtle grey placeholder while image loads */
  .project-image img {
    height: auto;
    width: 100%;
    max-width: 100%;
    max-height: none;
    background: var(--color-border);
    min-height: 80px; /* prevents invisible zero-height gap */
    pointer-events: auto; /* allow long-press to save on mobile */
  }

  /* Remove background once loaded */
  .project-image img.loaded {
    background: transparent;
  }

  .project-image__caption {
    padding: 8px var(--page-padding) 0;
  }

  .project-text-item {
    width: 100%;
    border-bottom: 1px solid var(--color-border);
    padding: 28px var(--page-padding);
  }

  .project-end-panel {
    width: 100%;
    align-self: auto;
    border-left: none;
    border-top: 1px solid var(--color-border);
    flex-direction: row;
    flex-wrap: wrap;
    padding: 28px var(--page-padding);
    gap: 12px 32px;
  }

  .project-end-panel__links {
    width: 100%;
    flex-direction: row;
    gap: 16px;
    margin-top: 8px;
  }
}

@media (max-width: 380px) {
  .projects-grid {
    grid-template-columns: 1fr;
  }
}

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

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

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

/* Full clickable stage — click outside image to close */
.lightbox__stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 80px;
  cursor: zoom-out;
}

.lightbox__img {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: default;
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.18s ease, transform 0.18s ease;
  /* stop click from reaching the stage */
  pointer-events: all;
}

.lightbox__img.fading {
  opacity: 0;
  transform: scale(0.98);
}

/* Close button */
.lightbox__close {
  position: absolute;
  top: 16px;
  right: 20px;
  z-index: 20;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 22px;
  line-height: 1;
  padding: 8px;
  cursor: pointer;
  transition: color 0.15s;
}
.lightbox__close:hover { color: #fff; }

/* Prev / Next hit areas */
.lightbox__prev,
.lightbox__next {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 10;
  width: 80px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0 20px;
  transition: color 0.15s;
}
.lightbox__prev { left: 0;  justify-content: flex-start; }
.lightbox__next { right: 0; justify-content: flex-end; }
.lightbox__prev:hover,
.lightbox__next:hover { color: rgba(255, 255, 255, 0.8); }

.lightbox__prev svg,
.lightbox__next svg { width: 20px; height: 20px; }

/* Counter */
.lightbox__counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

/* ============================================================
   Scroll fade-in via IntersectionObserver
   ============================================================ */

.fade-in {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in.visible {
  opacity: 1;
  transform: none;
}
