/* -----------------------------------------
   RESET & VARIABLES
------------------------------------------ */
* { margin:0; padding:0; box-sizing:border-box; }
::selection { background:#007aff; color:white; }

:root {
  --bg:#f2f2f2;
  --text:#222;
  --accent:#008cff;
  --sidebar-bg:#e0e0e0;
  --sidebar-border:#aaa;
  --shadow:0 2px 8px rgba(0,0,0,0.15);
}

[data-theme="dark"] {
  --bg:#111;
  --text:#eee;
  --sidebar-bg:#333;
  --sidebar-border:#444;
  --accent:#2a9cff;
}

body {
  font-family: 
    "Hiragino Kaku Gothic ProN", 
    "Hiragino Sans", 
    "Helvetica Neue", 
    Helvetica, 
    Arial, 
    sans-serif;
  
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* -----------------------------------------
   STRUCTURE & LAYOUT
------------------------------------------ */
.container {
  display:flex;
  width:100%;
  margin-left:220px;
  transition: margin-left .25s ease;
}

main.gallery {
  flex:1;
  padding:20px;
  min-height:100vh;
}

/* -----------------------------------------
   SIDEBAR (FIXE)
------------------------------------------ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: 220px; height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.sidebar h1 { font-size: 1.5rem; margin-bottom: 30px; }

.sidebar ul { list-style: none; flex-grow: 1; }

.sidebar li {
  padding: 10px 15px;
  margin-bottom: 5px;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.7;
  transition: all 0.2s;
}

.sidebar li:hover { opacity: 1; background: rgba(0,0,0,0.05); }
.sidebar li.active { opacity: 1; background: var(--accent); color: white; }

.about-me {
  padding-top: 15px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 0.85rem;
}

.sidebar-buttons { display: flex; gap: 8px; margin-top: 15px; }

.sidebar-buttons button {
  flex: 1; padding: 8px; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--sidebar-border);
  background: var(--bg); color: var(--text);
}

/* -----------------------------------------
   GRILLES UNIFIÉES (GALERIES & ZINES)
------------------------------------------ */
/* Remplace le bloc .gallery.grid dans style.css */
.gallery.grid, 
.gallery.zine-inner {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) !important; 
  /* AJOUT : Force les lignes à coller au contenu au lieu de s'étirer */
  grid-auto-rows: min-content; 
  align-items: start; 
  gap: 20px;
  width: 100%;
}
/* -----------------------------------------
   BOUTON RETOUR (STABLE & STICKY)
------------------------------------------ */
.back-button {
  grid-column: 1 / -1 !important;
  justify-self: start !important;
  position: sticky;
  top: 10px;
  z-index: 1100;
  
  width: auto !important;
  padding: 10px 20px;
  margin-bottom: 25px;
  
  background: rgba(242, 242, 242, 0.6) !important;
  backdrop-filter: blur(8px);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
}

[data-theme="dark"] .back-button {
  background: rgba(17, 17, 17, 0.6) !important;
}

.back-button:hover { background: var(--accent) !important; color: white !important; }

/* -----------------------------------------
   CATÉGORIES & CARTES
------------------------------------------ */
.category-selection {
  display: grid;
  /* Force exactement 3 colonnes de largeur égale */
  grid-template-columns: repeat(3, 1fr) !important; 
  /* Défini la hauteur des lignes pour qu'il y en ait exactement 2 à l'écran */
  /* 100vh (hauteur totale) - padding / 2 = environ 48vh */
  grid-auto-rows: calc(50vh - 30px); 
  gap: 20px;
  padding: 20px;
}

.category-card {
  position: relative;
  width: 100%;
  height: 100%; /* La carte remplit toute sa cellule de grille */
  overflow: hidden;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* On retire l'aspect-ratio pour que la hauteur vh soit prioritaire */
.category-card {
  aspect-ratio: auto !important; 
}

.category-card img { width: 100%; height: 100%; object-fit: cover; transition: 0.5s; }
.category-card:hover img { transform: scale(1.05); }

.category-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
}

.category-overlay span { 
  color: white; border: 2px solid white; padding: 12px 24px;
  font-weight: bold; font-size: 1.4rem; border-radius: 8px;
  text-transform: uppercase; letter-spacing: 2px;
}

/* -----------------------------------------
   IMAGES & CHARGEMENT PROGRESSIF
------------------------------------------ */
.gallery-item, .zine-item {
  background: var(--sidebar-bg);
  overflow: hidden;
  border-radius: 4px;
}

.gallery-item img, .zine-item img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: opacity 0.6s ease, filter 0.6s ease, transform 0.3s ease;
  filter: blur(15px);
  opacity: 0;
}

.zine-item img { aspect-ratio: auto; height: auto; }

