:root {
  --bg: #070b14;
  --panel: #0d1424;
  --panel-2: #121b30;
  --line: #1c2740;
  --text: #e8eefc;
  --muted: #7d8bab;
  --accent: #e10600;
  --green: #22d36b;
  --purple: #b25cff;
  --yellow: #ffd23f;
  --orange: #ff8a1f;
  --red: #ff3b3b;
  --blue: #3b8bff;
  --bright: 1;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Barlow Semi Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(10px, env(safe-area-inset-left));
  filter: brightness(var(--bright));
}

/* ---------- en-tête ---------- */
#top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 6px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  flex: 0 0 auto;
  font-weight: 800;
  font-style: italic;
  font-size: 20px;
  letter-spacing: .02em;
  padding: 2px 10px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
}
.logo.s-motogp { background: #111; border: 1px solid #c00; }
.titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.event { font-weight: 700; font-size: 16px; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.chip {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .04em;
  padding: 3px 9px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip.live { background: var(--green); color: #04220f; }
.chip.yellow { background: var(--yellow); color: #2a2000; }
.chip.sc { background: var(--orange); color: #2a1200; }
.chip.red, .chip.bad { background: var(--red); color: #fff; }
.chip.other { background: var(--panel-2); color: var(--text); }
.laps { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#clock { font-weight: 600; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
#menuBtn, #calBtn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .06em;
}

/* ---------- tableau ---------- */
#board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 14px;
  padding: 6px 0;
}
#board.empty { align-items: center; justify-content: center; }
#board.embed iframe { flex: 1 1 auto; width: 100%; height: 100%; border: 0; border-radius: 6px; background: #fff; }
.tile.link { margin-top: 8px; text-decoration: none; }
.logo.s-wec { background: #0a2a6b; }
.empty-msg { text-align: center; max-width: 520px; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.empty-msg b { font-size: 22px; }
.empty-msg span { color: var(--muted); font-size: 15px; line-height: 1.4; }

.half {
  flex: 1 1 0;
  min-width: 0;
  container-type: size;
  display: grid;
  grid-auto-rows: minmax(0, 1fr);
}
.hdr, .row {
  --fs: min(calc(100cqh / (var(--rows) + 1) * .56), calc(100cqw / 33));
  font-size: var(--fs);
  display: grid;
  grid-template-columns: 1.7em minmax(4.4em, 7em) 4.3em 4.8em 5.1em 5.1em 2.6em;
  justify-content: space-between;
  align-items: center;
  column-gap: .35em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-height: 0;
}
#board.tyres .hdr, #board.tyres .row {
  grid-template-columns: 1.7em minmax(4.4em, 7em) 4.3em 4.8em 5.1em 5.1em 3.1em 2.6em;
}
.hdr { color: var(--muted); font-size: calc(var(--fs) * .62); font-weight: 700; letter-spacing: .05em; align-self: end; padding-bottom: .2em; }
.hdr .int, .hdr .gap, .hdr .last, .hdr .best { text-align: right; }
.row { border-bottom: 1px solid rgba(255,255,255,.04); font-weight: 600; }
.row:nth-child(even) { background: rgba(255,255,255,.018); }
.row .pos { text-align: right; font-weight: 800; }
.row .name {
  position: relative;
  padding-left: .45em;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .name::before {
  content: "";
  position: absolute;
  left: 0; top: 12%; bottom: 12%;
  width: .16em;
  border-radius: 2px;
  background: var(--team, var(--muted));
}
.row .name em { font-style: normal; font-weight: 600; color: var(--muted); font-size: .72em; margin-right: .3em; }
.row .name i { font-style: normal; font-weight: 500; color: var(--muted); font-size: .7em; margin-left: .35em; }
.row .int { text-align: right; color: var(--green); }
.row .gap, .row .last, .row .best { text-align: right; }
.row .best { color: var(--muted); }
.row .last.pb { color: var(--green); }
.row .last.sb { color: var(--purple); }
.tyre { display: flex; align-items: center; gap: .2em; font-size: .85em; color: var(--muted); }
.tyre b {
  display: inline-grid;
  place-items: center;
  width: 1.25em; height: 1.25em;
  border-radius: 50%;
  border: .13em solid currentColor;
  font-size: .78em;
  font-weight: 800;
}
.tyre b.tS { color: #ff3333; }
.tyre b.tM { color: #ffd400; }
.tyre b.tH { color: #f2f2f2; }
.tyre b.tI { color: #39d353; }
.tyre b.tW { color: #2f8cff; }
.tyre b.used { opacity: .75; }
.st { font-size: .62em; font-weight: 800; color: var(--orange); text-align: left; }
.row.pit .st { color: var(--blue); }
.row.out { opacity: .45; }
.row.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: rgba(59,139,255,.28); } to { background: transparent; } }

/* ---------- pied ---------- */
#foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 2px 7px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.ok { background: var(--green); }
.dot.stale { background: var(--yellow); }
.dot.bad { background: var(--red); }
#msg { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
#msg.warn { color: var(--yellow); }
#wx, #ver { flex: 0 0 auto; white-space: nowrap; }
#next {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text);
}
#next b { color: #9cc8ff; font-weight: 700; }
#next .nlab { font-weight: 800; letter-spacing: .06em; color: var(--accent); margin-right: 2px; }
#next .nlive { color: var(--green); }

/* ---------- prochaines courses ---------- */
.sheet.wide { width: min(980px, 100%); }
.calf { margin: 8px 0 12px; }
.calf .tile { padding: 8px; }
.ev { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); padding: 10px 12px; margin-bottom: 10px; }
.ev-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ev-head .logo { font-size: 13px; padding: 1px 8px; }
.ev-name { font-weight: 800; font-size: 17px; text-transform: uppercase; }
.ev-circ { color: var(--muted); font-size: 14px; }
.ev-days { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 600; }
.ev-sess { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin-top: 8px; }
.ss { display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ss b { color: var(--text); font-size: 14px; }
.ss i { font-style: normal; font-weight: 700; font-size: 12px; color: #9cc8ff; }
.ss.race b { color: #fff; }
.ss.race { border-color: #3a4a6e; }
.ss.done { opacity: .4; }
.ss.nx { border-color: #3b8bff; box-shadow: inset 0 0 0 1px #3b8bff; }
.ss.live { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.ss.live i { color: var(--green); }
.ev-note { margin-top: 6px; font-size: 11px; color: var(--muted); }
#calSrc { font-size: 12px; color: var(--muted); }
#board.empty.with-cal { flex-direction: column; justify-content: flex-start; overflow: auto; gap: 4px; }
#board.with-cal .empty-msg { padding: 10px 20px 4px; }
.cal-inline { width: min(980px, 100%); align-self: center; }
.next-big { font-style: normal; margin-top: 6px; color: var(--text); font-size: 16px; line-height: 1.4; }
.next-big b { color: #9cc8ff; }

/* ---------- menu ---------- */
#menu, #cal {
  position: fixed;
  inset: 0;
  background: rgba(2,5,12,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
  filter: brightness(var(--bright));
}
#menu[hidden], #cal[hidden] { display: none; }
.sheet {
  width: min(760px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
}
.sheet h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: .05em; color: #6fb3ff; }
.sheet h3 { margin: 14px 0 6px; font-size: 12px; letter-spacing: .1em; color: var(--muted); }
.opt { font-weight: 400; letter-spacing: 0; }
.tiles { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tiles.four { grid-template-columns: repeat(4, 1fr); }
.tile {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 9px;
  padding: 12px 8px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .04em;
  color: #9cc8ff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}
.tile small { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: 0; min-height: 1em; }
.tile.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: #fff; }
.tile.sel small { color: #ff8f8a; }
.tile.off { opacity: .4; cursor: default; }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.relay { display: flex; gap: 8px; }
.relay input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  user-select: text;
}
.relay .tile { flex: 0 0 auto; padding: 10px 18px; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
#menuVer { font-size: 12px; color: var(--muted); }
.tile.close { padding: 10px 26px; }

/* ---------- portrait / petits écrans ---------- */
@media (max-aspect-ratio: 1/1) {
  .hdr, .row { --fs: min(calc(100cqh / (var(--rows) + 1) * .56), calc(100cqw / 27)); }
  /* portrait : une seule colonne de temps — meilleur tour en essais/qualifs, dernier tour en course */
  .hdr .best, .row .best { display: none; }
  .hdr, .row { grid-template-columns: 1.7em minmax(4.4em, 7em) 4.3em 4.8em 5.1em 2.6em; }
  #board.tyres .hdr, #board.tyres .row { grid-template-columns: 1.7em minmax(4.4em, 7em) 4.3em 4.8em 5.1em 3.1em 2.6em; }
}
@media (max-width: 640px) {
  .session, #wx, #clock { display: none; }
  #calBtn, #menuBtn { padding: 6px 8px; font-size: 12px; }
  #ver { display: none; }
  .tiles.four { grid-template-columns: repeat(2, 1fr); }
  .tiles.three { grid-template-columns: repeat(3, 1fr); }
}
@media (max-height: 420px) {
  #top { padding: 4px 2px; }
  #foot { padding: 3px 2px 4px; }
}

/* ---------- vue carte ---------- */
#viewBtn {
  border: 1px solid var(--accent);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .06em;
  color: #fff;
}
#viewBtn[hidden] { display: none; }
#board.maplayout { display: flex; gap: 12px; }
#mini {
  flex: 0 0 30%;
  min-width: 0;
  display: grid;
  grid-template-rows: repeat(var(--n, 22), minmax(0, 1fr));
  container-type: size;
}
.mr {
  --fs: min(calc(100cqh / var(--n, 22) * .58), 20px);
  font-size: var(--fs);
  display: grid;
  grid-template-columns: 1.7em minmax(2.6em, 1fr) 4.6em 1.6em;
  align-items: center;
  column-gap: .35em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid rgba(255,255,255,.04);
  white-space: nowrap;
  min-height: 0;
}
.mr .p { text-align: right; }
.mr .n { position: relative; padding-left: .45em; font-weight: 800; overflow: hidden; }
.mr .n::before { content: ""; position: absolute; left: 0; top: 15%; bottom: 15%; width: .16em; border-radius: 2px; background: var(--team); }
.mr .g { text-align: right; }
.mr .t { font-size: .7em; color: var(--blue); font-weight: 800; text-align: center; }
.mr .t b { display: inline-grid; place-items: center; width: 1.35em; height: 1.35em; border-radius: 50%; border: .14em solid currentColor; font-size: .95em; }
.mr .t b.tS { color: #ff3333; } .mr .t b.tM { color: #ffd400; } .mr .t b.tH { color: #f2f2f2; } .mr .t b.tI { color: #39d353; } .mr .t b.tW { color: #2f8cff; }
.mr.out { opacity: .4; }
#mapbox {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: radial-gradient(ellipse at center, #0e1730 0%, #070b14 75%);
  overflow: hidden;
}
#mapbox svg { position: absolute; inset: 0; width: 100%; height: 100%; }
#mapbox .corner { fill: #4a5778; font-weight: 700; font-family: inherit; }
#mapbox .lbl { fill: #fff; font-weight: 800; font-family: inherit; paint-order: stroke; stroke: #070b14; stroke-width: .28em; dominant-baseline: middle; }
#mapbox .trk { transition: stroke .4s; }
#mapmsg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); font-size: 15px; }
#mapmsg[hidden] { display: none; }
#pitbox { position: absolute; left: 10px; right: 10px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; font-size: 12px; font-weight: 800; }
#pitbox .plab { color: var(--blue); letter-spacing: .08em; margin-right: 2px; }
#pitbox .pc { border: 2px solid var(--team); border-radius: 5px; padding: 1px 6px; background: #070b14; }
.maptag { position: absolute; right: 10px; top: 8px; font-size: 11px; color: var(--muted); letter-spacing: .04em; }
@media (max-aspect-ratio: 1/1) {
  #board.maplayout { flex-direction: column; }
  #mapbox { flex: 0 0 52%; order: -1; }
  #mini { flex: 1 1 auto; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(11, minmax(0, 1fr)); grid-auto-flow: column; column-gap: 12px; }
  .mr { --fs: min(calc(100cqh / 11 * .58), 15px); }
}
@media (max-width: 640px) {
  #viewBtn { padding: 6px 8px; font-size: 12px; }
  /* en-tête sur deux lignes sur téléphone : titre en haut, boutons en dessous */
  #top { flex-wrap: wrap; row-gap: 6px; }
  .brand { flex: 1 1 100%; }
  .right { flex: 1 1 100%; justify-content: flex-end; gap: 6px; }
  .right .chip { margin-right: auto; }
  .mr { grid-template-columns: 1.5em minmax(2.9em, 1fr) 4.3em 1.4em; column-gap: .25em; }
  #mini { column-gap: 8px; }
  #calBtn, #menuBtn, #viewBtn { white-space: nowrap; }
}

/* ---------- compte à rebours ---------- */
.cd { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.empty-msg .cd-lab { font-size: 13px; font-weight: 800; letter-spacing: .12em; color: var(--accent); }
.empty-msg .cd-what { font-size: clamp(26px, 4.4vw, 46px); font-weight: 800; text-transform: uppercase; line-height: 1.05; color: #fff; }
.empty-msg .cd-ev { color: var(--muted); font-size: 15px; }
.empty-msg .cd-num { font-size: clamp(44px, 9vw, 110px); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; color: #9cc8ff; line-height: 1.05; margin-top: 6px; }
.empty-msg .cd-when { color: var(--text); font-size: 16px; }
.empty-msg .cd.live .cd-what { color: var(--green); }
.laps.cdh { font-size: 14px; color: #9cc8ff; }
.laps.cdh span { font-variant-numeric: tabular-nums; color: #fff; }

/* qualifs / essais : le premier affiche son meilleur temps dans la colonne ÉCART */
.row .gap.lead { color: var(--purple); font-weight: 800; }
.mr .g.lead { color: var(--purple); }

/* ---------- v2.1 : vue large (équipe + mini-secteurs) ---------- */
.row .name i { text-transform: uppercase; }
#board.wide .hdr, #board.wide .row {
  --fs: min(calc(100cqh / (var(--rows) + 1) * .56), calc(100cqw / 52));
  grid-template-columns: 1.7em minmax(4.4em, 6em) 6.2em 4.3em 4.8em 5.1em 5.1em 9.5em 2.6em;
}
#board.wide.tyres .hdr, #board.wide.tyres .row {
  grid-template-columns: 1.7em minmax(4.4em, 6em) 6.2em 4.3em 4.8em 5.1em 5.1em 9.5em 3.1em 2.6em;
}
.row .team, .hdr .team { display: flex; align-items: center; gap: .4em; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: .74em; font-weight: 600; color: var(--muted); }
.row .team u { flex: 0 0 auto; width: .8em; height: .8em; border-radius: 50%; background: var(--team, var(--muted)); }
.mini { display: flex; gap: 2px; height: .85em; align-items: stretch; min-width: 0; }
.hdr .mini { height: auto; }
.mini b { flex: 1 1 0; min-width: 2px; border-radius: 1px; background: #2a3550; }
.mini b.o { background: #f2a31b; }
.mini b.g { background: #22d36b; }
.mini b.p { background: #b25cff; }
.mini b.b { background: #3b8bff; }
.mini b.x { background: #6b7690; }

/* ---------- v2.2 : séries GT ---------- */
.logo.s-gte { background: #8a1c1c; }
.logo.s-gts { background: #1c5a8a; }
