/* =========================================
   1. Fonts & Reset
   ========================================= */

@font-face {
  font-family: 'Google Sans Flex';
  src: url('../fonts/GoogleSansFlex.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: block;
}

html {
  scrollbar-gutter: stable;
  overflow-y: scroll;
  overflow-anchor: none;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

/* =========================================
   2. CSS Variables (Theming)
   ========================================= */

/* Prevent transitions on load */
.preload, .preload * {
  transition: none !important;
}

:root {
  /* Light Mode (Default) */
  --bg-color: #F0F0F0;       /* Light grey background */
  --bg-color-rgb: 240, 240, 240;
  --card-color: #FFFFFF;     /* White cards */
  --text-color: #333333;     /* Dark text */
  --icon-color: #333333;     /* Dark icons */
  --overlay-bg: rgba(0, 0, 0, 0.2); /* Dark blur overlay */
  
  /* Animation & Transitions */
  --theme-transition: 0.3s ease; /* Synchronized full-site fading */
  
  /* Layout Dimensions */
  --header-height: 80px;
  --carousel-translate-y: -50%;
}

/* Dark Mode Override */
[data-theme="dark"] {
  --bg-color: #101010;       /* Dark grey background */
  --bg-color-rgb: 16, 16, 16;
  --card-color: #000000;     /* Black cards */
  --text-color: #FFFFFF;     /* Light text */
  --icon-color: #FFFFFF;     /* Light icons */
  --overlay-bg: rgba(0, 0, 0, 0.2); /* Dark blur overlay */
}

/* =========================================
   3. Base Styles
   ========================================= */

body {
  font-family: 'Google Sans Flex', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color var(--theme-transition), color var(--theme-transition);
  -webkit-font-smoothing: antialiased;
}

img {
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* =========================================
   Shared UI Components
   ========================================= */

.carousel-btn,
.lightbox-btn,
.lightbox-close,
.lightbox-dots {
  border-radius: 30px;
  transition: background-color var(--theme-transition), color var(--theme-transition), border-radius 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.carousel-btn.clicked, .carousel-btn:active,
.lightbox-btn.clicked, .lightbox-btn:active,
.lightbox-close.clicked, .lightbox-close:active,
.lightbox-dots.clicked, .lightbox-dots.holding {
  border-radius: 12px;
  transition: background-color var(--theme-transition), color var(--theme-transition), border-radius 0.2s cubic-bezier(0.25, 1, 0.5, 1);
}

/* =========================================
   4. Site Header
   ========================================= */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--header-height);
  background-color: rgba(var(--bg-color-rgb), 0.5);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  z-index: 1000;
  transition: background-color var(--theme-transition), height 0.6s cubic-bezier(0.25, 1, 0.5, 1);
  display: flex;
  align-items: flex-start;
  -webkit-tap-highlight-color: transparent;
}

.site-header * {
  -webkit-tap-highlight-color: transparent;
}

.header-content {
  width: 100%;
  height: var(--header-height);
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

/* Site Title */
.site-title {
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text-color);
  letter-spacing: -0.02em;
  transition: color var(--theme-transition), opacity 0.3s ease;
  display: flex;
  align-items: center;
}

/* Navigation (Desktop/Tablet) */
.desktop-nav {
  display: flex;
  gap: 32px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.nav-link {
  text-decoration: none;
  color: var(--text-color);
  font-size: 1rem;
  font-weight: 500;
  opacity: 0.6;
  transition: opacity 0.2s ease, color var(--theme-transition);
}

.nav-link:hover,
.nav-link.active {
  opacity: 1;
}

/* Header Controls (Right Side) */
.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-right: -8px;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--icon-color);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, color var(--theme-transition), opacity 0.3s ease;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

@media (hover: hover) {
  .icon-btn:hover {
    opacity: 0.7;
  }
}

/* Mobile Menu Button */
#menu-btn {
  display: none;
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .desktop-nav {
    display: none;
  }

  #menu-btn {
    display: flex;
  }
  
  .header-content {
    padding: 0 20px;
  }
}

/* =========================================
   Search Overlay
   ========================================= */

.site-header.search-active {
  height: 100vh;
  background-color: rgba(var(--bg-color-rgb), 0.8);
}

