/**
 * Couche "app-like" - standards web modernes pour un rendu PWA premium
 * sans migrer de stack. Chaque bloc dégrade gracefully si le navigateur
 * ne supporte pas la feature. Inspection commentaire par commentaire :
 * rien n'est magique, tout est progressive enhancement pur.
 *
 * Chargé APRÈS style.css pour pouvoir override si besoin.
 */

/* ═════════════════════════════════════════════════════════════════════
 * 1. Viewport moderne - 100dvh partout où 100vh reste fallback.
 *    Évite le "saut" quand la barre d'URL mobile disparaît/réapparaît.
 * ═══════════════════════════════════════════════════════════════════ */
@supports (height: 100dvh) {
  .uses-full-viewport { min-height: 100dvh; }
  html, body { min-height: 100dvh; }
}

/* ═════════════════════════════════════════════════════════════════════
 * 2. Safe-area iOS - respecte l'encoche et la home-bar sur iPhone X+
 *    sans toucher à chaque composant. Variables consommables partout.
 * ═══════════════════════════════════════════════════════════════════ */
:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --fab-offset:  max(1rem, env(safe-area-inset-bottom, 1rem));
}
/* Note : .site-header gère déjà --sat dans son propre padding (style.css).
   On évite de l'inclure ici pour ne pas écraser ses valeurs mobile. */
.hd-nav-float,
.hd-toolbar-float {
  padding-top: max(var(--safe-top), 0px);
  padding-left: max(var(--safe-left), 0px);
  padding-right: max(var(--safe-right), 0px);
}
.site-footer {
  padding-bottom: calc(var(--safe-bottom) + 2rem);
}

/* ═════════════════════════════════════════════════════════════════════
 * 3. View Transitions API - transitions entre pages cross-document.
 *    Activée sur Chrome/Edge/Safari TP 2024+. Fallback : nothing.
 *
 *    Les éléments avec view-transition-name doivent être uniques par
 *    page. On donne un nom stable au logo header et au BG principal
 *    pour que le navigateur puisse les "morpher" entre deux pages.
 * ═══════════════════════════════════════════════════════════════════ */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.32s;
  animation-timing-function: cubic-bezier(.4, 0, .2, 1);
}
::view-transition-group(site-logo) {
  animation-duration: 0.45s;
  animation-timing-function: cubic-bezier(.2, .9, .3, 1.1);
}

.site-header__brand,
.site-brand,
.site-logo {
  view-transition-name: site-logo;
}

/* Respect reduced-motion : neutralise les transitions. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root),
  ::view-transition-group(site-logo) {
    animation: none !important;
  }
}

/* ═════════════════════════════════════════════════════════════════════
 * 4. Scroll-snap mobile sur onglets du chart - sensation native quand
 *    on swipe horizontalement entre Synthèse / Type & Énergie / etc.
 * ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .tabs-nav,
  .hd-tabs__nav,
  .tabs-header {
    scroll-snap-type: x proximity;
    scroll-padding-inline: 1rem;
    scrollbar-width: none;
  }
  .tabs-nav > *,
  .hd-tabs__nav > *,
  .tabs-header > * {
    scroll-snap-align: center;
  }
  .tabs-nav::-webkit-scrollbar,
  .hd-tabs__nav::-webkit-scrollbar,
  .tabs-header::-webkit-scrollbar {
    display: none;
  }
}

/* ═════════════════════════════════════════════════════════════════════
 * 5. Scroll-driven reveal - éléments avec .reveal apparaissent au scroll
 *    via CSS scroll-driven animations (sans JS).
 *    Fallback ancien navigateur : .reveal reste visible (opacity 1).
 * ═══════════════════════════════════════════════════════════════════ */
.reveal {
  opacity: 1;
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .reveal {
      animation: reveal-fade linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 25%;
    }
    @keyframes reveal-fade {
      from { opacity: 0; transform: translateY(16px); }
      to   { opacity: 1; transform: translateY(0); }
    }
  }
}

/* ═════════════════════════════════════════════════════════════════════
 * 6. Container queries - archives de cards responsives au conteneur,
 *    pas au viewport. Bonus : reste correct en iframe ou en panneau.
 * ═══════════════════════════════════════════════════════════════════ */
.celeb-grid,
.archive-grid,
.cards-grid {
  container-type: inline-size;
}
@container (max-width: 640px) {
  .celeb-grid .celeb-card,
  .archive-grid .archive-card,
  .cards-grid > * {
    grid-column: 1 / -1;
  }
}

/* ═════════════════════════════════════════════════════════════════════
 * 7. Gestion tactile fine - supprime le tap-highlight natif mobile qui
 *    flashe en gris-bleu au tap (anti-natif), et garantit que les hovers
 *    ne collent pas sur mobile après un tap.
 * ═══════════════════════════════════════════════════════════════════ */
@media (hover: none) {
  a, button, [role="button"] {
    -webkit-tap-highlight-color: rgba(201, 168, 76, 0.18);
  }
  /* Neutralise les :hover qui resteraient "collés" post-tap */
  a:hover, button:hover { transition-duration: 0s; }
}

/* ═════════════════════════════════════════════════════════════════════
 * 8. Scroll horizontal élégant - la scrollbar du mode sombre est discrète
 *    et s'accorde avec la palette or/nuit.
 * ═══════════════════════════════════════════════════════════════════ */
@supports (scrollbar-color: auto) {
  html {
    scrollbar-color: rgba(201, 168, 76, 0.35) transparent;
    scrollbar-gutter: stable;
  }
  body.light-mode {
    scrollbar-color: rgba(139, 105, 20, 0.3) transparent;
  }
}

/* ═════════════════════════════════════════════════════════════════════
 * 9. Focus visible premium - anneau doré subtil au lieu du contour bleu
 *    natif, plus cohérent avec l'identité visuelle.
 * ═══════════════════════════════════════════════════════════════════ */
:focus-visible {
  outline: 2px solid rgba(201, 168, 76, 0.65);
  outline-offset: 2px;
  border-radius: 4px;
}
body.light-mode :focus-visible {
  outline-color: rgba(139, 105, 20, 0.7);
}
