:root {
  --bg: #0b0d12;
  --bg2: #12151d;
  --card: #181c26;
  --card2: #202534;
  --line: #2a3042;
  --text: #eef1f7;
  --muted: #8a93a8;
  --accent: #e5243b;
  --accent2: #ff5a5f;
  --ok: #2ecc71;
  --warn: #f5a623;
  --radius: 14px;
  --focus: 0 0 0 3px #fff, 0 0 0 6px var(--accent);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --fs: 16px;
}

/* Les écrans TV (1920 et +) : texte plus grand */
@media (min-width: 1280px) and (min-height: 700px) {
  :root { --fs: 18px; }
}
@media (min-width: 1900px) {
  :root { --fs: 22px; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: var(--fs)/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; user-select: text; -webkit-user-select: text; }
img { display: block; }
[hidden] { display: none !important; }

#app { height: 100%; display: flex; flex-direction: column; padding-top: var(--safe-top); }

.focusable { outline: none; transition: transform .12s, box-shadow .12s, background .12s; cursor: pointer; }
.focusable:focus-visible, .focusable:focus { box-shadow: var(--focus); z-index: 1; }
@media (hover: hover) { .focusable:hover { background-color: var(--card2); } }

/* ---------- En-tête ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  background: linear-gradient(180deg, #0f1219, transparent); flex-shrink: 0;
}
.topbar .back { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card); font-size: 1.3em; display: grid; place-items: center; }
.topbar h1 { font-size: 1.35em; margin: 0; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.4em; letter-spacing: .3px; }
.brand .logo { width: 38px; height: 38px; }
.brand b { color: var(--accent); }
.topbar .spacer { flex: 1; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.pill { padding: 6px 12px; border-radius: 999px; background: var(--card); color: var(--muted); font-size: .85em; white-space: nowrap; border: 0; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }

/* ---------- Accueil ---------- */
.home { flex: 1; overflow: auto; padding: 10px 20px calc(30px + var(--safe-bottom)); }
.home-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.home-tiles.big { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
@media (max-width: 640px) {
  .home-tiles.big { grid-template-columns: 1fr; }
  .home-tiles { grid-template-columns: repeat(2, 1fr); }
}
.tile {
  border: 0; border-radius: var(--radius); background: var(--card); padding: 20px; min-height: 110px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; text-align: left;
}
.tile .ico { font-size: 2em; line-height: 1; }
.tile .t { font-weight: 700; font-size: 1.1em; }
.tile .s { color: var(--muted); font-size: .85em; }
.tile.hero { min-height: 170px; color: #fff; }
.tile.hero.live { background: linear-gradient(135deg, #e5243b, #8f1022); }
.tile.hero.movies { background: linear-gradient(135deg, #3b5bdb, #1c2c7a); }
.tile.hero.series { background: linear-gradient(135deg, #7b2ff7, #3c1478); }
.tile.hero .s { color: rgba(255,255,255,.8); }
.tile:focus { transform: scale(1.03); }
.section-title { margin: 26px 0 10px; font-size: 1.1em; color: var(--muted); font-weight: 600; }

/* ---------- Mise en page à colonnes ---------- */
.browse { flex: 1; display: flex; min-height: 0; padding: 0 20px calc(16px + var(--safe-bottom)); gap: 16px; }
.col { background: var(--bg2); border-radius: var(--radius); overflow: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.col.cats { width: 280px; flex-shrink: 0; padding: 8px; }
.col.list { flex: 1; padding: 8px; }
.col.preview { width: 38%; flex-shrink: 0; display: flex; flex-direction: column; overflow: hidden; }
.cat {
  width: 100%; border: 0; background: transparent; padding: 12px 14px; border-radius: 10px; display: flex; gap: 10px;
  align-items: center; text-align: left;
}
.cat .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat .c { color: var(--muted); font-size: .85em; }
.cat.selected { background: var(--card2); color: #fff; }
.cat.selected .n { font-weight: 700; }

.chan {
  width: 100%; border: 0; background: transparent; padding: 8px 10px; border-radius: 10px; display: flex; gap: 12px;
  align-items: center; text-align: left;
}
.chan .num { width: 42px; color: var(--muted); font-size: .85em; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.chan .lg { width: 56px; height: 40px; border-radius: 6px; background: var(--card) center/contain no-repeat; flex-shrink: 0; }
.chan .info { flex: 1; min-width: 0; }
.chan .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.chan .ep { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: .85em; }
.chan .fav { color: var(--warn); }
.chan.playing { background: rgba(229,36,59,.18); }
.bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

.preview .pv-video { position: relative; background: #000; aspect-ratio: 16/9; flex-shrink: 0; }
.preview .pv-video video { width: 100%; height: 100%; object-fit: contain; }
.preview .pv-video .hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.preview .pv-info { padding: 14px; overflow: auto; flex: 1; }
.preview .pv-info h3 { margin: 0 0 4px; }
.prog { padding: 8px 0; border-bottom: 1px solid var(--line); }
.prog .tm { color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; }
.prog.now .tm { color: var(--accent2); }
.prog .ds { color: var(--muted); font-size: .85em; margin-top: 4px; }

/* ---------- Grille d'affiches ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; padding: 6px; }
@media (min-width: 1900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
.poster { border: 0; background: var(--card); border-radius: 12px; padding: 0; overflow: hidden; text-align: left; display: flex; flex-direction: column; }
.poster .img { aspect-ratio: 2/3; background: var(--card2) center/cover no-repeat; position: relative; width: 100%; }
.poster .img .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.5em; color: var(--line); }
.poster .img .rt { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.7); border-radius: 6px; padding: 2px 6px; font-size: .75em; }
.poster .img .fv { position: absolute; top: 6px; left: 6px; color: var(--warn); text-shadow: 0 1px 3px #000; }
.poster .img .rs { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.2); }
.poster .img .rs i { display: block; height: 100%; background: var(--accent); }
.poster .tt { padding: 8px 10px; font-size: .9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poster:focus { transform: scale(1.05); }
.more { grid-column: 1 / -1; text-align: center; padding: 14px; color: var(--muted); }

/* ---------- Mobile : colonnes empilées ---------- */
@media (max-width: 820px) {
  .browse { flex-direction: column; padding: 0 10px calc(10px + var(--safe-bottom)); gap: 10px; }
  .col.cats { width: auto; display: flex; overflow-x: auto; overflow-y: hidden; gap: 6px; padding: 6px; flex-shrink: 0; }
  .col.cats .cat { width: auto; flex-shrink: 0; white-space: nowrap; background: var(--card); padding: 8px 14px; border-radius: 999px; }
  .col.cats .cat .n { overflow: visible; }
  .col.cats .cat.selected { background: var(--accent); }
  .col.preview { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 10px; }
  .topbar { padding: 10px 12px; }
  .home { padding: 6px 12px 24px; }
}

/* ---------- Formulaires / fenêtres ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--bg2); border-radius: 18px; width: min(640px, 100%); max-height: calc(100% - 20px); overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal h2 { margin: 0 0 14px; }
.modal.wide { width: min(980px, 100%); }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { border: 0; background: var(--card); padding: 10px 16px; border-radius: 999px; }
.tab.selected { background: var(--accent); color: #fff; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; color: var(--muted); font-size: .85em; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229,36,59,.35); outline: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn { border: 0; padding: 12px 20px; border-radius: 10px; background: var(--card2); font-weight: 600; display: inline-flex; gap: 8px; align-items: center; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #3a1a20; color: #ff8a8a; }
.btn.small { padding: 8px 12px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.error { color: #ff8a8a; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--card); border-radius: 12px; margin-bottom: 10px; border: 0; width: 100%; text-align: left; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item.selected { outline: 2px solid var(--accent); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .ico { font-size: 3em; margin-bottom: 10px; }
.page { flex: 1; overflow: auto; padding: 0 20px calc(30px + var(--safe-bottom)); }
.page > .inner { max-width: 900px; margin: 0 auto; }
.card { background: var(--bg2); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.kv b { font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.3em; letter-spacing: 1px; color: #fff; }

/* Détails film / série */
.detail { display: flex; gap: 22px; }
.detail .cover { width: 220px; flex-shrink: 0; aspect-ratio: 2/3; border-radius: 12px; background: var(--card2) center/cover no-repeat; }
.detail .meta { flex: 1; min-width: 0; }
.detail h2 { margin-top: 0; }
.detail .plot { color: #c9cfdc; max-height: 9em; overflow: auto; }
@media (max-width: 640px) { .detail { flex-direction: column; } .detail .cover { width: 140px; } }
.episodes { margin-top: 16px; }
.episode { display: flex; gap: 12px; align-items: center; width: 100%; padding: 10px; border: 0; background: var(--card); border-radius: 10px; margin-bottom: 8px; text-align: left; }
.episode .en { width: 36px; color: var(--muted); text-align: center; flex-shrink: 0; }
.episode .grow { flex: 1; min-width: 0; }
.episode .grow div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Lecteur plein écran ---------- */
.player { position: fixed; inset: 0; background: #000; z-index: 40; }
.player video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.player-spinner, .player-error { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.player-error { color: #fff; text-align: center; padding: 30px; background: rgba(0,0,0,.6); font-size: 1.1em; pointer-events: auto; }
.spinner { width: 54px; height: 54px; border: 5px solid rgba(255,255,255,.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.osd {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 28px calc(22px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(0,0,0,.92), rgba(0,0,0,.6) 70%, transparent); transition: opacity .25s;
}
.osd.hide { opacity: 0; pointer-events: none; }
.osd .top { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.osd .top .lg { width: 80px; height: 56px; background: center/contain no-repeat; flex-shrink: 0; }
.osd .top h2 { margin: 0; font-size: 1.4em; }
.osd .epg-now { color: #fff; }
.osd .epg-next { color: var(--muted); font-size: .9em; }
.osd .timeline { display: flex; align-items: center; gap: 12px; margin: 12px 0; font-variant-numeric: tabular-nums; }
.osd .timeline .track { flex: 1; height: 6px; background: rgba(255,255,255,.25); border-radius: 3px; position: relative; cursor: pointer; }
.osd .timeline .track i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 3px; }
.osd .controls { display: flex; gap: 10px; flex-wrap: wrap; }
.osd .controls .btn { background: rgba(255,255,255,.12); }
.osd .closebtn { position: absolute; top: -40px; right: 20px; }
.player-top { position: absolute; top: calc(12px + var(--safe-top)); left: 16px; }
.zap { position: absolute; top: calc(30px + var(--safe-top)); right: 30px; background: rgba(0,0,0,.75); padding: 14px 20px; border-radius: 12px; font-size: 1.3em; }
.menu { position: absolute; right: 24px; bottom: 140px; background: rgba(18,21,29,.97); border-radius: 12px; padding: 8px; min-width: 240px; max-height: 60%; overflow: auto; }
.menu .opt { display: block; width: 100%; border: 0; background: transparent; text-align: left; padding: 10px 14px; border-radius: 8px; }
.menu .opt.selected::before { content: '✓ '; color: var(--accent); }
.chlist { position: absolute; top: 0; bottom: 0; left: 0; width: min(420px, 85%); background: rgba(11,13,18,.95); overflow: auto; padding: 10px; }
@media (max-width: 640px) {
  .osd { padding: 30px 14px calc(14px + var(--safe-bottom)); }
  .osd .controls .btn { padding: 10px 12px; }
  .osd .controls .lbl { display: none; }
}

.toast { position: fixed; left: 50%; bottom: calc(30px + var(--safe-bottom)); transform: translateX(-50%); background: #fff; color: #000; padding: 12px 20px; border-radius: 12px; z-index: 100; font-weight: 600; max-width: 90%; text-align: center; }
.loading { display: grid; place-items: center; flex: 1; gap: 14px; color: var(--muted); }
.lock-screen { flex: 1; display: grid; place-items: center; padding: 20px; text-align: center; }
.lock-screen .box { max-width: 560px; }
.search-bar { padding: 0 20px 10px; }
.search-bar input { width: 100%; padding: 14px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: 1.1em; }
.search-bar input:focus { outline: none; border-color: var(--accent); }
.result-group h3 { color: var(--muted); font-size: 1em; margin: 16px 6px 6px; }
.toggle { width: 52px; height: 30px; border-radius: 999px; background: var(--line); position: relative; border: 0; flex-shrink: 0; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 25px; }
.setting { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .grow { flex: 1; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.row-scroll { display: flex; gap: 14px; overflow-x: auto; padding: 6px 4px 12px; }
.row-scroll .poster { width: 140px; flex-shrink: 0; }
.row-scroll .poster.wide { width: 220px; }
.row-scroll .poster.wide .img { aspect-ratio: 16/9; background-size: contain; }
.device-line { margin-top: 28px; color: var(--muted); font-size: .85em; font-family: ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }
.player-status { position: absolute; top: calc(24px + var(--safe-top)); left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.8); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; pointer-events: none; }
.osd .bufinfo { position: absolute; right: 28px; top: 14px; color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; }
