/* Grand Prix des livrets, the chrono: the booklet's felt-tip notebook on a phone.
   Squared paper, marker titles, Lexend for reading; a world's colour tints its circuit. */
:root {
  --papier: #ffffff;
  --quadrillage: #dbe6f4;
  --carte: #ffffff;
  --encre: #1b1b1b;
  --gris: #555c64;
  --bord: #1b1b1b;
  --doux: #f1f4f8;
  --juste: #1a7a3e;
  --faux: #b3261e;
  --monde: #f2c419;
  --encre-monde: #1b1b1b;
  --titre: "Permanent Marker", "Comic Sans MS", cursive;
  --texte: "Lexend", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --papier: #14171c;
    --quadrillage: #222a35;
    --carte: #1c2129;
    --encre: #eef0f2;
    --gris: #a9b0b8;
    --bord: #6b7480;
    --doux: #262c36;
    --juste: #5fd38c;
    --faux: #ff8a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --papier: #14171c;
  --quadrillage: #222a35;
  --carte: #1c2129;
  --encre: #eef0f2;
  --gris: #a9b0b8;
  --bord: #6b7480;
  --doux: #262c36;
  --juste: #5fd38c;
  --faux: #ff8a80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--texte); font-size: 17px; line-height: 1.4; color: var(--encre);
  background-color: var(--papier);
  background-image: linear-gradient(var(--quadrillage) 1px, transparent 1px), linear-gradient(90deg, var(--quadrillage) 1px, transparent 1px);
  background-size: 22px 22px;
  min-height: 100vh;
}
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid #1c5fc0; outline-offset: 2px; border-radius: 8px; }
[tabindex="-1"]:focus { outline: none; }

