/* ==========================================================================
   HG PORTFOLIO — Enhanced UX/UI Layer
   Animations légères, ergonomie, micro-interactions, accessibilité
   ========================================================================== */

/* --------------------------------------------------------------------------
   STICKY HOME HERO — correction critique
   Le sticky nécessite que TOUS les parents aient overflow: visible.
   On s'assure ici qu'aucun de mes styles ne casse cette chaîne.
   -------------------------------------------------------------------------- */
body,
.hg-home-wrap,
.hg-projects-outer,
.hg-projects {
  overflow-x: clip; /* clip au lieu de hidden : préserve le sticky */
}

/* Garantie explicite du sticky */
.hg-home-hero {
  position: sticky !important;
  top: 56px !important;
  z-index: 50 !important;
  background: var(--bg) !important;
}
@media (max-width: 720px) {
  .hg-home-hero {
    top: 54px !important;
  }
}

/* --------------------------------------------------------------------------
   0. Skip link (accessibilité)
   -------------------------------------------------------------------------- */
.skip-link {
  position: fixed;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: var(--fg);
  color: var(--bg);
  padding: 10px 20px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus { top: 12px; }

/* --------------------------------------------------------------------------
   1. Scroll Reveal — intersection observer CSS hooks
   -------------------------------------------------------------------------- */
[data-reveal] {
  opacity: 0;
  transform: translateY(24px);
  transition:
    opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
[data-reveal="left"] { transform: translateX(-32px); }
[data-reveal="right"] { transform: translateX(32px); }
[data-reveal="scale"] { transform: scale(0.95); transform-origin: center bottom; }

[data-reveal].is-visible {
  opacity: 1;
  transform: none;
}

/* Délai en cascade pour les éléments dans une grille */
[data-reveal-delay="1"] { transition-delay: 80ms; }
[data-reveal-delay="2"] { transition-delay: 160ms; }
[data-reveal-delay="3"] { transition-delay: 240ms; }
[data-reveal-delay="4"] { transition-delay: 320ms; }

/* --------------------------------------------------------------------------
   2. Curseur personnalisé (desktop uniquement)
   Un seul anneau qui suit le pointeur — simple, stable, cohérent.
   -------------------------------------------------------------------------- */
@media (hover: hover) and (pointer: fine) {
  /* On masque le curseur natif uniquement sur les zones interactives */
  a, button, [role="button"],
  .hg-tile, .hg-masonry-btn,
  .hg-filter, .hg-acc-toggle,
  .hg-palette-btn, .hg-burger {
    cursor: none;
  }

  /* L'anneau lui-même */
  #hg-cursor {
    position: fixed;
    top: 0;
    left: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid var(--fg);
    pointer-events: none;
    z-index: 9998;
    opacity: 0;               /* invisible jusqu'au premier mouvement */
    transform: translate(-50%, -50%);
    will-change: transform;
    /* Légèrement en retard : donne l'effet "magnétique" */
    transition: opacity 0.3s,
                width 0.25s cubic-bezier(0.22, 1, 0.36, 1),
                height 0.25s cubic-bezier(0.22, 1, 0.36, 1),
                background 0.2s;
  }

  /* Point central fixe (suit exactement le curseur, sans lag) */
  #hg-cursor-dot {
    position: fixed;
    top: 0;
    left: 0;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--fg);
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transform: translate(-50%, -50%);
    will-change: transform;
    transition: opacity 0.3s, background 0.2s;
  }

  /* Visible dès le premier mouvement */
  #hg-cursor.is-active   { opacity: 0.5; }
  #hg-cursor-dot.is-active { opacity: 1; }

  /* Hover sur liens / boutons → anneau grossit un peu */
  #hg-cursor.is-hover {
    width: 48px;
    height: 48px;
    opacity: 0.7;
  }

  /* Hover sur images / cards → rempli, style "voir" */
  #hg-cursor.is-view {
    width: 60px;
    height: 60px;
    background: var(--fg);
    opacity: 0.12;
    border-radius: 50%;
  }
}

/* --------------------------------------------------------------------------
   3. Transitions de page (fade entre pages)
   -------------------------------------------------------------------------- */
