/* Audioguide : l'appareil prêté à l'accueil. Plastique crème, écran LCD vert, clavier 3 × 4.
   C'est un objet, pas une carte d'interface : il a des coins arrondis modestes, un relief et une ombre portée.
   Rangé, il se réduit à une pastille ; ouvert, le boîtier se déplie au-dessus d'elle. */

.ag {
  --ag-plastic: #efe9dc;
  --ag-plastic-2: #e3dccb;
  --ag-plastic-3: #d6ceba;
  --ag-edge: #cbc0a7;
  --ag-ink: #2b2922;
  --ag-print: #5d5647;
  --ag-lcd: #9fb28a;
  --ag-seg: #1d2618;
  --ag-bezel: #3a3a33;
  --ag-led-off: #5b2620;
  --ag-led-on: #ff3b2f;
  position: relative;
  display: inline-block;
  font-family: var(--f-sign);
  color: var(--ag-ink);
  -webkit-tap-highlight-color: transparent;
}

/* Placement conseillé du conteneur : en bas à droite de la visite, au-dessus de la zone de sécurité. */
.ag-dock {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  z-index: 40;
}

/* Remise à zéro sans poids : les règles de chaque bouton l'emportent. */
:where(.ag) button { font: inherit; color: inherit; margin: 0; }
.ag :focus-visible { outline: 2px solid var(--bordeaux); outline-offset: 2px; }

/* Voyant */
.ag-led {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ag-led-off);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.45);
}
.ag[data-state='playing'] .ag-led {
  background: var(--ag-led-on);
  box-shadow: 0 0 0 1px rgba(120, 0, 0, 0.35), 0 0 6px 1px rgba(255, 59, 47, 0.65);
  animation: ag-blink 1s steps(1, end) infinite;
}
@keyframes ag-blink {
  50% { background: var(--ag-led-off); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.45); }
}

/* Pastille : l'appareil rangé */
.ag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.4rem 0.45rem 0.4rem 0.75rem;
  background: var(--ag-plastic);
  border: 1px solid var(--ag-edge);
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 2px 0 var(--ag-edge), 0 12px 24px -16px rgba(0, 0, 0, 0.7);
  font-stretch: 80%;
  font-weight: 700;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.ag-pill:hover { background: #f5f0e6; }
.ag-pill:active { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 1px 0 var(--ag-edge); }
.ag-pill__n {
  min-width: 3.4ch;
  padding: 0.22rem 0.4rem;
  background: var(--ag-lcd);
  color: var(--ag-seg);
  border-radius: 2px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
  font-family: var(--f-admin);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-align: center;
}

/* Le boîtier */
.ag-device {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(252px, calc(100vw - 2rem));
  max-height: calc(100dvh - 6rem);   /* remplacé à l'ouverture par l'espace libre sous l'en-tête */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.55rem 0.8rem 0.8rem;
  background: var(--ag-plastic);
  border: 1px solid var(--ag-edge);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75), inset 0 -3px 0 rgba(0, 0, 0, 0.06), 0 26px 40px -22px rgba(0, 0, 0, 0.75);
}
.ag[data-side='left'] .ag-device { right: auto; left: 0; }
.ag[data-drop='down'] .ag-device { bottom: auto; top: calc(100% + 10px); }
.ag-device:focus { outline: none; }
.ag-device:focus-visible { outline: 2px solid var(--bordeaux); outline-offset: 3px; }
.ag[data-open='true'] .ag-device { animation: ag-unfold 0.16s var(--ease-out, ease-out) both; }
@keyframes ag-unfold { from { transform: translateY(8px); opacity: 0; } }

.ag-head { display: flex; align-items: center; gap: 0.55rem; min-height: 44px; margin-bottom: 0.25rem; }
.ag-brand {
  font-stretch: 75%;
  font-weight: 800;
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ag-print);
}
/* Grille du haut-parleur */
.ag-grille {
  flex: 1;
  height: 9px;
  background: repeating-linear-gradient(90deg, #bfb49a 0 2px, transparent 2px 5px);
  border-radius: 1px;
}
.ag-close {
  min-width: 44px;
  min-height: 44px;
  margin-right: -0.4rem;
  padding: 0 0.4rem;
  background: none;
  border: 0;
  font-stretch: 80%;
  font-weight: 700;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ag-print);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
  cursor: pointer;
}
.ag-close:hover { color: var(--ag-ink); }
/* Sans libellé court (t.ui.audio absent), le libellé complet prend la place de l'étiquette. */
.ag-head--long .ag-brand { display: none; }
.ag-head--long .ag-close { white-space: nowrap; }

