* { box-sizing: border-box; }

:root {
  --bg: #d7b07a;
  --wood: #7c3f19;
  --panel: #efe7c8;
  --accent: #c5522b;
  --accent-dark: #8f341c;
  --blue: #0f9bd7;
  --green: #1f8f45;
  --text: #24160d;
  --button-bg: #dcd98a;
  --button-bg-hover: #d5d17f;
  --score-bg: #e3de93;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.25), transparent 25%),
    linear-gradient(45deg, #c7975b, #f3d796 35%, #b4783c 70%, #efd398);
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  letter-spacing: .02em;
}

.subtitle {
  margin: 6px 0 0;
  font-weight: 600;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(105px, 1fr));
  gap: 10px;
}

.scoreboard div,
.best,
.panel,
.race-panel,
.photo-panel {
  border: 4px solid var(--wood);
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
}

.scoreboard div {
  background: var(--score-bg);
  padding: 8px 12px;
  text-align: center;
}

.scoreboard span {
  display: block;
  font-weight: 700;
  font-size: .9rem;
}

.scoreboard strong {
  font-size: 1.5rem;
}

.panel {
  background: rgba(239, 231, 200, .96);
  padding: 22px;
  border-radius: 10px;
}


.notice {
  font-weight: 700;
  color: var(--accent-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 16px;
  margin: 18px 0;
}

label {
  font-weight: 800;
}

input,
select {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  font-size: 1rem;
  border: 2px solid var(--wood);
  border-radius: 6px;
  background: white;
}

button {
  border: 3px solid var(--accent);
  background: var(--button-bg);
  color: #111;
  padding: 10px 16px;
  font-weight: 900;
  border-radius: 7px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
}

button:hover {
  background: var(--button-bg-hover);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0,0,0,.25);
}

button.primary {
  background: #d38b50;
  color: #111;
}

button.primary:hover {
  background: #c97f43;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.best {
  display: inline-block;
  background: var(--score-bg);
  padding: 8px 12px;
  margin-top: 18px;
}

.game {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 22px;
  align-items: start;
}

.race-panel,
.photo-panel {
  background: rgba(239, 231, 200, .94);
  padding: 16px;
  border-radius: 10px;
}

.race-panel h2 {
  margin-top: 0;
}

.race-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 9px;
}

.race-buttons button {
  padding: 8px 6px;
  min-height: 44px;
  font-size: .92rem;
}

.photo-panel {
  min-height: 600px;
  display: flex;
  flex-direction: column;
}

.status-line {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  min-height: 34px;
  font-weight: 900;
}

#message.ok {
  color: var(--green);
}

#message.error {
  color: var(--accent-dark);
}

.photo-frame {
  position: relative;
  flex: 1;
  min-height: 420px;
  border: 5px solid var(--wood);
  background: #dfc178;
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.photo-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.image-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 30px;
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 900;
  background:
    linear-gradient(135deg, rgba(255,255,255,.1), rgba(0,0,0,.08)),
    #dfc178;
}

.bottom-actions {
  margin-top: 14px;
  justify-content: center;
}

.hidden {
  display: none !important;
}

.result-summary {
  display: grid;
  gap: 8px;
  font-size: 1.15rem;
  margin: 15px 0 20px;
}

.api-result {
  background: #222;
  color: #e7ffe7;
  padding: 12px;
  overflow: auto;
  border-radius: 8px;
  min-height: 44px;
}

dialog {
  border: 4px solid var(--wood);
  border-radius: 10px;
  padding: 22px;
  max-width: 760px;
  width: min(94vw, 760px);
}

.online-scores {
  margin-top: 16px;
  overflow-x: auto;
}

.online-scores table {
  width: 100%;
  border-collapse: collapse;
}

