/* TVMalin — interface TV / mobile */

:root {
  --bg: #0b0f1a;
  --bg-2: #121828;
  --card: #161e33;
  --card-hi: #1d2745;
  --line: #263050;
  --text: #eef1f8;
  --muted: #94a0bd;
  --accent: #ff8c1a;
  --accent-2: #ffb25e;
  --danger: #ff5470;
  --focus-ring: 0 0 0 3px var(--accent), 0 8px 30px rgba(255, 140, 26, 0.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: clamp(14px, 0.55vw + 10px, 20px); }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1400px 700px at 85% -10%, #1a2340 0%, var(--bg) 55%);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  cursor: default;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* --- Écrans --- */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  overflow: hidden;
}
.screen.active { display: flex; }

/* --- Logo / marque --- */
.logo { font-size: 1.5rem; letter-spacing: 0.5px; user-select: none; }
.logo strong { color: var(--accent); font-weight: 800; }
.logo-lg { font-size: 2.6rem; }
.logo-xl { font-size: 3.4rem; }

/* --- Focus TV --- */
[data-focus] { outline: none; }
[data-focus].focused {
  box-shadow: var(--focus-ring);
  transform: scale(1.03);
  z-index: 2;
}

/* --- Boutons --- */
.btn {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 0.7rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--accent); }
.btn-icon {
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  border-radius: 50%;
}

/* --- Spinner --- */
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 1.2rem auto;
}
.spinner-sm { width: 20px; height: 20px; border-width: 3px; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Démarrage --- */
#screen-boot { align-items: center; justify-content: center; }
.boot-center { text-align: center; }

/* --- Appairage --- */
#screen-pairing { align-items: center; justify-content: center; overflow-y: auto; }
.pairing-wrap {
  text-align: center;
  max-width: 46rem;
  padding: 2rem;
}
.pairing-wrap h1 { font-size: 1.9rem; margin: 1rem 0 0.4rem; }
.pair-cards { display: flex; gap: 1.2rem; justify-content: center; margin: 1.6rem 0; flex-wrap: wrap; }
.pair-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.1rem 1.8rem;
  min-width: 15rem;
}
.pair-label { display: block; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 0.4rem; }
.pair-value { font-family: "Consolas", monospace; font-size: 1.7rem; letter-spacing: 2px; }
.pair-value.accent { color: var(--accent); font-weight: 700; }
.pair-qr-block { display: flex; flex-direction: column; align-items: center; margin: 0.5rem 0 1.6rem; }
.pair-qr {
  background: #fff;
  padding: 12px;
  border-radius: 16px;
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.pair-qr svg { width: 100%; height: 100%; display: block; }
.pair-qr a { font-size: 0.75rem; word-break: break-all; color: #111; }
.pair-qr-hint { color: var(--muted); font-size: 0.9rem; margin: 0.7rem auto 0; max-width: 26rem; }
.pair-steps {
  text-align: left;
  margin: 0 auto 1.5rem;
  max-width: 34rem;
  color: var(--muted);
  line-height: 1.9;
  padding-left: 1.4rem;
}
.pair-steps strong { color: var(--accent-2); }
.pair-status { display: flex; align-items: center; justify-content: center; gap: 0.7rem; color: var(--muted); margin-bottom: 1.4rem; }
.pair-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* --- En-tête commun --- */
.app-header {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  padding: 1.1rem 2rem;
  flex-shrink: 0;
}
.app-header .screen-title { font-size: 1.4rem; flex: 1; }
.header-center { flex: 1; text-align: center; color: var(--muted); }
.header-right { display: flex; align-items: center; gap: 1rem; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Accueil --- */
.home-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.4rem;
  padding: 1rem 3rem 2rem;
  align-content: center;
}
.home-card {
  background: linear-gradient(160deg, var(--card-hi), var(--card));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2rem 1.6rem;
  min-height: 15rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.4rem;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
  overflow: hidden;
}
.home-card .hc-icon { width: 3.4rem; height: 3.4rem; margin-bottom: auto; color: var(--accent); }
.home-card .hc-icon svg { width: 100%; height: 100%; }
.home-card .hc-title { font-size: 1.35rem; font-weight: 700; }
.home-card .hc-count { color: var(--muted); font-size: 0.95rem; }
.home-hint { text-align: center; padding-bottom: 1rem; font-size: 0.85rem; }

/* --- Navigation chaînes --- */
.browse-layout { flex: 1; display: flex; min-height: 0; }
.group-panel {
  width: 20rem;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 0.5rem 1rem 2rem 2rem;
  scrollbar-width: thin;
}
.group-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.2rem;
}
.group-item.selected { background: var(--card); color: var(--text); border-color: var(--line); }
.group-item .g-count { color: var(--muted); font-size: 0.8rem; margin-left: 0.4rem; }

.channel-panel {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 2rem 2rem 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.9rem;
  align-content: start;
  scrollbar-width: thin;
}
.channel-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  cursor: pointer;
  min-height: 4.4rem;
}
.ch-logo {
  width: 3rem;
  height: 3rem;
  border-radius: 10px;
  background: var(--bg-2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--accent);
  overflow: hidden;
}
.ch-logo img { width: 100%; height: 100%; object-fit: contain; }
.ch-name {
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.ch-sub { font-size: 0.78rem; color: var(--muted); }
.load-more { grid-column: 1 / -1; justify-self: center; margin-top: 0.6rem; }
.empty-msg { grid-column: 1 / -1; color: var(--muted); padding: 2rem; text-align: center; }

/* --- Séries --- */
.series-grid-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 2rem 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 1rem;
  align-content: start;
  scrollbar-width: thin;
}
.series-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
}
.series-poster {
  height: 9rem;
  background: linear-gradient(160deg, var(--card-hi), var(--bg-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
  overflow: hidden;
}
.series-poster img { width: 100%; height: 100%; object-fit: cover; }
.series-info { padding: 0.7rem 0.9rem; }
.series-title { font-weight: 600; font-size: 0.95rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.series-eps { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }

.sdetail-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 2rem 1rem; }
.season-row { display: flex; gap: 0.7rem; padding: 0.3rem 0 1rem; flex-wrap: wrap; flex-shrink: 0; }
.season-chip {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 20px;
  padding: 0.45rem 1.1rem;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}
.season-chip.selected { color: var(--accent-2); border-color: var(--accent); }
.episode-list { flex: 1; overflow-y: auto; padding-bottom: 2rem; scrollbar-width: thin; }
.episode-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 1.1rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
}
.ep-num { color: var(--accent); font-weight: 800; font-size: 1.05rem; min-width: 4.4rem; }
.ep-name { flex: 1; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Relecture --- */
.replay-wrap { flex: 1; overflow-y: auto; padding: 0.5rem 2rem 2rem; scrollbar-width: thin; }
.replay-section-title { font-size: 1.1rem; margin: 1rem 0 0.8rem; color: var(--accent-2); }
.replay-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 0.9rem; }
.progress-bar { height: 4px; background: var(--bg-2); border-radius: 2px; margin-top: 0.4rem; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); }
.replay-note { color: var(--muted); font-size: 0.85rem; margin: 0.6rem 0 1rem; }

