/* CSS Custom Properties */
:root {
  --panel-height: 37vh;
  --expanded-bottom: calc(37vh + 20px);
  --ease: cubic-bezier(0.51, 0.00, 0.50, 1.00);
  --dur: 800ms;
  --dur-fast: 400ms;
  --font-ui: 21px;
}

/* Custom Font */
@font-face {
  font-family: 'ABC Favorit';
  src: url('fonts/ABCFavorit-Medium.otf') format('opentype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'ABC Favorit';
  src: url('fonts/ABCFavorit-Light.otf') format('opentype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

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

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: 'ABC Favorit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f3f3f3;
  touch-action: none;
  user-select: none;
  overscroll-behavior: none;
  font-size: var(--font-ui);
}

html {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

/* Suppress tap highlight and focus outlines everywhere */
*, *::before, *::after {
  -webkit-tap-highlight-color: transparent;
}

/* Suppress focus outline on custom interactive elements */
.tab-button:focus-visible,
.detail-close:focus-visible,
.more-info-button:focus-visible,
.tile:focus-visible,
.project-title:focus-visible,
.project-image-item:focus-visible {
  outline: none;
}

#grid-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  will-change: transform;
  overflow: visible;
  transform-origin: center center;
}

#grid-container.dragging {
  cursor: grabbing;
}

/* Grid effects when zoomed into detail mode */
#grid-container.grid--zoomed {
  pointer-events: none;
}

.tile {
  position: absolute;
  width: 290px;
  height: 220px;
  overflow: hidden;
  will-change: transform;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Only enable tile clicks when grid container is active */
#grid-container.active .tile {
  pointer-events: auto;
}

/* Tile being animated during FLIP */
.tile--animating {
  pointer-events: none;
}

/* Tiles being scattered away */
.tile--scattering {
  transition: transform var(--dur) var(--ease);
}

.tile--scattering.scatter-out {
  transition: transform var(--dur) var(--ease),
              opacity 0.3s var(--ease) 0.5s;
  opacity: 0;
}

.tile img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
}

/* ============================================
   DETAIL VIEW OVERLAY
   ============================================ */
#detail-view {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh; /* dvh = dynamic viewport height, accounts for mobile URL bar */
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  background: #f3f3f3;
  overflow: hidden;
}

#detail-view.active {
  opacity: 1;
  pointer-events: auto;
}

/* Top bar — mirrors the bottom bar, solid background behind × and tabs */
#detail-view::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 70px;
  background: #f3f3f3;
  z-index: 1003;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

#detail-view.active::before {
  opacity: 1;
}

.detail-content {
  width: 100%;
  height: 100%;
  position: relative;
  padding: 0;
  overflow: visible;  /* Must be visible for 3D perspective to work */
  perspective: 1200px;
  perspective-origin: center center;
}

/* Close button — × centered in click target, aligned with tab text */
.detail-close {
  position: fixed;
  /* Align × center with tab text center: tabs at top:30px, font 21px → center ~40.5px; box 48px → top = 40.5-24 = 16.5 */
  top: 16px;
  left: 8px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  padding: 0;
  margin: 0;
  border: none;
  color: black;
  cursor: pointer;
  z-index: 1004;
  font-size: calc(var(--font-ui) * 1.3);
  line-height: 1;
  font-weight: 500;
  transition: transform var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
  font-family: 'ABC Favorit', sans-serif;
  transform: translateX(-100px);
  opacity: 0;
  pointer-events: auto;
}

#detail-view.active .detail-close {
  transform: translateX(0);
  opacity: 1;
}

.detail-close:hover {
  opacity: 0.6;
}

.detail-close:focus {
  outline: none;
}

.detail-close::before {
  content: '×';
}


/* ============================================
   3D CAROUSEL
   ============================================ */

/* Carousel container with 3D transforms */
/* NOTE: Must be position:absolute (not fixed) to inherit perspective from #detail-view */
.carousel-container {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
  pointer-events: none;
}

/* Base carousel item - size set by JavaScript based on viewport */
.carousel-item {
  position: absolute;
  top: 50%;
  left: 50%;
  overflow: hidden;
  transition: transform var(--dur-fast) var(--ease);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Only enable pointer events when detail view is active */
#detail-view.active .carousel-item {
  pointer-events: auto;
}

.carousel-item img {
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  object-position: center;
}

/* Portrait carousel items - height-constrained instead of width-constrained */
.carousel-item--portrait img {
  max-width: none;
  width: auto;
  max-height: 100%;
  height: 100%;
}

