/* css/ar-ui.css
 *
 * Styling for the AR view (#view-ar) only: the camera/AR canvas container,
 * the HUD overlay on top of it, and the states of the elements MindAR's
 * tracking drives (find-a-target hint, active station card, finish button).
 *
 * Does NOT redefine global resets/typography/color tokens — that's
 * css/reset.css and css/styles.css (owned elsewhere). Selectors here are
 * scoped to #view-ar and its children so nothing here leaks into other
 * views.
 *
 * Element IDs are fixed by index.html (see README.md "Module contracts")
 * and js/ar-controller.js (this stream) drives target-found/target-lost via
 * js/app.js toggling the `hidden` attribute on #ar-station-card / #btn-finish
 * and (optionally) an `.is-lost` class on #ar-overlay — see the "target
 * lost" block at the bottom of this file. Everything here also degrades
 * correctly using only the `hidden` attribute, in case that class is never
 * added.
 */

#view-ar {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

/* MindAR appends <video>/<canvas> elements into this element and positions
 * them absolutely, sized from this element's clientWidth/clientHeight — it
 * must be a positioned, fully-sized box with no padding/border eating into
 * that measurement.
 *
 * `z-index: 0` here is load-bearing, not decorative: MindAR sets its
 * injected <video> to inline `z-index: -2` (to sit behind the WebGL canvas,
 * which has no explicit z-index / "auto"). A `position` element only forms
 * a new CSS stacking context when its `z-index` is a number, not `auto`.
 * Without this, #ar-container never contains that negative z-index — it
 * escapes to the nearest ancestor stacking context instead, which puts the
 * camera video BELOW this element's own opaque `background: #000`,
 * permanently hiding the camera passthrough (looks like a black/VR void
 * instead of AR) even though the video is actually playing underneath.
 */
#ar-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  z-index: 0;
}

#ar-container video,
#ar-container canvas {
  /* MindAR sets inline position/size styles on these already; this is just
   * a safety net so nothing here (or in a global reset) adds a border/
   * outline/box-shadow that would show up over the camera feed. */
  border: 0;
  outline: 0;
  display: block;
}

/* HUD layer stacked above the camera feed. Pointer events pass through by
 * default so the camera area itself is never accidentally "clickable" —
 * individual controls opt back in below. */
#ar-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  box-sizing: border-box;
}

/* ---- find-a-target hint ---- */

#ar-hint {
  pointer-events: none;
  margin: 0.5rem auto 0;
  padding: 0.6rem 1.1rem;
  max-width: 22rem;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.3;
  color: #fff;
  background: rgba(15, 15, 20, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  animation: ar-hint-pulse 2.4s ease-in-out infinite;
}

#ar-hint[hidden] {
  display: none;
}

@keyframes ar-hint-pulse {
  0%,
  100% {
    opacity: 0.85;
  }
  50% {
    opacity: 1;
  }
}

/* ---- active station card (bottom sheet) ---- */

#ar-station-card {
  pointer-events: auto;
  width: min(100%, 26rem);
  margin: 0 auto max(0.5rem, env(safe-area-inset-bottom));
  padding: 1rem 1.25rem;
  color: #fff;
  background: rgba(12, 12, 16, 0.68);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 1.1rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
  animation: ar-card-in 0.25s ease-out;
}

#ar-station-card[hidden] {
  display: none;
}

#ar-station-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.25;
}

#ar-station-card p {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.82);
}

#btn-narrate {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #0c0c10;
  background: #fff;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

#btn-narrate:active {
  transform: scale(0.97);
}

#btn-narrate[aria-pressed="true"] {
  background: #fff;
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
}

@keyframes ar-card-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- finish button ---- */

#btn-finish {
  pointer-events: auto;
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: rgba(12, 12, 16, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  cursor: pointer;
}

#btn-finish[hidden] {
  display: none;
}

/* ---- target-lost visual state ----
 * Optional hook: js/app.js may add class "is-lost" to #ar-overlay (or just
 * re-show #ar-hint / hide #ar-station-card via the `hidden` attribute,
 * which is already fully styled above and requires no extra class). When
 * `.is-lost` is present, dim the HUD slightly and re-emphasize the hint so
 * it's clear tracking dropped rather than the app being stuck.
 */
#ar-overlay.is-lost #ar-hint {
  animation: ar-hint-pulse 1.2s ease-in-out infinite;
  border-color: rgba(255, 200, 120, 0.5);
}

#ar-overlay.is-lost #ar-station-card {
  opacity: 0.4;
  filter: saturate(0.6);
  transition: opacity 0.2s ease-out, filter 0.2s ease-out;
}