/* --- Paramètres --- */
.settings-wrap { flex: 1; overflow-y: auto; padding: 0.5rem 2.5rem 2rem; max-width: 50rem; scrollbar-width: thin; }
.settings-group { margin-bottom: 1.6rem; }
.settings-group h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin-bottom: 0.7rem; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1.2rem;
  margin-bottom: 0.5rem;
}
.settings-row .sr-label { color: var(--muted); font-size: 0.9rem; }
.settings-row .sr-value { font-family: "Consolas", monospace; letter-spacing: 1px; }
.settings-row.clickable { cursor: pointer; }
.settings-row .sr-danger { color: var(--danger); }

/* --- Lecteur --- */
.screen-player { background: #000; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(0,0,0,0.75) 0%, transparent 22%, transparent 75%, rgba(0,0,0,0.85) 100%);
  z-index: 5;
}
.player-top { display: flex; align-items: center; gap: 1.1rem; padding: 1.4rem 2rem; }
.player-meta { flex: 1; min-width: 0; }
.player-name { font-size: 1.3rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-group { font-size: 0.9rem; }
.player-bottom { display: flex; align-items: center; gap: 1rem; padding: 1.4rem 2rem; }
.player-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; min-width: 3.5rem; text-align: center; }
#player-seekbar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
}
#player-seekbar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
}
#player-seekbar.focused { box-shadow: var(--focus-ring); }
.live-badge { color: var(--danger); font-weight: 800; letter-spacing: 1px; font-size: 0.9rem; white-space: nowrap; }
.player-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  background: rgba(5, 8, 15, 0.92);
  z-index: 6;
  text-align: center;
  padding: 2rem;
}
.player-error p { font-size: 1.15rem; max-width: 34rem; }
.player-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 2.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-hi);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 12px;
  padding: 0.8rem 1.5rem;
  font-size: 0.95rem;
  z-index: 50;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  max-width: 80vw;
}