/* Exit animations when switching to Work or Grid view */
.detail-view--exiting-up .carousel-item {
  transition: transform var(--dur) var(--ease);
}

/* Center item exits up, side items exit to sides */
.detail-view--exiting-up .carousel-item[data-position="0"] {
  transform: translate(-50%, -50%) translate3d(0, -150vh, 0) !important;
}

.detail-view--exiting-up .carousel-item[data-position="-1"],
.detail-view--exiting-up .carousel-item[data-position="-2"] {
  transform: translate(-50%, -50%) translate3d(-150vw, 0, 0) !important;
}

.detail-view--exiting-up .carousel-item[data-position="1"],
.detail-view--exiting-up .carousel-item[data-position="2"] {
  transform: translate(-50%, -50%) translate3d(150vw, 0, 0) !important;
}

/* FLIP animation element - temporary clone for smooth transition */
.flip-clone {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flip-clone img {
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  object-position: center;
}

/* Portrait FLIP clone styling */
.flip-clone.portrait img {
  max-width: none;
  width: auto;
  max-height: 100%;
  height: 100%;
  object-fit: contain;
}

/* Video iframe overlay on carousel item */
.carousel-video-iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: none;
  z-index: 1;
  pointer-events: auto;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.15s ease-in;
}

/* Navigation click areas */
.nav-area {
  position: fixed;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 998;
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
}

.nav-area-left {
  left: 0;
  cursor: w-resize;
}

.nav-area-right {
  right: 0;
  cursor: e-resize;
}

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

/* ============================================
   BOTTOM BAR: Wrapper for controls + info panel
   Moves as ONE unit for expand/collapse.
   Layout (top to bottom): controls → gap → panel.
   Default: translated down so panel hides below viewport.
   Expanded: translated to 0 so panel is visible.
   ============================================ */
.detail-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  pointer-events: none;
  transition: transform var(--dur-fast) var(--ease);
  /* Default: push down by panel height so only controls + gap are in viewport */
  transform: translateY(var(--panel-height));
  background: #f3f3f3;
}

.detail-view--expanded .detail-bottom-bar {
  transform: translateY(0);
}

/* Controls row: button, title, counter */
.bottom-bar-controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  height: 30px;
  /* Gap = distance from viewport bottom when collapsed (matches top nav 30px) */
  margin-bottom: 30px;
  pointer-events: auto;
}

/* Image counter - right side of controls row */
.image-counter {
  background: transparent;
  color: black;
  padding: 0;
  border: none;
  font-size: var(--font-ui);
  font-weight: 400;
  pointer-events: none;
  line-height: 1;
  text-transform: uppercase;
  transform: translateX(100px);
  opacity: 0;
  transition: transform var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#detail-view.active .image-counter {
  transform: translateX(0);
  opacity: 1;
}

/* Reduced motion: simpler transitions */
@media (prefers-reduced-motion: reduce) {
  #grid-container {
    transition: opacity var(--dur) var(--ease);
  }

  .flip-clone {
    transition: opacity var(--dur) var(--ease) !important;
  }
}

/* ============================================
   MORE INFO FEATURE STYLES
   ============================================ */

/* Project title - center of controls row */
.detail-project-title {
  flex: 1;
  min-width: 0;
  transform: translateY(100px);
  font-size: var(--font-ui);
  font-weight: 400;
  color: black;
  margin: 0;
  padding: 0 10px;
  border: none;
  transition: transform var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
  line-height: 1.2;
  opacity: 0;
  text-transform: uppercase;
  text-align: center;
  box-sizing: border-box;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  hyphens: none;
  pointer-events: none;
}

#detail-view.active .detail-project-title {
  transform: translateY(0);
  opacity: 1;
}

/* More Info button - left side of controls row */
.more-info-button {
  transform: translateX(-100px);
  padding: 0;
  background: transparent;
  color: black;
  border: none;
  font-size: var(--font-ui);
  font-weight: 400;
  cursor: pointer;
  display: flex;
  text-transform: uppercase;
  align-items: center;
  gap: 8px;
  transition: transform var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
  line-height: 1;
  opacity: 0;
  font-family: 'ABC Favorit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 30px;
  flex-shrink: 0;
}

#detail-view.active .more-info-button {
  transform: translateX(0);
  opacity: 1;
}

.more-info-button:hover {
  opacity: 0.6;
}

.more-info-icon {
  display: inline-block;
  font-size: var(--font-ui);
  transition: transform var(--dur) var(--ease);
}

