/* ============================================================
   Tour virtual Sarria → Santiago
   El layout responsive se resuelve con CONTAINER QUERIES sobre .stage,
   para que el marco de 390 px de ?preview=1 use las mismas reglas
   que un móvil real. Punto de corte: 640 px de ancho.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

/* Variantes de copia por tamaño. El valor por defecto va aquí arriba a
   propósito: declarado al final pisaría a las container queries. */
.only-mobile { display: none; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--mist);
  font-family: var(--font-base);
  color: var(--graphite);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green-sendero); }
a:hover { color: var(--graphite); }

/* Todo el espaciado lo llevan los `gap` de los contenedores: los márgenes
   por defecto de párrafos y titulares falsearían las alturas de las tarjetas. */
.app h1, .app h2, .app h3, .app p { margin: 0; }

.app {
  width: 100%;
  height: 100dvh;
  min-height: 560px;
  display: flex;
  flex-direction: column;
  background: var(--mist);
  overflow: hidden;
}

/* ---------- barra de vista previa (solo ?preview=1) ---------- */

.preview-bar {
  flex: none;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--ink-100);
  border-bottom: 1px solid var(--mist);
}
.preview-bar__label {
  font-size: var(--text-eyebrow);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--gray);
}
.preview-bar__group {
  display: flex;
  gap: 4px;
  background: var(--white);
  border-radius: var(--radius-pill);
  padding: 4px;
}
.preview-bar__btn {
  font-family: inherit;
  border: none;
  border-radius: var(--radius-pill);
  padding: 8px 18px;
  background: transparent;
  color: var(--graphite);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dur-base) var(--ease-out);
}
.preview-bar__btn:hover { background: var(--ink-100); }
.preview-bar__btn[aria-pressed="true"] {
  background: var(--green-ways);
  color: var(--white);
  cursor: default;
}

/* ---------- escenario ---------- */

.app__viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage {
  container-type: size;
  container-name: stage;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--mist);
}

/* Marco de móvil de la herramienta de pruebas */
.stage--framed {
  width: 390px;
  height: min(844px, calc(100% - 32px));
  flex: none;
  border-radius: 44px;
  border: 10px solid var(--graphite);
  box-shadow: var(--shadow-box);
}

/* Especificidad doble a propósito: la hoja de Mapbox/MapLibre se inyecta
   después de esta y su `.mapboxgl-map { position: relative }` ganaría. */
.stage .stage__map {
  position: absolute;
  inset: 0;
  z-index: 0;
  isolation: isolate;
}

/* El punto del peregrino lo inserta tour.js dentro del contenedor del mapa */
.walker {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--green-ways);
  border: 4px solid var(--white);
  pointer-events: none;
  z-index: 2;
  will-change: transform;
}

.concha {
  position: absolute;
  top: 32px;
  right: 32px;
  width: 44px;
  height: auto;
  pointer-events: none;
  z-index: 4;
}

.maplibregl-ctrl-attrib,
.mapboxgl-ctrl-attrib { font-family: var(--font-base); font-size: 11px; }

/* ---------- botón de marca ---------- */

.btn {
  font-family: var(--font-base);
  font-weight: 700;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  box-shadow: none;
  font-size: 18px;
  padding: 16px 32px;
  background: var(--green-ways);
  color: var(--white);
  border: 2px solid var(--green-ways);
  transition: background var(--dur-base) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--green-700); border-color: var(--green-700); }
.btn:active { background: var(--green-800); border-color: var(--green-800); transform: scale(0.98); }

/* ---------- portada ---------- */

.intro {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 40px 64px 48px;
  overflow: auto;
  color: var(--white);
  background: linear-gradient(90deg, rgba(46,46,45,0.78) 0%, rgba(46,46,45,0.5) 45%, rgba(46,46,45,0) 80%);
}
.intro__logo { width: 220px; height: auto; flex: none; }
.intro__body {
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.6vh, 24px);
  margin-top: auto;
  margin-bottom: auto;
  align-items: flex-start;
}
.intro__eyebrow {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}
.intro__title {
  font-size: clamp(40px, 7vh, 64px);
  font-weight: 800;
  line-height: var(--lh-display);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}
.intro__text {
  font-size: 20px;
  line-height: var(--lh-base);
  max-width: 540px;
  text-wrap: pretty;
}
.intro__facts {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  font-size: 16px;
  font-weight: 700;
}