@keyframes hg-page-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hg-page-transition-active {
  animation: hg-page-in 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* --------------------------------------------------------------------------
   4. Header amélioré — indicateur de scroll progress
   -------------------------------------------------------------------------- */
#hg-scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--fg);
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
body.is-single #hg-scroll-progress { opacity: 1; }

/* --------------------------------------------------------------------------
   5. Strip/galerie — améliorations UX mobile
   -------------------------------------------------------------------------- */

/* Indicateur scroll horizontal */
.hg-strip-track {
  position: relative;
}
.hg-strip-hint {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  gap: 4px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
  animation: hg-hint-fade 1.2s 0.8s both;
}
@keyframes hg-hint-fade {
  from { opacity: 0; transform: translateY(-50%) translateX(8px); }
  50%  { opacity: 1; }
  to   { opacity: 0; transform: translateY(-50%) translateX(0); }
}
@media (hover: none), (pointer: coarse) {
  .hg-strip-hint { display: flex; }
}

/* Fade gradient sur les bords du strip */
.hg-strip-wrap {
  position: relative;
}
.hg-strip-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 60px;
  height: 100%;
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
  z-index: 1;
  opacity: 0.6;
}

/* --------------------------------------------------------------------------
   6. Cards projet — hover raffiné
   -------------------------------------------------------------------------- */
.hg-project-card {
  transition: opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.hg-project-card:not(.dimmed):hover {
  position: relative;
  z-index: 2;
}

/* Focus visible amélioré pour les liens de projets */
.hg-project-mainline a:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 4px;
  border-radius: 2px;
}

