/* ============================================================
   skingomz — design system (thème clair/sombre)
   ============================================================ */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #14161a;
  --muted: #626a76;
  --border: #e2e5ec;
  --accent: #4f7cff;
  --accent-weak: #4f7cff1f;
  --on-accent: #ffffff;
  --live: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(20, 22, 30, .08);
  --shadow-lg: 0 16px 48px rgba(20, 22, 30, .16);
  --header-h: 60px;
  --main-pad: clamp(16px, 3vw, 28px);
  color-scheme: light;
}

/* Sombre auto (système) sauf si l'utilisateur force le clair */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d10;
    --surface: #15181e;
    --surface-2: #1d212a;
    --text: #eceef2;
    --muted: #9aa3b2;
    --border: #262b34;
    --accent: #6a8bff;
    --accent-weak: #6a8bff26;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    --shadow-lg: 0 20px 56px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
/* Sombre forcé */
:root[data-theme="dark"] {
  --bg: #0b0d10;
  --surface: #15181e;
  --surface-2: #1d212a;
  --text: #eceef2;
  --muted: #9aa3b2;
  --border: #262b34;
  --accent: #6a8bff;
  --accent-weak: #6a8bff26;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

button { font: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Barre supérieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 clamp(14px, 3vw, 28px);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; font-size: 1.1rem; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }

.tabs { display: flex; gap: 4px; margin-left: 6px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 7px 16px; border-radius: 999px; font-weight: 600; font-size: .92rem;
  transition: color .2s, background .2s;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.spacer { flex: 1; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  transition: background .2s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 7px 12px; font-size: .85rem; font-weight: 600;
  transition: background .2s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.ghost { background: transparent; }
select {
  font: inherit; font-size: .85rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 8px;
}
[hidden] { display: none !important; }

/* ---------- Vues ---------- */
main { padding: var(--main-pad); }
.view { display: none; }
.view.active { display: block; }
.view-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 12px; margin: 4px 2px 18px; }
.head-acts { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; }
.view-head h1 { font-size: 1.35rem; letter-spacing: -.02em; }
.view-head p { color: var(--muted); font-size: .9rem; }

/* ---------- Radio ---------- */
.station-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  max-width: 900px; margin: 0 auto;
  padding-bottom: 120px; /* place pour la barre lecteur */
}
.station {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); text-align: left; width: 100%;
  transition: transform .15s ease, border-color .2s, box-shadow .2s;
}
.station:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.station[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak), var(--shadow); }

.logo {
  width: 52px; height: 52px; flex: 0 0 auto; border-radius: 12px;
  background: #fff; border: 1px solid var(--border);
  display: grid; place-items: center; overflow: hidden;
}
.logo img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }

.station-meta { min-width: 0; flex: 1; }
.station-meta .name { font-weight: 650; font-size: 1rem; }
.station-meta .state { font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.state.live { color: var(--live); font-weight: 600; }
.state.err { color: var(--warn); }

.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.eq i { width: 3px; height: 4px; background: currentColor; border-radius: 2px; animation: eq 900ms ease-in-out infinite; }
.eq i:nth-child(2){ animation-delay: .15s } .eq i:nth-child(3){ animation-delay: .3s } .eq i:nth-child(4){ animation-delay: .45s }
@keyframes eq { 0%,100% { height: 4px } 50% { height: 12px } }

/* ---------- Barre lecteur (radio) ---------- */
.player {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%) translateY(140%);
  width: min(680px, calc(100% - 24px));
  display: flex; align-items: center; gap: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 12px 14px; z-index: 60;
  transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.player.show { transform: translateX(-50%) translateY(0); }
.player .logo { width: 46px; height: 46px; }
.player .p-meta { flex: 1; min-width: 0; }
.player .p-meta .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .p-meta .state { font-size: .8rem; }
.play-btn {
  width: 46px; height: 46px; border-radius: 50%; border: none; flex: 0 0 auto;
  background: var(--accent); color: var(--on-accent); font-size: 1.1rem;
  display: grid; place-items: center; transition: transform .1s, filter .2s;
}
.play-btn:hover { filter: brightness(1.06); }
.play-btn:active { transform: scale(.92); }
.vol { display: flex; align-items: center; gap: 8px; }
.vol input { width: 96px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 6px; border-radius: 5px;
  background: var(--surface-2); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }

/* ---------- TV ---------- */
.tv-grid {
  --gap: 10px;
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(2, 1fr); /* < 901px : liste, une chaîne à la fois */
}
@media (max-width: 600px) { .tv-grid { grid-template-columns: 1fr; } }
/* Hors mode mur, le choix de grille n'a pas d'objet. */
@media (max-width: 900px) { .head-acts .field { display: none; } }

/* Mur (>= 901px) : la grille tient dans la hauteur visible, sans défilement.
   --cols et --tile-w sont calculés par tv.js d'après la place libre, le nombre
   de chaînes et la disposition choisie (voir layout() ). */
@media (min-width: 901px) {
  #view-tv.active {
    display: flex; flex-direction: column;
    height: calc(100vh - var(--header-h) - 2 * var(--main-pad));
    height: calc(100dvh - var(--header-h) - 2 * var(--main-pad));
  }
  .tv-stage {
    flex: 1 1 auto; min-height: 0;
    display: grid; place-content: safe center;
    overflow: auto; scrollbar-gutter: stable;  /* évite l'oscillation au recalcul */
  }
  .tv-grid { grid-template-columns: repeat(var(--cols, 3), var(--tile-w, 1fr)); }
}

