/* Livre Audio — feuille de style unique.
   Jetons issus de design-system/livre-audio/MASTER.md (style « Dark Mode OLED »
   + « Minimalism & Swiss »), avec la typographie ramenée à Inter — écart
   documenté dans MASTER.md.

   Pas de framework : la page doit s'afficher instantanément et fonctionner
   hors ligne sans dépendre d'un script distant. */

:root {
  --bg: #0F0F23;
  --fg: #F8FAFC;
  --card: #1B1B30;
  --muted: #27273B;
  --muted-fg: #94A3B8;
  --border: #312E81;
  --accent: #22C55E;
  --on-accent: #0F172A;
  --ring: #FFFFFF;

  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 48px;

  --r-md: 12px;
  --r-lg: 20px;
  --r-full: 999px;

  /* Encoches et barres système des téléphones. */
  --safe-haut: env(safe-area-inset-top, 0px);
  --safe-bas: env(safe-area-inset-bottom, 0px);

  --t-rapide: 150ms;
  --t-normal: 250ms;
}

* { box-sizing: border-box; }

/* Toute règle de classe posant un `display` l'emporterait sur le `display:none`
   que la feuille par défaut du navigateur associe à l'attribut `hidden` — le
   lecteur et le tiroir s'afficheraient alors dès le chargement. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2 { line-height: 1.25; margin: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* Anneau de focus toujours visible : jamais supprimé, seulement redessiné. */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 4px;
}

.vue { display: block; }

/* ── Bibliothèque ─────────────────────────────────────────────────────── */

.entete {
  padding: calc(var(--safe-haut) + var(--space-4)) var(--space-3) var(--space-2);
}
.entete h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }

.etat {
  margin: var(--space-2) 0 0;
  padding: var(--space-1) var(--space-2);
  background: var(--muted);
  border-radius: var(--r-md);
  color: var(--muted-fg);
  font-size: 0.875rem;
}

.grille {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--space-3) var(--space-2);
  padding: var(--space-2) var(--space-3) 140px;
}

.carte { text-align: left; width: 100%; }

/* 2:3 — proportions d'un livre. Le carré évoque un album de musique et
   déforme les couvertures extraites des fichiers source. */
.carte-pochette {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--r-lg);
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  transition: transform var(--t-normal) ease;
}
.carte:hover .carte-pochette,
.carte:focus-visible .carte-pochette { transform: scale(1.03); }

.carte-titre {
  margin: var(--space-1) 0 2px;
  font-size: 0.9375rem;
  font-weight: 600;
  /* Deux lignes maximum : au-delà, la grille se déforme. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.carte-detail { margin: 0; font-size: 0.8125rem; color: var(--muted-fg); }

.carte-jauge {
  margin-top: 6px;
  height: 3px;
  background: var(--muted);
  border-radius: var(--r-full);
  overflow: hidden;
}
.carte-jauge span { display: block; height: 100%; background: var(--accent); }

.vide {
  padding: var(--space-5) var(--space-3);
  text-align: center;
  color: var(--muted-fg);
}
.vide-detail { font-size: 0.875rem; }
code { background: var(--muted); padding: 2px 6px; border-radius: 6px; font-size: 0.8125rem; }

/* ── Mini-lecteur ─────────────────────────────────────────────────────── */

.mini {
  position: fixed;
  left: var(--space-2);
  right: var(--space-2);
  bottom: calc(var(--safe-bas) + var(--space-2));
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1);
  background: var(--card);
  border: 1px solid var(--muted);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  text-align: left;
  overflow: hidden;
}
.mini-pochette {
  width: 34px; height: 51px;
  border-radius: 10px;
  flex: 0 0 auto;
}
.mini-textes { flex: 1 1 auto; min-width: 0; }
.mini-titre, .mini-chapitre {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-titre { font-size: 0.875rem; font-weight: 600; }
.mini-chapitre { font-size: 0.8125rem; color: var(--muted-fg); }

.mini-play {
  width: 44px; height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
}
.mini-jauge {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--muted);
}
.mini-jauge span { display: block; height: 100%; width: 0; background: var(--accent); }

