/* --- Saisei Portfolio - Fixed & Perfected --- */

:root {
  --portfolio-bg: #050505;
  --portfolio-accent: #ffe00d;
  --portfolio-text-muted: rgba(255, 255, 255, 0.4);
  --card-width: 65vh;
  --card-height: 80vh;
}

body.portfolio-page {
  background-color: var(--portfolio-bg);
  color: #fff;
  font-family: 'Manjari', sans-serif;
  overflow: hidden;
  height: 100vh;
  margin: 0;
}

/* --- Grain Overlay --- */
.noise-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* --- Background Image Layer --- */
#gallery-bg-container {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

#gallery-bg {
  position: absolute;
  inset: -5%;
  background-size: cover;
  background-position: center;
  filter: blur(20px) brightness(0.25);
  transform: translateZ(0) scale(1.1);
  will-change: transform;
}

#gallery-bg-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 0%, rgba(0, 0, 0, 0.85) 100%);
}

/* --- Header --- */
#portfolio-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 50;
  background: transparent;
  padding: 30px 0;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.category-filters {
  display: flex;
  gap: 30px;
}

@media (max-width: 768px) {
  #portfolio-header {
    padding: 15px 0;
  }
  .header-container {
    flex-wrap: wrap;
    gap: 15px;
  }
  .header-right {
    width: 100%;
    display: flex;
    justify-content: center;
  }
  .category-filters {
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
  }
}

.filter-btn {
  background: transparent;
  border: none;
  color: var(--portfolio-text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  cursor: pointer;
  padding-bottom: 5px;
  transition: color 0.3s ease;
}

.filter-btn.active {
  color: #fff;
  border-bottom: 2px solid var(--portfolio-accent);
}

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

/* --- Gallery Infrastructure --- */
.gallery-wrapper {
  position: relative;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.gallery-container {
  width: 100%;
  height: var(--card-height);
  user-select: none;
}

.gallery-track {
  display: flex;
  align-items: center;
  height: 100%;
  padding-left: 90vw; /* Enough space to start with the first image on the right */
  padding-right: 50vw;
  will-change: transform;
}

.gallery-item {
  position: relative;
  flex-shrink: 0;
  width: var(--card-width);
  height: 100%;
  margin-right: 40vw; /* Spacing between cards */
  display: flex;
  flex-direction: column;
  justify-content: center;
  pointer-events: auto;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;

  span {
    display: block;
    margin-top: 0.5rem;
  }
}

.image-container img {
  pointer-events: none; /* Prevents native browser drag */
  -webkit-user-drag: none;
}

/* Project Index (Large faint numbers) stays on RIGHT */
.project-id {
  position: absolute;
  top: -10vh;
  right: -5vw;
  left: auto;
  font-family: 'Playfair Display', serif;
  font-size: 10rem;
  color: rgba(255, 255, 255, 0.03);
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  transform: translateY(40px);
  transition: all 1.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.gallery-item.active .project-id {
  opacity: 1;
  transform: translateY(0);
}

/* Image Container */
.image-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 2px;
  transform: scale(0.85) translateZ(0);
  opacity: 0.5;
  transition:
    transform 1.2s cubic-bezier(0.19, 1, 0.22, 1),
    opacity 1.2s ease;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.7);
  will-change: transform, opacity;
}

.gallery-item.active .image-container {
  transform: scale(1) translateZ(0);
  opacity: 1;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.15);
  transition: transform 2.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.gallery-item.active img {
  transform: scale(1);
}

/* Project Info overlay - Moved to the LEFT and limited in width */
.project-info {
  position: absolute;
  top: 50%;
  right: 105%; /* Position it to the left of the image */
  left: auto;
  transform: translateY(-50%);
  width: 45vw; /* Limited width to force wrapping */
  text-align: right; /* Keep it elegant */
  pointer-events: none;
}

.project-category {
  font-family: 'Manjari', sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.5em;
  color: var(--portfolio-accent);
  margin-bottom: 2rem;
  display: block;
  font-weight: 700;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.8s ease 0.4s;
}

.project-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(3rem, 6vw, 4.5rem);
  line-height: 1.2;
  margin: 0;
  color: #fff;
  font-weight: 400;
  letter-spacing: -0.02em;

  /* Mask/Reveal Effect */
  clip-path: inset(0 100% 0 0);
  transition: clip-path 1.5s cubic-bezier(0.19, 1, 0.22, 1) 0.2s;
}