/* ---------- cabecera ---------- */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-box);
}

.header {
  position: absolute;
  top: 24px;
  left: 24px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 28px 16px 24px;
  max-width: calc(100% - 140px);
}
.header__logo { width: 160px; height: auto; display: block; }
.header__divider { width: 1px; align-self: stretch; background: var(--mist); }
.header__text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.header__eyebrow {
  font-size: var(--text-eyebrow);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--green-sendero);
}
.header__route { font-size: var(--text-h4); font-weight: 700; line-height: var(--lh-snug); }

/* ---------- botón de mapa ---------- */

.map-btn {
  position: absolute;
  top: 100px;
  right: 24px;
  z-index: 2;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  color: var(--graphite);
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px 20px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-box);
  transition: background var(--dur-base) var(--ease-out);
}
.map-btn:hover { background: var(--sprout); }

/* ---------- panel de ajustes ---------- */

.panel {
  position: absolute;
  top: 160px;
  right: 24px;
  width: 380px;
  max-width: calc(100% - 48px);
  max-height: calc(100% - 184px);
  overflow: auto;
  z-index: 3;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel__title { font-size: var(--text-h4); font-weight: 700; line-height: var(--lh-snug); }
.panel__close {
  width: 44px;
  height: 44px;
  flex: none;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--ink-100);
  color: var(--graphite);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-base) var(--ease-out);
}
.panel__close:hover { background: var(--mist); }
.panel__group { display: flex; flex-direction: column; gap: 10px; }
.panel__label {
  font-size: var(--text-eyebrow);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--green-sendero);
}
.panel__hint { font-size: var(--text-small); line-height: var(--lh-small); color: var(--gray); }
.panel__note {
  background: var(--sprout);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: var(--text-small);
  line-height: var(--lh-small);
  color: var(--graphite);
}

/* Segmentado de cámara */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg__btn {
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--ink-100);
  color: var(--graphite);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dur-base) var(--ease-out);
}
.seg__btn:hover { background: var(--mist); }
.seg__btn[aria-pressed="true"] {
  background: var(--green-ways);
  color: var(--white);
  cursor: default;
}

/* Tarjetas de tipo de mapa */
#mapList { display: flex; flex-direction: column; gap: 10px; }
.map-opt {
  font-family: inherit;
  text-align: left;
  border: 2px solid var(--mist);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--white);
  color: var(--graphite);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color var(--dur-base) var(--ease-out);
}
.map-opt:hover { border-color: var(--green-ways); }
.map-opt[aria-pressed="true"] {
  border-color: var(--green-ways);
  background: var(--sprout);
  cursor: default;
}
.map-opt__name { font-size: 16px; font-weight: 800; }
.map-opt__desc { font-size: var(--text-small); line-height: var(--lh-small); color: var(--ink-700); }

/* ---------- ficha de punto de interés ---------- */

.poi {
  position: absolute;
  top: 160px;
  right: 24px;
  width: 340px;
  max-width: calc(100% - 48px);
  overflow: hidden;
  z-index: 2;
}
.poi__img {
  width: 100%;
  height: 190px;
  background-color: var(--mist);
  background-size: cover;
  background-position: center;
}
.poi__body { padding: 20px 24px 24px; display: flex; flex-direction: column; gap: 8px; }
.poi__eyebrow {
  font-size: var(--text-eyebrow);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--green-sendero);
}
.poi__title { font-size: var(--text-h4); font-weight: 700; line-height: var(--lh-snug); }
.poi__text { font-size: var(--text-body); line-height: var(--lh-base); text-wrap: pretty; }

/* Escritorio bajo (<760 px de alto): ficha horizontal arriba a la izquierda */
@container stage (max-height: 760px) {
  .poi {
    top: 112px;
    left: 24px;
    right: auto;
    width: 460px;
    display: flex;
  }
  .poi__img { width: 104px; height: auto; min-height: 112px; flex: none; align-self: stretch; }
}

/* ---------- barra inferior ---------- */

.bar {
  position: absolute;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  width: calc(100% - 48px);
  max-width: 1180px;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 2;
}
.bar__row { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }

