:root {
  --bg: #0b0d14;
  --bg2: #121521;
  --bg3: #1a1e2e;
  --line: #262b3f;
  --text: #e8eaf2;
  --muted: #8b91a8;
  --accent: #5b7cff;
  --accent2: #a35bff;
  --danger: #ff5b6e;
  --gold: #ffc94d;
  --radius: 10px;
  --top-h: 60px;
  --bottom-h: 0px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

input[type=text], input[type=password], input[type=search], select {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
  width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: var(--bg3);
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; color: #fff; }
.btn.danger { color: var(--danger); }
.icon-btn {
  background: transparent;
  border: 0;
  border-radius: 8px;
  width: 38px; height: 38px;
  font-size: 19px;
  cursor: pointer;
  flex: none;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--bg3); }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; letter-spacing: .3px; flex: none; }
.brand.big { font-size: 26px; justify-content: center; margin-bottom: 6px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  position: relative;
}
.logo::after {
  content: ""; position: absolute; left: 11px; top: 8px;
  border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}
.brand.big .logo { width: 38px; height: 38px; }
.brand.big .logo::after { left: 15px; top: 11px; border-left-width: 12px; border-top-width: 8px; border-bottom-width: 8px; }

/* ---------- Écrans connexion / chargement ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto;
  background: radial-gradient(1200px 600px at 20% -10%, #1d2550 0, transparent 60%), radial-gradient(900px 500px at 110% 110%, #2c1650 0, transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; display: grid; gap: 14px; }
.login-card p { margin: 0; text-align: center; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.error { color: var(--danger); text-align: center; }
.load-list { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 10px; }
.load-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg3); border-radius: 8px; }
.load-list li.done .spin { border-color: #3ddc97; animation: none; }
.load-list li.done .spin::after { content: "✓"; color: #3ddc97; font-size: 12px; display: grid; place-items: center; height: 100%; }
.load-list li.fail .spin { border-color: var(--danger); animation: none; }
.load-list .count { margin-left: auto; color: var(--muted); font-size: 13px; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Structure ---------- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.top {
  height: var(--top-h); flex: none;
  display: flex; align-items: center; gap: 18px;
  padding: 0 16px; padding-top: env(safe-area-inset-top);
  height: calc(var(--top-h) + env(safe-area-inset-top));
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 8px 14px; border-radius: 8px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.on { background: var(--bg3); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.search { flex: 1; max-width: 560px; margin-left: auto; }
.search input { border-radius: 20px; padding-left: 36px;
  background: var(--bg3) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238b91a8' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E") no-repeat 12px center; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px 1fr; }
aside { min-height: 0; display: flex; flex-direction: column; background: var(--bg2); border-right: 1px solid var(--line); }
.side-head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.side-list { list-style: none; margin: 0; padding: 6px; overflow: auto; flex: 1; overscroll-behavior: contain; }
.side-list li a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.side-list li a:hover { background: var(--bg3); }
.side-list li a.on { background: linear-gradient(90deg, rgba(91,124,255,.25), rgba(91,124,255,.05)); }
.side-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-list .ct { color: var(--muted); font-size: 12px; flex: none; }
.side-list .sep { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; padding: 12px 10px 4px; }
.badge { flex: none; min-width: 38px; text-align: center; font-size: 11px; font-weight: 800; letter-spacing: .5px; padding: 3px 5px; border-radius: 5px; background: var(--bg3); border: 1px solid var(--line); }
.badge.special { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; color: #fff; }
.badge.star { color: var(--gold); }
.badge.prov { background: #24203a; border-color: #3b3266; color: #c9b8ff; }

#content { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.content-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px 6px; }
.crumbs { flex: 1; min-width: 0; font-size: 20px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs .c-sub { color: var(--muted); font-weight: 600; }
.crumbs .count { color: var(--muted); font-size: 14px; font-weight: 500; margin-left: 6px; }
#sort { width: auto; flex: none; padding: 7px 10px; font-size: 13px; }
.back-btn { display: none; font-size: 28px; }
.chips { display: flex; gap: 6px; padding: 4px 16px 10px; overflow-x: auto; flex: none; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 16px; background: var(--bg3); border: 1px solid var(--line); cursor: pointer; font-size: 13px; white-space: nowrap; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .ct { opacity: .7; margin-left: 4px; font-size: 12px; }
.chips-label { flex: none; align-self: center; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-right: 2px; }
#chips:not(:empty) + .qchips { margin-top: -4px; }
.qchips .chip { padding: 4px 10px; font-size: 12.5px; }
.qchips .chip.on { background: #2a2350; border-color: var(--accent2); }
.qual { position: absolute; right: 6px; bottom: 8px; font-size: 10.5px; font-weight: 800; letter-spacing: .5px; padding: 2px 5px; border-radius: 4px; background: rgba(0,0,0,.75); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.qual.q-4K { background: linear-gradient(135deg, #c99a2e, #f5d77a); color: #1a1405; border: 0; }
.qual.q-CAM { background: #6b1d26; border-color: #b33a48; }
.qual-inline { color: var(--text); background: var(--bg3); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; font-weight: 700; font-size: 12.5px; }

/* ---------- Grille virtualisée ---------- */
.vgrid { flex: 1; min-height: 0; overflow-y: auto; position: relative; overscroll-behavior: contain; padding: 0 10px; }
.vg-sizer { position: relative; width: 100%; }
.vg-item { position: absolute; padding: 6px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.card { display: block; height: 100%; cursor: pointer; }
.poster {
  position: relative; width: 100%; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(160deg, var(--bg3), #141826); border: 1px solid var(--line);
  display: grid; place-items: center; transition: transform .15s, border-color .15s;
}
.card:hover .poster { transform: translateY(-2px); border-color: var(--accent); }
.poster .ph { font-size: 14px; font-weight: 700; color: #4a5175; padding: 8px; text-align: center; word-break: break-word; }
.poster img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.poster .rate { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.72); border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 700; color: var(--gold); }
.poster .fav { position: absolute; top: 6px; right: 6px; color: var(--gold); text-shadow: 0 1px 3px #000; }
.poster .prog { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.card .t { margin-top: 6px; font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.chan {
  height: 100%; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.chan:hover, .chan.on { border-color: var(--accent); background: var(--bg3); }
.chan .lg { width: 58px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 6px; background: #0e1018; overflow: hidden; position: relative; }
.chan .lg img { position: absolute; inset: 3px; width: calc(100% - 6px); height: calc(100% - 6px); object-fit: contain; }
.chan .lg .ph { font-size: 12px; font-weight: 800; color: #3a4060; }
.chan .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.chan .num { color: var(--muted); font-size: 12px; width: 34px; flex: none; text-align: right; }
.chan .fav { color: var(--gold); flex: none; }

/* ---------- Recherche ---------- */
.search-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.search-view .vgrid { flex: 1; }
.s-section { padding: 6px 16px 14px; }
.s-section h3 { margin: 6px 0 10px; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.s-section h3 .more { margin-left: auto; font-size: 13px; color: var(--accent); cursor: pointer; font-weight: 600; }
.s-scroll { overflow-y: auto; flex: 1; min-height: 0; }
.s-row { display: grid; grid-auto-flow: column; grid-auto-columns: 130px; gap: 12px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.s-row.chans { grid-auto-columns: 260px; }
.s-row .chan { height: 56px; }
.s-cats { display: flex; flex-wrap: wrap; gap: 6px; }
.s-cat { display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 6px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.s-cat:hover { border-color: var(--accent); }
.s-cat .ct { color: var(--muted); font-size: 12px; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow: auto; }
.modal { background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; }
.modal-card { width: 100%; max-width: 440px; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 16px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }

/* Fiche détail */
.detail-bg { position: fixed; inset: 0; background-size: cover; background-position: center; filter: blur(30px) brightness(.35); transform: scale(1.1); z-index: -1; }
.detail-wrap { position: relative; max-width: 1100px; margin: 0 auto; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.detail-top { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.detail-main { display: grid; grid-template-columns: 240px 1fr; gap: 26px; }
.detail-main .poster { box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.detail-main h1 { margin: 0 0 8px; font-size: 30px; line-height: 1.15; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.meta .gold { color: var(--gold); font-weight: 700; }
.plot { line-height: 1.55; margin: 0 0 16px; color: #cfd3e3; }
.credits { font-size: 14px; color: var(--muted); display: grid; gap: 4px; margin-bottom: 18px; }
.credits b { color: var(--text); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.seasons { display: flex; gap: 6px; overflow-x: auto; margin: 26px 0 12px; padding-bottom: 4px; }
.episodes { display: grid; gap: 8px; }
.ep { display: grid; grid-template-columns: 150px 1fr; gap: 14px; padding: 8px; border-radius: var(--radius); background: rgba(18,21,33,.8); border: 1px solid var(--line); cursor: pointer; align-items: center; }
.ep:hover { border-color: var(--accent); }
.ep .th { aspect-ratio: 16/9; border-radius: 6px; background: var(--bg3) center/cover; position: relative; overflow: hidden; display: grid; place-items: center; color: #3a4060; font-weight: 800; }
.ep .th .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
.ep .et { font-weight: 650; }
.ep .ed { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 3px; }
.ep.seen .et::after { content: " ✓"; color: #3ddc97; }

/* Lecteur */
.player { background: #000; display: grid; grid-template-columns: 1fr 340px; overflow: hidden; }
.player.no-side { grid-template-columns: 1fr; }
.player.no-side .player-side, .player.no-side:not(.eps) #prevCh, .player.no-side:not(.eps) #nextCh { display: none; }
.player.eps #prevCh::before { content: "⏮"; }
.player.eps #nextCh::before { content: "⏭"; }
.player.eps #prevCh, .player.eps #nextCh { font-size: 0; }
.player.eps #prevCh::before, .player.eps #nextCh::before { font-size: 18px; }
.player-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.player-bar { display: flex; align-items: center; gap: 4px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); background: #07080c; }
.player-title { flex: 1; min-width: 0; padding: 0 6px; }
.player-title div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#playerTitle { font-weight: 700; }
.video-wrap { position: relative; flex: 1; min-height: 0; background: #000; }
/* La vidéo est calée sur sa zone : sinon sa hauteur naturelle la fait déborder et la barre de contrôle est coupée */
video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.player-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(10,12,20,.92); border: 1px solid var(--line); padding: 14px 18px; border-radius: 10px; max-width: 90%; text-align: center; }
.player-msg .btn { margin-top: 10px; }
.epg { background: #07080c; padding: 10px 14px; display: grid; gap: 6px; font-size: 14px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.epg:empty { display: none; }
.epg .now { display: flex; gap: 10px; align-items: baseline; }
.epg .tm { color: var(--muted); font-size: 12.5px; flex: none; font-variant-numeric: tabular-nums; }
.epg .bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.epg .bar i { display: block; height: 100%; background: var(--accent); }
.epg .next { color: var(--muted); font-size: 13px; }
.player-side { min-height: 0; display: flex; flex-direction: column; background: var(--bg2); border-left: 1px solid var(--line); }
.player-side input { margin: 10px; width: auto; }
.player-side .vgrid { padding: 0 4px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--bottom-h) + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.5); max-width: 90%; }

.bottom-tabs { display: none; }

/* ---------- Mobile / tablette ---------- */
@media (max-width: 820px) {
  :root { --top-h: 56px; --bottom-h: 58px; }
  .top { gap: 10px; padding-left: 12px; padding-right: 8px; }
  .tabs, .brand-name { display: none; }
  .search { margin-left: 0; max-width: none; }
  .layout { grid-template-columns: 1fr; }
  aside { border-right: 0; }
  body:not(.show-side) aside { display: none; }
  body.show-side #content { display: none; }
  .back-btn { display: grid; margin-left: -8px; }
  body.searching .back-btn { display: none; }
  .content-head { padding: 10px 12px 4px; }
  .crumbs { font-size: 17px; }
  #sort { max-width: 130px; }
  .chips { padding: 4px 12px 8px; }
  .vgrid { padding: 0 6px; }
  .vg-item { padding: 4px; }
  .s-section { padding: 4px 12px 12px; }
  .s-row { grid-auto-columns: 110px; gap: 8px; }
  .bottom-tabs {
    display: flex; flex: none; background: var(--bg2); border-top: 1px solid var(--line);
    height: calc(var(--bottom-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-tabs a { flex: 1; display: grid; place-items: center; align-content: center; gap: 1px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
  .bottom-tabs a b { font-size: 19px; font-weight: normal; }
  .bottom-tabs a.on { color: var(--text); }

  .player { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow: auto; }
  .player-main { flex: none; }
  .video-wrap { flex: none; aspect-ratio: 16 / 9; }
  .player.no-side .video-wrap { flex: 1; aspect-ratio: auto; }
  .player.no-side { grid-template-rows: 1fr; }
  .player.no-side .player-main { flex: 1; }
  .player-side { border-left: 0; min-height: 0; }

  .detail-main { grid-template-columns: 1fr; gap: 16px; }
  .detail-main .poster { max-width: 200px; margin: 0 auto; }
  .detail-main h1 { font-size: 23px; text-align: center; }
  .meta { justify-content: center; }
  .ep { grid-template-columns: 112px 1fr; }
}
@media (max-width: 820px) and (orientation: landscape) and (max-height: 500px) {
  .player { grid-template-rows: 1fr; }
  .player .player-side, .player .epg { display: none; }
  .player-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 2; background: linear-gradient(#000c, transparent); }
  .video-wrap { aspect-ratio: auto; height: 100vh; }
}