.gallery-item.active .project-category {
  opacity: 1;
  transform: translateY(0);
}

.gallery-item.active .project-title {
  clip-path: inset(0 0 0 0);
}

/* Progress bar */
.scroll-progress {
  position: absolute;
  bottom: 8vh;
  left: 5vw;
  width: 20vw;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--portfolio-accent);
  transition: width 0.2s linear;
}

/* Desktop styles footer adjustment */
.portfolio-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 30px 0;
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.2);
}

/* Drag Instruction Feature */
.drag-instruction {
  position: absolute;
  bottom: 8vh;
  right: 5vw;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.6rem;
  letter-spacing: 0.25em;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  animation: drag-fade-in 1s forwards 1.5s; /* Entra depois que a tela carrega */
}

.drag-icon svg {
  color: var(--portfolio-accent);
  animation: bounce-x 2s infinite ease-in-out;
}

@keyframes drag-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.6;
  }
}

@keyframes bounce-x {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(-10px);
  }
}

/* --- Interactive Gallery Indicators & Modal --- */
.expand-gallery-btn {
  position: absolute;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 12px 30px 10px;
  font-family: 'Manjari', sans-serif;
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  font-weight: 700;
  cursor: pointer;
  border-radius: 999px;
  transition: all 0.6s cubic-bezier(0.19, 1, 0.22, 1);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

.gallery-item.active .expand-gallery-btn {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
  transition-delay: 0.4s;
}

.expand-gallery-btn:hover {
  background: var(--portfolio-accent);
  color: #000;
  border-color: var(--portfolio-accent);
  transform: translateX(-50%) translateY(-5px);
}

/* Project Modal */
.project-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition:
    opacity 0.5s ease,
    visibility 0.5s ease;
}

.project-modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 5, 0.98);
  backdrop-filter: blur(10px);
}

.modal-content {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1400px;
  display: flex;
  flex-direction: column;
  z-index: 1001;
}

.modal-close-btn {
  position: absolute;
  top: 30px;
  right: 40px;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  z-index: 1002;
  transition:
    color 0.3s ease,
    transform 0.3s ease;
}

.modal-close-btn:hover {
  color: var(--portfolio-accent);
}

.modal-gallery-vertical {
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 100px 5% 50px 5%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 40px;
  align-items: start;
}

.modal-gallery-vertical::-webkit-scrollbar {
  width: 5px;
}
.modal-gallery-vertical::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}
.modal-gallery-vertical::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 5px;
}

.modal-gallery-vertical img {
  width: 100%;
  height: auto;
  max-height: 80vh; /* Mostra a imagem confortavelmente na tela */
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(40px);
  animation: modal-img-fade 0.8s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

@keyframes modal-img-fade {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  #portfolio-header {
    padding: 20px 0;
  }
  .header-container {
    flex-wrap: wrap;
    gap: 15px;
  }
  .header-right {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-top: 10px; /* Mais espaço para os botões */
  }
  .category-filters {
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .portfolio-footer {
    display: none; /* Hide footer on mobile for a clean cinematic view */
  }
}

/* Responsividade Mobile */
@media (max-width: 768px) {
  :root {
    --card-width: 75vw;
    --card-height: 42vh;
  }

  .gallery-wrapper {
    align-items: flex-start;
    padding-top: 160px; /* Margem absoluta exata para escapar do cabeçalho */
  }

  .scroll-progress {
    width: 60vw;
    bottom: 16vh;
    left: 10vw;
    transform: none;
  }

  .drag-instruction {
    top: auto;
    bottom: 18vh; /* Posicionado levemente acima do scroll que está no 18vh */
    right: auto;
    left: 10vw; /* Alinhado exatamente no mesmo eixo que a ponta da barra de scroll */
  }

  .gallery-track {
    padding-left: 50vw !important;
    padding-right: 50vw !important;
  }

  .gallery-item {
    margin-right: 60vw;
  }

  .project-info {
    left: auto !important;
    right: 0 !important;
    top: calc(100% + 15px) !important;
    bottom: auto !important;
    width: 100%;
    text-align: right;
    transform: none !important;
  }

  .project-category {
    margin-bottom: 0.5rem;
  }

  .project-title {
    font-size: 2rem !important;
  }

  .project-id {
    font-size: 5rem;
    top: -8vh;
    right: 2vw;
  }

  .modal-gallery-vertical {
    display: flex;
    flex-direction: column;
    gap: 5vh;
  }
}
