:root {
  --bg: #ffffff;
  --surface: #f4f4f6;
  --surface-2: #e8e8ed;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgb(0 0 0 / .08);
  --accent: #0066cc;
  --live: rgb(0 102 204 / .08);
  --hit: #fff2b3;
  --shadow: 0 1px 3px rgb(0 0 0 / .12);
  --radius: 10px;
  --header-bg: rgb(255 255 255 / .85);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989d;
    --line: rgb(255 255 255 / .1);
    --accent: #4da3ff;
    --live: rgb(77 163 255 / .14);
    --hit: #4a3f12;
    --shadow: 0 1px 3px rgb(0 0 0 / .6);
    --header-bg: rgb(0 0 0 / .8);
    color-scheme: dark;
  }
}

/* manipulation : pas de zoom au double tap (le pincement pour zoomer reste possible) */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* En-tête */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + var(--safe-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 4px 0; max-width: 1400px; margin: 0 auto; }
.logo { font-size: 20px; font-weight: 700; letter-spacing: -.02em; margin: 0 auto 0 0; white-space: nowrap; }

/* Contrôle segmenté : rectangles à coins arrondis */
.seg { display: flex; gap: 2px; padding: 2px; background: var(--surface); border-radius: var(--radius); }
.seg button {
  border: 0; background: none; border-radius: 8px;
  min-height: 32px; padding: 0 14px;
  font-size: 14px; font-weight: 500; color: var(--muted); white-space: nowrap;
}
.seg button.on { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .seg button.on { background: var(--surface-2); } }

.days { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
.days::-webkit-scrollbar { display: none; }
.days[hidden] { display: none; }
.days button {
  flex: none; min-height: 32px; padding: 0 12px;
  border: 1px solid var(--line); background: none; border-radius: 8px;
  font-size: 14px; color: var(--muted); white-space: nowrap;
}
.days button.on { background: var(--text); border-color: var(--text); color: var(--bg); }

#search {
  flex: 1 1 220px; min-width: 0; height: 36px;
  padding: 0 12px; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; /* 16px : pas de zoom sur iOS */
  -webkit-appearance: none; appearance: none;
}
#search::placeholder { color: var(--muted); }
#search:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

main { flex: 1; padding: 16px; width: 100%; max-width: 1400px; margin: 0 auto; }
.msg { text-align: center; color: var(--muted); padding: 48px 0; }

/* Listes (En ce moment / Ce soir) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--surface); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.card h2 { font-size: 13px; font-weight: 600; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.chlogo { width: 40px; height: 28px; object-fit: contain; flex: none; }
.prog { text-align: left; border: 0; background: none; padding: 6px 8px; margin: 0 -8px; border-radius: 8px; display: block; width: calc(100% + 16px); min-height: 36px; }
.prog.cur strong { display: block; font-size: 16px; font-weight: 600; }
.prog em { display: block; color: var(--muted); font-style: normal; font-size: 13px; }
.prog.next { color: var(--muted); font-size: 14px; }
.prog.next strong { font-weight: 500; color: var(--text); }
.time { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; margin-right: 6px; }
.prog.cur > .time { display: block; font-size: 13px; }
.hit { background: var(--hit) !important; }
.none { color: var(--muted); margin: 6px 0; }
.progress { height: 3px; background: var(--surface-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); }

/* Foot */
.foot-day + .foot-day { margin-top: 20px; }
.day-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 0 0 8px; }
.cards.list { display: flex; flex-direction: column; gap: 0; background: var(--surface); border-radius: 12px; overflow: hidden; }
.match {
  display: flex; gap: 14px; align-items: flex-start; width: 100%; min-height: 56px;
  text-align: left; border: 0; background: none; padding: 12px 16px;
}
.match + .match { border-top: 1px solid var(--line); }
.match-time { flex: none; width: 64px; font-weight: 600; font-variant-numeric: tabular-nums; padding-top: 1px; }
.match-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.match-body strong { font-weight: 600; }
.match-body em { font-style: normal; color: var(--text); }
.match-ch { color: var(--muted); font-size: 13px; }
.live-badge {
  display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 1px 5px; white-space: nowrap;
}
.seg[hidden] { display: none; }

