:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1c2330; --muted: #6b7486; --line: #e1e4ea;
  --accent: #d62828; --accent-ink: #fff; --ok: #1f8a4c; --warn: #b7791f; --info: #2b6cb0;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171d; --card: #1d222b; --ink: #e8ebf0; --muted: #98a1b2; --line: #2d3440; --accent: #ef4444; --ok: #4ade80; --warn: #fbbf24; --info: #63b3ed; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
header { display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
header h1 b, .login-card h1 b { color: #E4125A; }
header .sp { flex: 1; }
nav { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); }
nav button { border: 0; background: none; padding: 10px 14px; font: inherit; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
nav button.on { color: var(--ink); border-color: var(--accent); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h2 { font-size: 18px; margin: 20px 0 8px; }
h3 { font-size: 15px; margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); font-size: 13px; }
button, select, input, textarea { font: inherit; color: inherit; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 12px; cursor: pointer; min-height: 36px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--accent); }
.btn.sm { padding: 3px 9px; min-height: 28px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: default; }
input[type=text], input[type=date], input[type=number], select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: var(--card); min-height: 36px; }
textarea { width: 100%; min-height: 120px; font-family: ui-monospace, monospace; font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: var(--ok); } .badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.info { color: var(--info); border-color: var(--info); } .badge.bad { color: var(--accent); border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 4px 10px; cursor: pointer; border-right: 1px solid var(--line); min-height: 30px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--bg); }
.seg button.on.present { background: var(--ok); color: #fff; } .seg button.on.absent { background: var(--muted); color: #fff; } .seg button.on.injured { background: var(--accent); color: #fff; }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-start; justify-content: center; padding: 20px 10px; overflow: auto; z-index: 10; }
#modal[hidden] { display: none; }
.dialog { background: var(--card); border-radius: 12px; width: min(720px, 100%); padding: 16px; border: 1px solid var(--line); }
.msg { padding: 8px 12px; border-radius: 8px; margin: 8px 0; border: 1px solid var(--line); }
.msg.warn { border-color: var(--warn); color: var(--warn); } .msg.err { border-color: var(--accent); color: var(--accent); } .msg.ok { border-color: var(--ok); color: var(--ok); }
.gates { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.gates button { width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-weight: 700; font-size: 17px; cursor: pointer; }
.gates button.free:hover { background: var(--accent); color: #fff; }
.gates button[disabled] { opacity: .3; }
.tag { font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--ink); color: var(--bg); }
@media (max-width: 640px) { th.hide-sm, td.hide-sm { display: none; } main { padding: 10px; } }
a.btn { color: inherit; text-decoration: none; display: inline-flex; align-items: center; }

/* Tablette de piste et affichage live */
body.tablet main { max-width: 1200px; }
.btn.big { min-height: 56px; padding: 10px 22px; font-size: 18px; }
.badge.big { font-size: 16px; padding: 8px 16px; }
.seg.big button { min-height: 56px; padding: 8px 20px; font-size: 17px; }
.heatbar { display: flex; align-items: center; gap: 10px; }
.rider { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.rider.out { opacity: .5; }
.gate { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; border-radius: 8px; background: var(--ink); color: var(--bg); font-weight: 800; font-size: 20px; }
.gate.none { background: var(--line); color: var(--muted); }
.pickbox { border-color: var(--accent); border-width: 2px; }
.gates.big button { width: 72px; height: 72px; font-size: 30px; }
body.live main { max-width: 1400px; }
body.live h2 { margin-top: 12px; }
.livecols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.livecols.three { grid-template-columns: repeat(3, 1fr); }
.card.now { border: 2px solid var(--accent); }
.card.now .lrow { font-size: 22px; }
.lrow { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.lname { font-weight: 600; flex: 1; }
.lgrid.compact .lrow { font-size: 14px; padding: 2px 0; } .lgrid.compact .gate { min-width: 28px; height: 28px; font-size: 14px; }
@media (max-width: 820px) { .livecols, .livecols.three { grid-template-columns: 1fr; } }
@media (min-width: 1500px) { body.live { font-size: 19px; } }

/* Numéro de plaque : l'élément d'identification principal des pilotes */
.plate { display: inline-flex; align-items: center; justify-content: center; min-width: 56px; padding: 2px 10px; border-radius: 8px; border: 3px solid var(--ink); background: var(--card);
  font-weight: 800; font-size: 28px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.plate.xl { font-size: calc(var(--pf, clamp(30px, 5.2vw, 64px)) * var(--k, 1)); border-width: 4px; padding: 2px 8px; }
.lrow .plate { font-size: 26px; min-width: 52px; }
.lgrid.compact .plate { font-size: 17px; min-width: 38px; border-width: 2px; padding: 0 6px; }
.now .lrow .plate { font-size: 34px; min-width: 70px; }

/* Grille de départ horizontale (vue du starter) */
.gaterow { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
.slot { border: 2px solid var(--line); border-radius: 12px; background: var(--card); padding: 8px 4px 10px; text-align: center; min-height: 190px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.slot .gnum { width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: var(--bg); font-weight: 800; font-size: 19px; display: flex; align-items: center; justify-content: center; }
.slot.empty { opacity: .35; border-style: dashed; }
.slot.out { opacity: .45; }
.slot .sname { font-weight: 600; font-size: 14px; line-height: 1.2; word-break: break-word; }
.slot .sclub { font-size: 12px; }
@media (max-width: 760px) { .gaterow { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.rider .plate { min-width: 84px; font-size: 32px; }

/* Tablette paysage : navigation à gauche, 8 pilotes visibles sans défilement */
body.tablet header { padding: 6px 12px; gap: 8px; }
body.tablet main { max-width: none; padding: 8px 10px; }
.ttabs { display: flex; gap: 2px; }
.ttabs button { border: 0; background: none; padding: 10px 14px; font: inherit; font-size: 16px; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.ttabs button.on { color: var(--ink); border-color: var(--accent); font-weight: 700; }
.ttabs button[disabled] { opacity: .3; cursor: default; }
.tlayout { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 10px; align-items: start; }
.tside { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 8px; }
.tside .card { margin: 0; padding: 10px; }
.tgroup { font-weight: 700; font-size: 17px; line-height: 1.2; } .tstage { font-size: 15px; margin: 2px 0 4px; }
.navbtn { flex: 1; min-height: 64px; font-size: 32px; padding: 0; }
.sidebox { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.tmain .card { margin-bottom: 6px; }
.rider.compact { padding: 3px 10px; gap: 10px; min-height: 50px; margin-bottom: 4px; }
.rider.compact .plate { font-size: 28px; min-width: 76px; padding: 0 8px; border-width: 3px; }
.rider.compact .gate { min-width: 34px; height: 34px; font-size: 17px; }
.rider.compact .rname { flex: 1; font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rider.compact .seg.big button { min-height: 42px; padding: 4px 16px; font-size: 16px; }
.msg.big { font-size: 20px; text-align: center; font-weight: 700; }
.slot.tap { cursor: pointer; } .slot.ok { background: #1f8a4c; border-color: #1f8a4c; color: #fff; }
.slot.ok .gnum { background: #fff; color: #1f8a4c; } .slot.ok .plate { background: #fff; color: #111; border-color: #fff; } .slot.ok .muted { color: #e8f6ee; }
.sprow { display: flex; align-items: center; gap: 14px; padding: 2px 12px; min-height: 52px; margin-bottom: 4px; }
.sprow.out { opacity: .4; }
.sprank { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 44px; border-radius: 50%; background: #E4125A; color: #fff; font-weight: 800; font-size: 24px; }
.spname { flex: 1; font-size: 28px; line-height: 1.1; min-width: 0; } .spfirst { font-weight: 500; } .splast { font-weight: 800; text-transform: uppercase; }
.spclub { font-size: 18px; text-align: right; min-width: 200px; }
.sprow .plate.xl { font-size: 30px; min-width: 90px; border-width: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); border-radius: 10px; background: var(--card); padding: 4px 8px; cursor: pointer; font: inherit; }
.chip.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.chip .plate { font-size: 22px; min-width: 44px; border-width: 2px; }
.note { padding: 8px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 700px) { .tlayout { grid-template-columns: 1fr; } .tside { position: static; } .ttabs button { padding: 8px 8px; font-size: 14px; } }
@media (max-height: 700px) and (orientation: landscape) { .slot { min-height: 160px; } .tmain .plate.xl { font-size: 40px; } }

/* Tablette en portrait : la navigation passe en barre au-dessus, la grille garde 8 colonnes */
@media (orientation: portrait) {
  .tlayout { grid-template-columns: 1fr; }
  .tside { position: static; flex-direction: row; flex-wrap: wrap; align-items: stretch; }
  .tside > .card { flex: 1 1 180px; } .tside > .row { flex: 1 1 160px; } .tside .navbtn { min-height: 52px; }
  .tside > .btn, .tside > .sidebox { flex: 0 1 auto; }
  .spname { font-size: 24px; } .spclub { min-width: 130px; font-size: 15px; }
}
.slot.ok .btn { color: #111; }
.sprow { min-height: 46px; margin-bottom: 3px; padding: 1px 12px; } .sprow .plate.xl { font-size: 27px; min-width: 84px; } .spname { font-size: 26px; }

/* Plaques longues : police réduite selon le nombre de caractères, jamais de débordement de la case */
.plate { max-width: 100%; box-sizing: border-box; white-space: nowrap; }
.plate[data-len="3"] { --k: .82; } .plate[data-len="4"] { --k: .64; } .plate[data-len="5"] { --k: .52; } .plate[data-len="6"] { --k: .44; }
.slot { min-width: 0; }
.slot .plate.xl { padding: 2px 6px; }
@media (max-height: 700px) and (orientation: landscape) { .tmain .plate.xl { --pf: 40px; font-size: calc(var(--pf) * var(--k, 1)); } }
.rider.compact .plate, .sprow .plate.xl { font-size: calc(28px * var(--k, 1)); }
.sprow .plate.xl { font-size: calc(27px * var(--k, 1)); }
.rider.compact .plate[data-len="4"], .rider.compact .plate[data-len="5"], .rider.compact .plate[data-len="6"] { --k: .8; }

/* Navigation en haut (retour à la barre horizontale) */
.tcol { display: block; }
.heatbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 10px; }
.heatbar .hinfo { flex: 1; text-align: center; min-width: 180px; }
.heatbar .tgroup { font-size: 18px; } .heatbar .tstage { font-size: 15px; }
.heatbar .navbtn { flex: 0 0 64px; min-height: 52px; }
.hextra { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; flex: 0 1 auto; }
.sidebox { flex-direction: row; align-items: center; gap: 8px; }
.note.sel { background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.ntext { white-space: pre-wrap; padding: 2px 0 0; }

/* Programme : course en piste toujours visible, photofinish */
tr.running td { background: color-mix(in srgb, #e8a400 14%, transparent); }
.badge.run { background: #e8a400; color: #111; }
.photo { color: #d11a1a; display: inline-flex; vertical-align: middle; margin-left: 6px; }
.photo-box { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.modal .plate.xl, #modal .plate.xl { font-size: 30px; min-width: 76px; }
#modal select option:disabled { color: #aaa; background: #eee; }
#rankTable.click-rank tbody tr { cursor: pointer; user-select: none; }
#rankTable.click-rank tbody tr:hover td { background: color-mix(in srgb, #1f6feb 10%, transparent); }
.res { font-weight: 800; font-size: 1.15em; }
.chip { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e8eef7; color: #24406b; }
.chip.ready { background: #1f8a4c; color: #fff; }
.timing-box { margin-top: 10px; }
.photo.ok { color: #1f8a4c; }

/* Live : cartes cliquables, statut du pilote */
.card.clickable { cursor: pointer; } .card.clickable:hover, .card.clickable:focus-visible { border-color: var(--ink); outline: none; }
tr.clickable-row { cursor: pointer; } tr.clickable-row:hover td { background: color-mix(in srgb, var(--info) 10%, transparent); }
.ico { vertical-align: -3px; flex: none; }
.chip-st { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 7px; border-radius: 99px; font-size: 13px; font-weight: 700; }
.st-registered { background: #e8eef7; color: #24406b; }
.st-confirmed { background: #e3f4ea; color: #14532d; } .st-confirmed .ico { color: var(--ok); }
.st-absent { background: var(--line); color: var(--muted); padding-left: 10px; }
@media (prefers-color-scheme: dark) { .st-registered { background: #26344d; color: #b9d0f5; } .st-confirmed { background: #173a28; color: #bbf7d0; } }
.lrow .res { margin-left: auto; }

/* Check-in : écran plein, vert (confirmé) ou rouge (voir le bureau) */
body.checkin main { max-width: none; padding: 0; }
.ck { min-height: calc(100vh - 58px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; padding: 24px; color: #fff; }
.ck.wait { background: var(--bg); color: var(--muted); }
.ck.ok { background: #15803d; --ico-mark: #15803d; }
.ck.denied { background: #b91c1c; --ico-mark: #b91c1c; }
.ck > .ico { color: #fff; width: clamp(110px, 22vmin, 220px); height: auto; }
.ck.wait > .ico { color: var(--muted); width: clamp(90px, 16vmin, 160px); }
.ck-title { font-size: clamp(30px, 6vw, 64px); font-weight: 800; line-height: 1.1; }
.ck-name { font-size: clamp(34px, 7vw, 76px); font-weight: 800; line-height: 1.1; }
.ck-sub { font-size: clamp(18px, 3vw, 32px); opacity: .95; }
.ck-serial { font-family: ui-monospace, monospace; margin-top: 6px; }
.ck .plate.xl { --pf: clamp(56px, 11vw, 120px); color: #111; background: #fff; border-color: #fff; }
.ck .chip-st { font-size: clamp(15px, 2.4vw, 24px); padding: 4px 16px 4px 12px; }
.ck .chip-st .ico { width: 1.3em; height: 1.3em; }
.ck-info { font-size: clamp(26px, 5vw, 52px); font-weight: 800; line-height: 1.15; }
.ck-title.de { margin-top: -6px; opacity: .92; }

/* Connexion */
body.login main { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { display: grid; gap: 14px; width: min(360px, 100%); padding: 24px; }
.login-card h1, .login-card h2 { margin: 0; }
.login-card input { font-size: 18px; padding: 10px 12px; }
.login-msg { color: var(--bad, #c0392b); min-height: 1.2em; margin: 0; }
.login-lang { justify-self: end; }

/* Live : accueil par organisation */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }
.chip { padding: 10px 16px; min-height: 44px; display: inline-flex; align-items: center; border-radius: 999px; border: 1px solid var(--line, #cbd5e1); text-decoration: none; color: inherit; font-weight: 600; }
.chip.on { background: var(--accent, #1d4ed8); border-color: var(--accent, #1d4ed8); color: #fff; }
a.evcard { display: block; text-decoration: none; color: inherit; }
.evgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.evgrid .card { margin: 0; }
.card.big { padding: 20px; margin-bottom: 10px; }
.card.big h3 { font-size: 1.4em; }

/* Logo BMX Racing Féroce */
.brand-rf { height: 34px; width: 34px; border-radius: 8px; display: block; }
.brand-full { width: 100%; max-width: 280px; height: auto; display: block; margin: 0 auto; }
.brand-hero { display: grid; place-items: center; }
body.login .login-card h1 { text-align: center; font-size: 18px; }
header .brand-full { height: 38px; width: auto; max-width: none; margin: 0; border-radius: 6px; }
.brand-hero .brand-full { border-radius: 10px; }

/* Page des classements */
.rk-wrap { overflow-x: auto; }
.rk-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rk-table th, .rk-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.rk-table .num { text-align: right; }
.rk-table .rk-rank { font-weight: 800; width: 2.2em; }
.rk-table .rk-name { font-weight: 600; }
.rk-table .tot { font-weight: 800; color: #E4125A; }
.rk-table .pts.none { color: var(--muted); }
.rk-table .pts.drop { text-decoration: line-through; opacity: .5; }
.show-sm { display: none; font-weight: 400; font-size: 13px; }
@media (max-width: 640px) { .show-sm { display: block; } .rk-table th, .rk-table td { padding: 6px 5px; } }
.rk-table th.ev { white-space: normal; min-width: 76px; max-width: 110px; font-size: 12px; line-height: 1.15; vertical-align: bottom; }
.rk-table th.ev small { display: block; font-weight: 400; }
.rk-table tfoot th { border-top: 2px solid var(--line); text-align: left; }
.rk-table tfoot th.num { text-align: right; }
.rk-table .pts.kept { font-weight: 800; }
.rk-detail > td { background: color-mix(in srgb, var(--line) 25%, var(--card)); padding: 8px 10px; white-space: normal; }
.rk-sub { display: grid; gap: 6px; }
.rk-sub .rk-table { background: transparent; }
button.linkish { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--ink); text-align: left; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
button.linkish:hover, button.linkish:focus-visible { color: #E4125A; }
