/* =============================================================================
   ADHKAR SABAH & MASSÂ — Lecteur de livre numérique (famille Audio Coran)
   app.css — composants propres au lecteur, préfixe reader- / bottom-nav /
   page-jump / splash. Étend style.css (design system) sans le modifier.
   Lecture : défilement vertical continu + mode nuit (inversion douce).
   ========================================================================== */

/* -------------------------------------------------------------------------
   1. LAYOUT PLEIN ÉCRAN
   ---------------------------------------------------------------------- */
.reader-body {
  overflow: hidden;
  height: 100svh;
  overscroll-behavior: none;
  user-select: none;              /* app native : pas de sélection accidentelle */
  -webkit-user-select: none;
}
.reader-page canvas {
  -webkit-touch-callout: none;    /* pas de menu « enregistrer l'image » au long-press */
}
.page-jump input { user-select: text; -webkit-user-select: text; }
/* Le halo d'ambiance du DS reste actif (body::before de style.css). */

/* -------------------------------------------------------------------------
   2. TOPBAR (variante lecteur — même ADN que .topbar du DS)
   ---------------------------------------------------------------------- */
.reader-topbar {
  position: fixed;
  inset: 0 0 auto 0;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-bottom: 12px;
  /* le sélecteur d'apps peut passer sur sa propre ligne sans rien comprimer */
  flex-wrap: wrap;
  column-gap: 14px;
  row-gap: 10px;
  transition: transform var(--dur-base) var(--ease-out),
              background var(--dur-base) var(--ease-out);
}

/* ---- Sélecteur d'applications Audio Coran (composant partagé) ---------- */
.ac-switch {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px; border-radius: 100px;
  background: rgba(127,127,127,0.10);
  border: 1px solid rgba(127,127,127,0.22);
}
.ac-switch__pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: 100px;
  font-size: 13.5px; font-weight: 600; line-height: 1;
  text-decoration: none; color: inherit; opacity: 0.72; white-space: nowrap;
  transition: opacity 0.18s ease, background 0.18s ease, transform 0.18s ease;
}
.ac-switch__pill svg { width: 17px; height: 17px; flex-shrink: 0; }
.ac-switch__pill:hover { opacity: 1; background: rgba(127,127,127,0.12); }
.ac-switch__pill:active { transform: scale(0.97); }
.ac-switch__pill.is-current {
  opacity: 1;
  background: linear-gradient(135deg, #1FA97A, #0F6D4C);
  color: #F6F3EA;
  box-shadow: 0 4px 14px rgba(15,109,76,0.32);
}
.ac-switch__pill.is-current:hover { color: #F6F3EA; }
/* Libellé long « Fonds d'écran » réservé aux grands écrans (aria-label pour le reste). */
.ac-switch__long { display: none; }
@media (min-width: 1100px) { .ac-switch__long { display: inline; } }
/* --- Sélecteur d'applications : aligné à droite sur desktop (≥860px). --- */
@media (min-width: 860px) {
  .ac-switch { margin-left: auto; }
}
/* Mobile & tablette (≤859px) : menu déroulant ouvert par le bouton burger
   (styles partagés dans design-system.css). Le header étant en position
   fixed, le menu se positionne juste dessous. */
@media (max-width: 859px) {
  .ac-switch {
    position: absolute; top: calc(100% + 8px); right: clamp(12px, 4vw, 24px);
    left: auto; transform: none; order: 0;
    width: min(264px, calc(100vw - 24px));
    display: none; flex-direction: column; align-items: stretch; gap: 4px;
    padding: 8px; border-radius: 16px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45); z-index: 80;
  }
  .ac-switch.is-open { display: flex; }
  .ac-switch__pill { width: 100%; justify-content: flex-start; min-height: 46px; padding: 11px 14px; border-radius: 12px; font-size: 14.5px; gap: 12px; }
  .ac-switch__pill svg { width: 18px; height: 18px; }
  .ac-switch.is-open .ac-switch__long { display: inline; }
}
@media (prefers-reduced-motion: reduce) {
  .ac-switch__pill { transition: none; }
  .ac-switch__pill:active { transform: none; }
}
.reader-brand { display: flex; flex-direction: column; gap: 0; min-width: 0; }
/* En-tête Adhkar optimisé : la marque occupe la gauche, le sélecteur et les
   contrôles de lecture sont groupés à droite (cohérent avec les autres apps). */
.reader-topbar .topbar__brand { margin-inline-end: auto; min-width: 0; flex: 0 1 auto; }
.reader-topbar .reader-chapter,
.reader-topbar .page-jump { min-height: 40px; }
@media (max-width: 520px) {
  .reader-brand__ar { font-size: 16px; line-height: 1.6; }
  .reader-brand__sub { font-size: 9px; }
  .reader-chapter { padding: 6px 11px; }
}
.reader-brand__ar {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 700;
  /* L'Amiri déborde d'une ligne standard (hampes, ligatures) : il lui faut
     de l'air vertical, sinon l'overflow de l'ellipse rogne les lettres. */
  line-height: 1.75;
  padding: 1px 0 2px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-brand__sub {
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Pill de chapitre courant — même style que .track-reciter / .lp-badge */
.reader-chapter {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  background: var(--surface-strong);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-pill);
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  white-space: nowrap;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.reader-chapter .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 25%, transparent);
}
/* Saisie directe du numéro de page (pill éditable, même ADN que .search-box) */
.page-jump {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono); font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  cursor: text; white-space: nowrap;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.page-jump:focus-within {
  border-color: var(--border-accent);
  background: var(--surface-strong);
}
.page-jump input {
  width: 3ch;
  border: none; background: none; outline: none;
  font: inherit; color: var(--accent); font-weight: 600;
  text-align: right; padding: 0;
  caret-color: var(--accent);
}
.page-jump input::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--text); }
.page-jump__total { pointer-events: none; }