/* ── Lecteur ──────────────────────────────────────────────────────────── */

.lecteur {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-haut) + var(--space-2)) var(--space-3)
           calc(var(--safe-bas) + var(--space-3));
  z-index: 20;
}

.lecteur-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.lecteur-livre {
  font-size: 0.8125rem;
  color: var(--muted-fg);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pochette-zone {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: var(--space-3) 0;
  min-height: 0;
}
.pochette {
  width: min(56vw, 240px);
  aspect-ratio: 2 / 3;
  border-radius: 28px;
  display: grid;
  place-items: center;
  font-size: 5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.lecteur-titres { text-align: center; margin-bottom: var(--space-3); }
.lecteur-titres h2 { font-size: 1.25rem; font-weight: 600; }
.lecteur-position { margin: 4px 0 0; color: var(--muted-fg); font-size: 0.875rem; }

/* ── Barre de progression ─────────────────────────────────────────────── */

.scrub { margin-bottom: var(--space-3); }

#scrubber {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;            /* zone tactile large, piste fine */
  background: transparent;
  cursor: pointer;
}
#scrubber::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--r-full);
  background: linear-gradient(
    to right,
    var(--accent) var(--avancement, 0%),
    var(--muted) var(--avancement, 0%)
  );
}
#scrubber::-moz-range-track {
  height: 4px;
  border-radius: var(--r-full);
  background: linear-gradient(
    to right,
    var(--accent) var(--avancement, 0%),
    var(--muted) var(--avancement, 0%)
  );
}
#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -5px;
  border-radius: var(--r-full);
  background: var(--fg);
}
#scrubber::-moz-range-thumb {
  width: 14px; height: 14px;
  border: 0;
  border-radius: var(--r-full);
  background: var(--fg);
}

.temps {
  display: flex;
  justify-content: space-between;
  color: var(--muted-fg);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

/* ── Commandes ────────────────────────────────────────────────────────── */

.controles {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

/* 44×44 minimum : sous cette taille, la cible devient difficile au pouce. */
.btn-icone {
  width: 48px; height: 48px;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  color: var(--fg);
  transition: background var(--t-rapide) ease, transform var(--t-rapide) ease;
}
.btn-icone:hover { background: var(--muted); }
.btn-icone:active { transform: scale(0.92); }

.btn-play {
  width: 72px; height: 72px;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--on-accent);
  transition: transform var(--t-rapide) ease;
}
.btn-play:active { transform: scale(0.94); }

.outils {
  display: flex;
  justify-content: center;
  gap: var(--space-1);
}
.btn-outil {
  min-height: 44px;
  padding: 0 var(--space-2);
  border-radius: var(--r-full);
  background: var(--muted);
  color: var(--fg);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--t-rapide) ease;
}
.btn-outil:hover { background: var(--border); }
.btn-outil[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ── Tiroir des chapitres ─────────────────────────────────────────────── */

.voile {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 25;
}

.tiroir {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(90vw, 420px);
  background: var(--card);
  border-left: 1px solid var(--muted);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-haut) + var(--space-2)) 0 var(--safe-bas);
  transform: translateX(0);
  transition: transform var(--t-normal) ease;
}
.tiroir[data-ferme] { transform: translateX(100%); }

.tiroir-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-2) var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--muted);
}
.tiroir-entete h2 { font-size: 1.125rem; font-weight: 600; }

