/* ==========================================================================
   Tolosa – styles
   Palette : brique toulousaine + violette, thème clair / sombre automatique.
   ========================================================================== */
:root {
  --brick: #b5523b;
  --brick-dark: #8f3d2b;
  --violet: #6b4c9a;
  --bg: #faf5ef;
  --surface: #ffffff;
  --surface-2: #f3ebe2;
  --text: #2b211c;
  --muted: #76675d;
  --border: #e5d8cb;
  --ok: #2e8b57;
  --ok-bg: #e3f4ea;
  --ko: #c8402f;
  --ko-bg: #fbe7e3;
  --warn: #c98a12;
  --shadow: 0 6px 24px rgba(60, 30, 15, 0.14);
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --title-font: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1715;
    --surface: #272020;
    --surface-2: #322928;
    --text: #f3ebe4;
    --muted: #b3a49a;
    --border: #44393a;
    --ok-bg: #1d3a2a;
    --ko-bg: #4a2420;
    --brick: #d4694f;
    --violet: #9c7fd0;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1c1715;
  --surface: #272020;
  --surface-2: #322928;
  --text: #f3ebe4;
  --muted: #b3a49a;
  --border: #44393a;
  --ok-bg: #1d3a2a;
  --ko-bg: #4a2420;
  --brick: #d4694f;
  --violet: #9c7fd0;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

a { color: var(--brick); }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--surface-2);
}

/* ----- Écrans ----- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 10;
}
.screen.active { display: block; }
.screen-solid {
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen-overlay { pointer-events: none; }
.screen-overlay > * { pointer-events: auto; }

/* ----- Chargement ----- */
.loading {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.logo-big { font-family: var(--title-font); font-size: 3.2rem; color: var(--brick); font-weight: 700; }
.spinner {
  width: 36px; height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--brick);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Accueil ----- */
.home {
  max-width: 980px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px 32px;
}
.home-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.logo {
  font-family: var(--title-font);
  font-size: 2.6rem;
  margin: 0;
  color: var(--brick);
  letter-spacing: 0.5px;
}
.tagline { margin: 4px 0 0; color: var(--muted); max-width: 520px; }

.level-chip {
  display: grid;
  gap: 4px;
  min-width: 190px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
}
.level-chip:hover { border-color: var(--brick); }
#level-name { font-weight: 700; color: var(--violet); }
.xp-bar { display: block; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
#xp-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brick), var(--violet)); transition: width 0.4s; }

.review-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--ko-bg);
  border-radius: var(--radius);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s, border-color 0.12s;
}
.mode-card:hover { transform: translateY(-2px); border-color: var(--brick); }
.mode-card:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.mode-icon { font-size: 2rem; line-height: 1; }
.mode-title { font-size: 1.2rem; font-weight: 700; }
.mode-desc { color: var(--muted); font-size: 0.92rem; }
.mode-meta { margin-top: auto; padding-top: 6px; font-size: 0.8rem; color: var(--violet); font-weight: 600; }

.home-footer { margin-top: 28px; text-align: center; line-height: 1.6; }

