:root {
  --bg-top: #12356b;
  --bg-bottom: #07142b;
  --ink: #eaf1ff;
  --ink-dim: #9db4d8;
  --accent: #6ea8ff;
  --north: #e23b4e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* L'attribut `hidden` doit toujours masquer, même si la classe définit `display`. */
[hidden] { display: none !important; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
  user-select: none;
  -webkit-user-select: none;
}

h1 { font-weight: 700; letter-spacing: 0.2px; }

/* ---------- Écran d'activation ---------- */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-top), var(--bg-bottom));
  z-index: 50;
}
.gate-card { max-width: 360px; text-align: center; }
.gate-logo { font-size: 64px; line-height: 1; margin-bottom: 8px; }
.gate-card h1 { font-size: 26px; margin: 8px 0 12px; }
.gate-card p { color: var(--ink-dim); font-size: 15px; line-height: 1.5; margin: 0 0 20px; }
.gate-hint { font-size: 13px; margin-top: 16px; }

.btn-primary {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #06122a;
  font-size: 17px;
  font-weight: 700;
  padding: 16px 28px;
  border-radius: 999px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(110, 168, 255, 0.35);
}
.btn-primary:active { transform: scale(0.98); }

/* ---------- Interface principale ---------- */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 16px);
}

.app-header { text-align: center; margin-bottom: 4px; }
.app-header h1 { font-size: 22px; margin: 0; }
.subtitle { color: var(--ink-dim); font-size: 13px; margin: 4px 0 0; }

/* ---------- Boussole ---------- */
.compass-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.compass {
  position: relative;
  width: min(78vw, 320px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 45%, rgba(110,168,255,0.10), transparent 60%),
    #0c213f;
  box-shadow:
    inset 0 0 0 2px rgba(110,168,255,0.25),
    inset 0 0 40px rgba(0,0,0,0.5),
    0 18px 50px rgba(0,0,0,0.45);
}

/* Triangle fixe en haut = « droit devant le téléphone » */
.compass-fixed-marker {
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 14px solid var(--accent);
  z-index: 4;
}

.dial {
  position: absolute;
  inset: 0;
  transition: transform 0.12s ease-out;
}
.card {
  position: absolute;
  left: 50%;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-dim);
  transform: translateX(-50%);
}
.card-n { top: 12px; color: var(--ink); }
.card-s { bottom: 12px; }
.card-e { right: 12px; top: 50%; left: auto; transform: translateY(-50%); }
.card-o { left: 12px; top: 50%; transform: translateY(-50%); }

/* Aiguille vers Châtel */
.needle {
  position: absolute;
  inset: 0;
  transition: transform 0.12s ease-out;
  z-index: 3;
}
.needle-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(226, 59, 78, 0.45));
}
.compass-center {
  position: absolute;
  top: 50%; left: 50%;
  width: 18px; height: 18px;
  transform: translate(-50%, -50%);
  background: #dfe9ff;
  border-radius: 50%;
  z-index: 5;
  box-shadow: 0 0 0 4px rgba(12,33,63,0.9);
}

/* ---------- Distance ---------- */
.readout { text-align: center; margin-top: 8px; }
.distance { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.distance-value { font-size: 52px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.distance-unit { font-size: 22px; font-weight: 600; color: var(--ink-dim); }
.distance-label { color: var(--ink-dim); font-size: 14px; margin-top: 6px; }
.direction { margin-top: 6px; font-size: 14px; color: var(--accent); font-weight: 600; min-height: 18px; }

.status {
  text-align: center;
  font-size: 13px;
  color: var(--ink-dim);
  min-height: 18px;
  margin: 10px 0 0;
}
.status.warn { color: #ffd166; }
.status.err { color: #ff8a9a; }

/* ---------- Bouton urgence ---------- */
.emergency {
  appearance: none;
  margin-top: auto;
  width: 100%;
  max-width: 420px;
  border: none;
  border-radius: 18px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #e23b4e, #b81d35);
  box-shadow: 0 10px 28px rgba(226,59,78,0.4);
  cursor: pointer;
}
.emergency:active { transform: scale(0.98); }
.emergency-icon { font-size: 22px; }

/* ---------- Diaporama ---------- */
.slideshow {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
}
.slides { position: absolute; inset: 0; }
.slide {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.8s ease-in-out;
}
.slide.active { opacity: 1; }

.slideshow-overlay {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 80px);
  text-align: center;
  pointer-events: none;
}
.slideshow-caption {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 16px rgba(0,0,0,0.8);
  margin: 0 24px 16px;
}
.slideshow-progress {
  width: 60%;
  max-width: 240px;
  height: 4px;
  margin: 0 auto;
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  overflow: hidden;
}
.slideshow-progress span {
  display: block;
  height: 100%;
  width: 100%;
  background: #fff;
  transform-origin: left;
  transform: scaleX(0);
}
.slideshow-close {
  position: absolute;
  top: calc(var(--safe-top) + 16px);
  right: 16px;
  appearance: none;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

/* Au-delà du mobile : on garde l'app centrée et lisible */
@media (min-width: 560px) {
  .app { max-width: 480px; margin: 0 auto; }
}
