/* ===== Couleurs ===== */
:root {
  --fond: #f6f1ec;
  --surface: #ffffff;
  --surface-2: #efe7f3;
  --texte: #2a2530;
  --texte-doux: #6f6878;
  --bord: #e4dbe6;
  --accent: #8b5cf6;
  --accent-fonce: #6d3fd8;
  --accent-doux: #ede4ff;
  --rose: #f472b6;
  --vert: #16a34a;
  --danger: #dc2626;
  --ombre: 0 2px 10px rgba(60, 30, 90, .08);
  --rayon: 18px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #1c1a1f;
    --surface: #27242c;
    --surface-2: #322d3a;
    --texte: #f2eef6;
    --texte-doux: #aaa2b4;
    --bord: #3b3542;
    --accent: #a78bfa;
    --accent-fonce: #c4b5fd;
    --accent-doux: #3a2f52;
    --ombre: 0 2px 10px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px; }
h1, h2 { margin: 0; line-height: 1.25; }
a { color: var(--accent-fonce); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.discret { color: var(--texte-doux); font-size: .9rem; margin: .4rem 0; }
.centre { text-align: center; }
.erreur { background: #fee2e2; color: #991b1b; padding: 12px 14px; border-radius: 12px; margin: 12px 0; }

/* ===== En-tête & navigation ===== */
.entete {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--fond) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 12px;
  text-align: center;
}
.entete h1 { font-size: 1.15rem; }

.onglets {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--bord);
  padding-bottom: env(safe-area-inset-bottom);
}
.onglet {
  flex: 1; height: var(--nav-h); border: 0; background: none; color: var(--texte-doux);
  font: inherit; font-size: .8rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.onglet span { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
.onglet.actif { color: var(--accent-fonce); font-weight: 600; }
.onglet.actif span { filter: none; opacity: 1; }

/* ===== Boutons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 14px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--surface-2); color: var(--texte);
  transition: transform .08s ease, background .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-principal { background: var(--accent); color: #fff; }
.btn-secondaire { background: var(--surface); border-color: var(--bord); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-petit { min-height: 44px; padding: 8px 14px; }
.btn-large { width: 100%; margin: 12px 0; }
.btn-geant {
  width: 100%; min-height: 84px; margin: 8px 0 16px; font-size: 1.35rem; border-radius: 22px;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--rose));
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-geant .icone { font-size: 1.6rem; }
.btn-statut.fait { outline: 3px solid var(--vert); outline-offset: 2px; }
.lien { background: none; border: 0; color: var(--texte-doux); text-decoration: underline; font: inherit; padding: 12px; margin-top: 8px; }

/* ===== Réglages ===== */
.reglages { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 4px; }
.reglages .champ { flex: 1 1 200px; margin: 0; }
.champ { display: block; margin: 0 0 12px; }
.champ > span { display: block; font-size: .85rem; color: var(--texte-doux); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px évite le zoom auto sur iPhone */
  color: var(--texte); background: var(--surface); border: 1px solid var(--bord); border-radius: 12px;
  padding: 11px 12px; min-height: 48px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.interrupteur { display: inline-flex; align-items: center; gap: 10px; min-height: 48px; cursor: pointer; user-select: none; font-weight: 500; }
.interrupteur input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.piste { width: 48px; height: 28px; border-radius: 14px; background: var(--bord); position: relative; transition: background .2s; flex: none; }
.piste::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.interrupteur input:checked + .piste { background: var(--accent); }
.interrupteur input:checked + .piste::after { transform: translateX(20px); }
.interrupteur input:focus-visible + .piste { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== Chargement ===== */
.chargement { text-align: center; padding: 24px 8px; }
.chargement p { margin: 8px 0 0; font-weight: 500; }
.spinner { width: 42px; height: 42px; margin: 0 auto 8px; border-radius: 50%; border: 4px solid var(--accent-doux); border-top-color: var(--accent); animation: tourne 0.9s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

/* ===== Blocs de résultat ===== */
.bloc { background: var(--surface); border-radius: var(--rayon); padding: 16px; margin: 0 0 14px; box-shadow: var(--ombre); }
.bloc-tete { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.bloc-tete h2 { font-size: .95rem; color: var(--texte-doux); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.btn-copier {
  border: 0; border-radius: 999px; background: var(--accent-doux); color: var(--accent-fonce);
  font: inherit; font-size: .9rem; font-weight: 600; padding: 8px 16px; min-height: 40px; cursor: pointer; flex: none;
}
.btn-copier.copie { background: var(--vert); color: #fff; }
.sujet { font-size: 1.3rem; font-weight: 700; margin: 0 0 10px; }
.angle { margin: 10px 0 0; }
.puces { display: flex; flex-wrap: wrap; gap: 6px; }
.puce { background: var(--accent); color: #fff; border-radius: 999px; padding: 4px 12px; font-size: .85rem; font-weight: 600; }
.puce-douce { background: var(--surface-2); color: var(--texte); font-weight: 500; }
.texte { white-space: pre-wrap; word-wrap: break-word; font-size: 1.02rem; }
.texte-ecran { font-size: 1.4rem; font-weight: 800; text-align: center; margin: 4px 0; padding: 14px; border-radius: 12px; background: #111; color: #fff; }
.source { font-size: .9rem; margin: 14px 0 0; padding-top: 12px; border-top: 1px dashed var(--bord); word-break: break-word; }

.actions-idee { margin: 18px 0 8px; }
.actions-idee > .btn { width: 100%; margin-bottom: 12px; }
.statuts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.statuts .btn:last-child { grid-column: 1 / -1; min-height: 56px; font-size: 1.05rem; }

/* ===== Boucles vidéo ===== */
.recherche-boucle { display: flex; gap: 8px; margin: 10px 0 12px; }
.boucles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.boucles > p { grid-column: 1 / -1; }
.boucle { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.boucle video { width: 100%; aspect-ratio: 9 / 16; object-fit: cover; border-radius: 12px; background: #000; display: block; }
.boucle .btn { min-height: 40px; padding: 6px 8px; font-size: .85rem; border-radius: 10px; }
.credit { font-size: .72rem; color: var(--texte-doux); line-height: 1.3; overflow-wrap: anywhere; }
@media (max-width: 380px) {
  .boucles { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Historique ===== */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 14px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px 8px; text-align: center; box-shadow: var(--ombre); }
.stat b { display: block; font-size: 1.25rem; }
.stat small { color: var(--texte-doux); font-size: .78rem; }
.stats .top { grid-column: 1 / -1; text-align: left; padding: 12px 14px; font-size: .9rem; }
.top ol { margin: 6px 0 0; padding-left: 20px; }

.barre-histo { display: flex; gap: 8px; }
.barre-histo input { flex: 1; }
.barre-histo select { width: auto; flex: none; }

.liste-videos { list-style: none; padding: 0; margin: 0; }
.video {
  display: flex; gap: 10px; align-items: center; background: var(--surface); border-radius: 14px; padding: 12px 14px;
  margin-bottom: 8px; box-shadow: var(--ombre); cursor: pointer; min-height: 64px;
}
.video .infos { flex: 1; min-width: 0; }
.video .titre { font-weight: 600; overflow-wrap: anywhere; }
.video .meta { font-size: .8rem; color: var(--texte-doux); margin-top: 2px; }
.video .vues { font-weight: 700; font-size: .9rem; white-space: nowrap; text-align: right; }
.video .vues.vide { color: var(--accent-fonce); font-weight: 600; font-size: .8rem; }
.badge { display: inline-block; border-radius: 6px; padding: 1px 6px; font-size: .72rem; font-weight: 700; margin-right: 4px; }
.badge.publiee { background: #dcfce7; color: #166534; }
.badge.tournee { background: #fef3c7; color: #92400e; }
.badge.proposee { background: var(--accent-doux); color: var(--accent-fonce); }

.sauvegarde { margin-top: 24px; padding: 16px; background: var(--surface); border-radius: var(--rayon); text-align: center; }
.sauvegarde h2 { font-size: 1rem; }
.ligne-boutons { display: flex; gap: 10px; margin-top: 10px; }
.ligne-boutons > * { flex: 1; }

/* ===== Fiche (dialog) ===== */
dialog {
  border: 0; padding: 0; width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh;
  border-radius: 22px 22px 0 0; margin: auto auto 0; background: var(--surface); color: var(--texte);
}
dialog::backdrop { background: rgba(20, 10, 30, .45); }
@media (min-width: 700px) { dialog { border-radius: 22px; margin: auto; } }
.fiche { padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); }
.fiche h2 { margin-bottom: 14px; }
.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details { margin: 0 0 12px; }
summary { cursor: pointer; padding: 10px 0; color: var(--accent-fonce); font-weight: 600; }
.fiche-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; position: sticky; bottom: 0; background: var(--surface); padding: 8px 0 4px; }
.lien-danger { display: block; width: 100%; color: var(--danger); }

/* ===== Connexion ===== */
.ecran-centre { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.carte { background: var(--surface); padding: 28px 20px; border-radius: 22px; box-shadow: var(--ombre); width: 100%; max-width: 380px; text-align: center; }
.connexion input { margin: 16px 0 12px; }
.connexion .btn { width: 100%; }
.logo { font-size: 2.6rem; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--texte); color: var(--fond); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  transition: all .25s; max-width: calc(100% - 32px); text-align: center; z-index: 20;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
