/* =====================================================================
   CAKEDA POD — Design System "App Native"
   Marque : noir + orange. Mobile-first, safe-areas, tab bar, cartes.
   Inclure APRÈS Tailwind CDN. Un seul fichier partagé par toutes les pages.
   ===================================================================== */

/* ---------- Police ---------- */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

/* ---------- Tokens ---------- */
:root {
  --bg:            #0a0a0b;   /* fond app */
  --bg-elev:       #121214;   /* fond légèrement surélevé */
  --surface:       #18181b;   /* cartes */
  --surface-2:     #232328;   /* cartes surélevées / champs */
  --border:        rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);

  --accent:        #ff8c00;   /* orange marque */
  --accent-2:      #ffa733;
  --accent-soft:   rgba(255,140,0,.14);
  --accent-glow:   rgba(255,140,0,.35);

  --text:          #f5f5f6;
  --text-muted:    #a1a1aa;
  --text-faint:    #6b6b73;

  --radius-sm: 12px;
  --radius:    18px;
  --radius-lg: 26px;
  --radius-xl: 32px;

  --shadow-card: 0 6px 24px rgba(0,0,0,.45);
  --shadow-pop:  0 12px 40px rgba(0,0,0,.55);

  --topbar-h: 56px;
  --tabbar-h: 60px;
  --gutter: 18px;   /* marge latérale du contenu */
  --sidebar-w: 250px; /* largeur de la barre latérale desktop */

  /* safe areas iOS / Android (notch + home indicator) */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ease: cubic-bezier(.22,.61,.36,1);
}

/* ---------- Reset doux ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Manrope', -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  /* feeling natif : pas de sélection ni de surbrillance au tap */
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  /* place pour la top bar (fixe) et la tab bar (fixe) */
  padding-top: calc(var(--topbar-h) + var(--safe-top));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
}

/* le contenu texte (lecture) reste sélectionnable si besoin */
.selectable { -webkit-user-select: text; user-select: text; }

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Conteneur app (largeur "téléphone" centrée sur tablette/PC) ---------- */
.app-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}
/* Le comportement grand écran (≥1024px) est défini dans la section
   « DESKTOP — coquille app desktop » en bas de ce fichier (barre latérale). */

/* =====================================================================
   TOP APP BAR
   ===================================================================== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  padding-right: 12px;
  background: rgba(10,10,11,.72);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}
.topbar__title {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -.02em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__title .brand-accent { color: var(--accent); }
.topbar__btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.15rem;
  transition: background .2s var(--ease);
}
.topbar__btn:hover, .topbar__btn:active { background: rgba(255,255,255,.08); }
.topbar--center .topbar__title { text-align: center; }

/* =====================================================================
   BOTTOM TAB BAR (navigation native)
   ===================================================================== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(10,10,11,.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  z-index: 50;
}
.tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: .68rem;
  font-weight: 600;
  min-height: 44px;
  transition: color .2s var(--ease);
  position: relative;
}
.tabbar__item i { font-size: 1.15rem; }
.tabbar__item.active { color: var(--accent); }
.tabbar__item.active::before {
  content: '';
  position: absolute;
  top: 6px;
  width: 34px; height: 30px;
  background: var(--accent-soft);
  border-radius: 12px;
  z-index: -1;
}
.tabbar__item:active { transform: scale(.94); }

/* bouton central proéminent (lecture/scan) */
.tabbar__fab {
  flex: 0 0 auto;
  width: 56px; height: 56px;
  margin: -18px 6px 0;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  color: #1a1205;
  display: grid; place-items: center;
  font-size: 1.4rem;
  box-shadow: 0 8px 24px var(--accent-glow);
  align-self: center;
}
.tabbar__fab:active { transform: scale(.92); }
.tabbar__fab.active { box-shadow: 0 8px 24px var(--accent-glow), 0 0 0 4px var(--accent-soft); }

/* =====================================================================
   TYPOGRAPHIE & SECTIONS
   ===================================================================== */
.page { padding-top: 18px; padding-bottom: 8px; }   /* ne pas écraser le padding horizontal de .app-container */
.page-title {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -.03em;
  margin-bottom: 4px;
}
.page-subtitle { color: var(--text-muted); font-size: .95rem; margin-bottom: 18px; }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 26px 0 14px;
}
.section-head h2 { font-size: 1.18rem; font-weight: 700; letter-spacing: -.02em; }
.section-head a { color: var(--accent); font-size: .85rem; font-weight: 600; }

