:root {
  --verre: rgba(255, 255, 255, .72);
  --verre-fort: rgba(255, 255, 255, .92);
  --encre: #3d4a6b;
  --doux: #7b86a6;
  --accent: #6f8fe0;
  --ombre: 0 6px 22px rgba(60, 80, 140, .18);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; overflow: hidden; background: #a9c8ee; }

body {
  color: var(--encre);
  font: 500 15px/1.3 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#haut {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#haut > * { pointer-events: auto; }
.titre { font-weight: 800; letter-spacing: .22em; font-size: .95rem; color: #fff; text-shadow: 0 2px 10px rgba(60, 80, 140, .35); }
.espace { flex: 1; }

.rond, .pilule {
  min-height: 44px;
  background: var(--verre);
  box-shadow: var(--ombre);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.rond { width: 44px; border-radius: 50%; display: grid; place-items: center; }
.pilule { padding: 0 16px; border-radius: 22px; font-weight: 700; }
.pilule.fort { background: var(--accent); color: #fff; }
button:active { transform: scale(.95); }

#niveau {
  position: fixed;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#niv {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: var(--ombre);
}

#aide {
  position: fixed;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 84px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 8px 14px;
  border-radius: 16px;
  background: var(--verre);
  box-shadow: var(--ombre);
  color: var(--doux);
  font-size: .86rem;
  text-align: center;
  transition: opacity .4s;
}
#aide.cache { opacity: 0; }

#outils {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 24px;
  background: var(--verre);
  box-shadow: var(--ombre);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#outils button {
  width: 56px;
  min-height: 58px;
  border-radius: 18px;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--doux);
  font-size: .72rem;
  font-weight: 700;
}
#outils button.actif { background: var(--verre-fort); color: var(--accent); box-shadow: 0 2px 10px rgba(60, 80, 140, .14); }

#palette {
  position: fixed;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 80px);
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  max-width: calc(100% - 28px);
  overflow-x: auto;
  padding: 6px;
  border-radius: 20px;
  background: var(--verre);
  box-shadow: var(--ombre);
  scrollbar-width: none;
}
#palette[hidden] { display: none; }
#palette button { flex: none; min-height: 40px; padding: 0 12px; border-radius: 14px; background: transparent; color: var(--doux); font-weight: 700; font-size: .82rem; }
#palette button.actif { background: var(--accent); color: #fff; }
body:has(#palette:not([hidden])) #aide { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 138px); }
#son.coupe { opacity: .5; }

/* Mode photo : l'interface s'efface, la caméra tourne seule. */
#barre-photo {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(20px, env(safe-area-inset-bottom));
  display: none;
  align-items: center;
  justify-content: space-around;
}
body.photo .interface { display: none !important; }
body.photo #barre-photo { display: flex; }
#barre-photo .vide { width: 90px; }
.declencheur { width: 72px; height: 72px; border-radius: 50%; background: #fff; border: 5px solid rgba(255, 255, 255, .55); background-clip: padding-box; box-shadow: var(--ombre); }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .35s; }
#flash.on { opacity: .85; transition: none; }

#confirmer { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(60, 80, 140, .25); }
#confirmer[hidden] { display: none; }
.boite { max-width: 300px; margin: 16px; padding: 18px; border-radius: 22px; background: var(--verre-fort); box-shadow: var(--ombre); text-align: center; }
.boite p { margin: 0 0 14px; }
.choix { display: flex; gap: 8px; justify-content: center; }

/* Palette des éléments : verrouillés jusqu'au souhait correspondant. */
#palette button.verrou { opacity: .45; }

/* Visite d'un village partagé. */
#visite {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 54px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border-radius: 24px;
  background: var(--verre-fort);
  box-shadow: var(--ombre);
  font-weight: 700;
  white-space: nowrap;
}
#visite[hidden] { display: none; }

/* Bulle de pensée d'un habitant suivi. */
#bulle {
  position: fixed;
  left: 0;
  top: 0;
  max-width: 220px;
  padding: 8px 12px;
  border-radius: 16px;
  background: var(--verre-fort);
  box-shadow: var(--ombre);
  font-size: .86rem;
  transform: translate(-50%, -100%);
  pointer-events: none;
}
#bulle[hidden] { display: none; }
#bulle strong { display: block; color: var(--accent); font-size: .78rem; }
#bulle::after { content: ""; position: absolute; left: 50%; bottom: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: var(--verre-fort); transform: translateX(-50%); }
#barre-suivi {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 16px;
  border-radius: 24px;
  background: var(--verre-fort);
  box-shadow: var(--ombre);
  font-weight: 700;
  white-space: nowrap;
}
#barre-suivi[hidden] { display: none; }
body.suivi #outils, body.suivi #palette, body.suivi #niveau, body.suivi #aide { display: none; }

/* Tutoriel. */
#tuto {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 56px);
  left: 14px;
  right: 14px;
  max-width: 420px;
  margin: auto;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--verre-fort);
  box-shadow: var(--ombre);
}
#tuto[hidden] { display: none; }
#tuto .etape { color: var(--accent); font-weight: 800; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; }
#tuto p { margin: 4px 0 0; }
.lien { background: none; color: var(--doux); text-decoration: underline; padding: 6px 0 0; font-size: .82rem; }

/* Menu : une feuille qui monte du bas. */
#panneau { position: fixed; inset: 0; background: rgba(60, 80, 140, .22); display: flex; align-items: flex-end; justify-content: center; }
#panneau[hidden] { display: none; }
.feuille {
  width: 100%;
  max-width: 520px;
  max-height: 78vh;
  overflow: auto;
  padding: 14px 16px max(18px, env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0;
  background: #f7f9fe;
  box-shadow: 0 -10px 30px rgba(60, 80, 140, .2);
}
.onglets { position: sticky; top: -14px; display: flex; gap: 4px; align-items: center; padding: 0 0 10px; background: #f7f9fe; }
.onglets button[data-onglet] { flex: 1; min-height: 40px; border-radius: 14px; background: transparent; color: var(--doux); font-weight: 700; font-size: .85rem; }
.onglets button.actif { background: var(--accent); color: #fff; }
.rond.petit { width: 40px; min-height: 40px; box-shadow: none; }
#contenu-panneau h3 { margin: 14px 0 8px; font-size: .95rem; }
#contenu-panneau p.doux { color: var(--doux); font-size: .85rem; margin: 0 0 10px; }
.galerie { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.vignette { border-radius: 16px; overflow: hidden; background: #fff; box-shadow: 0 2px 10px rgba(60, 80, 140, .12); border: 2px solid transparent; text-align: left; padding: 0; }
.vignette.courant { border-color: var(--accent); }
.vignette img, .vignette .vide-apercu { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: linear-gradient(#a9c8ee, #e8f0fb); }
.vignette span { display: block; padding: 8px 10px; font-weight: 700; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rangee { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.pilule.clair { box-shadow: none; background: #e8eefb; }
.reglage { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #e3e9f6; }
.reglage label { font-weight: 700; }
.choix-seg { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.choix-seg button { min-height: 36px; padding: 0 10px; border-radius: 12px; background: #e8eefb; color: var(--encre); font-size: .8rem; font-weight: 700; }
.choix-seg button.actif { background: var(--accent); color: #fff; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.souhait { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid #e3e9f6; }
.souhait .coche { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #e8eefb; color: var(--doux); font-weight: 800; }
.souhait.fait .coche { background: var(--accent); color: #fff; }
.souhait small { display: block; color: var(--doux); }