/* -------------------------------------------------------------------------
   3. DÉFILEMENT CONTINU
   ---------------------------------------------------------------------- */
.reader-scroll {
  position: fixed; inset: 0;
  overflow-y: auto;
  overflow-x: auto;
  touch-action: pan-y pan-x; /* pinch géré par app.js */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.reader-flow {
  position: relative;
  margin: 0 auto;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  /* espace pour la topbar et la nav (constantes lues par app.js) */
  padding: calc(84px + env(safe-area-inset-top)) 12px 28px;
  width: max-content;
  min-width: 100%;
  transform-origin: 50% 0;
  will-change: transform;
}

/* La page = la « carte » de lecture (héritière de .player-card) */
.reader-page {
  position: relative;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-elevated); /* placeholder avant rendu */
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}
.reader-page canvas { display: block; width: 100%; height: 100%; }

/* Numéro fantôme sur les pages non encore rendues */
.reader-page::before {
  content: attr(data-page);
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 13px;
  color: var(--text-tertiary);
}
.reader-page.is-rendered::before { display: none; }

/* ---- MODE NUIT : inversion douce (papier sombre, texte clair, teintes
   préservées par hue-rotate). La couverture (photo) est seulement atténuée. */
html:not([data-theme="light"]) .reader-page.is-rendered {
  background: #101314;
}
html:not([data-theme="light"]) .reader-page canvas {
  filter: invert(0.92) hue-rotate(180deg) contrast(0.92) brightness(1.05);
}
html:not([data-theme="light"]) .reader-page--cover canvas {
  filter: brightness(0.82);
}
[data-theme="light"] .reader-page.is-rendered { background: #FFFFFF; }
[data-theme="light"] .reader-page canvas { filter: none; }

/* -------------------------------------------------------------------------
   3ter. CARTE VIDÉO (fin de livre) — même ADN que .player-card du DS
   ---------------------------------------------------------------------- */
.video-card {
  position: relative;
  /* même largeur maximale que les pages du livre (MAX_PAGE_W dans app.js) */
  width: min(760px, calc(100% - 24px));
  margin: 44px auto 0;
  padding: 24px 24px 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  text-align: center;
}
/* Liseré dégradé signature en haut de la carte */
.video-card::after {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--emerald-light), var(--gold), transparent);
  opacity: 0.85;
}
.video-card__badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--emerald) 14%, transparent);
  border: 1px solid var(--border-accent);
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent-2);
}
.video-card__badge .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 25%, transparent);
}
.video-card__title {
  font-family: var(--font-display);
  font-size: 24px; font-weight: 700; line-height: 1.5;
  margin-top: 14px;
}
.video-card__subtitle {
  color: var(--text-secondary); font-size: 13.5px;
  margin: 4px 0 18px;
}
.video-embed {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.video-embed img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-base);
}
.video-embed:hover img { transform: scale(1.03); }
/* voile pour détacher le bouton lecture */
.video-embed::before {
  content: "";
  position: absolute; inset: 0; z-index: 1;
  background: radial-gradient(60% 60% at 50% 50%, rgba(10, 12, 14, 0.35), rgba(10, 12, 14, 0.05));
  pointer-events: none;
}
.video-embed__play {
  position: absolute; left: 50%; top: 50%; z-index: 2;
  transform: translate(-50%, -50%);
  width: 68px; height: 68px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--emerald-light), var(--emerald));
  color: var(--offwhite);
  box-shadow: 0 10px 30px rgba(15, 109, 76, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}