/* ----- Boutons, puces ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
.btn:hover { border-color: var(--brick); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--brick); border-color: var(--brick); color: #fff; }
.btn-primary:hover { background: var(--brick-dark); }
.btn-violet { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn-big { padding: 12px 28px; font-size: 1.05rem; }
.btn-small { padding: 6px 12px; min-height: 34px; font-size: 0.9rem; }
.btn-ghost { background: transparent; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 36px;
  user-select: none;
}
.chip[aria-pressed="true"] { background: var(--violet); border-color: var(--violet); color: #fff; }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.chip .count { opacity: 0.7; font-size: 0.8em; margin-left: 4px; }
.chips-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.chips-scroll::-webkit-scrollbar { display: none; }
.chips-scroll .chip { flex: 0 0 auto; }

.icon-btn {
  width: 44px; height: 44px;
  flex: 0 0 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.icon-btn:hover { border-color: var(--brick); background: var(--surface-2); }
.icon-btn:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn .ico { width: 18px; height: 18px; margin-left: -4px; }

/* ----- Fenêtre de réglages ----- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 10, 5, 0.45);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 22px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 40px 4px 0; }
.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none; border-radius: 10px; background: transparent; cursor: pointer; color: var(--muted);
  transition: background-color 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.field { margin-top: 16px; }
.field-label { font-weight: 700; margin-bottom: 8px; font-size: 0.95rem; }
.field-help { margin-top: 6px; }
.seg { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.seg button {
  flex: 1;
  padding: 10px 6px;
  border: none;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button[aria-pressed="true"] { background: var(--brick); color: #fff; }
.seg small { display: block; font-weight: 400; font-size: 0.75rem; opacity: 0.85; }
.custom-points { display: grid; gap: 8px; margin-top: 10px; }
.custom-points input, .answer-input, .explore-search input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  min-height: 44px;
}
.custom-points input:focus, .answer-input:focus, .explore-search input:focus { outline: 2px solid var(--violet); border-color: transparent; }

/* ----- Jeu : bandeau ----- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  z-index: 20;
}
.question { flex: 1; min-width: 0; }
.q-kicker { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--violet); font-weight: 700; }
.q-text { font-size: 1.15rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.q-text .target { color: var(--brick); }
.game-stats { text-align: right; white-space: nowrap; }
.g-progress { font-size: 0.8rem; color: var(--muted); }
.g-score { font-weight: 800; font-size: 1.1rem; color: var(--brick); }
.g-timer { font-variant-numeric: tabular-nums; font-size: 0.85rem; font-weight: 700; }
.g-timer.urgent { color: var(--ko); }

.map-tools {
  position: absolute;
  right: 12px;
  top: 92px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 15;
}
.tool-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 700;
}
.tool-btn[aria-pressed="true"] { background: var(--violet); color: #fff; border-color: var(--violet); }

/* ----- Jeu : panneau du bas ----- */
.sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(640px, 100%);
  max-height: 55dvh;
  overflow-y: auto;
  padding: 14px 16px max(14px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.16);
  z-index: 20;
}
.sheet:empty { display: none; }
/* Le bouton « Suivant » reste visible même quand la correction défile */
.sheet .sticky-actions {
  position: sticky;
  bottom: calc(-1 * max(14px, env(safe-area-inset-bottom)));
  margin: 4px -16px calc(-1 * max(14px, env(safe-area-inset-bottom)));
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
@media (max-height: 640px) and (max-width: 899px) {
  .sheet { max-height: 48dvh; padding-top: 10px; }
  .fb-info, .fb-hint { font-size: 0.82rem; }
  .fb-hint { padding: 6px 8px; }
  .feedback { gap: 5px; }
  .choice { min-height: 42px; padding: 8px 12px; }
}
@media (min-width: 900px) {
  .sheet {
    left: auto; right: 16px; bottom: 16px;
    transform: none;
    width: 400px;
    max-height: calc(100dvh - 120px);
    border-radius: 20px;
  }
}
.sheet-hint { color: var(--muted); font-size: 0.92rem; margin: 0 0 10px; }
.choices { display: grid; gap: 8px; }
@media (min-width: 520px) { .choices.two-cols { grid-template-columns: 1fr 1fr; } }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  min-height: 48px;
  font-weight: 600;
}
.choice:hover:not(:disabled) { border-color: var(--violet); }
.choice kbd {
  flex: 0 0 auto;
  display: inline-grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--muted);
}
.choice.correct { background: var(--ok-bg); border-color: var(--ok); }
.choice.wrong { background: var(--ko-bg); border-color: var(--ko); }
.choice:disabled { cursor: default; }

.feedback { display: grid; gap: 8px; }
.fb-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.fb-title { font-size: 1.15rem; font-weight: 800; }
.fb-title.ok { color: var(--ok); }
.fb-title.mid { color: var(--warn); }
.fb-title.ko { color: var(--ko); }
.fb-points { font-weight: 800; font-size: 1.2rem; color: var(--brick); white-space: nowrap; }
.fb-answer { font-weight: 700; }
.fb-info { font-size: 0.92rem; }
.fb-hint {
  font-size: 0.88rem;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 10px;
  line-height: 1.45;
}
.fb-hint b { color: var(--violet); }
.route-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.route-stat { padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 0.9rem; }
.route-stat b { display: block; font-size: 1rem; }
.route-stat.you b { color: var(--violet); }
.route-stat.best b { color: var(--ok); }
.roadbook { margin: 0; padding-left: 0; list-style: none; font-size: 0.88rem; display: grid; gap: 3px; counter-reset: rb; }
.roadbook li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.roadbook li span:last-child { color: var(--muted); white-space: nowrap; }
.leg-warning { color: var(--ko); font-size: 0.88rem; font-weight: 600; }

