/* ==========================================================================
   Mon TV Time — thème sombre, mobile-first
   ========================================================================== */

:root {
  --fond: #0b0e18;
  --fond-2: #121629;
  --surface: #171c33;
  --surface-haute: #1f2542;
  --bordure: #262d4d;
  --texte: #f2f4ff;
  --texte-doux: #9aa3c7;
  --texte-faible: #6d759b;
  --accent: #ffc531;
  --accent-sombre: #d9a41c;
  --menthe: #2ee6c5;
  --rouge: #ff5470;
  --rayon: 16px;
  --rayon-s: 10px;
  --ombre: 0 8px 24px rgba(0, 0, 0, .45);
  --transition: 180ms cubic-bezier(.2, .7, .3, 1);
  --hauteur-onglets: calc(58px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body { padding-bottom: var(--hauteur-onglets); }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.cache { display: none !important; }

/* --- Barre de titre ------------------------------------------------------ */
.entete {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 12px;
  background: linear-gradient(180deg, var(--fond) 72%, rgba(11, 14, 24, 0));
  backdrop-filter: blur(12px);
}

.entete h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
.actions-entete { display: flex; gap: 8px; }

/* --- Contenu ------------------------------------------------------------- */
.vue { padding: 4px 0 32px; min-height: 60vh; }
.section { margin-bottom: 26px; }

.section-titre {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 18px 10px;
}

.section-titre h2 { margin: 0; font-size: 1.05rem; letter-spacing: -.01em; }
.section-titre span { color: var(--texte-faible); font-size: .82rem; }

/* --- Carrousels ---------------------------------------------------------- */
.carrousel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 2px 18px 6px;
  scroll-snap-type: x mandatory;
  /* Sans cela, l'accroche ramène la première affiche contre le bord gauche
     en avalant le padding du conteneur. */
  scroll-padding-inline: 18px;
  scrollbar-width: none;
}

.carrousel::-webkit-scrollbar { display: none; }
.carrousel .affiche { flex: 0 0 128px; scroll-snap-align: start; }

/* --- Affiches ------------------------------------------------------------ */
.grille {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 14px 12px;
  padding: 4px 18px 8px;
}

.affiche { position: relative; cursor: pointer; transition: transform var(--transition); }
.affiche:active { transform: scale(.96); }

.affiche-image {
  position: relative;
  aspect-ratio: 2 / 3;
  width: 100%;
  border-radius: var(--rayon);
  overflow: hidden;
  background: var(--surface) center/cover no-repeat;
  box-shadow: var(--ombre);
}

.affiche-image img { width: 100%; height: 100%; object-fit: cover; }

.affiche-vide {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--texte-faible);
  font-size: 1.6rem;
}

.affiche-titre {
  margin-top: 7px;
  font-size: .8rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.affiche-sous { color: var(--texte-faible); font-size: .72rem; }

.pastille {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(11, 14, 24, .82);
  backdrop-filter: blur(6px);
  font-size: .68rem;
  font-weight: 600;
}

.pastille-type { left: auto; right: 8px; color: var(--menthe); }
.pastille-note { color: var(--accent); }

/* Badge de progression sur les affiches de séries */
.progression-affiche {
  position: absolute;
  inset: auto 0 0 0;
  padding: 16px 8px 7px;
  background: linear-gradient(180deg, transparent, rgba(6, 8, 16, .92));
  font-size: .7rem;
  font-weight: 600;
}

.progression-barre {
  height: 3px;
  margin-top: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .22);
  overflow: hidden;
}

.progression-barre i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width var(--transition);
}

/* --- Boutons ------------------------------------------------------------- */
.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 16px;
  border: 1px solid var(--bordure);
  border-radius: 999px;
  background: var(--surface);
  color: var(--texte);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), opacity var(--transition);
}