.play {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--green-ways);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--dur-base) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.play:hover { background: var(--green-700); }
.play:active { background: var(--green-800); transform: scale(0.98); }

.stats { display: flex; flex-direction: column; gap: 2px; min-width: 170px; }
.stats__km { display: flex; align-items: baseline; gap: 6px; }
.stats__km-big {
  font-size: 28px;
  font-weight: 800;
  line-height: var(--lh-tight);
  display: flex;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.stats__km-total { font-size: 16px; color: var(--gray); }
.stats__up { font-size: 15px; color: var(--graphite); line-height: var(--lh-small); }
.stats__up strong { color: var(--green-sendero); font-variant-numeric: tabular-nums; }
.stats__up span { color: var(--gray); }

/* Perfil de altitud */
.profile { flex: 1; min-width: 240px; height: 72px; position: relative; }
.profile__inner { display: flex; gap: 8px; width: 100%; height: 100%; }
.profile__scale {
  position: relative;
  width: 46px;
  flex: none;
  font-size: var(--text-eyebrow);
  font-weight: 700;
  color: var(--gray);
  text-align: right;
}
.profile__scale span {
  position: absolute;
  right: 0;
  transform: translateY(-50%);
  white-space: nowrap;
}
.profile__plot { position: relative; flex: 1; min-width: 0; height: 100%; }
.profile__svg { display: block; overflow: visible; }
.profile__bubble {
  position: absolute;
  left: 0;
  top: 94%;
  transform: translate(-50%, -135%);
  background: var(--green-sendero);
  color: var(--white);
  font-size: var(--text-eyebrow);
  font-weight: 700;
  line-height: 1;
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.speed {
  flex: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--green-sendero);
  background: transparent;
  border: 2px solid var(--green-ways);
  border-radius: var(--radius-pill);
  padding: 12px 22px;
  cursor: pointer;
  transition: background var(--dur-base) var(--ease-out);
}
.speed:hover { background: var(--sprout); }

/* Pestañas de días */
.days { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.day {
  font-family: inherit;
  text-align: left;
  border: none;
  flex: none;
  min-width: 150px;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  background: var(--ink-100);
  color: var(--graphite);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background var(--dur-base) var(--ease-out);
}
.day:hover { background: var(--mist); }
.day__label { font-size: 16px; font-weight: 800; }
.day__route { font-size: var(--text-small); line-height: var(--lh-small); color: var(--ink-700); }
.day[aria-pressed="true"] { background: var(--green-ways); color: var(--white); }
.day[aria-pressed="true"]:hover { background: var(--green-ways); }
.day[aria-pressed="true"] .day__route { color: var(--white); font-weight: 700; }

/* ---------- fin de etapa ---------- */

/* La capa ocupa todo el escenario para centrar la tarjeta donde siempre,
   pero no intercepta clics: así la barra sigue pulsable y se puede repetir
   la etapa o saltar de día sin cerrar el cartel. */
.end {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-bottom: 220px;
  pointer-events: none;
}
/* El velo es aparte y acaba encima de la barra, para no apagar unos
   controles que sí funcionan. */
.end::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--bar-h, 200px) + 48px);
  background: rgba(46, 46, 45, 0.28);
}
.end__card {
  position: relative;
  width: 440px;
  max-width: 100%;
  padding: 36px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
  pointer-events: auto;
}
/* Sin círculo gris de serie: una aspa fina que solo se apoya en un fondo
   suave al pasar por encima. El área de pulsación sigue siendo de 44 px. */
.end__close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--gray);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
}
.end__close:hover { background: var(--ink-100); color: var(--graphite); }
.end__close:active { background: var(--mist); }
.end__close:focus-visible { outline: 2px solid var(--green-ways); outline-offset: 2px; }
/* El aspa no debe ser el objetivo del clic: con trazos finos, pulsar «entre»
   las líneas haría que el objetivo fuese el SVG y no el botón. */
.end__close svg { pointer-events: none; }
.end__eyebrow {
  font-size: var(--text-eyebrow);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--green-sendero);
  padding-right: 52px;   /* deja sitio al botón de cerrar */
}
.end__title { font-size: var(--text-h2); font-weight: 800; line-height: var(--lh-tight); }
.end__text { font-size: var(--text-body); line-height: var(--lh-base); margin-bottom: 12px; text-wrap: pretty; }