/* ----- Marqueurs ----- */
.pin {
  width: 30px; height: 30px;
  margin: -30px 0 0 -15px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--violet);
  border: 3px solid #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}
.pin-wrap { width: 0; height: 0; }
/* Épingle de la bonne réponse : plus grande, colorée selon le résultat, avec un point blanc */
.pin.pin-answer {
  position: relative;
  width: 36px; height: 36px;
  margin: -36px 0 0 -18px;
  animation: pin-drop 0.35s ease-out;
}
.pin.pin-answer::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 10px; height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: #fff;
}
.pin.pin-ok { background: var(--ok); }
.pin.pin-mid { background: #d08a0e; }
.pin.pin-ko { background: var(--ko); }
.pin.pin-sel { background: var(--brick); }
@keyframes pin-drop {
  from { transform: translateY(-18px) rotate(-45deg); opacity: 0; }
  to { transform: rotate(-45deg); opacity: 1; }
}
.flag {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  font-size: 0.85rem;
}
.flag-a { background: #2e8b57; }
.flag-b { background: #c8402f; }
.wp {
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--violet);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.pulse {
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: var(--brick);
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(181, 82, 59, 0.6);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(181, 82, 59, 0.55); }
  70% { box-shadow: 0 0 0 18px rgba(181, 82, 59, 0); }
  100% { box-shadow: 0 0 0 0 rgba(181, 82, 59, 0); }
}
.leaflet-tooltip.answer-label {
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 8px;
  padding: 4px 8px;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.leaflet-tooltip.exit-label { font-weight: 700; font-size: 0.78rem; padding: 2px 6px; }
.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-top.leaflet-left { top: 84px; }
@media (max-width: 899px) { .leaflet-control-zoom { display: none; } }

/* ----- Résultats ----- */
.results, .stats {
  max-width: 720px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px 40px;
}
.results h2, .stats h2 { font-family: var(--title-font); font-size: 2rem; margin: 0 0 4px; color: var(--brick); }
.big-score { font-size: 3rem; font-weight: 800; color: var(--violet); line-height: 1.1; }
.stars { font-size: 2rem; letter-spacing: 4px; color: #e0a526; }
.stars .off { color: var(--border); }
.res-list { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 8px; }
.res-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.res-item .ico { font-size: 1.1rem; }
.res-item .name { flex: 1; min-width: 0; }
.res-item .name small { display: block; color: var(--muted); }
.res-item .pts { font-weight: 800; white-space: nowrap; }
.card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 14px;
}
.card h3 { margin: 0 0 10px; font-size: 1.05rem; }
.mastery-row { display: grid; grid-template-columns: 150px 1fr 48px; gap: 10px; align-items: center; margin: 7px 0; font-size: 0.92rem; }
.mastery-bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.mastery-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--brick), var(--ok)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kpi { padding: 12px; border-radius: 12px; background: var(--surface-2); }
.kpi b { display: block; font-size: 1.4rem; color: var(--violet); }

/* ----- Apprendre ----- */
.mode-card-featured {
  border: 2px solid var(--violet);
  background: linear-gradient(135deg, color-mix(in srgb, var(--violet) 10%, var(--surface)), var(--surface) 60%);
}
.learn {
  max-width: 760px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px 40px;
}
.learn-head { display: flex; align-items: center; gap: 12px; }
.learn-head h2 { font-family: var(--title-font); font-size: 2rem; margin: 0; color: var(--brick); }
.learn-intro { margin: 10px 0 14px; line-height: 1.5; font-size: 0.95rem; }
.learn-tabs { margin: 0 -16px; padding: 0 16px 4px; }
.learn-parcours { margin-top: 12px; }
.learn-desc { margin: 0 0 10px; }
.learn-continue {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--violet) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--violet) 35%, var(--border));
}
.learn-continue-text { display: grid; gap: 2px; min-width: 0; }
.lesson-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.lesson-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  min-height: 56px;
}
.lesson-row:hover { border-color: var(--violet); }
.lesson-row.is-next { border: 2px solid var(--violet); }
.lesson-num {
  flex: 0 0 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--muted);
}
.lesson-row.is-next .lesson-num { background: var(--violet); color: #fff; }
.lesson-row.is-done .lesson-num { background: var(--ok); color: #fff; }
.lesson-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.lesson-title { font-weight: 700; overflow-wrap: anywhere; }
.lesson-meta { font-size: 0.82rem; color: var(--muted); }
.lesson-go { font-size: 1.5rem; color: var(--muted); }
.lesson-row.is-eval { background: color-mix(in srgb, var(--brick) 7%, var(--surface)); border-style: dashed; }
.lesson-row.is-eval.is-next { border-style: solid; }
.lesson-row.is-eval .lesson-num { background: transparent; font-size: 1.2rem; }
.lesson-row.is-eval.is-done .lesson-num { background: var(--ok); font-size: 0.9rem; }
.learn:has(.learn-fab) { padding-bottom: 170px; }
.learn-fab {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  justify-items: start;
  gap: 8px;
}
/* Sélecteur du fond de carte, en bas à droite : vignettes centrées sur la Garonne */
.map-fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  gap: 6px;
  padding: 6px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  --plan-preview: url("https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/13/2991/4128");
}
:root[data-theme="dark"] .map-fab { --plan-preview: url("https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/13/2991/4128"); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .map-fab { --plan-preview: url("https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/13/2991/4128"); }
}
.map-fab-title { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); text-align: center; }
.map-tile {
  position: relative;
  width: 52px;
  height: 46px;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 11px;
  background: var(--surface-2) center / 220% no-repeat;
  cursor: pointer;
  transition: border-color 0.15s;
}
.map-tile[data-base="sat"] { background-image: url("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/13/2991/4128"); }
.map-tile[data-base="plain"] { background-image: var(--plan-preview); }
.map-tile:hover { border-color: color-mix(in srgb, var(--violet) 50%, transparent); }
.map-tile[aria-checked="true"] { border-color: var(--violet); box-shadow: 0 0 0 2px color-mix(in srgb, var(--violet) 30%, transparent); }
.map-tile:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.map-tile-label {
  position: absolute;
  inset: auto 0 0;
  padding: 10px 2px 3px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
}
.learn-fab { max-width: calc(100vw - 32px - 74px); }
.learn-fab-row { display: flex; flex-wrap: wrap; gap: 8px; }
.learn-fab .btn { border-radius: 999px; box-shadow: var(--shadow); padding: 10px 14px; white-space: nowrap; }
.learn-fab .btn:not(.btn-violet) { border-color: color-mix(in srgb, var(--violet) 45%, var(--border)); }
.learn-fab .btn-violet .learn-fab-count { background: #fff; color: var(--violet); }
.learn-fab .learn-fab-icon { width: 40px; padding: 0; font-size: 1.15rem; }
.learn-fab-count {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--violet);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}
.select-all { margin: 12px 0 0; }
.lesson-check {
  flex: 0 0 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 2px solid var(--border);
  color: #fff;
  font-weight: 800;
}
.lesson-row.is-selected { border-color: var(--violet); background: color-mix(in srgb, var(--violet) 8%, var(--surface)); }
.lesson-row.is-selected .lesson-check { background: var(--violet); border-color: var(--violet); }
.select-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  gap: 10px;
  margin: 16px -16px -40px;
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.1);
}
.select-bar-info { font-size: 0.95rem; }
.select-bar .seg button { min-height: 40px; padding: 6px; }
.lesson-done-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 4px; }
.lesson-verdict { margin: 8px 0 4px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-weight: 600; }
.lesson-verdict.ok { background: var(--ok-bg); color: var(--ok); }
.leaflet-tooltip.prev-label { font-size: 0.75rem; font-weight: 600; padding: 2px 6px; opacity: 0.85; }