.bouton:active { transform: scale(.95); }
.bouton-primaire { background: var(--accent); border-color: var(--accent); color: #14161f; }
.bouton-menthe { background: var(--menthe); border-color: var(--menthe); color: #04231e; }
.bouton-fantome { background: transparent; }
.bouton-danger { color: var(--rouge); border-color: rgba(255, 84, 112, .4); }
.bouton-actif { background: var(--accent); border-color: var(--accent); color: #14161f; }
.bouton-petit { padding: 7px 12px; font-size: .78rem; }
.bouton-icone { padding: 9px; border-radius: 50%; }
.bouton-large { width: 100%; }
.bouton:disabled { opacity: .5; cursor: default; }

/* --- Filtres ------------------------------------------------------------- */
.filtres {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 18px 14px;
  scrollbar-width: none;
}

.filtres::-webkit-scrollbar { display: none; }
.filtres .bouton { flex: 0 0 auto; }

/* --- Cartes « à suivre » ------------------------------------------------- */
.liste-episodes { display: flex; flex-direction: column; gap: 12px; padding: 4px 18px 8px; }

.carte-episode {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: var(--rayon);
  background: var(--surface);
  box-shadow: var(--ombre);
}

.carte-episode-affiche {
  flex: 0 0 68px;
  aspect-ratio: 2 / 3;
  border-radius: var(--rayon-s);
  overflow: hidden;
  background: var(--surface-haute);
}

.carte-episode-corps { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.carte-episode-serie { font-weight: 700; font-size: .95rem; }

.carte-episode-code {
  display: inline-block;
  align-self: flex-start;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-haute);
  color: var(--accent);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
}

.carte-episode-titre {
  color: var(--texte-doux);
  font-size: .84rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.carte-episode-meta { color: var(--texte-faible); font-size: .74rem; }
.carte-episode-actions { margin-top: 6px; display: flex; gap: 8px; }
.carte-episode-actions .bouton { flex: 1; }

/* --- Fiche détail -------------------------------------------------------- */
.fiche {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--fond);
  animation: monte var(--transition);
  -webkit-overflow-scrolling: touch;
}

@keyframes monte {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: none; }
}

.fiche-entete { position: relative; padding-bottom: 14px; }

.fiche-backdrop {
  position: relative;
  height: 46vw;
  max-height: 260px;
  background: var(--surface) center/cover no-repeat;
}

.fiche-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 14, 24, .3) 0%, rgba(11, 14, 24, .75) 60%, var(--fond) 100%);
}

.fiche-fermer {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 14px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(11, 14, 24, .7);
  backdrop-filter: blur(8px);
  color: var(--texte);
  font-size: 1.1rem;
  cursor: pointer;
}

.fiche-haut {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 14px;
  margin-top: -64px;
  padding: 0 18px;
}

.fiche-affiche {
  flex: 0 0 104px;
  aspect-ratio: 2 / 3;
  border-radius: var(--rayon);
  overflow: hidden;
  background: var(--surface-haute);
  box-shadow: var(--ombre);
}

.fiche-infos { flex: 1; min-width: 0; padding-top: 66px; }
.fiche-infos h2 { margin: 0 0 4px; font-size: 1.25rem; line-height: 1.2; }
.fiche-meta { color: var(--texte-faible); font-size: .8rem; }
.fiche-note { color: var(--accent); font-weight: 700; font-size: .85rem; }

.fiche-corps { padding: 16px 18px 40px; }
.fiche-resume { color: var(--texte-doux); font-size: .9rem; margin: 0 0 18px; }
.fiche-bloc { margin-bottom: 22px; }
.fiche-bloc h3 { margin: 0 0 10px; font-size: .95rem; color: var(--texte-doux); }

.rangee-statuts { display: flex; flex-wrap: wrap; gap: 8px; }

.etoiles { display: flex; flex-wrap: wrap; gap: 3px; }

.etoile {
  border: 0;
  background: none;
  padding: 2px;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--texte-faible);
  cursor: pointer;
  transition: transform var(--transition), color var(--transition);
}

.etoile.pleine { color: var(--accent); }
.etoile:active { transform: scale(1.25); }

textarea.champ, input.champ {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-s);
  background: var(--surface);
  color: var(--texte);
  outline: none;
  resize: vertical;
}

textarea.champ:focus, input.champ:focus { border-color: var(--accent); }

/* --- Saisons / épisodes -------------------------------------------------- */
.saison { margin-bottom: 10px; border-radius: var(--rayon); background: var(--surface); overflow: hidden; }