.video-embed__play .icon { width: 26px; height: 26px; margin-left: 3px; }
.video-embed__play:hover {
  transform: translate(-50%, -50%) scale(1.07);
  box-shadow: 0 14px 38px rgba(15, 109, 76, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.video-embed__play:active { transform: translate(-50%, -50%) scale(0.95); }
.video-embed iframe {
  position: absolute; inset: 0;
  width: 100%; height: 100%; border: 0;
}

/* -------------------------------------------------------------------------
   3bis. COLOPHON DE FIN DE LIVRE (footer)
   ---------------------------------------------------------------------- */
.reader-footer {
  position: relative;
  text-align: center;
  padding: 32px 16px calc(150px + env(safe-area-inset-bottom));
}
/* Liseré dégradé signature au-dessus du colophon */
.reader-footer::before {
  content: "";
  display: block;
  width: 56px; height: 2px;
  margin: 0 auto 20px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--emerald-light), var(--gold));
  opacity: 0.7;
}
.reader-footer__copyright {
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary);
}
.reader-footer__credit {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
}
/* .kito-credit / .kito-credit__digital viennent du design system (style.css) */

/* -------------------------------------------------------------------------
   4. BANNIÈRE D'ÉTAT — action de mise à jour + masquage fiable
   ---------------------------------------------------------------------- */
.status-banner__action {
  height: 30px; min-width: auto; margin-left: 4px;
  color: var(--accent); border-color: var(--border-accent);
}
.status-banner__action[hidden] { display: none; }
/* Le transform seul ne suffit pas quand la bannière est décalée sous la
   topbar (mobile) : on force opacité + visibilité à l'état masqué. */
.status-banner {
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform var(--dur-base) var(--ease-out),
              opacity var(--dur-base) var(--ease-out),
              visibility var(--dur-base);
}
.status-banner.is-visible {
  opacity: 1; visibility: visible; pointer-events: auto;
}

/* -------------------------------------------------------------------------
   4bis. SCRUBBER DE PAGES (réutilise .seek du DS) — balayage rapide,
   complémentaire du champ numéro de page (précision) de la topbar.
   ---------------------------------------------------------------------- */
.page-scrubber {
  position: fixed; left: 0; right: 0; z-index: 40;
  bottom: calc(76px + max(10px, env(safe-area-inset-bottom)));
  display: flex; align-items: center; gap: 14px;
  max-width: 560px; margin: 0 auto;
  padding: 10px 18px;
  width: calc(100% - 32px);
  background: color-mix(in srgb, var(--bg-elevated) 82%, transparent);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-soft);
  transition: transform var(--dur-base) var(--ease-out),
              opacity var(--dur-base) var(--ease-out);
}
@supports not (backdrop-filter: blur(1px)) {
  .page-scrubber { background: var(--bg-elevated); }
}
.page-scrubber__label {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 30px; text-align: center;
}
.page-scrubber .seek { --pct: 0%; }

/* -------------------------------------------------------------------------
   5. BOTTOM NAVIGATION (signature glassmorphism du DS)
   ---------------------------------------------------------------------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; align-items: stretch; justify-content: space-around;
  padding: 8px clamp(8px, 4vw, 40px) max(10px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-top: 1px solid var(--border);
  transition: transform var(--dur-base) var(--ease-out);
}
@supports not (backdrop-filter: blur(1px)) {
  .bottom-nav { background: var(--bg); }
}
/* Liseré dégradé signature au-dessus de la barre */
.bottom-nav::before {
  content: "";
  position: absolute; top: -1px; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--emerald-light), var(--gold), transparent);
  opacity: 0.55;
}