/* ----- Explorer ----- */
.explore-bar { flex-wrap: nowrap; }
.explore-search { flex: 1; min-width: 0; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; white-space: nowrap; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--violet); }
.explore-layers {
  position: absolute;
  top: 78px;
  left: 0; right: 0;
  padding: 6px 12px;
  z-index: 19;
}
.explore-layers .chip { box-shadow: var(--shadow); }
.info-title { font-size: 1.2rem; font-weight: 800; margin: 0 0 2px; }
.info-sub { color: var(--violet); font-weight: 600; font-size: 0.88rem; }
.line-badge {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 6px;
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  text-align: center;
  margin-right: 3px;
}

/* ----- Toast ----- */
.toast {
  position: fixed;
  left: 50%;
  top: 90px;
  transform: translateX(-50%);
  z-index: 100;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

@media (max-width: 520px) {
  .logo { font-size: 2.1rem; }
  .mode-grid { gap: 10px; }
  .mode-card {
    display: grid;
    grid-template-columns: 40px 1fr;
    column-gap: 12px;
    row-gap: 2px;
    padding: 14px;
  }
  .mode-icon { grid-row: span 3; font-size: 1.7rem; }
  .mode-meta { padding-top: 2px; }
  .q-text { font-size: 1.02rem; }
  .topbar { gap: 8px; padding-left: 8px; padding-right: 8px; }
  .mastery-row { grid-template-columns: 110px 1fr 42px; }
  .switch { font-size: 0.78rem; }
  .map-tools { top: 84px; right: 8px; }
}

/* ==========================================================================
   Animations (discrètes, désactivées si l'utilisateur limite les animations)
   ========================================================================== */
:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-10px); } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } }
@keyframes pop-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, -6px); } }