.site-header.search-active .header-content {
  flex-shrink: 0;
}

.search-container {
  position: absolute;
  top: var(--header-height);
  left: 0;
  width: 100%;
  height: calc(100vh - var(--header-height));
  padding: 0 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.6s cubic-bezier(0.25, 1, 0.5, 1), visibility 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.site-header.search-active .search-container {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.search-container::-webkit-scrollbar {
  display: none;
}

.search-bar-wrapper {
  position: absolute;
  top: 20px;
  left: 50%;
  width: calc(100% - 40px);
  max-width: 1300px;
  margin-bottom: 0;
  flex-shrink: 0;
  z-index: 20;
  opacity: 0;
  transform: translate(-50%, 20px);
  transition: opacity 0.8s cubic-bezier(0.25, 1, 0.5, 1), transform 0.8s cubic-bezier(0.25, 1, 0.5, 1);
}

.site-header.search-active .search-bar-wrapper {
  opacity: 1;
  transform: translate(-50%, 0);
}

.search-input {
  width: 100%;
  height: 60px;
  background: var(--card-color);
  border: 1px solid rgba(var(--bg-color-rgb), 0.8);
  font-family: 'Google Sans Flex', sans-serif;
  font-size: 1.25rem;
  color: var(--text-color);
  padding: 0 60px;
  text-align: center;
  outline: none;
  border-radius: 100px;
  transition: background-color var(--theme-transition), color var(--theme-transition), border-color var(--theme-transition);
}

.search-input::placeholder {
  color: var(--text-color);
  opacity: 0.3;
}

.search-icon-input, .search-clear-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  transition: color var(--theme-transition);
}

.search-icon-input { left: 10px; pointer-events: none; }
.search-clear-btn { right: 10px; background: none; border: none; cursor: pointer; }
.search-clear-btn svg, .search-icon-input svg { width: 24px; height: 24px; fill: currentColor; }

.search-clear-btn[hidden] {
  display: none;
}

.search-container .search-results {
  width: 100%;
  max-width: 1300px;
  padding: 100px 0 40px;
  padding-left: 0;
  padding-right: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(300px, 30%), 1fr));
  gap: 20px;
  grid-auto-rows: max-content;
  overflow-y: auto;
  height: 100%;
  scrollbar-width: none;
  mask-image: linear-gradient(to bottom, transparent 50px, black 50px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 50px, black 50px);
}

.search-container .search-results::-webkit-scrollbar {
  display: none;
}

.no-results {
  font-size: 1.2rem;
  color: var(--text-color);
  opacity: 0.6;
  position: absolute;
  top: 200px;
  width: 100%;
  text-align: center;
  transition: color var(--theme-transition);
  animation: noResultsEnter 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes noResultsEnter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 0.6; transform: translateY(0); }
}

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

.search-card-enter {
  opacity: 0;
  animation: searchCardEnter 0.4s cubic-bezier(0.25, 1, 0.5, 1) both;
}

/* =========================================
   Mobile Menu
   ========================================= */

.site-header.menu-active {
  height: 100vh;
  background-color: rgba(var(--bg-color-rgb), 0.8);
}

.site-header.menu-active .header-content {
  flex-shrink: 0;
}

.site-header.menu-active .site-title,
.site-header.menu-active .header-controls .icon-btn:not(#menu-btn) {
  opacity: 0;
  pointer-events: none;
}

.mobile-nav {
  position: fixed;
  top: calc(50vh - 40px);
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  z-index: 1001; /* Ensure it's above the header content */
  transition: opacity 0.6s cubic-bezier(0.25, 1, 0.5, 1), visibility 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.site-header.menu-active .mobile-nav {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.mobile-nav .nav-link {
  font-size: 2rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-20px);
  transition: opacity 0.8s cubic-bezier(0.25, 1, 0.5, 1), transform 0.8s cubic-bezier(0.25, 1, 0.5, 1), color var(--theme-transition);
}

.site-header.menu-active .mobile-nav .nav-link {
  opacity: 1;
  transform: translateY(0);
}
.site-header.menu-active .mobile-nav .nav-link:nth-child(2) { transition-delay: 0.1s; }
.site-header.menu-active .mobile-nav .nav-link:nth-child(3) { transition-delay: 0.2s; }

/* =========================================
   5. Main Layout
   ========================================= */

main {
  padding-top: var(--header-height);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 40px;
  padding-bottom: 20px;
}

/* =========================================
   6. Project Carousel
   ========================================= */

.carousel-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  padding: min(80px, 10vh) 0 42px;
}