.bottom-nav__btn {
  position: relative;
  flex: 1; max-width: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: color var(--dur-fast), background var(--dur-fast),
              transform var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav__btn .icon { width: 23px; height: 23px; }
.bottom-nav__btn span:not(.icon) {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em;
}
.bottom-nav__btn:hover { color: var(--text-secondary); }
.bottom-nav__btn:active { transform: scale(0.92); }

/* État actif : accent + point sous le label (pattern .ctrl-btn--xs.is-active) */
.bottom-nav__btn.is-active { color: var(--accent); }
.bottom-nav__btn.is-active::after {
  content: "";
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.bottom-nav__btn[aria-pressed="true"] { color: var(--accent); }

/* -------------------------------------------------------------------------
   6. MODE IMMERSIF (tap au centre ou défilement vers le bas — Apple Books)
   ---------------------------------------------------------------------- */
body.is-immersive .reader-topbar  { transform: translateY(-110%); }
body.is-immersive .bottom-nav     { transform: translateY(110%); }
body.is-immersive .page-scrubber  { transform: translateY(180%); opacity: 0; pointer-events: none; }

/* -------------------------------------------------------------------------
   7. SPLASH DE CHARGEMENT
   ---------------------------------------------------------------------- */
.splash {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity var(--dur-slow) var(--ease-out), visibility var(--dur-slow);
}
.splash.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash__inner {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 24px; text-align: center;
  animation: cardIn 0.55s var(--ease-out) both;
}
.splash__mark {
  position: relative; width: 74px; height: 74px; margin-bottom: 10px;
  border-radius: 50%;
  background: var(--surface-strong);
  border: 1px solid var(--border-accent);
  box-shadow: var(--shadow-glow);
}
.splash__crescent {
  position: absolute; inset: 17px;
  border-radius: 50%;
  background: var(--gold);
  -webkit-mask: radial-gradient(circle at 68% 34%, transparent 55%, #000 56%);
          mask: radial-gradient(circle at 68% 34%, transparent 55%, #000 56%);
}
.splash__sun {
  position: absolute; top: 20px; right: 18px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--emerald-light);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--emerald-light) 30%, transparent);
}
.splash__title {
  font-family: var(--font-display);
  font-size: clamp(26px, 6vw, 34px); font-weight: 700; line-height: 1.5;
}
.splash__subtitle { color: var(--text-secondary); font-size: 13.5px; }
.splash__bar {
  width: min(240px, 60vw); height: 4px; margin-top: 22px;
  border-radius: var(--radius-pill);
  background: var(--border); overflow: hidden;
}
.splash__bar i {
  display: block; height: 100%; width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--emerald-light), var(--gold));
  transition: width var(--dur-base) var(--ease-out);
}
.splash__hint {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-tertiary); letter-spacing: 0.08em;
}

/* -------------------------------------------------------------------------
   8. RESPONSIVE & ACCESSIBILITÉ
   ---------------------------------------------------------------------- */
@media (max-width: 640px) {
  .reader-topbar {
    padding-left: 14px; padding-right: 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: 10px;
  }
  .reader-brand__ar { font-size: 16px; max-width: 44vw; }
  .reader-brand__sub { font-size: 9px; }
  .reader-chapter { font-size: 11px; padding: 5px 10px; }
  .topbar__actions { gap: 8px; }
  .reader-flow { gap: 10px; padding-left: 8px; padding-right: 8px; }
  /* La bannière d'état passe SOUS la topbar, jamais derrière */
  .status-banner { top: calc(64px + env(safe-area-inset-top)); }
  .page-scrubber { bottom: calc(70px + max(10px, env(safe-area-inset-bottom))); }
}

/* Très petits écrans : le chapitre est déjà indiqué par la nav active */
@media (max-width: 420px) {
  .reader-chapter { display: none; }
  .reader-brand__ar { max-width: 56vw; }
}

@media (pointer: coarse) {
  .bottom-nav__btn { padding-top: 10px; padding-bottom: 8px; }
  /* iOS zoome automatiquement sur tout input < 16px : on l'en empêche */
  .page-jump { font-size: 15px; padding-top: 7px; padding-bottom: 7px; }
  .page-jump input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .reader-flow { transition: none !important; }
  .splash__bar i { transition: none; }
}
