:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #ecebe6;
  --text: #1b1c20;
  --muted: #6b6d75;
  --accent: #d9480f;
  --accent-soft: #fde4d6;
  --border: #dedcd5;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1d2028;
    --surface-2: #272b35;
    --text: #eceef3;
    --muted: #9298a6;
    --accent: #ff7a3d;
    --accent-soft: #3a2519;
    --border: #2e323d;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
}
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }

.icon-btn {
  border: 0; background: var(--surface-2); color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; font-size: 20px; cursor: pointer;
}
.icon-btn[aria-pressed="true"] { background: var(--accent); color: #fff; }

.toolbar {
  position: sticky; top: 60px; z-index: 4; background: var(--bg);
  display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 10px; scrollbar-width: none;
}
.toolbar:empty { display: none; }
.toolbar::-webkit-scrollbar { display: none; }
.toolbar:has(.chip-row) { flex-direction: column; overflow: visible; padding-left: 0; padding-right: 0; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 999px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.search-input {
  width: 100%; padding: 12px 14px; font-size: 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

main { padding: 4px 16px 16px; display: grid; gap: 10px; }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Carte chaîne (vues Maintenant / Ce soir) */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 12px;
  display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: start;
  border: 1px solid var(--border);
}
.logo {
  width: 48px; height: 48px; border-radius: 10px; background: #fff; object-fit: contain;
  padding: 4px; border: 1px solid var(--border);
}
.logo.placeholder {
  display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #333;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.channel-name { font-weight: 600; font-size: 13px; color: var(--muted); }
.star { border: 0; background: none; font-size: 18px; color: var(--muted); cursor: pointer; padding: 0 2px; }
.star.on { color: var(--accent); }

.prog { cursor: pointer; border-radius: 8px; padding: 2px 0; }
.prog-title { font-weight: 650; font-size: 16px; margin: 2px 0; }
.prog-meta { color: var(--muted); font-size: 13px; }
.prog + .prog { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }

.progress { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

/* Grille : liste horaire d'une chaîne */
.slot {
  display: grid; grid-template-columns: 56px 1fr; gap: 10px; padding: 10px 12px;
  background: var(--surface); border-radius: 12px; border: 1px solid var(--border); cursor: pointer;
}
.slot .time { font-variant-numeric: tabular-nums; font-weight: 600; }
.slot.past { opacity: .5; }
.slot.live { border-color: var(--accent); background: var(--accent-soft); }

/* Résultats de recherche */
.result { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; }
.result .logo { width: 40px; height: 40px; }

/* Fiche détail */
dialog {
  border: 0; padding: 0; width: min(560px, 100%); max-height: 88vh; margin: auto auto 0;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
@media (min-width: 700px) { dialog { margin: auto; border-radius: 20px; } }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog article { padding: 20px; position: relative; }
dialog .close { position: absolute; top: 12px; right: 12px; }
.detail-img { width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; margin-bottom: 12px; background: var(--surface-2); }
.detail-title { font-size: 21px; margin: 0 40px 4px 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.tag { background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.credits dt { font-weight: 600; margin-top: 8px; font-size: 13px; color: var(--muted); }
.credits dd { margin: 0; }

/* Barre d'onglets */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar button {
  border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar .ico { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

.offline { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