.tile {
  position: relative; background: #000; border-radius: 12px; overflow: hidden;
  aspect-ratio: 16 / 9; border: 1px solid var(--border);
}
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }

.tile .poster {
  position: absolute; inset: 0; display: grid; place-items: center; gap: 10px;
  background: radial-gradient(120% 120% at 50% 0%, #1b1f27 0%, #0a0c10 100%);
  cursor: pointer; border: none; width: 100%;
}
.tile .poster .logo { width: 64px; height: 64px; }
.tile .poster .play-hint { color: #fff; font-size: .85rem; opacity: .85; display: flex; align-items: center; gap: 6px; }
.tile.playing .poster { display: none; }

.tile .loading { position: absolute; inset: 0; display: grid; place-items: center; color: #8b93a1; font-size: .8rem; pointer-events: none; }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.tile .bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; background: linear-gradient(transparent, rgba(0,0,0,.75));
  opacity: 0; transition: opacity .2s;
}
.tile:hover .bar, .tile:focus-within .bar { opacity: 1; }
@media (hover: none) { .tile .bar { opacity: 1; } }
.tile .ch { display: flex; align-items: center; gap: 7px; color: #fff; font-size: .8rem; font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: 0 0 auto; }
.dot.live { background: var(--live); animation: pulse 2s infinite; }
.dot.err { background: var(--live); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.tile .tbtns { display: flex; gap: 6px; }
.tbtn { width: 30px; height: 30px; border-radius: 8px; border: none; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; font-size: .8rem; }
.tbtn:hover { background: rgba(255,255,255,.28); }
.tbtn.on { background: var(--ok); }

@keyframes eq2 { 0%,100% { height: 4px } 50% { height: 12px } }

.hint { max-width: 900px; margin: 14px auto 0; color: var(--muted); font-size: .82rem; text-align: center; }

/* Pastille de secours : chaînes sans logo local */
.logo-text {
  background: hsl(var(--hue, 220) 42% 32%); color: #fff; border-color: transparent;
  font-weight: 800; font-size: .95rem; letter-spacing: .02em;
}
.tile .poster .logo-text { font-size: 1.5rem; }

/* Chaînes lues via une intégration YouTube */
.tile iframe.yt { width: 100%; height: 100%; border: 0; display: block; background: #000; }

.tv-empty { color: var(--muted); font-size: .92rem; text-align: center; padding: 40px 16px; }

/* ---------- Réglage des chaînes (feuille modale) ---------- */
.sheet {
  width: min(720px, calc(100vw - 24px)); max-height: min(80vh, 760px);
  margin: auto;  /* le reset global annule le centrage natif du <dialog> */
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.sheet-head h2 { font-size: 1.05rem; letter-spacing: -.01em; }
.sheet-count { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.sheet-search {
  flex: 1; min-width: 0; margin-left: auto; font: inherit; font-size: .88rem;
  padding: 8px 11px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.sheet-x { width: 34px; height: 34px; flex: 0 0 auto; }
.sheet-body { flex: 1; overflow: auto; padding: 4px 16px 14px; }

.grp h3 {
  display: flex; align-items: center; gap: 8px; margin: 16px 0 6px;
  font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.grp-acts { margin-left: auto; display: flex; gap: 4px; }
.link {
  border: none; background: none; color: var(--accent);
  font-size: .76rem; font-weight: 700; text-transform: none; letter-spacing: 0;
  padding: 3px 7px; border-radius: 7px;
}
.link:hover { background: var(--accent-weak); }
.grp ul { list-style: none; display: grid; gap: 2px 10px; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }
.grp label {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 10px; cursor: pointer; font-size: .9rem;
}
.grp label:hover { background: var(--surface-2); }
.grp input[type="checkbox"] { width: 16px; height: 16px; flex: 0 0 auto; accent-color: var(--accent); }
.grp .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp .tag {
  margin-left: auto; flex: 0 0 auto; font-size: .64rem; font-weight: 700;
  color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 2px 7px;
}
.sheet-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.sheet-warn { color: var(--warn); font-size: .8rem; }
.sheet-foot .primary { margin-left: auto; }

/* ---------- Mini-lecteur TV flottant (visible sur l'onglet Radio) ---------- */
.tv-mini {
  position: fixed; top: calc(var(--header-h) + 12px); right: 12px;
  width: 264px; max-width: 46vw; aspect-ratio: 16 / 9;
  background: #000; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  z-index: 70; cursor: pointer;
}
.tv-mini video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.tv-mini .tv-mini-tag {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  display: flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 7px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: .72rem; font-weight: 700;
  max-width: calc(100% - 12px); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.tv-mini .tv-mini-tag::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--live); flex: 0 0 auto; }
@media (max-width: 600px) {
  .tv-mini { width: 184px; top: calc(var(--header-h) + 8px); right: 8px; }
}
