:root {
  --bg: #0f0f0f;
  --bg2: #1a1a1a;
  --bg3: #272727;
  --line: #303030;
  --text: #f1f1f1;
  --muted: #a5a5a5;
  --accent: #e52d27;
  --ok: #3ea66b;
  --radius: 12px;
  --topbar-h: 56px;
  --bottomnav-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* --- Barre du haut / navigation ----------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h);
  padding: 0 12px 0 16px;
  background: rgba(15, 15, 15, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; margin-right: auto; }
.nav { display: flex; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; color: var(--muted); font-weight: 550;
}
.nav a:hover { background: var(--bg2); color: var(--text); }
.nav a.active { background: var(--text); color: #0f0f0f; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: transparent; border: 0;
}
.icon-btn:hover { background: var(--bg3); }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  :root { --bottomnav-h: 60px; }
  /* backdrop-filter piégerait la barre du bas (position: fixed) dans la barre du haut */
  .topbar { backdrop-filter: none; background: var(--bg); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--bottomnav-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: rgba(15, 15, 15, .97);
    border-top: 1px solid var(--line);
    gap: 0;
  }
  .nav a {
    flex: 1; flex-direction: column; justify-content: center; gap: 2px;
    border-radius: 0; font-size: 11px; padding: 6px 0;
  }
  .nav a.active { background: transparent; color: var(--text); }
  .nav a.active svg { stroke-width: 2.6; }
  main { padding-bottom: calc(var(--bottomnav-h) + var(--safe-b)); }
  body.watching .nav { display: none; }
  body.watching main { padding-bottom: var(--safe-b); }
}

main { max-width: 1500px; margin: 0 auto; }

/* --- Barre de filtres ------------------------------------------------- */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 16px 4px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  background: var(--bg3); border: 0; color: var(--text); font-size: 14px; font-weight: 550;
  white-space: nowrap;
}
.chip:hover { background: #3a3a3a; }
.chip.on { background: var(--text); color: #0f0f0f; }
.chip svg { width: 16px; height: 16px; }
select.chip { appearance: none; padding-right: 28px; max-width: 220px; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat; }
.toolbar .spacer { flex: 1; }
.page-title { padding: 16px 16px 4px; margin: 0; font-size: 22px; }
.channel-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 2px; }
.channel-head img { width: 44px; height: 44px; border-radius: 50%; }
.channel-head h2 { margin: 0; font-size: 19px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Grille de vidéos ------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 22px 16px;
  padding: 12px 16px 24px;
}
@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; gap: 18px; padding: 8px 0 16px; }
  .card .meta { padding: 0 12px; }
  .card .thumb { border-radius: 0; }
}
.card { position: relative; min-width: 0; transition: opacity .25s, transform .25s; }
.card.leaving { opacity: 0; transform: scale(.96); }
.card.watched .thumb img { opacity: .45; }
.thumb {
  position: relative; display: block; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden; background: var(--bg2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  position: absolute; right: 6px; bottom: 6px;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(0, 0, 0, .82); font-size: 12px; font-weight: 600;
}
.badge.live { background: #cc0000; }
.badge.upcoming { background: rgba(0, 0, 0, .82); }
.badge.watched { left: 6px; right: auto; background: rgba(0, 0, 0, .82); color: #8fd6a9; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .25); }
.progress i { display: block; height: 100%; background: var(--accent); }

.meta { display: flex; gap: 10px; padding-top: 10px; align-items: flex-start; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--bg3); flex: none; object-fit: cover; }
.meta .text { flex: 1; min-width: 0; }
.meta .title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-weight: 600; font-size: 15px; line-height: 1.35;
}
.meta .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.meta .sub a:hover { color: var(--text); }
.card-actions { display: flex; gap: 2px; margin: -6px -6px 0 0; }
.card-actions .icon-btn { width: 38px; height: 38px; color: var(--muted); }
.card-actions .icon-btn:hover { color: var(--text); }
.card-actions .icon-btn.on { color: var(--text); }
.card-actions .icon-btn.on.watch-btn { color: #8fd6a9; }
.card-actions svg { width: 20px; height: 20px; }

.empty { padding: 60px 24px; text-align: center; color: var(--muted); max-width: 520px; margin: 0 auto; }
.empty h2 { color: var(--text); font-size: 19px; }
.sentinel { height: 1px; }
.loading { padding: 24px; text-align: center; color: var(--muted); }

/* --- Page de lecture ------------------------------------------------- */
.watch { max-width: 1280px; margin: 0 auto; padding: 16px; }
@media (max-width: 760px) { .watch { padding: 0; } .watch .info { padding: 0 12px 24px; } }
.player-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - var(--topbar-h) - 140px);
  background: #000; border-radius: var(--radius); overflow: hidden;
}
@media (max-width: 760px) { .player-wrap { border-radius: 0; max-height: none; } }
.player-wrap iframe, .player-wrap #player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-wrap:fullscreen { max-height: none; border-radius: 0; aspect-ratio: auto; }