.gallery-item img.loaded, .zine-item img.loaded {
  opacity: 1;
  filter: blur(0);
}

.gallery-item:hover img { transform: scale(1.03); }

.zine-page-counter {
  text-align: center; font-size: 0.8rem; margin: 10px 0; opacity: 0.6;
}

/* -----------------------------------------
   LIGHTBOX
------------------------------------------ */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.95);
  display: none; align-items: center; justify-content: center;
  touch-action: none;
  z-index: 3000;
}

.lightbox.show { display: flex; }

.lb-content { display: flex; flex-direction: column; align-items: center; z-index: 3100; }

#lb-counter { color: white; margin-top: 15px; letter-spacing: 2px; font-size: 0.9rem; }

#lightbox-img {
  max-width: 95vw; /* Plus d'espace sur les bords */
  max-height: 85vh;
  object-fit: contain;
  /* Évite le zoom sauvage sur mobile */
  touch-action: pinch-zoom; 
  user-select: none;
  -webkit-user-drag: none;
}
#lightbox-img.loaded { opacity: 1; }

.lb-nav-area { position: absolute; top: 0; bottom: 0; width: 35%; z-index: 3200; cursor: pointer; }
.lb-prev { left: 5%; }
.lb-next { right: 5%; }

.lb-close {
  position: absolute; top: 20px; right: 25px; background: none; border: none;
  color: white; font-size: 40px; cursor: pointer; z-index: 3300;
}

/* -----------------------------------------
   MOBILE & BURGER
------------------------------------------ */
/* 1. STYLE DE BASE (Burger fermé) */
.burger {
  display: flex !important;
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 2000;
  width: 45px;
  height: 45px;
  align-items: center;
  justify-content: center;
  padding: 0 0 6px 0 !important; 
  font-size: 32px;
  cursor: pointer;
  /* Fond clair par défaut */
  background: rgba(242, 242, 242, 0.4) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent;
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 4px;
  transition: transform 0.2s ease-in-out, background 0.2s, color 0.2s;
}

/* 2. ÉTAT OUVERT (La Croix Bleue) */
/* Ce sélecteur change le fond en bleu dès que le menu a la classe .open */
body:has(.mobile-menu.open) .burger {
  background: var(--accent) !important;
  color: white !important;
  border-color: var(--accent) !important;
  transform: rotate(90deg); /* Rotation incluse ici */
}

/* 3. INTERACTIONS (Hover & Active) */
@media (hover: hover) {
  .burger:hover {
    background: var(--accent) !important;
    color: white !important;
  }
}

.burger:active {
  background: var(--accent) !important;
  color: white !important;
}

/* 4. ADAPTATIONS MOBILES & MODE SOMBRE */
@media (max-width: 900px) {
  /* Correction focus iPhone (évite que le bleu reste bloqué sur le burger fermé) */
  .burger:focus {
    background: rgba(242, 242, 242, 0.4) !important;
    color: var(--text) !important;
  }

  /* Forcer le bleu sur le focus UNIQUEMENT si ouvert */
  body:has(.mobile-menu.open) .burger:focus {
    background: var(--accent) !important;
    color: white !important;
  }

  /* Harmonisation Mode Sombre (Burger fermé) */
  [data-theme="dark"] .burger {
    background: rgba(17, 17, 17, 0.8) !important;
    color: #eee !important;
  }

  /* Correction focus Mode Sombre (Burger fermé) */
  [data-theme="dark"] .burger:focus {
    background: rgba(17, 17, 17, 0.8) !important;
  }
}
/* Cache le burger uniquement sur Desktop (plus de 900px) */
@media (min-width: 901px) {
  .burger { 
    display: none !important; 
  }
}

/* 5. LE MENU */
.mobile-menu {
  position: fixed; inset: 0 0 0 0; width: 280px; height: 100vh;
  background: var(--sidebar-bg); z-index: 1800; padding: 80px 20px;
  transform: translateX(-100%); transition: transform .3s ease-out;
}
.mobile-menu.open { transform: translateX(0); }
.mobile-menu li { padding: 15px; border-bottom: 1px solid var(--sidebar-border); list-style: none; }

/* Overlay qui s'affiche derrière le menu mobile */
.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1700; /* Juste en dessous du menu (1800) */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* -----------------------------------------
   RESPONSIVE (PRIORITAIRE)
------------------------------------------ */
@media (max-width: 900px) {
  .category-selection {
    /* Retour à 1 ou 2 colonnes sur tablette/mobile */
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)) !important;
    grid-auto-rows: auto; /* Hauteur naturelle sur mobile */
  }

}