.carousel-viewport {
  width: min(1300px, calc(100% - 120px), 110vh);
  aspect-ratio: 16 / 9;
  min-height: 400px;
  min-width: calc(400px * 16 / 9);
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-track {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1440px;
  animation: searchCardEnter 1.2s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}

.carousel-card {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: var(--card-color);
  border-radius: 30px;
  overflow: hidden;
  transition: all 0.6s cubic-bezier(0.25, 1, 0.5, 1),
              background-color var(--theme-transition),
              color var(--theme-transition);
  width: 100%;
  height: 100%;
  padding: 20px;
  text-decoration: none;
  color: var(--text-color);
  max-width: 1300px;
}

.carousel-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 14px;
}

/* Overlay & Text (Desktop/Tablet) */
.card-overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  opacity: 0;
  transition: opacity 0.3s ease, backdrop-filter 0.3s ease, background-color var(--theme-transition), color var(--theme-transition);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #FFFFFF;
  padding: 20px;
  text-align: center;
}

.project-info {
  transform: translateY(20px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease, color var(--theme-transition);
}

/* Hide mobile-specific text on desktop */
.carousel-card > .project-info,
.grid-card > .project-info {
  display: none;
}

.project-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  transition: color var(--theme-transition);
}

.project-date {
  font-size: 1rem;
  font-weight: 500;
  opacity: 0.9;
  transition: color var(--theme-transition);
}

/* Hover Effects (Desktop) */
@media (min-width: 769px) {
  .carousel-card:hover .card-overlay,
  .grid-card:hover .card-overlay {
    opacity: 1;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
  }
  
  .carousel-card:hover .card-overlay .project-info,
  .grid-card:hover .card-overlay .project-info {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Carousel Controls */
.carousel-controls {
  display: flex;
  gap: 6px;
  margin-top: 20px;
  z-index: 10;
}

.carousel-controls .carousel-btn {
  animation: searchCardEnter 1.2s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}

.carousel-btn {
  background-color: var(--card-color);
  border: none;
  cursor: pointer;
  color: var(--icon-color);
  width: 60px;
  height: 60px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#play-pause-btn {
  width: 120px;
}

.carousel-btn svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

#prev-btn svg,
#next-btn svg,
#play-pause-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#play-pause-btn.show-play svg {
  fill: currentColor;
}

/* Responsive Adjustments */
@media (max-width: 1024px) {
  .carousel-viewport {
    width: min(calc(100% - 120px), 80vh);
    aspect-ratio: 5 / 4;
    min-width: calc(400px * 5 / 4);
  }

  .carousel-card {
    max-width: none;
    max-height: none;
  }
}

@media (max-width: 768px) {
  .carousel-viewport {
    aspect-ratio: 4 / 5;
    min-width: calc(400px * 4 / 5);
    margin-bottom: 0;
  }

  .carousel-card {
    overflow: visible;
  }

  .card-overlay {
    display: none;
  }

  .carousel-card > .project-info,
  .grid-card > .project-info {
    display: block;
  }

  .project-info {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    transform: none;
    opacity: 1;
    padding-top: 12px;
    text-align: center;
    color: var(--text-color);
  }
  
  .project-title {
    font-size: 1.25rem;
    color: var(--text-color);
  }
  
  .project-date {
    color: var(--text-color);
    opacity: 0.6;
  }

  /* Ensure buttons don't overlap with text hanging below cards */
  .carousel-controls {
    margin-top: 90px;
  }
}

/* =========================================
   7. Project Grid
   ========================================= */

.grid-section {
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(300px, 30%), 1fr));
  gap: 20px;
}

.grid-card {
  background-color: var(--card-color);
  border-radius: 30px;
  padding: 20px;
  overflow: hidden;
  position: relative;
  display: block;
  aspect-ratio: 5 / 4;
  text-decoration: none;
  color: var(--text-color);
  transition: background-color var(--theme-transition), color var(--theme-transition);
}