/* Accordion — animation fluide */
.hg-accordion {
  transition: max-height 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

/* --------------------------------------------------------------------------
   7. Lightbox — améliorée
   -------------------------------------------------------------------------- */
.hg-lightbox {
  animation: hg-lb-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes hg-lb-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.hg-lb-stage img,
.hg-lb-stage video {
  animation: hg-lb-img-in 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes hg-lb-img-in {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* Compteur lightbox */
.hg-lb-counter {
  font-size: 12px;
  color: rgba(240, 235, 227, 0.5);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Swipe indicator mobile */
.hg-lb-swipe-hint {
  display: none;
  position: absolute;
  bottom: 40px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: rgba(240, 235, 227, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
@media (hover: none), (pointer: coarse) {
  .hg-lb-swipe-hint { display: block; }
}

/* --------------------------------------------------------------------------
   8. Formulaire contact — champs améliorés
   -------------------------------------------------------------------------- */
.hg-field input,
.hg-field textarea {
  transition: border-color 0.2s, box-shadow 0.2s;
}
.hg-field input:focus,
.hg-field textarea:focus {
  border-bottom-color: var(--fg);
  box-shadow: 0 1px 0 0 var(--fg);
  outline: none;
}
.hg-field input::placeholder,
.hg-field textarea::placeholder {
  color: var(--muted);
  opacity: 0.6;
  transition: opacity 0.2s;
}
.hg-field input:focus::placeholder,
.hg-field textarea:focus::placeholder {
  opacity: 0.3;
}

/* État de chargement du bouton submit */
.hg-submit.loading {
  pointer-events: none;
  opacity: 0.6;
}
.hg-submit.loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--bg);
  border-top-color: transparent;
  border-radius: 50%;
  animation: hg-spin 0.7s linear infinite;
  margin-left: 8px;
}
@keyframes hg-spin {
  to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   9. Footer — liens avec hover amélioré
   -------------------------------------------------------------------------- */
.hg-footer-col a {
  position: relative;
  display: inline-block;
  transition: color 0.2s;
}
.hg-footer-col a::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--fg);
  transition: width 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.hg-footer-col a:hover { color: var(--fg); }
.hg-footer-col a:hover::after { width: 100%; }

/* --------------------------------------------------------------------------
   10. Mobile nav — améliorations UX
   -------------------------------------------------------------------------- */
.hg-mobile-panel {
  overscroll-behavior: contain;
}
.hg-mobile-nav a {
  -webkit-tap-highlight-color: transparent;
}

/* Zone de tap suffisante (min 44px) */
.hg-burger {
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
  align-items: center;
}

/* --------------------------------------------------------------------------
   11. Images — lazy load avec placeholder raffiné
   -------------------------------------------------------------------------- */
.hg-tile img.hg-lazy,
.hg-masonry-btn img.hg-lazy {
  filter: blur(3px) brightness(0.9);
  transition: filter 0.4s, opacity 0.4s;
}
.hg-tile img:not(.hg-lazy),
.hg-masonry-btn img:not(.hg-lazy) {
  filter: none;
  opacity: 1;
}

/* Skeleton shimmer pour les images en cours de chargement */
@keyframes hg-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.hg-tile:not(.video-ready):not([data-loaded="1"]) .hg-tile,
img.hg-lazy {
  background: linear-gradient(
    90deg,
    var(--bg2) 25%,
    color-mix(in srgb, var(--fg) 5%, var(--bg2)) 50%,
    var(--bg2) 75%
  );
  background-size: 200% 100%;
  animation: hg-shimmer 1.6s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   12. Single projet — améliorations layout
   -------------------------------------------------------------------------- */

/* Breadcrumb amélioré */
.hg-back {
  gap: 10px;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wider);
}
.hg-back svg {
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
.hg-back:hover svg {
  transform: translateX(-4px);
}

/* Navigation prev/next améliorée */
.hg-single-foot a {
  position: relative;
  overflow: hidden;
}
.hg-single-foot a::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--fg);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: -1;
}
.hg-single-foot a:hover {
  color: var(--bg);
}
.hg-single-foot a:hover::before {
  transform: scaleX(1);
}

/* --------------------------------------------------------------------------
   13. À propos — raffinements
   -------------------------------------------------------------------------- */
.hg-parcours-line {
  transition: opacity 0.2s;
}
.hg-parcours-line:hover {
  opacity: 0.8;
}

/* --------------------------------------------------------------------------
   14. Palette switcher — améliorations UX
   -------------------------------------------------------------------------- */
.hg-palette-btn {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--rule2);
  transition: border-color 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
}
.hg-palette-btn:hover {
  border-color: var(--fg);
  transform: scale(1.1);
}
.hg-palette-dot {
  width: 50%;
  height: 100%;
  display: block;
  flex-shrink: 0;
}
.hg-palette-dot--bg { background: var(--palette-bg, var(--bg)); }
.hg-palette-dot--fg { background: var(--palette-fg, var(--fg)); }

.hg-palette-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--rule2);
  padding: 16px;
  min-width: 240px;
  z-index: 300;
  animation: hg-panel-in 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes hg-panel-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hg-palette-panel[hidden] { display: none; }

/* Boutons preset améliorés */
.hg-palette-presets button {
  position: relative;
  overflow: hidden;
  border-radius: 3px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.hg-palette-presets button:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.hg-palette-presets button.is-active::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

/* --------------------------------------------------------------------------
   15. Toolbar typographie (panneau de dev uniquement)
   -------------------------------------------------------------------------- */
#hg-typo-debug {
  display: none;
}
body.hg-debug #hg-typo-debug {
  display: flex;
  position: fixed;
  bottom: 16px;
  left: 16px;
  background: var(--bg);
  border: 1px solid var(--rule2);
  padding: 12px 16px;
  z-index: 9000;
  flex-direction: column;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted2);
}

/* --------------------------------------------------------------------------
   16. Sélection de texte thématique
   -------------------------------------------------------------------------- */
::selection {
  background: var(--fg);
  color: var(--bg);
}

/* --------------------------------------------------------------------------
   17. Focus global propre — accessibilité
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   18. print — masquer le superflu
   -------------------------------------------------------------------------- */
@media print {
  .hg-header,
  .hg-footer,
  .hg-mobile-panel,
  #hg-cursor,
  #hg-scroll-progress,
  .hg-palette-control,
  .hg-burger {
    display: none !important;
  }
  body { background: #fff; color: #000; }
}

/* --------------------------------------------------------------------------
   19. Performance : content-visibility pour sections hors viewport
   -------------------------------------------------------------------------- */
.hg-footer {
  content-visibility: auto;
  contain-intrinsic-size: 0 300px;
}

/* --------------------------------------------------------------------------
   20. Reduced motion — respect total des préférences système
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .hg-lightbox,
  .hg-lb-stage img,
  .hg-lb-stage video,
  .hg-page-transition-active {
    animation: none !important;
  }
  #hg-cursor { display: none !important; }
  html { cursor: auto !important; }
  a, button, [role="button"] { cursor: pointer !important; }
  @keyframes hg-shimmer { 0%, 100% { background-position: 0 0; } }
}
