:root {
  --ink: #1F2A24;
  --pencil: #5B6B61;
  --mist: #E6ECE7;
  --paper: #FFFFFF;
  --focus: #2F6BFF;
  --alert: #B3261E;
  --panel-h: 160px;
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; overflow: hidden;
  position: fixed; inset: 0; overscroll-behavior: none;
  background: var(--ink);
}
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

#map { position: fixed; inset: 0; }

/* Barre de recherche : cadre au crayon, comme une annotation sur la carte */
.bar {
  position: fixed; z-index: 2;
  top: calc(env(safe-area-inset-top) + 10px); left: 10px; right: 10px;
  max-width: 520px; display: flex; gap: 8px;
}
.search { position: relative; flex: 1; }
#q {
  width: 100%; height: 48px; padding: 0 14px;
  font: inherit; font-size: 17px; color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 12px;
  -webkit-appearance: none; appearance: none;
}
#q::placeholder { color: var(--pencil); }
#q { padding-right: 44px; }
.geo-btn {
  position: absolute; top: 50%; right: 5px; transform: translateY(-50%);
  width: 38px; height: 38px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 10px; color: var(--ink);
}
.geo-btn:active { background: var(--mist); }
#results {
  position: absolute; top: 54px; left: 0; right: 0; margin: 0; padding: 4px 0;
  list-style: none; background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 12px; max-height: 50vh; overflow: auto;
}
#results li { padding: 10px 14px; cursor: pointer; }
#results li[aria-selected="true"], #results li:hover { background: var(--mist); }
#results .r-name { font-weight: 700; }
#results .r-sub { color: var(--pencil); font-size: 14px; }
#results .msg { color: var(--pencil); cursor: default; }

.icon-btn {
  width: 48px; height: 48px; flex: none; display: grid; place-items: center;
  background: var(--ink); color: var(--paper); border: 0; border-radius: 12px;
}

/* Panneau bas */
.panel {
  position: fixed; z-index: 2;
  left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px);
  max-width: 520px; padding: 14px 16px 16px;
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 16px;
}
.view { display: grid; gap: 14px; }
.view[hidden] { display: none; }
.panel.collapsed .view { display: none; }

.panel-toggle {
  position: absolute; top: -35px; right: 14px; z-index: 1;
  width: 40px; height: 35px; display: grid; place-items: center;
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--ink); border-bottom: 0; border-radius: 12px 12px 0 0;
}
.panel-toggle[hidden] { display: none; }
.panel-toggle svg { transition: transform .2s ease; }
.panel.collapsed .panel-toggle svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .panel-toggle svg { transition: none; } }

/* Repliée, la vue tracé garde la légende des types visible */
.mini-legend[hidden] { display: none; }

/* Compteur de distance surlignée */
.stat { display: flex; align-items: baseline; gap: 7px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--pencil); }

.legal-text { display: grid; gap: 10px; font-size: 14px; line-height: 1.5; max-height: 42vh; overflow-y: auto; }
.legal-text p { margin: 0; }

.field { display: grid; gap: 6px; }
.field-label { font-size: 14px; color: var(--pencil); margin: 0; }
.style-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.style-picker button {
  padding: 8px 14px; font-size: 14px; background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 999px;
}
.style-picker button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 700; }
.place { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.place-name { font-size: 20px; font-weight: 700; line-height: 1.2; }
.place-sub { font-size: 14px; color: var(--pencil); margin-top: 2px; }
.text-btn {
  flex: none; padding: 6px 10px; font-size: 14px; background: none;
  border: 1.5px solid var(--ink); border-radius: 999px;
}
#set-default:disabled { border-color: transparent; color: var(--pencil); cursor: default; padding-inline: 0; }
.text-btn:disabled { opacity: .4; cursor: default; }
.text-btn.danger { border-color: var(--alert); color: var(--alert); }
.text-btn.danger.confirm { background: var(--alert); color: var(--paper); }

.radius { display: flex; border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden; }
.radius button {
  flex: 1; height: 38px; background: var(--paper); border: 0; font-size: 15px;
}
.radius button + button { border-left: 1.5px solid var(--ink); }
.radius button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 700; }