.grid-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 14px;
  display: block;
}

@media (max-width: 1024px) {
  .grid-section {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

  .grid-card {
    overflow: visible;
    margin-bottom: 80px;
  }

  .search-container .search-results {
    grid-template-columns: 1fr;
  }
}

/* =========================================
   8. Site Footer
   ========================================= */

footer {
  height: 20px;
}

/* =========================================
   9. Project Page
   ========================================= */

.project-content {
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
  padding: 40px 40px 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.project-header {
  animation: searchCardEnter 1.2s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}

.project-hero {
  width: 100%;
  background-color: var(--card-color);
  border-radius: 30px;
  padding: 20px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  aspect-ratio: 16 / 9;
  cursor: pointer;
  transition: background-color var(--theme-transition), color var(--theme-transition);
  animation: searchCardEnter 1.2s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}

.project-hero img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.project-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(300px, 30%), 1fr));
  gap: 20px;
  width: 100%;
}

.gallery-card {
  background-color: var(--card-color);
  border-radius: 30px;
  padding: 20px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color var(--theme-transition);
  animation: searchCardEnter 1.2s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}

.project-gallery img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

@media (max-width: 1024px) {
  .project-hero {
    aspect-ratio: 5 / 4;
  }
}

@media (max-width: 768px) {
  .project-content {
    padding: 40px 20px 0;
  }
  
  .project-hero {
    aspect-ratio: 1 / 1;
  }

  .project-gallery {
    grid-template-columns: minmax(0, 1fr);
  }
  
  .gallery-card {
    aspect-ratio: 1 / 1;
  }
}

/* =========================================
   10. Lightbox
   ========================================= */

.lightbox {
  position: fixed;
  inset: 0;
  background-color: var(--card-color);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  display: block;
  padding: 0;
  transition: opacity 0.3s ease, visibility 0.3s ease, background-color var(--theme-transition);
  --lightbox-ui-size: min(60px, 15vw);
  --lightbox-gap: 40px;
  overscroll-behavior: none;
  touch-action: none;
  min-height: 360px;
  min-width: 140px;
}

.lightbox.active {
  opacity: 1;
  visibility: visible;
}

.lightbox-track {
  display: flex;
  height: 100%;
  width: 100%;
  will-change: transform;
}

.lightbox-image {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: calc(max(20px, env(safe-area-inset-top, 20px)) + var(--lightbox-ui-size) + var(--lightbox-gap)) 20px calc((var(--lightbox-gap) * 2) + var(--lightbox-ui-size) + env(safe-area-inset-bottom, 0px));
  transition: padding 0.3s ease;
}

.lightbox-controls {
  position: absolute;
  bottom: calc(var(--lightbox-gap) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  z-index: 2010;
  flex-shrink: 0;
  max-width: calc(100% - 40px);
}

.lightbox-btn {
  background-color: var(--bg-color);
  border: none;
  cursor: pointer;
  color: var(--icon-color);
  width: var(--lightbox-ui-size);
  height: var(--lightbox-ui-size);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lightbox-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lightbox-close {
  position: absolute;
  top: max(20px, env(safe-area-inset-top, 20px));
  right: max(20px, env(safe-area-inset-right, 20px));
  background-color: var(--bg-color);
  border: none;
  cursor: pointer;
  color: var(--icon-color);
  z-index: 2020;
  width: var(--lightbox-ui-size);
  height: var(--lightbox-ui-size);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.lightbox-close svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.lightbox-dots {
  display: flex;
  background-color: var(--bg-color);
  height: var(--lightbox-ui-size);
  padding: 0 10px;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.lightbox-dots-inner {
  display: flex;
  gap: 12px;
  width: 100%;
  height: 100%;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  touch-action: pan-x;
  padding: 0 14px;
  mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
}

.lightbox-dots::-webkit-scrollbar {
  display: none;
}

.lightbox-dots-inner::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.lightbox-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--icon-color);
  opacity: 0.3;
  border: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--theme-transition), opacity var(--theme-transition);
}

.lightbox-dot:hover,
.lightbox-dot.active {
  background-color: var(--icon-color);
  opacity: 1;
}