.online-scores th,
.online-scores td {
  border-bottom: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

@media (max-width: 700px) {
  .topbar,
  .game {
    display: block;
  }

  .scoreboard {
    margin-top: 14px;
  }

  .race-panel {
    margin-bottom: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}



.brand h1 {
  white-space: nowrap;
}

.credits {
  margin: 4px 0 0;
  font-size: .9rem;
  font-weight: 700;
  opacity: .78;
}



/* Les compteurs ne sont utiles que pendant le jeu */
body:has(#welcome:not(.hidden)) .scoreboard {
  display: none;
}
.btn-encyclopedia {
  display: inline-block;
  border: 3px solid #0a7abf;
  background: #d6eaf8;
  color: #111;
  padding: 10px 16px;
  font-weight: 900;
  border-radius: 7px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
  text-decoration: none;
  font-family: inherit;
  font-size: 1rem;
}
.btn-encyclopedia:hover {
  background: #bcd9ef;
  transform: translateY(-1px);
}

.penalty-info {
  border: 2px solid var(--wood);
  border-radius: 6px;
  background: rgba(255,255,255,.35);
  padding: 6px 10px;
  font-weight: 800;
  min-height: 34px;
  display: flex;
  align-items: center;
}
/* Version téléphone portrait : photo en haut, boutons dessous en 2 colonnes */
@media (max-width: 700px) and (orientation: portrait) {
  .app {
    padding: 8px;
  }

  .topbar {
    display: block;
    margin-bottom: 8px;
  }

  .brand h1 {
    font-size: 1.55rem;
    line-height: 1.05;
    white-space: normal;
  }

  .subtitle {
    font-size: .78rem;
  }

  .credits {
    font-size: .72rem;
  }

  .scoreboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-top: 8px;
  }

  .scoreboard div {
    padding: 5px 4px;
    border-width: 3px;
  }

  .scoreboard span {
    font-size: .62rem;
  }

  .scoreboard strong {
    font-size: .9rem;
  }

  .game {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .photo-panel {
    order: 1;
    min-height: auto;
    padding: 8px;
  }

  .race-panel {
    order: 2;
    padding: 8px;
    margin-bottom: 0;
  }

  .race-panel h2 {
    margin: 0 0 8px;
    font-size: 1.05rem;
  }

  .photo-frame {
    height: 38vh;
    min-height: 220px;
    border-width: 4px;
  }

  .photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .status-line {
    min-height: 24px;
    font-size: .8rem;
    margin-bottom: 5px;
  }

  .race-buttons {
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
  }

  .race-buttons button {
    min-height: 32px;
    padding: 4px 3px;
    font-size: .70rem;
    line-height: 1.05;
    border-width: 2px;
    border-radius: 5px;
  }

  .bottom-actions {
    margin-top: 8px;
    gap: 6px;
  }

  .bottom-actions button {
    padding: 6px 8px;
    font-size: .72rem;
    border-width: 2px;
  }
}
/* Les panneaux spéciaux mobile paysage sont cachés par défaut */
.mobile-landscape-races {
  display: none;
}

/* Mobile paysage : 10 races à gauche, photo au centre, 10 races à droite */
@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .app {
    max-width: none;
    padding: 3px 4px;
    min-height: 100svh;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px;
    margin-bottom: 3px;
  }

  .brand h1 {
    font-size: .95rem;
    line-height: 1;
    white-space: nowrap;
  }

  .subtitle,
  .credits {
    display: none;
  }

  .scoreboard {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    gap: 3px;
    margin-top: 0;
  }

  .scoreboard div {
    padding: 2px 3px;
    border-width: 2px;
    box-shadow: 0 2px 0 rgba(0,0,0,.2);
  }

  .scoreboard span {
    font-size: .48rem;
    line-height: 1;
  }

  .scoreboard strong {
    font-size: .72rem;
    line-height: 1.05;
  }

  .game {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr) 104px;
    gap: 3px;
    align-items: stretch;
  }

  .desktop-race-panel {
    display: none;
  }

  .mobile-landscape-races {
    display: block;
    background: rgba(239, 231, 200, .94);
    border: 2px solid var(--wood);
    border-radius: 5px;
    box-shadow: 0 2px 0 rgba(0,0,0,.2);
    padding: 3px;
    min-height: 0;
    overflow: hidden;
  }

  .mobile-landscape-left {
    grid-column: 1;
  }

  .photo-panel {
    grid-column: 2;
    min-height: 0;
    padding: 3px;
    border-width: 2px;
    border-radius: 5px;
    box-shadow: 0 2px 0 rgba(0,0,0,.2);
  }

  .mobile-landscape-right {
    grid-column: 3;
  }

.race-buttons-landscape {
  display: grid;
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: 2px;
  height: 100%;
  min-height: 0;
}

.race-buttons-landscape button {
  min-height: 0;
  padding: 0 2px;
  font-size: .47rem;
  line-height: .88;
  border-width: 1px;
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}

  .status-line {
    min-height: 14px;
    margin-bottom: 2px;
    font-size: .56rem;
    line-height: 1;
  }

  .photo-frame {
    height: calc(100svh - 76px);
    min-height: 135px;
    border-width: 2px;
    border-radius: 4px;
  }

  .photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .bottom-actions {
    margin-top: 2px;
    gap: 4px;
  }

  .bottom-actions button {
    padding: 2px 5px;
    font-size: .52rem;
    border-width: 2px;
    border-radius: 4px;
    box-shadow: 0 2px 0 rgba(0,0,0,.2);
  }
}