/* Cache posé sur le lecteur à la pause (masque « Plus de vidéos »).
   La barre de contrôle (en bas) reste accessible pour se déplacer dans la vidéo. */
.cover {
  position: absolute; left: 0; right: 0; top: 0; bottom: 52px; z-index: 2;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .78);
  border: 0; padding: 0; width: 100%;
}
.cover .play-big {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(255, 255, 255, .14);
}
.cover .play-big svg { width: 38px; height: 38px; fill: #fff; stroke: none; margin-left: 5px; }
.cover .hint { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: #ddd; font-size: 13px; }
.end-cover {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: #0b0b0b; text-align: center; padding: 16px;
}
.end-cover .done { font-size: 18px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.end-cover .done svg { color: var(--ok); width: 26px; height: 26px; stroke-width: 2.6; }
.end-cover .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.fs-corner { position: absolute; top: 8px; right: 8px; z-index: 4; background: rgba(0, 0, 0, .5); color: #fff; }

.info h1 { font-size: 20px; line-height: 1.3; margin: 14px 0 10px; word-break: break-word; }
.channel-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.channel-line a { color: var(--text); font-weight: 600; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px; border: 0;
  background: var(--bg3); color: var(--text); font-weight: 600; font-size: 14px;
}
.btn:hover { background: #3a3a3a; }
.btn.on { background: var(--text); color: #0f0f0f; }
.btn.primary { background: var(--text); color: #0f0f0f; }
.btn.primary:hover { background: #d9d9d9; }
.btn.danger { background: #4a1715; color: #ffb4ab; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.desc {
  background: var(--bg2); border-radius: var(--radius); padding: 12px 14px;
  white-space: pre-wrap; word-break: break-word; font-size: 14px; color: #ddd;
}
.desc a { color: #7fb3ff; }
.desc a:hover { text-decoration: underline; }
.desc.collapsed { max-height: 7.5em; overflow: hidden; position: relative; cursor: pointer; }
.desc.collapsed::after {
  content: "… plus"; position: absolute; right: 0; bottom: 0; padding: 0 14px 0 30px;
  background: linear-gradient(90deg, transparent, var(--bg2) 30%); color: var(--text); font-weight: 600;
}
.player-error { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); }

/* --- Réglages -------------------------------------------------------- */
.settings { max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }
.panel { background: var(--bg2); border-radius: var(--radius); padding: 16px; margin: 14px 0; }
.panel h2 { font-size: 16px; margin: 0 0 10px; }
.panel p { margin: 8px 0; color: #ccc; }
.panel .muted, .muted { color: var(--muted); font-size: 13px; }
.panel code { background: var(--bg3); padding: 2px 6px; border-radius: 6px; word-break: break-all; font-size: 13px; }
.panel ol { padding-left: 20px; color: #ccc; }
.panel ol li { margin: 6px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #555; border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.ok-text { color: #8fd6a9; }
.err-text { color: #ff8a80; }
input[type="date"], input[type="password"], input[type="text"] {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font: inherit; color-scheme: dark;
}
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* --- Connexion -------------------------------------------------------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login img { margin: 0 auto; }
.login h1 { margin: 0; font-size: 22px; }
.login input { width: 100%; font-size: 16px; padding: 12px 14px; }
.login .btn { justify-content: center; padding: 12px; font-size: 15px; }
.login .err-text { min-height: 1.4em; margin: 0; }

/* --- Toast ------------------------------------------------------------ */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--bottomnav-h) + var(--safe-b)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #f1f1f1; color: #0f0f0f; padding: 10px 16px; border-radius: 10px;
  font-weight: 600; font-size: 14px; transition: .25s; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 12px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: none; border: 0; color: #065fd4; font-weight: 700; padding: 0; }
