:root {
  --jaune: #f5c428; --rouge: #c4202c; --vert: #1c763e; --bleu: #1c3a8c; --orange: #ee761c;
  --encre: #1d1b1b; --papier: #fffdf6; --gris: #6b6560; --bord: #e4dccb;
  --rayon: 14px; --tactile: 48px;
  --madras: repeating-linear-gradient(90deg, var(--jaune) 0 26px, var(--rouge) 26px 40px, var(--jaune) 40px 48px, var(--vert) 48px 70px, var(--jaune) 70px 78px, var(--encre) 78px 82px, var(--jaune) 82px 90px, var(--orange) 90px 112px, var(--bleu) 112px 132px, var(--jaune) 132px 160px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--papier); color: var(--encre);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- galerie ---------- */
#galerie { min-height: 100%; padding-bottom: env(safe-area-inset-bottom); }
.entete { position: relative; background: var(--papier); border-bottom: 1px solid var(--bord); }
.madras-bande { height: 18px; background: var(--madras); }
.entete-texte { max-width: 1100px; margin: 0 auto; padding: 14px 16px 12px; }
.entete h1 { margin: 0 0 4px; font-size: clamp(1.3rem, 4.2vw, 2.1rem); line-height: 1.15; }
.sous-titre { margin: 0; color: var(--gris); }
.retour-whaoo { margin: 0 0 6px; font-size: .9rem; } .retour-whaoo a { color: var(--gris); text-underline-offset: 2px; }
.actions-entete { margin: 10px 0 0; min-height: 0; }
#bouton-installer { background: var(--vert); color: #fff; border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 600; min-height: 44px; }
#astuce-ios { font-size: .9rem; color: var(--gris); }

.filtres { max-width: 1100px; margin: 0 auto; padding: 12px 16px 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filtres-titre { font-weight: 600; }
#filtres { display: flex; gap: 8px; flex-wrap: wrap; }
.filtre { min-height: 44px; min-width: 44px; padding: 0 14px; border-radius: 999px; border: 2px solid var(--bord); background: #fff; font-weight: 600; }
.filtre[aria-pressed="true"] { background: var(--encre); color: #fff; border-color: var(--encre); }

.section { max-width: 1100px; margin: 0 auto; padding: 18px 16px 6px; }
.section h2 { margin: 0 0 4px; font-size: 1.25rem; }
.section .aide { margin: 0 0 12px; color: var(--gris); font-size: .95rem; }
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.carte { display: flex; flex-direction: column; text-align: left; padding: 0; background: #fff; border: 2px solid var(--bord);
  border-radius: var(--rayon); overflow: hidden; }
.carte:focus-visible, .carte:hover { border-color: var(--orange); }
.carte .vignette { aspect-ratio: 3 / 4; background: #fff; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--bord); }
.carte.paysage .vignette { aspect-ratio: 3 / 2; }
.carte img { max-width: 100%; max-height: 100%; display: block; }
.carte .infos { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.carte .nom { font-weight: 600; font-size: .95rem; line-height: 1.2; }
.carte .niveau { display: flex; align-items: center; gap: 4px; font-size: .78rem; color: var(--gris); }
.points { display: inline-flex; gap: 3px; }
.points i { width: 9px; height: 9px; border-radius: 50%; background: var(--bord); display: block; }
.points i.plein { background: var(--rouge); }
.etiquette-fait { margin-left: auto; background: var(--vert); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: .72rem; font-weight: 600; }
.pied { max-width: 1100px; margin: 24px auto 0; padding: 16px; color: var(--gris); border-top: 1px solid var(--bord); }
.pied p { margin: 0 0 4px; } .petit { font-size: .85rem; }

/* ---------- éditeur ---------- */
#editeur { position: fixed; inset: 0; display: flex; flex-direction: column; background: #d9d4c7; touch-action: none; }
.barre-haut { position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 8px; padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--papier); border-bottom: 1px solid var(--bord); flex: 0 0 auto; }
.titre-dessin { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.titre-dessin strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titre-dessin small { color: var(--gris); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.groupe-boutons { display: flex; gap: 4px; }
.bouton-icone { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: var(--tactile); min-height: var(--tactile);
  padding: 2px 6px; background: #fff; border: 1px solid var(--bord); border-radius: 12px; font-size: 1.25rem; line-height: 1; }
.bouton-icone span { font-size: .62rem; margin-top: 2px; color: var(--gris); }
.bouton-icone:disabled { opacity: .35; cursor: default; }
.menu-liste { position: absolute; right: 8px; top: calc(100% - 2px); z-index: 20; display: flex; flex-direction: column; min-width: 260px; background: #fff;
  border: 1px solid var(--bord); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); overflow: hidden; }
.menu-liste button { text-align: left; background: #fff; border: 0; border-bottom: 1px solid var(--bord); padding: 14px 16px; min-height: var(--tactile); }
.menu-liste button:last-child { border-bottom: 0; }
.menu-liste button[aria-pressed="true"] { background: #f2f9ee; font-weight: 600; }

#scene { position: relative; flex: 1 1 auto; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: crosshair; }
#scene.deplacer { cursor: grab; }
#monde { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.25); will-change: transform; }
#monde canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; image-rendering: auto; pointer-events: none; }
#traits { mix-blend-mode: multiply; }
#message { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(29,27,27,.9); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: .9rem; max-width: 90%; text-align: center; }

.barre-bas { flex: 0 0 auto; background: var(--papier); border-top: 1px solid var(--bord); padding: 6px 8px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
.rangee { display: flex; align-items: center; gap: 6px; }
.outils { flex-wrap: wrap; row-gap: 4px; }
.outil { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 58px; min-height: var(--tactile); padding: 2px 6px; background: #fff;
  border: 2px solid var(--bord); border-radius: 12px; }
.outil b { font-size: 1.3rem; line-height: 1; font-weight: 400; } .outil span { font-size: .66rem; color: var(--gris); }
.outil.actif { border-color: var(--encre); background: #fff3c4; }
.reglage { display: flex; flex-direction: column; font-size: .7rem; color: var(--gris); min-width: 110px; flex: 1 1 110px; max-width: 220px; }
.reglage input { width: 100%; height: 28px; }
.palette { margin-top: 6px; overflow-x: auto; padding: 4px 2px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.pastille { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); padding: 0; }
.pastille[aria-checked="true"] { box-shadow: 0 0 0 3px var(--encre); }
.pastille-perso { position: relative; flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: 2px dashed var(--gris); background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); overflow: hidden; }
.pastille-perso input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

@media (max-width: 520px) { .bouton-icone span { display: none; } .bouton-icone { min-width: 42px; } .reglage { min-width: 90px; } }
@media (min-width: 900px) { .grille { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } .pastille { width: 44px; height: 44px; } }
@media (prefers-reduced-motion: no-preference) { .carte { transition: border-color .15s; } }

/* hub des territoires et musique */
.tuiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tuile { display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; padding: 10px; background: #fff; border: 2px solid var(--bord); border-radius: 14px; color: inherit; text-decoration: none; }
.tuile:focus-visible, .tuile:hover { border-color: var(--orange); }
.tuile img { width: 100%; height: 72px; object-fit: contain; }
.tuile .nom { font-weight: 700; }
.tuile .detail { font-size: .8rem; color: var(--gris); }
.musique-bouton { margin-left: 10px; padding: 4px 12px; border: 2px solid var(--bord); border-radius: 999px; background: #fff; font: inherit; font-size: .85rem; cursor: pointer; }
.musique-bouton[aria-pressed="true"] { background: var(--orange); color: #fff; border-color: var(--orange); }