.liste-chapitres {
  list-style: none;
  margin: 0;
  padding: var(--space-1) 0;
  overflow-y: auto;
  flex: 1 1 auto;
}
.chapitre {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 56px;
  padding: var(--space-1) var(--space-3);
  text-align: left;
  transition: background var(--t-rapide) ease;
}
.chapitre:hover { background: var(--muted); }
.chapitre[aria-current="true"] { color: var(--accent); }
.chapitre-num {
  width: 28px;
  flex: 0 0 auto;
  color: var(--muted-fg);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.chapitre[aria-current="true"] .chapitre-num { color: var(--accent); }
.chapitre-nom { flex: 1 1 auto; font-size: 0.9375rem; }
.chapitre-etat { flex: 0 0 auto; color: var(--muted-fg); display: grid; place-items: center; }

/* ── Feuille d'options (vitesse, minuteur) ────────────────────────────── */

.feuille {
  position: fixed;
  left: var(--space-2);
  right: var(--space-2);
  bottom: calc(var(--safe-bas) + var(--space-2));
  max-width: 420px;
  margin: 0 auto;
  padding: var(--space-3);
  background: var(--card);
  border: 1px solid var(--muted);
  border-radius: var(--r-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  z-index: 40;
}
.feuille-titre { font-size: 1rem; font-weight: 600; margin-bottom: var(--space-2); }
.feuille-options { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.feuille-options button {
  min-height: 44px;
  padding: 0 var(--space-2);
  border-radius: var(--r-full);
  background: var(--muted);
  font-size: 0.9375rem;
}
.feuille-options button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ── Écrans larges ────────────────────────────────────────────────────── */

@media (min-width: 768px) {
  .grille { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .entete, .grille { max-width: 1100px; margin-inline: auto; }
  .mini { left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); }
}

/* ── Mouvement réduit ─────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Ajout d'un livre et avancement de conversion ─────────────────────── */

.entete-ligne {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.btn-ajouter {
  min-height: 44px;
  padding: 0 var(--space-2);
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  transition: filter var(--t-rapide) ease, transform var(--t-rapide) ease;
}
.btn-ajouter:hover { filter: brightness(1.08); }
.btn-ajouter:active { transform: scale(0.96); }

/* Un livre en conversion reste visible mais n'est pas ouvrable : le rendre
   cliquable pour aboutir à un lecteur vide serait plus déroutant que de le
   désactiver franchement. */
.carte:disabled { cursor: default; }
.carte:disabled .carte-pochette { opacity: 0.55; }
.carte:disabled:hover .carte-pochette { transform: none; }

.carte-badge {
  position: absolute;
  left: var(--space-1);
  right: var(--space-1);
  bottom: var(--space-1);
  padding: 4px 8px;
  border-radius: var(--r-md);
  background: rgba(15, 15, 35, 0.88);
  color: var(--fg);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  text-shadow: none;
}

/* ── Écran de connexion ───────────────────────────────────────────────── */

.connexion {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--space-3);
  background: var(--bg);
}

.connexion-boite {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.connexion-titre { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.connexion-texte {
  margin: 0 0 var(--space-2);
  color: var(--muted-fg);
  font-size: 0.9375rem;
}
.connexion-label { font-size: 0.875rem; font-weight: 500; }

.connexion-champ {
  min-height: 48px;
  padding: 0 var(--space-2);
  border: 1px solid var(--muted);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 1rem;   /* 16px minimum : en dessous, iOS zoome à la saisie */
}
.connexion-champ:focus-visible { border-color: var(--accent); }

.connexion-erreur {
  margin: 0;
  color: #FCA5A5;
  font-size: 0.875rem;
}
.connexion-valider { margin-top: var(--space-2); }

/* ── Logo ─────────────────────────────────────────────────────────────── */

.connexion-logo {
  width: 112px;
  height: 112px;
  margin: 0 auto var(--space-2);
  display: block;
}

/* Pas de logo dans l'en-tête : à 32 px son texte devient illisible, et il
   pousse « Ma bibliothèque » sur deux lignes face au bouton d'ajout. La marque
   est portée par l'icône d'accueil et l'écran de connexion. */