/* Grille */
.grid {
  overflow: auto; max-height: calc(100dvh - 210px);
  border: 1px solid var(--line); border-radius: 12px;
  overscroll-behavior: contain;
}
.gridin { position: relative; }
.ruler, .row { display: flex; }
.ruler { position: sticky; top: 0; z-index: 3; background: var(--bg); border-bottom: 1px solid var(--line); height: 28px; }
.corner, .ch {
  position: sticky; left: 0; z-index: 2; flex: none; width: 130px;
  background: var(--bg); border-right: 1px solid var(--line);
}
.corner { z-index: 4; }
.ch { display: flex; align-items: center; gap: 6px; padding: 0 8px; font-size: 12px; font-weight: 600; }
.ch .chlogo { width: 30px; height: 22px; }
.ch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track { position: relative; flex: none; }
.ruler .track span { position: absolute; top: 6px; font-size: 12px; color: var(--muted); padding-left: 4px; border-left: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.ruler .track span.half { opacity: .5; }
.row { height: 56px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.gp {
  position: absolute; top: 4px; bottom: 4px;
  text-align: left; border: 0; background: var(--surface);
  border-radius: 8px; padding: 5px 8px; font-size: 13px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.gp .time { display: block; font-size: 11px; }
.gp.past { color: var(--muted); background: none; }
.gp.live { background: var(--live); box-shadow: inset 0 0 0 1px var(--accent); }
.nowline { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); z-index: 1; pointer-events: none; }

@media (hover: hover) {
  .match:hover { background: var(--surface-2); }
  .prog:hover, .gp:hover { background: var(--surface-2); }
  .seg button:not(.on):hover, .days button:not(.on):hover { color: var(--text); }
}

/* Détail */
dialog {
  overscroll-behavior: contain; /* le défilement d'une longue fiche ne passe pas à la page */
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  border: 0; border-radius: 14px; padding: 20px;
  background: var(--bg); color: var(--text);
  box-shadow: 0 10px 40px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin: 4px 0; font-size: 22px; letter-spacing: -.01em; }
dialog form { float: right; margin: 0 0 8px 8px; }
dialog .close {
  border: 0; background: var(--surface); border-radius: 8px;
  min-height: 32px; padding: 0 12px; font-size: 14px; font-weight: 500;
}
.poster { width: 100%; max-height: 240px; object-fit: cover; border-radius: 10px; margin-bottom: 10px; }
.kicker { color: var(--muted); margin: 0; font-size: 13px; }
.sub { margin: 0; color: var(--muted); }
.facts { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.desc { white-space: pre-line; line-height: 1.5; }

.foot {
  display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: center;
  padding: 16px; color: var(--muted); font-size: 12px;
}
.foot select {
  font: inherit; font-size: 12px; color: var(--text);
  background: var(--surface); border: 0; border-radius: 6px; padding: 4px 6px;
}

/* iPhone et petits écrans */
@media (max-width: 640px) {
  /* Fond opaque : un backdrop-filter ici piégerait la barre d'onglets fixe dans l'en-tête */
  .top { padding-bottom: 6px; background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .bar { gap: 8px; }
  .logo { font-size: 22px; }
  #search { flex-basis: 100%; }

  /* Onglets en barre fixe en bas, à portée de pouce */
  .tabs {
    position: fixed; z-index: 10; left: 0; right: 0; bottom: 0;
    border-radius: 0; gap: 0;
    padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + var(--safe-bottom));
    background: var(--header-bg);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--line);
  }
  .tabs button { flex: 1; min-height: 44px; font-size: 13px; }
  .tabs button.on { background: none; box-shadow: none; color: var(--accent); font-weight: 600; }
  .countries button, .days button { min-height: 36px; }

  main { padding: 12px 0; }
  .foot { padding: 16px 16px calc(76px + var(--safe-bottom)); }

  /* Liste groupée façon iOS */
  .cards { grid-template-columns: 1fr; gap: 0; margin: 0 12px; background: var(--surface); border-radius: 12px; overflow: hidden; }
  .card { border-radius: 0; padding: 12px 16px; }
  .card + .card { border-top: 1px solid var(--line); }
  .prog { min-height: 44px; }
  .prog.next { min-height: 36px; }

  .foot-day { margin: 0 12px; }
  .foot-day .cards.list { margin: 0; }
  .day-title { padding-left: 4px; }

  .grid {
    margin: 0 12px;
    max-height: calc(100dvh - 240px - var(--safe-top) - var(--safe-bottom));
  }
  .corner, .ch { width: 92px; }
  .ch .chlogo { display: none; }

  /* Fiche en panneau depuis le bas */
  dialog {
    width: 100%; max-width: 100%; margin: auto 0 0; max-height: 85dvh;
    border-radius: 16px 16px 0 0;
    padding: 20px 20px calc(20px + var(--safe-bottom));
  }
}