/* ── Mode apprentissage ────────────────────────────────────── */

button.learn {
  background: #4a9e6b;
  border-color: #2d7a4f;
  color: #fff;
}

button.learn:hover {
  background: #3d8a5c;
}

/* Bouton race maîtrisée (bonne réponse) */
button.learn-mastered {
  background: #1f8f45 !important;
  border-color: #155e2e !important;
  color: #fff !important;
  box-shadow: 0 3px 0 rgba(0,0,0,.3);
}

/* Bouton race ratée (mauvaise réponse — montre la bonne) */
button.learn-missed {
  background: #e07b20 !important;
  border-color: #a0551a !important;
  color: #fff !important;
  box-shadow: 0 3px 0 rgba(0,0,0,.3);
}

/* Badge "mode apprentissage" affiché pendant la partie */
.learn-badge {
  margin-top: 10px;
  text-align: center;
  font-weight: 800;
  font-size: .88rem;
  color: #2d7a4f;
  background: rgba(31, 143, 69, .12);
  border: 2px solid #2d7a4f;
  border-radius: 6px;
  padding: 5px 10px;
}

/* Bandeau révélation flottant sur la photo */
.learn-reveal {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 18px;
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  font-weight: 900;
  text-align: center;
  letter-spacing: .02em;
  pointer-events: none;
  transition: opacity .2s;
}

.learn-reveal-ok {
  background: rgba(31, 143, 69, .88);
  color: #fff;
}

.learn-reveal-error {
  background: rgba(197, 82, 43, .90);
  color: #fff;
}

/* Notice résultats mode apprentissage */
.learn-finish-notice {
  font-weight: 900;
  font-size: 1.1rem;
  color: #2d7a4f;
  background: rgba(31, 143, 69, .1);
  border: 2px solid #2d7a4f;
  border-radius: 6px;
  padding: 8px 12px;
}

/* Adaptation mobile portrait */
@media (max-width: 700px) and (orientation: portrait) {
  .learn-badge {
    font-size: .72rem;
    padding: 3px 6px;
    margin-top: 6px;
  }
}