/* Écran LCD : cristaux liquides verts dans un cadre sombre, segments fantômes visibles */
.ag-lcd {
  position: relative;
  padding: 0.35rem 0.5rem 0.3rem;
  background: var(--ag-lcd) linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.05));
  color: var(--ag-seg);
  border: 4px solid var(--ag-bezel);
  border-radius: 4px;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.7);
}
.ag-icons { display: flex; justify-content: space-between; align-items: center; height: 10px; }
.ag-icons svg { width: auto; height: 10px; overflow: visible; }
.ag-ico { fill: currentColor; stroke: currentColor; opacity: 0.09; }
.ag-ico[fill='none'] { fill: none; }
.ag-ico.on { opacity: 1; }
.ag-digits { width: auto; height: 46px; margin: 0.2rem 0 0.15rem auto; overflow: visible; }
.ag-seg { fill: var(--ag-seg); opacity: 0.07; }
.ag-seg.on { opacity: 1; }
.ag-lcd__line {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 1.35em;
  font-family: var(--f-admin);
  font-weight: 500;
  font-size: 0.68rem;
  line-height: 1.35;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}

/* Voyant et consigne imprimée sur le boîtier */
.ag-row { display: flex; align-items: flex-start; gap: 0.55rem; min-height: 2.9rem; margin: 0.6rem 0.1rem 0.55rem; }
.ag-row .ag-led { margin-top: 0.3rem; }
.ag-msg { font-family: var(--f-admin); font-size: 0.7rem; line-height: 1.4; color: var(--ag-print); }

/* Clavier */
.ag-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.ag-key {
  display: grid;
  place-items: center;
  min-height: 46px;
  padding: 0;
  background: var(--ag-plastic-2);
  border: 1px solid #c4b99f;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), 0 2px 0 #b6aa8e;
  font-stretch: 90%;
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.05s linear, box-shadow 0.05s linear;
}
.ag-key:active, .ag-key.is-down { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 0 0 #b6aa8e; }
.ag-key--c { background: var(--ag-plastic-3); font-size: 1rem; font-weight: 700; }
.ag-key--play { background: var(--bordeaux); border-color: #4a141d; color: #f7f1ea; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 2px 0 #3d1018; }
.ag-key--play:hover { background: var(--bordeaux-2); }
.ag-key svg { width: 13px; height: 15px; fill: currentColor; }

.ag-stop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 44px;
  margin-top: 9px;
  background: var(--ag-bezel);
  color: var(--ag-plastic);
  border: 1px solid #25251f;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 2px 0 #1b1b17;
  font-stretch: 80%;
  font-weight: 700;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
}
.ag-stop:active { transform: translateY(2px); box-shadow: 0 0 0 #1b1b17; }
.ag-stop svg { width: 9px; height: 9px; fill: currentColor; }

.ag-note, .ag-sticker { font-family: var(--f-admin); line-height: 1.4; color: var(--ag-print); }
.ag-note { margin: -0.15rem 0.1rem 0.6rem; font-size: 0.64rem; }
.ag-sticker {
  margin-top: 0.6rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--ag-edge);
  font-size: 0.62rem;
  letter-spacing: 0.02em;
}

.ag-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Peu de place entre l'en-tête et la pastille (téléphone, écran bas) : l'essentiel seulement.
   L'attribut est posé par audioguide.js, qui mesure l'espace réellement libre. */
.ag[data-compact] :is(.ag-note, .ag-sticker) { display: none; }
.ag[data-compact] .ag-row { min-height: 0; }
.ag[data-compact] .ag-key { min-height: 44px; }
.ag[data-compact] .ag-digits { height: 40px; }

@media (prefers-reduced-motion: reduce) {
  .ag[data-state='playing'] .ag-led { animation: none; }
  .ag[data-open='true'] .ag-device { animation: none; }
  .ag-key, .ag-key:active, .ag-key.is-down, .ag-stop:active, .ag-pill:active { transition: none; transform: none; }
}