/* Info panel - sits below controls in the bottom bar */
.detail-info-panel {
  width: 100%;
  height: var(--panel-height);
  background: transparent;
  padding: 33px 80px 80px;
  overflow: hidden;
  pointer-events: auto;
}

.detail-info-content {
  max-width: 400px;
  margin: 0 auto;
  text-align: center;
}

.info-section {
  margin-bottom: 0;
}

.info-section-text {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: black;
  margin: 0;
}

.info-credits-list {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: center;
}

.info-credits-list li {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: black;
}

.info-tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.info-tag {
  padding: 0;
  background: transparent;
  border-radius: 0;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: black;
}

/* Expanded state - the entire bottom bar slides up as one unit (handled by .detail-bottom-bar rule above) */

/* ============================================
   VIEW TABS NAVIGATION
   ============================================ */
.view-tabs {
  position: fixed;
  top: 30px;
  right: 40px;
  display: flex;
  gap: 20px;
  z-index: 1004;
  background: transparent;
  padding: 0;
  font-family: 'ABC Favorit', sans-serif;
}

/* Mobile L and below - centered tabs */
@media (max-width: 685px) {
  .view-tabs {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

.tab-button {
  padding: 0 4px;
  background: transparent;
  border: none;
  font-size: var(--font-ui);
  cursor: pointer;
  color: black;
  font-family: inherit;
  text-decoration: none;
  position: relative;
  text-transform: uppercase;
  overflow: visible;
}

.tab-button:hover {
  font-style: italic;
}

.tab-button.active:hover {
  font-style: normal;
}

.tab-button.active {
  text-decoration: none;
}

.tab-button.active::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  top: 50%;
  height: 3px;
  background-color: black;
  transform: translateY(-50%) scaleX(0);
  transform-origin: left center;
  pointer-events: none;
  animation: drawLine var(--dur) var(--ease) forwards;
}

@keyframes drawLine {
  from {
    transform: translateY(-50%) scaleX(0);
  }
  to {
    transform: translateY(-50%) scaleX(1);
  }
}

/* ============================================
   VIEW CONTAINER MANAGEMENT
   ============================================ */
.view-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
  overflow: hidden;
}

.view-container.active {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   BIO (Top Left - Global Element)
   ============================================ */

.bio {
  position: fixed;
  top: 30px;
  left: 30px;
  z-index: 1004;
  max-width: 280px;
  transform: translateX(0);
  opacity: 1;
  transition: transform var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
}

/* Mobile L and below - hide bio */
@media (max-width: 685px) {
  .bio {
    display: none;
  }
}

.bio p {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

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

.bio a:hover {
  text-decoration: underline;
}

/* Hide bio when detail mode is active (scatters with grid) */
.bio.hidden {
  transform: translateX(-100%);
  opacity: 0;
}

/* ============================================
   INFO VIEW CAROUSEL
   ============================================ */
#info-container {
  background: #f3f3f3;
}

.info-carousel {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  cursor: grab;
  perspective: 1200px;
  perspective-origin: 50% 50%;
  transform-style: preserve-3d;
}

.info-carousel.dragging {
  cursor: grabbing;
}

.info-slide {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60vw;
  margin-left: -30vw;
  height: 80vh;
  margin-top: -40vh;
  background: #f3f3f3;
  color: #000000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  will-change: transform;
  pointer-events: none;
  padding: 60px;
}

.info-slide-content {
  width: 100%;
  max-width: 380px;
  text-align: left;
}

.info-slide-content h2 {
  font-size: var(--font-ui);
  font-weight: 400;
  margin: 0 0 20px 0;
  text-transform: none;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.info-slide-content p {
  font-size: var(--font-ui);
  font-weight: 400;
  line-height: 1.3;
  margin: 0 0 10px 0;
  letter-spacing: -0.02em;
  text-align: justify;
  text-align-last: left;
}

.info-slide-content p:last-child {
  margin-bottom: 0;
}

.info-slide-content ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.info-slide-content ul li {
  font-size: var(--font-ui);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin: 0;
}

.info-slide-content .brands-intro {
  margin-bottom: 10px;
}

.info-slide-content .brands-list {
  columns: 1;
}

.info-slide-content .brands-list li {
  margin-bottom: 5px;
}

.info-counter {
  position: fixed;
  bottom: 30px;
  right: 40px;
  background: transparent;
  color: black;
  padding: 0;
  font-size: var(--font-ui);
  font-weight: 400;
  z-index: 100;
  pointer-events: none;
  line-height: 1;
  opacity: 0;
  transform: translateX(100px);
  transition: transform var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
}

#info-container.active .info-counter {
  opacity: 1;
  transform: translateX(0);
}

/* Hide bio on Info page */
#info-container.active ~ .bio {
  transform: translateX(-100%);
  opacity: 0;
}