/* Adaptation mobile paysage */
@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .learn-badge {
    font-size: .60rem;
    padding: 2px 5px;
  }
}
@keyframes flash-ok {
  0%   { background: #1f8f45; color: #fff; border-color: #1f8f45; }
  100% { background: var(--button-bg); color: #111; border-color: var(--accent); }
}

@keyframes flash-err {
  0%   { background: #c5522b; color: #fff; border-color: #8f341c; }
  100% { background: var(--button-bg); color: #111; border-color: var(--accent); }
}

button.flash-ok {
  animation: flash-ok 0.4s ease-out forwards;
}

button.flash-err {
  animation: flash-err 0.4s ease-out forwards;
}
/* Logo dans l'en-tête */
.brand {
  display: flex;
  align-items: center;
  gap: 22px;
  min-width: 0;
}

.brand-text {
  min-width: 0;
}

.header-logo {
  width: 150px;
  max-width: 20vw;
  height: auto;
  display: block;
}


/* Correction accueil avec logo dans l'en-tête */
body:has(#welcome:not(.hidden)) .app {
  padding-top: 10px;
}

body:has(#welcome:not(.hidden)) .topbar {
  max-width: 760px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  margin-bottom: 10px !important;
}

body:has(#welcome:not(.hidden)) .brand {
  width: 100%;
  justify-content: space-between;
}

body:has(#welcome:not(.hidden)) h1 {
  font-size: clamp(2rem, 3.4vw, 2.8rem);
}

body:has(#welcome:not(.hidden)) .subtitle {
  margin-top: 4px;
}

body:has(#welcome:not(.hidden)) .credits {
  margin-top: 2px;
}

body:has(#welcome:not(.hidden)) .header-logo {
  width: 120px;
  max-width: 18vw;
  height: auto;
}

body:has(#welcome:not(.hidden)) .welcome-layout {
  max-width: 760px !important;
  margin: 10px auto 0 !important;
  display: block !important;
}

body:has(#welcome:not(.hidden)) .welcome-form {
  max-width: 760px !important;
  margin: 0 auto !important;
  padding: 18px 22px !important;
}

body:has(#welcome:not(.hidden)) .welcome-form h2 {
  margin: 0 0 10px;
}

body:has(#welcome:not(.hidden)) .welcome-form .notice {
  margin: 0 0 14px;
}

body:has(#welcome:not(.hidden)) .welcome-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 14px;
}

body:has(#welcome:not(.hidden)) .welcome-heading-text {
  min-width: 0;
}

body:has(#welcome:not(.hidden)) .welcome-heading .btn-encyclopedia {
  flex-shrink: 0;
  margin-top: 0;
  white-space: nowrap;
}

body:has(#welcome:not(.hidden)) .welcome-form .form-grid {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px 16px;
  margin: 12px 0;
}

body:has(#welcome:not(.hidden)) .welcome-form .actions {
  margin-top: 10px;
}

body:has(#welcome:not(.hidden)) .best {
  margin-top: 12px;
}

/* Sur l'accueil, on masque les compteurs inutiles */
body:has(#welcome:not(.hidden)) .scoreboard {
  display: none;
}

/* En-tête compact sur téléphone portrait */
@media (max-width: 700px) {
  body:has(#welcome:not(.hidden)) .topbar,
  body:has(#welcome:not(.hidden)) .welcome-layout,
  body:has(#welcome:not(.hidden)) .welcome-form {
    max-width: 100% !important;
  }

  body:has(#welcome:not(.hidden)) .brand {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  body:has(#welcome:not(.hidden)) .brand-text {
    min-width: 0;
  }

  body:has(#welcome:not(.hidden)) .brand h1 {
    font-size: 1.45rem;
    line-height: 1.05;
    white-space: normal;
  }

  body:has(#welcome:not(.hidden)) .subtitle {
    font-size: .72rem;
  }

  body:has(#welcome:not(.hidden)) .credits {
    font-size: .68rem;
  }

  body:has(#welcome:not(.hidden)) .header-logo {
    width: 75px !important;
    max-width: 22vw !important;
    margin-top: 0 !important;
    flex-shrink: 0;
  }

  body:has(#welcome:not(.hidden)) .welcome-form .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  body:has(#welcome:not(.hidden)) .welcome-heading {
    flex-direction: column;
    gap: 10px;
  }

  body:has(#welcome:not(.hidden)) .welcome-heading .btn-encyclopedia {
    width: 100%;
    text-align: center;
  }
}

/* Logo plus petit sur téléphone en mode paysage */
@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  body:has(#welcome:not(.hidden)) .app {
    padding-top: 6px;
  }

  body:has(#welcome:not(.hidden)) .brand {
    display: flex !important;
    align-items: center;
    gap: 8px;
  }

  body:has(#welcome:not(.hidden)) .brand h1 {
    font-size: 1.15rem !important;
    line-height: 1 !important;
    white-space: nowrap;
  }

  body:has(#welcome:not(.hidden)) .subtitle,
  body:has(#welcome:not(.hidden)) .credits {
    display: none;
  }

  body:has(#welcome:not(.hidden)) .header-logo {
    width: 48px !important;
    max-width: 12vw !important;
    height: auto !important;
    margin-top: 0 !important;
    flex-shrink: 0;
  }
}
/* Adaptation PC / vidéoprojecteur / écran 1366×768 */
@media (min-width: 901px) and (max-height: 780px) {
  .app {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .topbar {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 10px;
    align-items: center;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 18px;
  }

  .brand h1 {
    font-size: 2.15rem;
    line-height: 1.05;
  }

  .subtitle {
    margin-top: 4px;
    font-size: .86rem;
  }

  .credits {
    margin-top: 2px;
    font-size: .78rem;
  }

  .header-logo {
    width: 92px !important;
    max-width: 92px !important;
  }

  .scoreboard {
    grid-template-columns: repeat(3, 72px);
    gap: 6px;
  }

  .scoreboard div {
    padding: 5px 6px;
    border-width: 3px;
  }

  .scoreboard span {
    font-size: .68rem;
  }

  .scoreboard strong {
    font-size: 1rem;
  }

  .game {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
    grid-template-columns: 260px 1fr;
    gap: 14px;
    align-items: start;
  }

  .race-panel,
  .photo-panel {
    padding: 10px;
    border-width: 3px;
  }

  .race-panel h2 {
    margin: 0 0 8px;
    font-size: 1.15rem;
  }

  .race-buttons {
    gap: 5px;
  }

  .race-buttons button {
    min-height: 32px;
    padding: 4px 5px;
    font-size: .72rem;
    line-height: 1.05;
    border-width: 2px;
  }

  .photo-panel {
    min-height: 0;
  }

  .status-line {
    min-height: 22px;
    margin-bottom: 4px;
    font-size: .78rem;
  }

  .photo-frame {
    height: min(52vh, 365px);
    min-height: 300px;
    border-width: 4px;
  }

  .photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .bottom-actions {
    margin-top: 8px;
    gap: 7px;
  }

  .bottom-actions button {
    padding: 6px 10px;
    font-size: .76rem;
    border-width: 2px;
  }

  .learn-badge {
    margin-top: 6px;
    padding: 3px 8px;
    font-size: .72rem;
  }
}
/* ── En-tête écran résultats : même grille que l'écran jeu ── */

body:has(#results:not(.hidden)) .topbar {
  max-width: 1120px;
  margin-left: auto;
  margin-right: auto;
  display: grid;
  grid-template-columns: 1fr 120px auto;
  align-items: center;
  gap: 22px;
  margin-bottom: 14px;
}

body:has(#results:not(.hidden)) .brand {
  display: contents;
}

body:has(#results:not(.hidden)) .brand-text {
  grid-column: 1;
}

body:has(#results:not(.hidden)) .header-logo {
  grid-column: 2;
  justify-self: center;
  width: 100px;
  max-width: 100px;
  height: auto;
}

body:has(#results:not(.hidden)) .scoreboard {
  grid-column: 3;
  justify-self: end;
}

/* Alignement général écran de jeu sur ordinateur */
@media (min-width: 901px) {
  body:has(#game:not(.hidden)) .topbar,
  body:has(#game:not(.hidden)) .game {
    max-width: 1120px;
    margin-left: auto;
    margin-right: auto;
  }

  body:has(#game:not(.hidden)) .topbar {
    display: grid;
    grid-template-columns: 1fr 120px auto;
    align-items: center;
    gap: 22px;
    margin-bottom: 14px;
  }

  body:has(#game:not(.hidden)) .brand {
    display: contents;
  }

  body:has(#game:not(.hidden)) .brand-text {
    grid-column: 1;
  }

  body:has(#game:not(.hidden)) .header-logo {
    grid-column: 2;
    justify-self: center;
    width: 100px;
    max-width: 100px;
    height: auto;
  }

  body:has(#game:not(.hidden)) .scoreboard {
    grid-column: 3;
    justify-self: end;
  }

  body:has(#game:not(.hidden)) .game {
    grid-template-columns: 340px 1fr;
    gap: 18px;
  }

  body:has(#game:not(.hidden)) .race-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
/* Adaptation PC / vidéoprojecteur / écran 1366×768 */
@media (min-width: 901px) and (max-height: 780px) {
  body:has(#game:not(.hidden)) .app {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  body:has(#game:not(.hidden)) .topbar,
  body:has(#game:not(.hidden)) .game {
    max-width: 1060px;
  }

  body:has(#game:not(.hidden)) .topbar {
    grid-template-columns: 1fr 95px auto;
    gap: 16px;
    margin-bottom: 8px;
  }

  body:has(#game:not(.hidden)) h1 {
    font-size: 2.05rem;
    line-height: 1.05;
  }

  body:has(#game:not(.hidden)) .subtitle {
    margin-top: 3px;
    font-size: .84rem;
  }

  body:has(#game:not(.hidden)) .credits {
    margin-top: 1px;
    font-size: .76rem;
  }

  body:has(#game:not(.hidden)) .header-logo {
    width: 82px !important;
    max-width: 82px !important;
  }

  body:has(#game:not(.hidden)) .scoreboard {
    grid-template-columns: repeat(3, 72px);
    gap: 6px;
  }

  body:has(#game:not(.hidden)) .scoreboard div {
    padding: 5px 6px;
    border-width: 3px;
  }

  body:has(#game:not(.hidden)) .scoreboard span {
    font-size: .68rem;
  }

  body:has(#game:not(.hidden)) .scoreboard strong {
    font-size: 1rem;
  }

  body:has(#game:not(.hidden)) .game {
    grid-template-columns: 320px 1fr;
    gap: 14px;
  }

  body:has(#game:not(.hidden)) .race-panel,
  body:has(#game:not(.hidden)) .photo-panel {
    padding: 10px;
    border-width: 3px;
  }

  body:has(#game:not(.hidden)) .race-panel h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
  }

  body:has(#game:not(.hidden)) .race-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  body:has(#game:not(.hidden)) .race-buttons button {
    min-height: 32px;
    padding: 4px 4px;
    font-size: .70rem;
    line-height: 1.05;
    border-width: 2px;
  }

  body:has(#game:not(.hidden)) .photo-panel {
    min-height: 0;
  }

  body:has(#game:not(.hidden)) .status-line {
    min-height: 22px;
    margin-bottom: 4px;
    font-size: .78rem;
  }

  body:has(#game:not(.hidden)) .photo-frame {
    height: min(52vh, 365px);
    min-height: 300px;
    border-width: 4px;
  }

  body:has(#game:not(.hidden)) .photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  body:has(#game:not(.hidden)) .bottom-actions {
    margin-top: 8px;
    gap: 7px;
  }

  body:has(#game:not(.hidden)) .bottom-actions button {
    padding: 6px 10px;
    font-size: .76rem;
    border-width: 2px;
  }

  body:has(#game:not(.hidden)) .learn-badge {
    margin-top: 6px;
    padding: 3px 8px;
    font-size: .72rem;
  }
}
/* Mobile paysage — bloc unique, sans doublons ni !important */
@media (max-width: 950px) and (max-height: 620px) and (orientation: landscape) {

  body:has(#game:not(.hidden)) .app {
    padding: 3px 4px;
    min-height: 100dvh; /* dvh = tient compte de la barre navigateur Android */
    overflow: hidden;
  }

  body:has(#game:not(.hidden)) .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px auto;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
  }

  body:has(#game:not(.hidden)) .brand {
    display: contents;
  }

  body:has(#game:not(.hidden)) .brand-text {
    grid-column: 1;
    min-width: 0;
  }

  body:has(#game:not(.hidden)) .brand h1 {
    font-size: .95rem;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body:has(#game:not(.hidden)) .subtitle,
  body:has(#game:not(.hidden)) .credits {
    display: none;
  }

  body:has(#game:not(.hidden)) .header-logo {
    grid-column: 2;
    justify-self: center;
    width: 44px;
    max-width: 44px;
    height: auto;
  }

  body:has(#game:not(.hidden)) .scoreboard {
    grid-column: 3;
    display: grid;
    grid-template-columns: repeat(3, 54px);
    gap: 4px;
    justify-self: end;
  }

  body:has(#game:not(.hidden)) .scoreboard div {
    padding: 2px 3px;
    border-width: 2px;
    box-shadow: 0 2px 0 rgba(0,0,0,.2);
  }

  body:has(#game:not(.hidden)) .scoreboard span {
    font-size: .48rem;
    line-height: 1;
  }

  body:has(#game:not(.hidden)) .scoreboard strong {
    font-size: .72rem;
    line-height: 1.1;
  }

  body:has(#game:not(.hidden)) .game {
    display: grid;
    /* Marge gauche 12px pour éviter le panneau système Android */
    grid-template-columns: 104px minmax(0, 1fr) 104px;
    gap: 3px;
    align-items: stretch;
    padding-left: 12px;
  }

  body:has(#game:not(.hidden)) .desktop-race-panel {
    display: none;
  }

  body:has(#game:not(.hidden)) .mobile-landscape-races {
    display: flex;
    flex-direction: column;
    padding: 3px;
    border-width: 2px;
    border-radius: 5px;
    box-shadow: 0 2px 0 rgba(0,0,0,.2);
    min-height: 0;
    overflow: hidden;
  }

  body:has(#game:not(.hidden)) .race-buttons-landscape {
    display: grid;
    grid-template-rows: repeat(10, 1fr);
    gap: 2px;
    flex: 1;
    min-height: 0;
  }

  body:has(#game:not(.hidden)) .race-buttons-landscape button {
    min-height: 0;
    padding: 1px 2px;
    font-size: .52rem;
    line-height: .95;
    border-width: 2px;
    border-radius: 4px;
    box-shadow: 0 1px 0 rgba(0,0,0,.2);
  }

  body:has(#game:not(.hidden)) .photo-panel {
    min-height: 0;
    padding: 3px;
    border-width: 2px;
    border-radius: 5px;
    box-shadow: 0 2px 0 rgba(0,0,0,.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body:has(#game:not(.hidden)) .status-line {
    min-height: 14px;
    margin-bottom: 2px;
    font-size: .56rem;
    line-height: 1;
  }

  body:has(#game:not(.hidden)) .photo-frame {
    /* dvh garantit que la barre navigateur Android est exclue */
    height: calc(100dvh - 82px);
    min-height: 135px;
    border-width: 2px;
    border-radius: 4px;
  }

  body:has(#game:not(.hidden)) .photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  body:has(#game:not(.hidden)) .bottom-actions {
    margin-top: 2px;
    gap: 3px;
  }

  body:has(#game:not(.hidden)) .bottom-actions button {
    padding: 2px 5px;
    font-size: .52rem;
    border-width: 2px;
    border-radius: 4px;
  }

  body:has(#game:not(.hidden)) .learn-badge {
    margin-top: 2px;
    padding: 1px 4px;
    font-size: .50rem;
    line-height: 1;
  }
}
.contribute-box {
  margin-top: 18px;
  padding: 14px 16px;
  border: 2px dashed var(--wood);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.42);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.contribute-text h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  color: var(--accent-dark);
}

.contribute-text p {
  margin: 4px 0;
  font-size: 0.88rem;
  line-height: 1.35;
}

.contribute-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 190px;
}

.contribute-btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  font-weight: 900;
  border-radius: 7px;
  padding: 9px 12px;
  border: 3px solid var(--accent);
  color: #111;
}

.primary-link {
  background: #d38b50;
}

.primary-link:hover {
  background: #c97f43;
}

.secondary-link {
  background: var(--button-bg);
}

.secondary-link:hover {
  background: var(--button-bg-hover);
}

@media (max-width: 720px) {
  .contribute-box {
    flex-direction: column;
    align-items: stretch;
  }

  .contribute-actions {
    min-width: 0;
  }
}
.game-credits-summary {
  margin-top: 18px;
  padding: 14px 16px;
  border: 2px dashed var(--wood);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.42);
}

.game-credits-summary h3 {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 1.05rem;
}

.game-credits-summary p {
  margin: 0 0 10px;
  line-height: 1.35;
}

.game-credits-summary ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.game-credits-summary li {
  padding: 9px 10px;
  border: 1px solid rgba(124, 63, 25, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.game-credit-name {
  font-weight: 900;
  color: var(--accent-dark);
}

.game-credit-name a,
.all-contributors-link {
  color: var(--accent-dark);
  font-weight: 900;
  text-decoration: underline;
}

.game-credit-detail {
  margin-top: 3px;
  font-size: 0.88rem;
}

.all-contributors-link {
  display: inline-block;
  margin-top: 12px;
}
/* Scores groupés : une ligne par joueur + détail dépliable */
.grouped-scores-table {
  width: 100%;
  border-collapse: collapse;
}

.grouped-scores-table th,
.grouped-scores-table td {
  vertical-align: middle;
}

.score-toggle {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid var(--wood);
  background: var(--button-bg);
  font-weight: 900;
  cursor: pointer;
  line-height: 1;
}

.score-toggle:hover {
  background: var(--button-bg-hover);
}

.score-player-row td {
  border-bottom: 1px solid rgba(124, 63, 25, 0.28);
}

.score-details-row > td {
  padding: 0 0 10px;
  background: rgba(255, 255, 255, 0.38);
}

.score-details-box {
  margin: 6px 8px 10px 42px;
  padding: 10px;
  border: 1px solid rgba(124, 63, 25, 0.45);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.score-details-title {
  margin-bottom: 8px;
  font-weight: 900;
  color: var(--accent-dark);
}

.nested-scores-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.nested-scores-table th,
.nested-scores-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(124, 63, 25, 0.22);
}

.nested-scores-table th {
  text-align: left;
}

@media (max-width: 720px) {
  .score-details-box {
    margin-left: 0;
    overflow-x: auto;
  }

  .grouped-scores-table,
  .nested-scores-table {
    font-size: 0.85rem;
  }
}
/* Meilleurs scores : affichage groupé et plus lisible */
#scoresDialog {
  width: min(920px, calc(100vw - 28px));
  max-width: 920px;
}

#onlineScores {
  margin-top: 16px;
  overflow-x: auto;
}

.scores-table,
.grouped-scores-table,
.nested-scores-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.grouped-scores-table th,
.grouped-scores-table td {
  padding: 10px 9px;
  vertical-align: middle;
}

.grouped-scores-table thead th {
  color: var(--accent-dark);
  background: rgba(220, 217, 138, 0.45);
  border-top: 2px solid rgba(124, 63, 25, 0.35);
  border-bottom: 2px solid rgba(124, 63, 25, 0.35);
  text-align: left;
  font-weight: 900;
}

.score-player-row {
  background: rgba(255, 255, 255, 0.42);
}

.score-player-row:nth-child(4n + 1) {
  background: rgba(255, 255, 255, 0.62);
}

.score-player-row:hover,
.score-player-row.is-open {
  background: rgba(220, 217, 138, 0.55);
}

.score-player-row td {
  border-bottom: 1px solid rgba(124, 63, 25, 0.25);
}

.score-toggle-cell {
  width: 38px;
  text-align: center;
}

.score-toggle {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 2px solid var(--wood);
  background: var(--button-bg);
  box-shadow: 2px 2px 0 rgba(124, 63, 25, 0.32);
  color: #111;
  font-weight: 900;
  cursor: pointer;
  line-height: 1;
}

.score-toggle:hover,
.score-toggle[aria-expanded="true"] {
  background: var(--button-bg-hover);
  transform: translateY(1px);
}

.score-rank {
  width: 34px;
  text-align: center;
  font-weight: 800;
}

.score-player-name {
  font-weight: 900;
}

.score-city {
  max-width: 170px;
}

.score-best {
  font-weight: 900;
  color: var(--accent-dark);
  white-space: nowrap;
}

.score-errors {
  text-align: center;
}

.score-date {
  white-space: nowrap;
  font-size: 0.92rem;
}

.score-history-badge {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid rgba(124, 63, 25, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  font-weight: 800;
  white-space: nowrap;
}

.score-details-row > td {
  padding: 0 8px 12px 56px;
  background: rgba(255, 255, 255, 0.32);
  border-bottom: 1px solid rgba(124, 63, 25, 0.25);
}

.score-details-box {
  margin: 8px 0 10px;
  padding: 12px;
  border: 2px solid rgba(124, 63, 25, 0.38);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.score-details-title {
  margin-bottom: 8px;
  font-weight: 900;
  color: var(--accent-dark);
}

.nested-scores-table {
  font-size: 0.92rem;
}

.nested-scores-table th,
.nested-scores-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(124, 63, 25, 0.18);
  text-align: left;
}

.nested-scores-table thead th {
  background: rgba(220, 217, 138, 0.35);
  color: #111;
}

.nested-scores-table tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 720px) {
  #scoresDialog {
    width: calc(100vw - 18px);
    padding: 14px;
  }

  .grouped-scores-table th,
  .grouped-scores-table td {
    padding: 8px 6px;
  }

  .score-details-row > td {
    padding-left: 6px;
  }

  .grouped-scores-table,
  .nested-scores-table {
    font-size: 0.85rem;
  }

  .score-city {
    max-width: 120px;
  }
}