.saison-entete {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.saison-entete .chevron { transition: transform var(--transition); color: var(--texte-faible); }
.saison.ouverte .chevron { transform: rotate(90deg); }
.saison-entete-texte { flex: 1; min-width: 0; }
.saison-entete-texte b { display: block; font-size: .92rem; }
.saison-entete-texte small { color: var(--texte-faible); font-size: .75rem; }
.saison-corps { display: none; padding: 0 14px 12px; }
.saison.ouverte .saison-corps { display: block; }
.saison-actions { display: flex; gap: 8px; padding: 4px 0 10px; }

.episode {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 9px 0;
  border-top: 1px solid var(--bordure);
}

.episode-case {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border: 2px solid var(--texte-faible);
  border-radius: 50%;
  background: none;
  color: transparent;
  font-size: .8rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.episode-case.vu { background: var(--accent); border-color: var(--accent); color: #14161f; }
.episode-case:active { transform: scale(.85); }
.episode-corps { flex: 1; min-width: 0; }
.episode-titre { font-size: .87rem; }
.episode-titre b { color: var(--accent); font-weight: 700; margin-right: 6px; }
.episode-meta { color: var(--texte-faible); font-size: .73rem; }
.episode.futur .episode-titre { color: var(--texte-faible); }

/* --- Listes -------------------------------------------------------------- */
.cartes-listes { display: flex; flex-direction: column; gap: 12px; padding: 4px 18px; }

.carte-liste {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--rayon);
  background: var(--surface);
  cursor: pointer;
  transition: transform var(--transition);
}

.carte-liste:active { transform: scale(.98); }
.carte-liste-apercu { display: flex; flex: 0 0 auto; }

.carte-liste-apercu span {
  width: 34px;
  height: 51px;
  margin-left: -14px;
  border: 2px solid var(--surface);
  border-radius: 7px;
  background: var(--surface-haute) center/cover no-repeat;
}

.carte-liste-apercu span:first-child { margin-left: 0; }
.carte-liste-corps { flex: 1; min-width: 0; }
.carte-liste-corps b { display: block; font-size: .95rem; }
.carte-liste-corps small { color: var(--texte-faible); font-size: .76rem; }

/* --- Feuille modale ------------------------------------------------------ */
.feuille { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; }
.feuille-fond { position: absolute; inset: 0; background: rgba(4, 6, 12, .65); backdrop-filter: blur(3px); }

.feuille-contenu {
  position: relative;
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 22px);
  border-radius: 22px 22px 0 0;
  background: var(--fond-2);
  animation: remonte var(--transition);
}

@keyframes remonte {
  from { transform: translateY(100%); }
  to   { transform: none; }
}

.feuille-contenu h3 { margin: 4px 0 14px; font-size: 1.05rem; }
.feuille-contenu .bouton { margin-bottom: 8px; }

/* --- Profil / divers ----------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 4px 18px 18px; }

.stat {
  padding: 14px;
  border-radius: var(--rayon);
  background: var(--surface);
}

.stat b { display: block; font-size: 1.6rem; color: var(--accent); line-height: 1.1; }
.stat small { color: var(--texte-faible); font-size: .78rem; }

.carte-compte {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 4px 18px 16px;
  padding: 14px;
  border-radius: var(--rayon);
  background: var(--surface);
}

.carte-compte-avatar {
  display: flex;
  flex: 0 0 46px;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  color: #14161f;
  font-size: 1.3rem;
  font-weight: 700;
}

.carte-compte b { display: block; font-size: 1rem; }
.carte-compte small { color: var(--texte-faible); font-size: .78rem; }

.bloc-profil { padding: 0 18px 20px; display: flex; flex-direction: column; gap: 10px; }

.vide {
  padding: 48px 24px;
  text-align: center;
  color: var(--texte-faible);
}

.vide-emoji { font-size: 2.4rem; margin-bottom: 10px; }

.squelette {
  border-radius: var(--rayon);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-haute) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: brille 1.3s ease-in-out infinite;
}

@keyframes brille {
  from { background-position: 100% 0; }
  to   { background-position: 0 0; }
}

.erreur { color: var(--rouge); font-size: .85rem; }

/* --- Barre d'onglets ----------------------------------------------------- */
.onglets {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(13, 16, 30, .93);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--bordure);
}

.onglets a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  color: var(--texte-faible);
  font-size: .63rem;
  transition: color var(--transition);
}

.onglets a svg { width: 22px; height: 22px; fill: currentColor; }
.onglets a.actif { color: var(--accent); }

/* --- Connexion ----------------------------------------------------------- */
.ecran-connexion {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #1d2445 0%, var(--fond) 65%);
}

.connexion-carte { width: 100%; max-width: 340px; text-align: center; }
.connexion-logo { font-size: 3rem; }
.connexion-carte h1 { margin: 6px 0 8px; font-size: 1.5rem; }
.connexion-aide { color: var(--texte-doux); font-size: .86rem; margin-bottom: 18px; }
.connexion-carte code { color: var(--accent); font-size: .8rem; }
.connexion-onglets {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
}

.connexion-onglet {
  flex: 1;
  padding: 9px 6px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--texte-doux);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.connexion-onglet.actif { background: var(--accent); color: #14161f; }

.connexion-carte input { width: 100%; margin-bottom: 10px; padding: 13px 15px; border: 1px solid var(--bordure); border-radius: var(--rayon-s); background: var(--surface); outline: none; }
.connexion-carte input:focus { border-color: var(--accent); }
.connexion-carte .bouton { width: 100%; }

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--hauteur-onglets) + 14px);
  z-index: 90;
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--surface-haute);
  box-shadow: var(--ombre);
  font-size: .85rem;
  animation: monte var(--transition);
}

/* --- Écrans larges ------------------------------------------------------- */
@media (min-width: 720px) {
  .vue, .entete, .fiche-corps { max-width: 900px; margin-inline: auto; }
  .grille { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .carrousel .affiche { flex-basis: 148px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