/* ============================================
   LIST VIEW
   ============================================ */
#list-container {
  width: 100%;
  height: 100vh;
  overflow: hidden; /* No scrollbars, use panning instead */
  background: #f3f3f3;
  position: relative;
  cursor: grab;
}

#list-container-inner {
  position: absolute;
  padding: 160px 60px 40px 60px;
  width: 100%;
  will-change: transform;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  transform-origin: center top;
}

.project-section {
  margin-bottom: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 1200px;
  width: 100%;
}

.project-section:last-child {
  margin-bottom: 0;  /* Remove margin from last section to prevent excess scroll */
}

.project-title {
  font-size: var(--font-ui);
  font-weight: 400;
  margin-bottom: 30px;
  color: black;
  transform: translate3d(0, 0, 0); /* Initial transform for animation */
  text-align: center;
  width: 100%;
  text-transform: uppercase;
  cursor: pointer;
  transition: font-style 200ms ease;
}

.project-title:hover {
  font-style: italic;
}

.project-images-grid {
  display: grid;
  grid-template-columns: repeat(5, 220px);
  grid-auto-flow: row;
  gap: 30px;
  max-width: fit-content;
  width: 100%;
  justify-content: center;
  align-items: start;
  position: relative;
  margin: 0 auto;
}

.project-image-item {
  width: 220px;
  height: auto;
  overflow: hidden;
  cursor: pointer;
  transform: translate3d(0, 0, 0);
  transition: width var(--dur) var(--ease),
              height var(--dur) var(--ease),
              transform var(--dur) var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
}

.project-image-item img {
  max-width: 100%;
  height: auto;
  object-fit: contain;
  object-position: center;
  display: block;
}

/* List view scatter animation */
.list-item--scattering {
  transition: transform var(--dur) var(--ease);
}

.list-item--scattering.scatter-out {
  transition: transform var(--dur) var(--ease),
              opacity 0.3s var(--ease) 0.5s;
  opacity: 0;
}

/* Allow scattered items to fly beyond the list container */
#list-container.scattering {
  overflow: visible;
}

/* Portrait video/image placeholder in list view */
.project-image-item--video {
  width: auto;
  height: 100%;
  overflow: hidden;
}

.project-image-item--video img {
  width: auto;
  height: 100%;
  max-width: none;
}

/* Landscape video placeholder in list view */
.project-image-item--video-landscape {
  width: 220px;
  height: auto;
}

.project-image-item--video-landscape img {
  max-width: 100%;
  height: auto;
}

/* ============================================
   MOBILE: Info view slide sizing
   ============================================ */
@media (max-width: 574px) {
  .info-slide {
    width: 85vw;
    margin-left: -42.5vw;
    padding: 30px;
  }
}

/* ============================================
   MOBILE: UI chrome — page furniture
   ============================================ */
@media (max-width: 430px) {
  :root {
    --font-ui: 14px;
  }

  /* Navigation tabs */
  .view-tabs {
    top: 15px;
    gap: 12px;
  }

  .tab-button.active::after {
    height: 2px;
  }

  /* Top bar — shorter on mobile */
  #detail-view::before {
    height: 50px;
  }

  /* Detail view close button — align with nav tabs on mobile */
  .detail-close {
    /* Tabs at top:15px on mobile, font 14px → center ~22px; box 48px → top = 22-24 = -2 */
    top: -2px;
    left: -2px;
  }

  /* Bottom bar controls — tighter padding on mobile */
  .bottom-bar-controls {
    padding: 0 20px;
  }

  /* More info panel */
  .detail-info-panel {
    padding: 20px 20px 30px;
  }

  /* Info view counter */
  .info-counter {
    right: 20px;
    bottom: 30px;
  }

  /* Info slide text — left-align */
  .info-slide-content h2,
  .info-slide-content p,
  .info-slide-content ul li {
    text-align: left;
  }

}

/* Narrow phones (e.g. iPhone SE 375px, Galaxy S8+ 360px) — scale down to fit */
@media (max-width: 379px) {
  .view-tabs {
    gap: 8px;
  }

  .detail-close {
    left: 0;
  }

  .bottom-bar-controls {
    padding: 0 20px;
  }

  .info-counter {
    right: 15px;
  }
}
