:root {
  --fond: #0b0f17;
  --surface: #151b27;
  --surface-2: #1e2636;
  --bord: #2b3547;
  --texte: #e8edf6;
  --discret: #9aa6ba;
  --accent: #4f8cff;
  --accent-texte: #ffffff;
  --erreur: #ff7a7a;
  --succes: #4fd18b;
  --barre: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: .95em; word-break: break-all; }
.cache { display: none !important; }
.discret { color: var(--discret); }
.petit { font-size: .85rem; }

/* Vues ------------------------------------------------------------------- */
.vue { display: none; }
.vue.active { display: flex; }
.vue-centree {
  min-height: 100%;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.carte {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.carte h1 { margin: 0; font-size: 1.35rem; }
.carte p { margin: 0; }
.carte img { align-self: center; background: #fff; border-radius: 8px; padding: 6px; }

.logo {
  width: 48px; height: 48px;
  background: url("/icones/icone.svg") center / contain no-repeat;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; color: var(--discret); }
input, select {
  background: var(--fond);
  border: 1px solid var(--bord);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--texte);
  min-height: 44px;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.erreur { color: var(--erreur); min-height: 1.2em; }
.erreur:empty { display: none; }

button {
  cursor: pointer;
  border: 1px solid var(--bord);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
}
button:hover { border-color: var(--accent); }
button.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 600; }
button:disabled { opacity: .55; cursor: wait; }

/* Prise en main -------------------------------------------------------- */
#vue-ecran {
  position: fixed;
  inset: 0;
  background: #000;
  flex-direction: row;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#zone {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#ecran {
  display: block;
  background: #000;
  touch-action: none;
  cursor: crosshair;
  outline: none;
  image-rendering: auto;
}
#ecran.attente { visibility: hidden; }

.etat-ecran {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}
.etat-ecran p { margin: 0; max-width: 520px; }
#etat-titre { font-size: 1.15rem; font-weight: 600; }
#etat-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; pointer-events: auto; margin-top: 8px; }
#etat-actions a { color: var(--accent); }

#barre {
  width: calc(var(--barre) + env(safe-area-inset-right));
  padding: max(8px, env(safe-area-inset-top)) env(safe-area-inset-right) max(8px, env(safe-area-inset-bottom)) 0;
  background: #07090e;
  border-left: 1px solid #161c28;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
#barre .groupe { display: flex; flex-direction: column; gap: 6px; align-items: center; }
#barre button, .icone-bouton {
  width: 46px; height: 46px;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--texte);
}
#barre button:hover { background: var(--surface-2); border-color: var(--bord); }
#barre button[aria-pressed="true"] { background: var(--accent); }
svg.icone { width: 24px; height: 24px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }

#saisie {
  position: fixed;
  left: -1000px;
  top: 0;
  width: 10px;
  height: 10px;
  opacity: 0;
  /* Sinon hérité de #vue-ecran : Safari et Firefox refusent alors toute saisie dans le champ. */
  user-select: text;
  -webkit-user-select: text;
}

.annonce {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(21, 27, 39, .95);
  border: 1px solid var(--bord);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: .92rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  max-width: 80vw;
  text-align: center;
}
.annonce.visible { opacity: 1; }

/* Panneaux (menu, dialogue) --------------------------------------------- */
.panneau {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 12px calc(var(--barre) + 12px + env(safe-area-inset-right)) 12px 12px;
  z-index: 10;
}
#dialogue { justify-content: center; padding: 12px; z-index: 11; }
.panneau-contenu {
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panneau-contenu header { display: flex; align-items: center; justify-content: space-between; }
.panneau-contenu h2 { margin: 0; font-size: 1.15rem; }
.panneau-contenu p { margin: 0; }
.fermer { width: 40px; height: 40px; min-height: 0; padding: 0; font-size: 1.4rem; line-height: 1; }
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.grille button { display: flex; align-items: center; gap: 8px; text-align: left; font-size: .9rem; padding: 8px 10px; }
.ligne { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; color: var(--texte); }
.ligne select { flex: 1; max-width: 260px; }
.ligne input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
label.ligne:has(input[type="checkbox"]) { justify-content: flex-start; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.code-association {
  font: 700 2rem/1.2 ui-monospace, Menlo, monospace;
  letter-spacing: .12em;
  text-align: center;
  background: var(--fond);
  border: 1px dashed var(--bord);
  border-radius: 12px;
  padding: 14px;
}
.apercu-texte {
  width: 100%;
  background: var(--fond);
  border: 1px solid var(--bord);
  border-radius: 10px;
  padding: 10px;
  resize: vertical;
  user-select: text;
}
.apercu-image {
  display: block;
  max-width: 100%;
  max-height: 50vh;
  margin: 0 auto;
  border-radius: 8px;
  background: repeating-conic-gradient(#2b3547 0% 25%, #1e2636 0% 50%) 0 0 / 16px 16px;
}
.lien-bouton {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  color: var(--texte);
  text-decoration: none;
}
.lien-bouton:hover { border-color: var(--accent); }
.qr-apk {
  display: block;
  margin: 0 auto;
  background: #fff;
  padding: 8px;
  border-radius: 10px;
}
ol.etapes { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* Rotation demandée ------------------------------------------------------- */
.tourner {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--fond);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
}
.tourner-icone {
  width: 64px; height: 100px;
  border: 4px solid var(--texte);
  border-radius: 12px;
  animation: pivoter 2s ease-in-out infinite;
}
@keyframes pivoter { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (pointer: coarse) {
  body.prise-en-main .tourner { display: flex; }
}
@media (prefers-reduced-motion: reduce) { .tourner-icone { animation: none; transform: rotate(-90deg); } }