@media (max-width: 900px) {
  .container { margin-left: 0; }
  .sidebar { display: none; }
  .burger { display: block; }

  .gallery.grid, .gallery.zine-inner, .category-selection {
    padding-top: 100px !important; 
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
  }

  .back-button {
    top: 70px !important; /* Sous le burger */
    margin-left: 0;
  }
  .about-section {
    padding-top: 120px !important; /* Un peu plus d'espace pour le texte sur mobile */
    padding-left: 20px;
    padding-right: 20px;
    justify-content: flex-start;
  }
}

@media (max-width: 500px) {
  .gallery.grid { grid-template-columns: 1fr !important; }
  .category-overlay span {
    font-size: 0.85rem;    /* Encore plus petit pour les mobiles étroits */
    padding: 6px 12px;
    border-width: 1px;     /* Bordure plus fine pour plus de légèreté */
  }
}

/* Animations */
.fade-out { opacity: 0; transition: opacity 0.3s; }

/* Force la couverture à prendre toute la largeur de la ligne */
.gallery.zine-inner .zine-cover {
  grid-column: 1 / -1;
  justify-self: center; /* Centre la couverture si elle n'est pas assez large */
  width: 100%;
  max-width: 500px;    /* Optionnel : limite la taille pour ne pas qu'elle soit géante sur ordi */
  margin: 0 auto 20px auto;
}

/* Optionnel : Ajuster l'image de couverture pour qu'elle garde son ratio naturel */
.zine-cover img {
  aspect-ratio: auto !important;
  height: auto !important;
  object-fit: contain !important;
}

.about-section {
  display: flex;
  justify-content: flex-start; /* Aligne le bloc à gauche au lieu de center */
  align-items: flex-start;
  padding-top: 50px !important;
  padding-left: 10%; /* Optionnel : ajoute une marge à gauche pour ne pas coller à la sidebar */
}

.about-content {
  max-width: 600px;
  line-height: 1.6;
  text-align: left; /* Force l'alignement du texte à gauche */
  animation: fadeIn 0.5s ease;
}

.about-content h2 {
  margin-bottom: 20px;
  color: var(--text); /* Utilise le noir en mode clair et le blanc en mode sombre */
  font-weight: bold;
}

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

/* Style pour la barre de chargement professionnelle */
.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  width: 0%; /* Commence à 0 */
  z-index: 9999;
  transition: width 0.3s ease, opacity 0.5s ease;
  box-shadow: 0 0 10px var(--accent);
}

.gallery-item {
  /* On garde le min-height mais on s'assure que le fond ne soit visible 
     que si l'image n'est pas encore là ou transparente */
  background: rgba(0,0,0,0.03); 
  height: fit-content; /* Force le conteneur à épouser l'image */
  align-self: start;   /* Empêche le conteneur de s'étirer verticalement */
}

/* Optionnel : Supprimer le gris quand l'image est chargée */
.gallery-item:has(img.loaded) {
  background: transparent;
}
[data-theme="dark"] .gallery-item {
  background: rgba(255,255,255,0.03);
}

/* --- ADAPTATION TABLETTES (768px à 1100px) --- */
@media (max-width: 1100px) {
  .container { margin-left: 200px; } /* Sidebar légèrement plus étroite */
  .sidebar { width: 200px; }
  
  .category-selection {
    grid-template-columns: repeat(2, 1fr) !important; /* 2 colonnes au lieu de 3 */
    grid-auto-rows: auto;
  }
}

/* --- ADAPTATION PETITES TABLETTES / PORTRAIT (Sous 900px) --- */
@media (max-width: 900px) {
  .container { margin-left: 0; }
  .sidebar { display: none; }
  .burger { display: block; }
  
  .gallery.grid, .gallery.zine-inner, .category-selection {
    padding-top: 80px !important; 
    /* Sur tablette portrait, on peut mettre 2 ou 3 colonnes */
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;
  }

  .back-button {
    top: 75px !important;
  }
}

@media (min-width: 1800px) {
  .gallery.grid {
    /* Max 5 colonnes sur les écrans géants pour garder de la lisibilité */
    grid-template-columns: repeat(5, 1fr) !important; 
    max-width: 1600px;
    margin: 0 auto;
  }
}
/* Agrandir les zones de clic navigation pour le tactile */
@media (max-width: 1024px) {
  .lb-nav-area { width: 45%; } 
  .lb-close { top: 10px; right: 15px; font-size: 50px; }
}

.about-section {
  padding: 50px 5% !important;
}

.about-content {
  max-width: 800px; /* Un peu plus large pour les tablettes */
  width: 100%;
}

/* Méthode simple : quand la lightbox a la classe .show, on cache le burger */
#lightbox.show ~ .burger {
  opacity: 0;
  pointer-events: none;
}

/* Et pour être certain, on ajoute une règle spécifique au mode mobile */
@media (max-width: 900px) {
  body:has(#lightbox.show) .burger {
    display: none !important;
  }
}