:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f0ebe3;
  --text: #1d1a17;
  --muted: #6d655c;
  --line: #e4ddd2;
  --red: #b3222b;
  --red-deep: #8a1c22;
  --green: #0b6b3a;
  --green-soft: #e3f1e8;
  --amber: #b77a07;
  --amber-soft: #fbf0d9;
  --live: #d92d20;
  --fav: #fff6d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141210;
    --surface: #1e1b18;
    --surface-2: #2a2622;
    --text: #f2ede6;
    --muted: #a69d92;
    --line: #36312b;
    --red: #e0535a;
    --red-deep: #5c1418;
    --green: #4cc583;
    --green-soft: #173323;
    --amber: #e5b04a;
    --amber-soft: #3a2d12;
    --fav: #3a3216;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #141210;
    --surface: #1e1b18;
    --surface-2: #2a2622;
    --text: #f2ede6;
    --muted: #a69d92;
    --line: #36312b;
    --red: #e0535a;
    --red-deep: #5c1418;
    --green: #4cc583;
    --green-soft: #173323;
    --amber: #e5b04a;
    --amber-soft: #3a2d12;
    --fav: #3a3216;
    --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.4 "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* En-tête */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: linear-gradient(120deg, var(--red-deep), #b3222b 60%, #0b6b3a);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 10px; background: #fff2; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.sub { margin: 0; font-size: 12px; opacity: .85; }
.phase {
  font-size: 12px; font-weight: 600; background: #0003; padding: 6px 10px;
  border-radius: 999px; white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff5a4f; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

main { max-width: 1100px; margin: 0 auto; padding-block: 12px 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); outline: none; }

/* Barre d'onglets */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.tabs button {
  border: 0; background: none; padding: 8px 4px 10px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs .ico { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--red); font-weight: 700; }
.tabs button.active .ico { filter: none; opacity: 1; }

/* Jours */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; margin: 0 -16px; padding-inline: 16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  padding: 7px 12px; border-radius: 999px; font-size: 13px; text-transform: capitalize;
}
.chip.today { border-color: var(--red); }
.chip.on { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }

.day-title, .page-title { font-size: 20px; margin: 6px 0 2px; text-transform: capitalize; }
.page-title { text-transform: none; }
.venue-note, .legend, .note { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.note { margin-top: 12px; }
.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 16px 0 8px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Carte de match */
.match {
  display: block; width: 100%; text-align: left; border: 1px solid var(--line);
  background: var(--surface); border-radius: var(--radius); padding: 10px 12px 12px;
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.match.is-fav { background: linear-gradient(var(--fav), var(--fav)) padding-box; }
.match.live { border-color: var(--live); }
.meta { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; font-size: 11.5px; }
.tag { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.badge { padding: 2px 7px; border-radius: 999px; font-weight: 600; }
.badge.done { background: var(--surface-2); color: var(--muted); }
.badge.live { background: var(--live); color: #fff; }
.badge.pending { background: var(--amber-soft); color: var(--amber); }
.badge.local { background: var(--amber-soft); color: var(--amber); }
.row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.team { display: flex; align-items: center; gap: 8px; min-width: 0; }
.team.a { flex-direction: row-reverse; text-align: right; }
.team .flag { font-size: 26px; line-height: 1; }
.tname { font-weight: 600; display: flex; flex-direction: column; min-width: 0; overflow-wrap: break-word; hyphens: auto; font-size: 14px; }
.team.fav .tname::after { content: " ⭐"; font-size: 11px; }
.team.tbd .tname { color: var(--muted); font-weight: 500; font-size: 13px; }
.prov { font-size: 10.5px; font-weight: 500; color: var(--muted); font-style: italic; }
.mid { text-align: center; min-width: 64px; }
.score { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.score i { font-style: normal; color: var(--muted); margin: 0 4px; }
.mid small { display: block; color: var(--muted); font-size: 11px; }
.time { font-size: 17px; font-weight: 700; background: var(--surface-2); border-radius: 8px; padding: 4px 8px; display: inline-block; }

/* Cartes / grille */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.grid .card { margin-bottom: 0; }
.card header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.card h3 { margin: 0; font-size: 16px; }
.prog { font-size: 12px; color: var(--muted); }

/* Tableau de classement */
.std { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.std th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.std td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.std tr:last-child td { border-bottom: 0; }
.std tbody tr { cursor: pointer; }
.std .tm { text-align: left; white-space: nowrap; }
.std .tm small { color: var(--muted); }
.std .flag { margin-right: 8px; font-size: 18px; vertical-align: -2px; }
.std .pos { width: 26px; font-weight: 700; position: relative; }
.std tr.q .pos { color: var(--green); }
.std tr.q .pos::before, .std tr.q3 .pos::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 2px; background: var(--green); }
.std tr.q3 .pos { color: var(--amber); }
.std tr.q3 .pos::before { background: var(--amber); }
.std tr.fav td { background: var(--fav); }
.std .pts { font-weight: 800; }
.form { white-space: nowrap; }
.f { font-style: normal; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 4px; font-size: 10px; font-weight: 700; color: #fff; margin: 0 1px; }
.f.V { background: #16a34a; } .f.N { background: #8a8278; } .f.D { background: #dc2626; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 8px; vertical-align: -1px; }
.dot.q { background: var(--green); } .dot.q3 { background: var(--amber); }
.legend .dot:first-child { margin-left: 0; }

@media (max-width: 520px) { .hide-s { display: none; } }
@media (max-width: 380px) { .hide-xs { display: none; } }

/* Tableau final */
.bracket { display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; margin: 0 -16px; padding-inline: 16px; }
.bcol { display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.bcol h4 { margin: 0 0 2px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.bcol h4.mt { margin-top: 14px; }
.bm { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 8px; text-align: left; width: 100%; box-shadow: var(--shadow); }
.bh { font-size: 10.5px; color: var(--muted); margin-bottom: 4px; }
.bl { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 13px; }
.bl .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.bl.provl .n { font-style: italic; font-weight: 500; color: var(--muted); }
.bl.fav { background: var(--fav); border-radius: 4px; }
.bl b { font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  .bracket { grid-template-columns: repeat(4, 210px); }
}

/* Équipes */
.teams { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tcard { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tcard.fav { outline: 2px solid var(--amber); }
.tcard .big { font-size: 34px; line-height: 1.1; }
.tcard small { color: var(--muted); font-size: 11.5px; }
.tools p { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { border: 0; background: var(--red); color: #fff; padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.btn.ghost { background: var(--surface-2); color: var(--text); }

/* Fiche (dialog) */
dialog {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, 100%); max-height: 88vh; border-radius: 18px 18px 0 0;
  margin: auto auto 0; box-shadow: 0 -8px 30px rgba(0,0,0,.25);
}
@media (min-width: 640px) { dialog { margin: auto; border-radius: 18px; } }
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet { padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.sh-head { display: flex; justify-content: space-between; align-items: center; }
.x { border: 0; background: var(--surface-2); width: 32px; height: 32px; border-radius: 50%; }
.sh-teams { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; text-align: center; margin: 16px 0 8px; }
.sh-teams span { font-size: 26px; font-weight: 800; }
.sh-info { color: var(--muted); font-size: 13px; text-align: center; }
.edit { border: 1px solid var(--line); border-radius: 12px; margin: 14px 0 0; }
.edit legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
.inputs { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 6px 0 12px; }
.inputs input { width: 64px; font-size: 22px; text-align: center; padding: 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.inputs.pens input { width: 52px; font-size: 16px; }
.inputs.pens small { color: var(--muted); }
.edit .btns { justify-content: center; }
.sh-team { text-align: center; margin: 6px 0 12px; }
.sh-team .big { font-size: 56px; }
.sh-team h3 { margin: 4px 0; font-size: 22px; }
.sh-team p { margin: 0; color: var(--muted); }
.sheet > .btn { width: 100%; margin-bottom: 12px; }
.sh-list .match { margin-bottom: 8px; }

/* Drapeaux (images) */
img.flag, .flag.noflag { width: 30px; height: 20px; object-fit: cover; border-radius: 3px; flex: none; box-shadow: 0 0 0 1px #0002; background: var(--surface-2); display: inline-block; }
.std img.flag, .std .noflag { width: 22px; height: 15px; vertical-align: -3px; }
.bl img.flag, .bl .noflag { width: 22px; height: 15px; }
img.flag.sm { width: 18px; height: 12px; vertical-align: -1px; margin-right: 2px; }
img.big { width: 52px; height: 35px; object-fit: cover; border-radius: 5px; box-shadow: 0 0 0 1px #0002; margin-bottom: 4px; }
.sh-team img.big { width: 84px; height: 56px; }

/* Typo display (chiffres de score, titres) */
.brand h1, .day-title, .page-title, .score, .time, .sh-teams span, .card h3, .sh-team h3 { font-family: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif; }
.score { font-size: 28px; }
.day-title, .page-title { font-size: 24px; font-weight: 700; text-wrap: balance; }
button:focus-visible, .chip:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.copybox { width: 100%; min-height: 120px; margin-top: 10px; font: 12px ui-monospace, monospace; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* Regarder */
.watch { margin-left: auto; font-weight: 700; color: var(--red); font-size: 11.5px; }
.watch.live { color: #fff; background: var(--live); padding: 2px 7px; border-radius: 999px; }
.watchbox { display: grid; gap: 8px; margin-top: 14px; }
.watchbox h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.wlink { display: flex; flex-direction: column; gap: 1px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); text-decoration: none; }
.wlink small { color: var(--muted); font-size: 12px; }
.wlink.primary { background: var(--red); border-color: var(--red); color: #fff; }
.wlink.primary small { color: #ffffffcc; }
.wlink.primary.live { background: var(--live); border-color: var(--live); }
.chans { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.chan { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.chan span { display: flex; flex-direction: column; min-width: 0; }
.chan small { color: var(--muted); font-size: 12.5px; }
.chan em { font-style: normal; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chan.main { border-color: var(--red); }
.chan.main em { background: var(--green-soft); color: var(--green); }
.wlink:focus-visible, .chan:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.tabs button { font-size: 10.5px; }