/* Légende : les libellés sont littéralement surlignés */
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 0; padding: 0; list-style: none; }
.hl {
  display: inline-block; padding: .08em .45em; font-size: 15px;
  background: var(--hl); mix-blend-mode: multiply;
  border-radius: .25em .6em .3em .7em / .7em .25em .6em .3em;
  transform: rotate(-1.2deg);
}
.legend li:nth-child(even) .hl { transform: rotate(.9deg); }

/* Repère de l'adresse */
.pin {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--ink); border: 3px solid var(--paper);
  box-shadow: 0 0 0 1.5px var(--ink);
}

/* Contrôles Mapbox hors des panneaux */
.mapboxgl-ctrl-top-right { display: none; } /* géolocalisation déclenchée depuis la barre de recherche */
.mapboxgl-ctrl-bottom-left { bottom: calc(var(--panel-h) + env(safe-area-inset-bottom) + 12px); }
.mapboxgl-ctrl-bottom-right { bottom: calc(var(--panel-h) + env(safe-area-inset-bottom) + 48px); } /* passe au-dessus du chevron de minimisation */
@media (min-width: 900px) {
  .mapboxgl-ctrl-bottom-left, .mapboxgl-ctrl-bottom-right { bottom: 0; }
  .mapboxgl-ctrl-bottom-left { left: 540px; }
}

.primary-btn {
  height: 48px; padding: 0 20px; border: 0; border-radius: 12px;
  background: var(--ink); color: var(--paper); font-size: 16px; font-weight: 700;
}
.primary-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.small { width: 36px; height: 36px; border-radius: 10px; font-size: 22px; line-height: 1; }

/* Choix du type : on touche le trait de surligneur */
.types { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.chip { padding: 5px 6px; background: none; border: 1.5px solid transparent; border-radius: 10px; }
.chip[aria-pressed="true"] { border-color: var(--ink); }
.chip[aria-pressed="true"] .hl { font-weight: 700; }

.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.switch input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions .primary-btn { margin-left: auto; }
.alert { color: var(--alert); }

#gate { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: var(--ink); }
#gate[hidden] { display: none; }
#gate form { width: 100%; max-width: 420px; display: grid; gap: 12px; background: var(--paper); border-radius: 16px; padding: 20px; }
#gate h1 { margin: 0; font-size: 22px; }
#gate p { color: var(--pencil); font-size: 14px; line-height: 1.4; }
#gate input { height: 48px; padding: 0 12px; font: inherit; font-size: 16px; border: 1.5px solid var(--ink); border-radius: 12px; }
#gate .err { color: var(--alert); min-height: 1.2em; }

/* Écran de démarrage GravelAxe */
#splash {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 24px; text-align: center;
  background: var(--ink); color: var(--paper);
  transition: opacity .45s ease, visibility .45s ease;
}
#splash.out { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-art { width: min(78vw, 320px); height: auto; margin-bottom: 4px; }
.wheel-spin { transform-origin: 280px 205px; animation: wheel-spin .9s linear infinite; }
@keyframes wheel-spin { to { transform: rotate(360deg); } }
.splash-word {
  margin: 0; font-size: clamp(32px, 9vw, 44px); font-weight: 700; letter-spacing: -.02em;
}
.splash-word .hl {
  font-size: inherit; padding: 0 .1em; color: var(--ink); mix-blend-mode: normal;
  border-radius: .15em .3em .18em .32em / .35em .15em .3em .18em;
}
.splash-tag { margin: 2px 0 18px; font-size: 15px; color: #C9BDA0; max-width: 280px; }
.loader { display: flex; gap: 8px; }
.loader span {
  width: 9px; height: 9px; border-radius: 50%; background: #FFE81A;
  animation: gc-bounce 1.1s ease-in-out infinite;
}
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
@keyframes gc-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-8px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  #splash { transition: none; }
  .loader span { animation: none; opacity: .85; }
  .wheel-spin { animation: none; }
}

/* Bouton et pastille de synchronisation */
.icon-btn { position: relative; }
.dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--alert); border: 1.5px solid var(--ink);
}
.dot.ok { background: #5EE06A; }
.dot.busy { background: #FFE81A; animation: gc-bounce 1.1s ease-in-out infinite; }

.sync-form { display: grid; gap: 12px; }
.sync-form label { display: grid; gap: 5px; font-size: 14px; color: var(--pencil); }
.sync-form input {
  height: 48px; padding: 0 12px; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 12px;
}