/* Changement d'écran.
   Pas de transform sur #learn-body : il contient les boutons flottants (position: fixed). */
.screen-solid.is-entering > :not(.learn) { animation: fade-up 0.32s var(--ease-out) both; }
.screen.is-entering .learn > :not(.learn-fab, .map-fab, .lesson-list) { animation: fade-up 0.32s var(--ease-out) both; }
.screen-overlay.is-entering .topbar { animation: slide-down 0.3s var(--ease-out) both; }

/* Écran Apprendre : leçons en cascade, boutons flottants qui se posent */
.screen.is-entering .lesson-list li:nth-child(-n + 8) { animation: fade-up 0.34s var(--ease-out) both; }
.screen.is-entering .lesson-list li:nth-child(2) { animation-delay: 0.03s; }
.screen.is-entering .lesson-list li:nth-child(3) { animation-delay: 0.06s; }
.screen.is-entering .lesson-list li:nth-child(4) { animation-delay: 0.09s; }
.screen.is-entering .lesson-list li:nth-child(5) { animation-delay: 0.12s; }
.screen.is-entering .lesson-list li:nth-child(6) { animation-delay: 0.15s; }
.screen.is-entering .lesson-list li:nth-child(7) { animation-delay: 0.18s; }
.screen.is-entering .lesson-list li:nth-child(8) { animation-delay: 0.21s; }
.screen.is-entering .learn-fab > *,
.screen.is-entering .map-fab { animation: pop-in 0.38s var(--ease-out) 0.15s both; }
.screen.is-entering .learn-fab > :nth-child(2) { animation-delay: 0.21s; }
.learn.tab-in .learn-parcours,
.learn.tab-in .lesson-list { animation: fade-up 0.28s var(--ease-out) both; }
.learn.tab-in .lesson-list { animation-delay: 0.04s; }
.learn.view-in > * { animation: fade-up 0.28s var(--ease-out) both; }

/* Fenêtre de réglages */
.modal:not(.hidden) { animation: fade-in 0.2s ease-out both; }
.modal:not(.hidden) .modal-card { animation: pop-in 0.28s var(--ease-out) both; }
.modal.is-closing { animation: fade-out 0.16s ease-in both; }
.modal.is-closing .modal-card { animation: pop-out 0.16s ease-in both; }
.modal-card .field { animation: fade-up 0.3s var(--ease-out) both; }
.modal-card .field:nth-child(2) { animation-delay: 0.03s; }
.modal-card .field:nth-child(3) { animation-delay: 0.06s; }
.modal-card .field:nth-child(n + 4) { animation-delay: 0.09s; }

/* Panneau des questions et notifications */
.sheet.sheet-in > * { animation: fade-up 0.24s var(--ease-out) both; }
.toast:not(.hidden) { animation: toast-in 0.24s var(--ease-out) both; }
.toast.is-leaving { animation: toast-out 0.18s ease-in both; }

/* Retours au toucher */
.btn, .chip, .seg button, .lesson-row, .choice {
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.12s, box-shadow 0.15s;
}
.btn:active:not(:disabled), .chip:active:not(:disabled), .icon-btn:active, .map-tile:active { transform: scale(0.97); }
.lesson-row:active { transform: scale(0.99); }
.lesson-check { transition: background-color 0.15s, border-color 0.15s; }

/* Pas sur #map : la carte (zoom, fondus de Leaflet) est hors des écrans et garde ses transitions. */
@media (prefers-reduced-motion: reduce) {
  .screen, .screen *, .modal, .modal *, .toast {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
  }
}