.eyebrow {
  display: inline-block;
  font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

/* =====================================================================
   BOUTONS
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 22px;
  border: none; border-radius: 999px;
  font-size: 1rem; font-weight: 700;
  transition: transform .15s var(--ease), background .2s var(--ease), box-shadow .2s var(--ease);
  min-height: 48px;
}
.btn:active { transform: scale(.97); }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  color: #1a1205;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 8px 26px var(--accent-glow); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: #2c2c33; }
.btn-ghost { background: transparent; color: var(--accent); }

/* =====================================================================
   CARTES & LISTES
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* tuile catégorie */
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
.cat-tile {
  position: relative;
  padding: 18px 16px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  min-height: 120px;
  display: flex; flex-direction: column; justify-content: space-between;
  transition: transform .2s var(--ease), border-color .2s var(--ease);
}
.cat-tile:active { transform: scale(.97); }
.cat-tile:hover { border-color: var(--accent); }
.cat-tile__icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 1.2rem;
}
.cat-tile__name { font-weight: 700; font-size: 1rem; margin-top: 14px; }

/* carousel horizontal (étagère de livres) */
.shelf {
  display: flex; gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
  margin: 0 calc(-1 * var(--gutter));        /* edge-to-edge */
  padding-left: var(--gutter); padding-right: var(--gutter);
  scrollbar-width: none;
}
.shelf::-webkit-scrollbar { display: none; }
.book-card {
  flex: 0 0 auto;
  width: 140px;
  scroll-snap-align: start;
}
.book-card__cover {
  width: 140px; height: 140px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.book-card__title {
  font-size: .9rem; font-weight: 700; margin-top: 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-card__author { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

/* rangée de liste (item bibliothèque) */
.list-row {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row__thumb {
  width: 56px; height: 56px; border-radius: 14px; object-fit: cover;
  background: var(--surface-2); flex: 0 0 auto;
}
.list-row__body { flex: 1; min-width: 0; }
.list-row__title { font-weight: 700; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row__sub { color: var(--text-muted); font-size: .84rem; }
.list-row__chev { color: var(--text-faint); }

/* =====================================================================
   CHAMPS DE FORMULAIRE
   ===================================================================== */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 7px; }
.input {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
  -webkit-user-select: text; user-select: text;
}
.input::placeholder { color: var(--text-faint); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-group { position: relative; }
.input-group .input { padding-left: 46px; }
.input-group i {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint);
}

/* =====================================================================
   LECTEUR AUDIO (carte de lecture)
   ===================================================================== */
.player-cell { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-card); }
.player-cell .plyr__video-embed, .plyr__video-embed { display: none !important; }
.player-row { display: flex; align-items: center; gap: 14px; }
.player-cover {
  width: 64px; height: 64px; border-radius: 16px; object-fit: cover; flex: 0 0 auto;
  border: 1px solid var(--border);
}
.player-meta { flex: 1; min-width: 0; }
.player-meta h3 { font-size: 1rem; font-weight: 700; }
.player-meta p { font-size: .85rem; color: var(--text-muted); }
.play-btn {
  width: 52px; height: 52px; flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  color: #1a1205;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px var(--accent-glow);
  border: none;
  transition: transform .15s var(--ease);
}
.play-btn:active { transform: scale(.92); }
.play-btn svg { width: 24px; height: 24px; }

/* pied de carte : sélecteur de vitesse + bouton YouTube (injecté par app-player.js) */
.player-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.yt-link {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 15px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #ff4d4d;
  font-size: .82rem; font-weight: 700;
  transition: background .2s var(--ease), transform .15s var(--ease);
}
.yt-link i { font-size: 1.05rem; }
.yt-link:hover { background: #2c2c33; }
.yt-link:active { transform: scale(.92); }

.seek { margin-top: 14px; }
.seek input[type="range"] {
  width: 100%; height: 6px; appearance: none; -webkit-appearance: none;
  background: var(--surface-2); border-radius: 999px; cursor: pointer;
}
.seek input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #1a1205;
}
.seek input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid #1a1205;
}
.seek-times { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-faint); font-variant-numeric: tabular-nums; margin-top: 6px; }
.speed-select {
  background: var(--surface-2); color: var(--accent); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: .8rem; font-weight: 600;
}

/* =====================================================================
   DIVERS UI NATIF
   ===================================================================== */
.chip-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 16px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .85rem; font-weight: 600; color: var(--text-muted);
  transition: all .2s var(--ease);
}
.chip.active { background: var(--accent); color: #1a1205; border-color: var(--accent); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state i { font-size: 2.4rem; color: var(--text-faint); margin-bottom: 14px; display: block; }

/* drapeaux d'apparition douce */
.fade-up { animation: fadeUp .5s var(--ease) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* respecter les préférences de mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* masquer un ancien footer web s'il traîne encore */
.legacy-hide { display: none !important; }

/* pages sans barre d'onglets (Connexion / Inscription) : pas de réserve en bas */
body.no-tabbar { padding-bottom: var(--safe-bottom); }

/* carte d'accès rapide (ex : points clés des livres) */
.feature-card {
  display: flex; align-items: center; gap: 14px;
  margin: 18px 0 4px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(255,140,0,.16), transparent 60%),
    linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  transition: transform .15s var(--ease), border-color .2s var(--ease);
}
.feature-card:active { transform: scale(.98); }
.feature-card:hover { border-color: var(--accent); }
.feature-card__icon {
  width: 46px; height: 46px; flex: 0 0 auto; border-radius: 14px;
  display: grid; place-items: center; font-size: 1.25rem;
  background: var(--accent-soft); color: var(--accent);
}
.feature-card__txt { flex: 1; min-width: 0; }
.feature-card__txt strong { display: block; font-size: 1rem; }
.feature-card__txt span { color: var(--text-muted); font-size: .84rem; }
.feature-card__chev { color: var(--text-faint); font-size: .85rem; }
.badge-new { display: inline-block; vertical-align: middle; margin-left: 6px; font-size: .58rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: #000; background: linear-gradient(145deg, var(--accent-2), var(--accent)); padding: 2px 7px; border-radius: 999px; }

/* =====================================================================
   DESKTOP (≥1024px) — coquille « app desktop » : barre latérale + contenu large.
   Le mobile n'est PAS affecté (tout est sous ce media query).
   La barre latérale (.sidebar) est rendue par app-tabbar.php ; la tab bar du bas
   est masquée sur desktop. Objectif : desktop-first, jamais une app mobile étirée.
   ===================================================================== */
.sidebar { display: none; }   /* cachée en mobile (la tab bar du bas prend le relais) */

@media (min-width: 1024px) {
  /* Les règles de gabarit ne s'appliquent QUE sur les pages qui ont la barre latérale
     (body:has(.sidebar)). Les pages sans barre (connexion, inscription, lecteurs)
     gardent leur mise en page centrée, sans vide à gauche. */

  /* coquille pleine largeur, sans cadre « téléphone » ; contenu décalé après la sidebar */
  body:has(.sidebar) .app-shell { max-width: none; margin: 0; box-shadow: none; min-height: 100vh; padding-left: var(--sidebar-w); }
  body:has(.sidebar) .app-container { max-width: 1200px; margin: 0 auto; padding: 0 40px; }
  body:has(.sidebar) { padding-bottom: 28px; }        /* plus de tab bar en bas */

  /* barre du haut : au-dessus du contenu seulement (démarre après la sidebar) */
  body:has(.sidebar) .topbar { left: var(--sidebar-w); padding-left: 26px; padding-right: 26px; }
  body:has(.sidebar) .topbar #topbarMenuBtn { display: none; }   /* le menu, c'est la sidebar */

  body:has(.sidebar) .tabbar { display: none; }        /* on masque la nav mobile */

  /* ---------- Barre latérale ---------- */
  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    padding: 16px 12px 20px;
    z-index: 60; overflow-y: auto;
  }
  .sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; }
  .sidebar__brand img { height: 28px; width: auto; object-fit: contain; }
  .sidebar__brand .logo-text { font-size: 1.22rem; font-weight: 800; letter-spacing: -.02em; }
  .sidebar__sep { height: 1px; background: var(--border); margin: 12px 8px; }
  .sidebar__label { font-size: .66rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text-faint); padding: 8px 12px 4px; }
  .sidebar__spacer { flex: 1 1 auto; min-height: 12px; }
  .sidebar a {
    display: flex; align-items: center; gap: 13px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: .94rem; color: var(--text-muted);
    transition: background .18s var(--ease), color .18s var(--ease);
  }
  .sidebar a i { width: 22px; text-align: center; font-size: 1.02rem; }
  .sidebar a:hover { background: rgba(255,255,255,.05); color: var(--text); }
  .sidebar a.active { background: var(--accent-soft); color: var(--accent); }
  .sidebar a.sidebar-logout { color: #ff8585; }
  .sidebar a.sidebar-logout i { color: #ff8585; }

  /* grilles qui remplissent la largeur desktop */
  .cat-grid { grid-template-columns: repeat(4, 1fr); }
}