/* --- Mobile --- */
@media (max-width: 760px) {
  body { overflow: auto; }
  .home-grid { grid-template-columns: 1fr 1fr; padding: 0.5rem 1.2rem 1.5rem; gap: 0.9rem; }
  .home-card { min-height: 10rem; padding: 1.2rem; }
  .app-header { padding: 0.9rem 1.1rem; }
  .browse-layout { flex-direction: column; }
  .group-panel {
    width: 100%;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.4rem 1.1rem;
    gap: 0.4rem;
    flex-shrink: 0;
  }
  .group-item { width: auto; flex-shrink: 0; margin-bottom: 0; }
  .channel-panel { padding: 0.6rem 1.1rem 2rem; grid-template-columns: 1fr; }
  .series-grid-wrap { grid-template-columns: repeat(2, 1fr); padding: 0.5rem 1.1rem 2rem; }
  .settings-wrap, .replay-wrap { padding: 0.5rem 1.1rem 2rem; }
  .sdetail-layout { padding: 0 1.1rem 1rem; }
  .pair-cards { flex-direction: column; align-items: center; }
  .home-hint { display: none; }
}

/* ==========================================================================
   Refonte UX : accueil enrichi, rangées, recherche, drapeaux pays
   ========================================================================== */

/* En-tête : bouton actualiser qui tourne pendant le chargement */
.btn-icon.spinning { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-icon[disabled] { opacity: 0.5; }

/* Accueil défilable */
.home-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: 1rem; }
.home-hero:empty { display: none; }
.home-updated { text-align: center; font-size: 0.82rem; padding: 0.2rem 1rem 0.6rem; margin: 0; }

/* Rangées horizontales (Reprendre, Chaînes françaises, résultats) */
.home-row { padding: 0.2rem 2rem 0.4rem; }
.home-row:empty { display: none; }
.row-title { font-size: 1.15rem; font-weight: 700; margin: 0.6rem 0 0.6rem; color: var(--text); }
.row-track {
  display: flex; gap: 0.8rem; overflow-x: auto; overflow-y: hidden;
  padding: 0.2rem 0.2rem 0.6rem; scroll-padding: 0 2rem;
}
.row-track::-webkit-scrollbar { height: 6px; }
.row-track::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* Carte compacte (rangées + résultats de recherche) */
.mini-card {
  flex: 0 0 auto; width: 10.5rem; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 0.7rem; display: flex; flex-direction: column; gap: 0.45rem;
  cursor: pointer; transition: transform 0.12s, border-color 0.12s;
}
.mini-card .ch-logo { width: 100%; height: 5rem; border-radius: 10px; }
.mini-card.focused { transform: translateY(-3px); border-color: var(--accent); }
.mini-name {
  font-size: 0.9rem; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.mini-more { align-items: center; justify-content: center; color: var(--accent-2); font-weight: 700; }

/* Groupes avec drapeau (TV en direct / Films) */
.group-item { display: flex; align-items: center; gap: 0.5rem; }
.group-item .g-flag { font-size: 1.1rem; }
.group-item .g-name { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-item .g-count { color: var(--muted); font-size: 0.78rem; margin-left: auto; }

/* Champ de recherche */
.search-input {
  flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 0.6rem 1rem; font-size: 1.05rem; margin: 0 0.8rem;
}
.search-input::placeholder { color: var(--muted); }
.search-input.focused { box-shadow: var(--focus-ring); }
.search-input-sm { max-width: 16rem; font-size: 0.95rem; padding: 0.45rem 0.8rem; }
.search-results { flex: 1; overflow-y: auto; padding: 0.5rem 2rem 2rem; }
.search-grid { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-bottom: 1rem; }

@media (max-width: 900px) {
  .home-row { padding: 0.2rem 1.1rem; }
  .mini-card { width: 8.5rem; }
  .mini-card .ch-logo { height: 4rem; }
  .search-input-sm { max-width: 9rem; }
  .search-results { padding: 0.5rem 1.1rem 2rem; }
}