/* Header bar: the course's name, and the theme menu kept small */
.barre {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 760px; margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px));
}
.marque { font-family: var(--titre); font-size: 20px; text-decoration: none; color: #c8323b; line-height: 1.2; }
.marque span { color: var(--encre); }
.theme { position: relative; flex: none; }
.theme-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--bord); background: var(--carte); display: grid; place-items: center; }
.theme-btn svg, .theme-menu svg { width: 20px; height: 20px; }
.theme-menu { position: absolute; right: 0; top: 46px; z-index: 20; background: var(--carte); border: 1px solid var(--bord); border-radius: 12px; padding: 6px; min-width: 160px; display: grid; gap: 2px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.theme-menu button { display: flex; align-items: center; gap: 10px; background: none; border: 0; border-radius: 8px; padding: 8px 10px; text-align: left; }
.theme-menu button[aria-checked="true"] { background: var(--encre); color: var(--papier); font-weight: 600; }

main {
  max-width: 760px; margin: 0 auto; display: grid; gap: 14px;
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) max(28px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.carte { background: var(--carte); border: 2px solid var(--bord); border-radius: 14px; padding: 16px; display: grid; gap: 12px; }
.titre { font-family: var(--titre); font-weight: 400; font-size: 30px; line-height: 1.2; }
.note, .retour { font-size: 15px; color: var(--gris); }
.retour { text-align: center; }
.lien { justify-self: start; background: none; border: 0; padding: 4px 0; text-decoration: underline; color: var(--gris); }
.grand { justify-self: stretch; background: var(--encre); color: var(--papier); border: 0; border-radius: 12px; padding: 16px; font-weight: 700; font-size: 20px; }

/* Home: the circuits */
.circuits { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.circuit { display: grid; text-decoration: none; background: var(--carte); border: 2px solid var(--bord); border-radius: 14px; overflow: hidden; }
.circuit img { aspect-ratio: 3 / 1; width: 100%; object-fit: cover; object-position: 30% 50%; border-bottom: 2px solid var(--bord); }
.circuit .nom { padding: 8px 12px 0; font-family: var(--titre); font-size: 22px; line-height: 1.25; display: grid; }
.circuit .nom small { font-family: var(--texte); font-size: 13px; color: var(--gris); }
.circuit .table { margin: 6px 12px 12px; justify-self: start; background: var(--monde); color: var(--encre-monde); border-radius: 8px; padding: 2px 10px; font-weight: 700; }

/* Circuit: banner, start, engine classes, bonus */
.bandeau { position: relative; border: 2px solid var(--bord); border-radius: 14px; overflow: hidden; background: #fff; }
.bandeau img { width: 100%; aspect-ratio: 3 / 1; object-fit: cover; object-position: 30% 50%; }
.etiquette { position: absolute; right: 10px; top: 10px; background: #fff; color: #1b1b1b; border: 2px solid #1b1b1b; border-radius: 10px; padding: 6px 12px; display: grid; gap: 4px; max-width: 60%; }
.etiquette small { font-size: 12px; font-weight: 600; }
.etiquette h1 { font-family: var(--titre); font-weight: 400; font-size: 26px; line-height: 1.15; }
.etiquette .table { justify-self: start; background: var(--monde); color: var(--encre-monde); font-family: var(--titre); font-size: 18px; border-radius: 6px; padding: 0 8px; }
.pret { display: flex; align-items: center; gap: 12px; font-family: var(--titre); font-size: 24px; line-height: 1.2; }
.avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; object-position: center top; border: 2px solid var(--bord); background: #fff; flex: none; }
.cylindrees { display: grid; gap: 10px; }
.cylindree { display: grid; grid-template-columns: 56px 1fr; gap: 14px; align-items: center; text-align: left; background: var(--doux); border: 2px solid var(--bord); border-radius: 14px; padding: 12px 14px; }
.cylindree:hover { background: var(--carte); }
.cylindree .texte { display: grid; gap: 2px; }
.cylindree b { font-family: var(--titre); font-weight: 400; font-size: 26px; line-height: 1.1; }
.cylindree small { color: var(--gris); font-size: 14px; }
.medaille { width: 56px; height: auto; color: #1b1b1b; }
.medaille.grande { width: 110px; justify-self: center; }
.drapeau { width: 56px; height: 56px; border-radius: 8px; border: 2px solid #1b1b1b; background: conic-gradient(#1b1b1b 25%, #fff 0 50%, #1b1b1b 0 75%, #fff 0) 0 0 / 14px 14px; }
.bonus-liste { display: grid; gap: 10px; }
.bonus { display: grid; grid-template-columns: 70px 1fr; gap: 12px; align-items: center; background: var(--carte); border: 2px solid var(--bord); border-left: 10px solid var(--monde); border-radius: 12px; padding: 10px 12px; }
.bonus img { width: 70px; height: 70px; object-fit: contain; background: #fff; border-radius: 8px; }
.bonus small { font-weight: 700; text-transform: uppercase; letter-spacing: .05em; font-size: 12px; color: var(--gris); }
.bonus p { font-weight: 600; }
.bonus .exemple { font-weight: 400; font-size: 15px; }

/* Pilot */
.pilotes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pilote { padding: 0; border: 2px solid var(--bord); border-radius: 12px; overflow: hidden; background: #fff; aspect-ratio: 3 / 4; }
.pilote img { width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.pilote.choisi { outline: 4px solid var(--juste); outline-offset: 1px; }

/* Start lights */
.depart { justify-items: center; text-align: center; padding: 28px 16px; }
.depart h2 { font-family: var(--titre); font-weight: 400; font-size: 54px; line-height: 1; }
.feux { display: flex; gap: 16px; background: #1b1b1b; padding: 14px 18px; border-radius: 16px; }
.feux i { width: 46px; height: 46px; border-radius: 50%; background: #3a3f47; }
.feux i.allume { background: #e5392f; }
.feux.vert i { background: #2fbf5a; }

/* The race */
.course { display: grid; gap: 12px; }
.hud { display: flex; justify-content: space-between; font-family: var(--titre); font-size: 24px; }
.piste { position: relative; height: 64px; border: 2px solid var(--bord); border-radius: 32px; background: repeating-linear-gradient(90deg, var(--doux) 0 26px, var(--carte) 26px 52px); overflow: hidden; }
.piste .arrivee { position: absolute; right: 8px; top: 6px; bottom: 6px; width: 16px; background: conic-gradient(#1b1b1b 25%, #fff 0 50%, #1b1b1b 0 75%, #fff 0) 0 0 / 8px 8px; border-radius: 3px; }
.piste .moi, .piste .fantome { position: absolute; top: 4px; left: calc(4px + var(--avance, 0) * (100% - 84px)); width: 52px; height: 52px; border-radius: 50%; transition: left .3s ease-out; }
.piste .moi .avatar { width: 52px; height: 52px; }
.piste .fantome { border: 3px dashed var(--gris); background: transparent; opacity: .8; }
.question { background: var(--carte); border: 2px solid var(--bord); border-radius: 16px; padding: 14px; display: grid; justify-items: center; gap: 6px; }
.question h2 { font-family: var(--titre); font-weight: 400; font-size: 56px; line-height: 1.1; }
.question output { min-width: 120px; min-height: 56px; text-align: center; font-size: 40px; font-weight: 700; border-bottom: 4px solid var(--encre); font-variant-numeric: tabular-nums; }
.question.juste { animation: juste .35s; }
.question.faux { animation: faux .35s; }
@keyframes juste { 0% { background: var(--juste); } 100% { background: var(--carte); } }
@keyframes faux { 0% { background: var(--faux); } 100% { background: var(--carte); } }
.pave { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.touche { min-height: 64px; border: 2px solid var(--bord); border-radius: 14px; background: var(--carte); font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; touch-action: manipulation; }
.touche:active { background: var(--doux); }
.touche.effacer { font-size: 17px; }
.touche.ok { background: var(--juste); border-color: var(--juste); color: #fff; }

/* Finish and result */
.arrivee-carte, .resultat { text-align: center; justify-items: center; }
.damier { width: 100%; height: 18px; border-radius: 4px; background: conic-gradient(#1b1b1b 25%, #fff 0 50%, #1b1b1b 0 75%, #fff 0) 0 0 / 18px 18px; }
.chiffres { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.chiffres div { background: var(--doux); border-radius: 12px; padding: 10px 6px; display: grid; gap: 2px; }
.chiffres dt { font-size: 14px; color: var(--gris); }
.chiffres dd { margin: 0; font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chiffres .total { background: var(--encre); color: var(--papier); }
.chiffres .total dt { color: var(--papier); opacity: .85; }
.record { font-weight: 700; color: var(--juste); font-size: 19px; }
.consigne { font-size: 18px; }
.bravo { font-family: var(--titre); font-size: 24px; }
.fautes { justify-self: stretch; text-align: left; background: var(--doux); border-radius: 12px; padding: 10px 14px; display: grid; gap: 6px; }
.fautes h2 { font-size: 16px; }
.fautes ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.fautes span { color: var(--gris); }
.actions { display: grid; gap: 8px; justify-self: stretch; }
.actions .lien { justify-self: center; }
.sans-js { max-width: 760px; margin: 16px auto; padding: 0 16px; }

@media (min-width: 640px) {
  .cylindrees { grid-template-columns: 1fr 1fr; }
  .touche { min-height: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  .piste .moi, .piste .fantome { transition: none; }
  .question.juste, .question.faux { animation: none; }
}