/* ============================================================
   MÓVIL · ancho de contenedor ≤ 640 px
   ============================================================ */

@container stage (max-width: 640px) {
  .concha { top: 22px; right: 18px; width: 30px; }

  .intro {
    background: linear-gradient(0deg, rgba(46,46,45,0.85) 0%, rgba(46,46,45,0.55) 55%, rgba(46,46,45,0.2) 100%);
    justify-content: flex-end;
    padding: 24px 24px 40px;
  }
  .intro__logo { position: absolute; top: 24px; left: 24px; width: 160px; }
  .intro__body { gap: 18px; margin-top: 0; margin-bottom: 0; }
  .intro__eyebrow { font-size: var(--text-eyebrow); }
  .intro__title { font-size: 38px; line-height: 1.08; }
  .intro__text { font-size: 17px; }
  .intro__facts { gap: 18px; font-size: 15px; }
  .intro .btn { width: 100%; }
  .only-desktop { display: none; }
  .only-mobile { display: inline; }

  .header {
    top: 12px;
    left: 12px;
    right: 62px;
    max-width: none;
    border-radius: 18px;
    padding: 12px 16px;
    gap: 2px;
    flex-direction: column;
    align-items: stretch;
  }
  .header__logo, .header__divider { display: none; }
  .header__eyebrow-long { display: none; }
  .header__route { font-size: 17px; }

  /* El botón de mapa pasa a icono y ocupa la esquina de la concha, al lado
     del bloque del día. La concha vuelve en cuanto se sale del tour. */
  .started .concha { display: none; }

  .map-btn {
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    padding: 0;
    gap: 0;
    justify-content: center;
  }
  /* Oculto a la vista, no para el lector de pantalla: sin esto el botón
     se quedaría sin nombre accesible. */
  .map-btn__text {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    max-height: 80%;
    border-radius: 24px 24px 0 0;
    padding: 20px;
  }

  /* Anclada sobre la barra, no flotando a media altura: así el mapa queda en
     una sola franja continua y la ficha no puede solaparse con la barra.
     --bar-h la publica tour.js, porque la barra cambia de alto según el ancho. */
  .poi {
    top: auto;
    bottom: calc(var(--bar-h, 240px) + 46px);
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
    display: flex;
  }
  .poi__img { width: 84px; height: auto; min-height: 96px; flex: none; align-self: stretch; }
  .poi__body { padding: 12px 14px; gap: 5px; }
  .poi__eyebrow { font-size: 11px; }
  .poi__title { font-size: 18px; }
  .poi__text {
    font-size: 14px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .bar {
    left: 12px;
    right: 12px;
    bottom: 34px;
    width: auto;
    max-width: none;
    transform: none;
    padding: 16px;
    gap: 12px;
  }
  .bar__row { gap: 12px; }
  .stats { flex: 1; min-width: 0; }
  .profile { flex: 1 1 100%; order: 5; height: 48px; min-width: 0; }
  .speed { padding: 12px 18px; }
  .speed__long { display: none; }

  .days {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin: 0 -16px;
    padding: 0 16px 2px;
  }

  .end { padding-bottom: 180px; }
  .end::before { bottom: calc(var(--bar-h, 200px) + 46px); }
  .end__card { padding: 24px; }
  .end__close { top: 10px; right: 10px; }
  /* Medido: con más de 44 px el antetítulo parte «KM» a una segunda línea. */
  .end__eyebrow { padding-right: 44px; }
  .end__title { font-size: var(--text-h3); }
}

/* Pantallas estrechas (iPhone SE y similares): sin estos ajustes el contador
   «10,7 km de 22,2» y la línea de desnivel parten en dos líneas. */
@container stage (max-width: 400px) {
  .play { width: 56px; height: 56px; }
  .stats__km-big { font-size: 24px; }
  .stats__km-total { font-size: 14px; }
  .stats__up { font-size: 13px; }
  .speed { padding: 10px 14px; font-size: 14px; }
  .bar { padding: 14px; }
}

/* Pantallas realmente estrechas: el título no debe desbordar */
@container stage (max-width: 380px) {
  .intro__title { font-size: 32px; }
}

/* ---------- utilidades ---------- */

[hidden] { display: none !important; }

/* Accesible para lectores de pantalla, invisible en pantalla */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; }
}
