/* Componentes base. Los tokens de color/tipografía se definen en index.html. */
:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  /* Para algo que se mueve dentro de la pantalla (el afiche que viaja a la ficha). */
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  /* Movimiento: nada de interfaz dura más de 250ms. */
  --dur-fast: 160ms;
  --dur: 200ms;
  --dur-slow: 250ms;
  /* Escala tipográfica: nueve pasos, nada fuera de ella. */
  --t-2xs: 0.6875rem; /* 11px: contadores */
  --t-xs: 0.75rem; /* 12px: metadatos, pestañas */
  --t-sm: 0.8125rem; /* 13px: texto secundario */
  --t-base: 0.9375rem; /* 15px: interfaz y cuerpo */
  --t-md: 1.125rem; /* 18px: subtítulos, horas */
  --t-lg: 1.375rem; /* 22px: secciones */
  --t-xl: 1.75rem; /* 28px: títulos de ficha */
  --t-2xl: 2.25rem; /* 36px: títulos de pantalla */
  --t-3xl: 2.625rem; /* 42px: la hora de las destacadas */
  /* Radios: tres tamaños y la píldora. */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* App, no documento: sin "tirar para recargar" ni rebote de toda la página (los paneles tienen su propio scroll). */
  overscroll-behavior: none;
}

/* Controles: responden al tocar (sin la espera del doble toque) y mantener apretado no selecciona su texto. */
button,
a,
label.chip,
.tab,
.seg,
.pin {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* iOS agranda la página si un campo tiene letra de menos de 16px. */
@media (pointer: coarse) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

html.has-sheet body {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  display: block;
  flex: none;
}

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

/* Feedback al presionar: rápido y sutil. */
.press {
  transition: transform 160ms var(--ease-out), background-color 160ms var(--ease-out), color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}

.press:active {
  transform: scale(0.97);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
}

/* ---------- Póster y logos ---------- */
.poster {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 2 / 3;
  background: var(--surface-2);
}

.poster img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out);
}

.poster.is-loaded img {
  opacity: 1;
}

/* Mientras el afiche descarga: un brillo suave en vez de un recuadro vacío (se apaga al cargar). */
.poster:not(.is-loaded):not(.is-fallback) {
  background: linear-gradient(90deg, var(--surface-2) 0%, color-mix(in srgb, var(--surface-2) 70%, var(--ink) 8%) 50%, var(--surface-2) 100%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.poster.is-fallback {
  display: flex;
  align-items: flex-end;
  padding: 10px;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
}

.poster.is-fallback::after {
  content: attr(data-title);
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--t-xs);
  font-weight: 600;
  line-height: 1.2;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.vlogo {
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  height: 48px;
  overflow: hidden;
  border-radius: var(--r-md);
  background: #fafaf8;
  box-shadow: inset 0 0 0 1px var(--line);
}

.vlogo img {
  width: 100%;
  height: 100%;
  padding: 12%;
  object-fit: contain;
}

/* Sala sin logo: su inicial en la tipografía de títulos, sobre su propio color. */
.vlogo--text {
  background: color-mix(in srgb, var(--vc, #596c78) 24%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--vc, #596c78) 35%, transparent);
  color: color-mix(in srgb, var(--vc, #596c78) 45%, var(--ink));
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-stretch: 80%;
  font-weight: 800;
  line-height: 1;
}

.vlogo--sm.vlogo--text {
  font-size: var(--t-md);
}

.vlogo--xs.vlogo--text {
  font-size: var(--t-base);
}

.pin-logo--text {
  background: color-mix(in srgb, var(--vc, #596c78) 30%, #fafaf8);
  color: color-mix(in srgb, var(--vc, #596c78) 70%, #151413);
  font-family: var(--font-display);
  font-size: 15px;
  font-stretch: 80%;
}

.vlogo--sm {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
}

/* ---------- Badges y horarios ---------- */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badges:empty {
  display: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--t-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge--uru {
  background: var(--uru-soft);
  color: var(--uru);
}

.badge--uru::before {
  content: "";
  width: 8px;
  height: 8px;
  border: 2px solid var(--uru);
  border-radius: 50%;
  background: #f5c518;
}

.badge--free {
  background: var(--free-soft);
  color: var(--free);
}

.times {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.time {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.time small {
  color: var(--muted);
  font-size: var(--t-xs);
  font-weight: 500;
}

/* ---------- Guardar ---------- */
.save {
  display: inline-grid;
  grid-auto-flow: column;
  place-items: center;
  gap: 6px;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
}

.save[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

.save svg {
  transition: transform var(--dur-fast) var(--ease-out), fill var(--dur-fast) var(--ease-out);
}

/* Feedback con transiciones (no keyframes): se puede tocar dos veces seguidas sin que el corazón salte. */
.save:active svg {
  transform: scale(0.78);
}

/* Íconos con dos variantes (contorno y relleno): el estado activo muestra el relleno. */
.i-on,
.save[aria-pressed="true"] .i-off,
[aria-current="page"] > .i-off {
  display: none;
}

.save[aria-pressed="true"] .i-on,
[aria-current="page"] > .i-on {
  display: block;
}

.save[aria-pressed="true"] svg {
  /* Al soltar, el corazón lleno vuelve a su tamaño un poco más despacio: se nota que "quedó". */
  transition-duration: var(--dur-slow), var(--dur-fast);
}

.save--label {
  padding: 0 14px;
  font-size: var(--t-sm);
  font-weight: 600;
}

/* ---------- Esqueletos de carga ---------- */
.sk {
  display: block;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* ---------- Paneles ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.6);
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(100dvh - max(28px, env(safe-area-inset-top)));
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  box-shadow: 0 -20px 60px rgb(var(--shadow, 0 0 0) / 0.35);
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease-drawer);
}

.sheet.is-open .sheet-backdrop {
  opacity: 1;
}

.sheet.is-open .sheet-panel {
  transform: none;
}

.sheet-panel.is-dragging {
  transition: none;
}

/* El panel recibe el foco al abrirse (para lectores de pantalla y Tab); el anillo va en sus controles, no en el borde. */
.sheet-panel:focus,
.sheet-panel:focus-visible {
  outline: none;
}

/* Panel tapado por otro: queda atrás, un poco más chico (como las hojas apiladas de iOS). */
.sheet.is-covered .sheet-panel {
  transform: translateY(-8px) scale(0.95);
}

.sheet.is-covered .sheet-backdrop {
  opacity: 0;
}

.sheet.is-instant .sheet-panel,
.sheet.is-instant .sheet-backdrop {
  transition: none;
}

.sheet-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 10px;
  background: linear-gradient(var(--surface) 70%, transparent);
  cursor: grab;
}

.sheet-grab {
  position: absolute;
  top: 7px;
  left: 50%;
  width: 38px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  transform: translateX(-50%);
}

.sheet-bar .icon-btn {
  width: 36px;
  height: 36px;
}

.sheet-bar-title {
  flex: 1;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}

.sheet.is-scrolled .sheet-bar-title {
  opacity: 1;
  transform: none;
}

.sheet-bar-actions {
  display: flex;
  gap: 8px;
}

.sheet-body {
  padding: 0 20px calc(32px + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  .sheet-panel {
    top: 0;
    left: auto;
    width: 480px;
    max-height: none;
    border-radius: 0;
    box-shadow: -24px 0 60px rgb(var(--shadow, 0 0 0) / 0.3);
    transform: translateX(100%);
  }

  .sheet-grab {
    display: none;
  }

  .sheet-bar {
    cursor: auto;
  }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar, 0px) + 20px + env(safe-area-inset-bottom));
  z-index: 1100;
  padding: 10px 16px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--t-base);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px) scale(0.96);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
}

.toast.has-action.is-visible {
  pointer-events: auto;
}

.toast-action {
  padding: 4px 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- Mapa ---------- */
.mapx,
.mapx-canvas,
.mapx-map {
  position: absolute;
  inset: 0;
}

.mapx-canvas {
  background: var(--map-land);
}

.mapx-canvas.is-loading::after {
  content: "Cargando mapa…";
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: var(--t-base);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

.mapx-error {
  display: grid;
  place-items: center;
  height: 100%;
  margin: 0;
  color: var(--muted);
}

.mapx-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  padding-top: 40px;
  background: linear-gradient(180deg, transparent, var(--map-fade) 45%);
  pointer-events: none;
}

.mapx-panel > * {
  pointer-events: auto;
}

.mapx-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  order: 2;
  padding: 0 16px 12px;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--glass-2);
  backdrop-filter: blur(12px);
}

.seg button {
  padding: 7px 12px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  font-size: var(--t-sm);
  font-weight: 600;
  white-space: nowrap;
}

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

/* Indicador deslizante (CU.segThumb): la copia activa se revela con clip-path sobre la opción elegida. */
.seg.has-thumb {
  position: relative;
}

.seg.has-thumb button[aria-pressed="true"] {
  background: transparent;
  color: var(--muted);
}

.seg-copy {
  position: absolute;
  inset: 0;
  display: flex;
  padding: 3px;
  border-radius: inherit;
  background: var(--ink);
  color: var(--bg);
  pointer-events: none;
  transition: clip-path var(--dur-slow) var(--ease-in-out);
}

.seg-copy span {
  padding: 7px 12px;
  font-size: var(--t-sm);
  font-weight: 600;
  white-space: nowrap;
}

.mapx-locate {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--glass-2);
  backdrop-filter: blur(12px);
}

.mapx-list {
  display: flex;
  gap: 10px;
  margin: 0;
  padding: 0 16px 14px;
  overflow-x: auto;
  list-style: none;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 16px;
  scrollbar-width: none;
}

.vrow {
  flex: 0 0 min(84%, 340px);
  align-self: flex-end;
  max-height: 34dvh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--glass-2);
  backdrop-filter: blur(16px);
  scroll-snap-align: start;
  transition: border-color 160ms var(--ease-out);
}

.vrow.is-selected {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.vrow.is-empty .vrow-main {
  opacity: 0.55;
}

.vrow-main {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 0;
  background: transparent;
  text-align: left;
}

.vrow-text {
  display: grid;
  flex: 1;
  min-width: 0;
}

/* Dos líneas antes que "Cinemateca Ur...": el nombre es lo que se busca en el carrusel. */
.vrow-text strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: var(--t-base);
  line-height: 1.2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-wrap: balance;
}

.vrow-text span,
.vrow-meta small {
  color: var(--muted);
  font-size: var(--t-xs);
}

.vrow-meta {
  display: grid;
  justify-items: end;
}

.vrow-meta b {
  font-variant-numeric: tabular-nums;
}

.vrow-films {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0 12px 10px;
  list-style: none;
}

.vrow-films li {
  display: grid;
  gap: 6px;
}

.vrow-film {
  padding: 0;
  border: 0;
  background: none;
  font-weight: 600;
  text-align: left;
}

.vrow-films .time {
  padding: 2px 6px;
  font-size: var(--t-xs);
}

.vrow-empty {
  margin: 0;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: var(--t-sm);
}

.vrow-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: calc(100% - 24px);
  margin: 0 12px 12px;
  padding: 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: var(--t-sm);
  font-weight: 600;
}

.vrow-actions {
  display: flex;
  gap: 8px;
  margin: 0 12px 10px;
}

.vrow-actions .vrow-more {
  flex: 1;
  width: auto;
  margin: 0;
}

/* Tarjeta del camino ("Cómo llegar"): ocupa el lugar libre a la izquierda del botón de ubicación. */
.mapx-route {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 4px 10px;
  min-width: 0;
  min-height: 42px;
  padding: 6px 6px 6px 14px;
  border-radius: var(--r-md);
  background: var(--glass-2);
  backdrop-filter: blur(12px);
  font-size: var(--t-sm);
  line-height: 1.3;
}

/* Orden de la lista: mientras se ve un camino, la tarjeta de la ruta ocupa su lugar. */
.mapx-route:not([hidden]) ~ .mapx-order {
  display: none;
}

.mapx-route-text {
  flex: 1;
  min-width: 0;
}

.mapx-route-text b {
  font-variant-numeric: tabular-nums;
}

.mapx-route-link {
  flex: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.mapx-route-x {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

/* Pines: logo de la sala en una píldora con punta; de cerca suman la próxima función.
   Independientes en claro (se destacan), comerciales en gris, la elegida en rojo. */
.pin {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.pin-body {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--pin-bg);
  color: var(--pin-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgb(var(--shadow, 0 0 0) / 0.35);
  transform-origin: 50% calc(100% + 7px);
  transition: transform var(--dur) var(--ease-out), background-color var(--dur) var(--ease-out), opacity var(--dur) var(--ease-out);
}

.pin-body::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 9px;
  height: 9px;
  border-radius: 0 0 2px 0;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}

.pin-logo {
  position: relative;
  z-index: 1;
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border-radius: 50%;
  background: #fafaf8;
  color: #151413;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.pin-logo img {
  width: 100%;
  height: 100%;
  padding: 3px;
  object-fit: contain;
}

.vlogo--photo img,
.pin-logo--photo img {
  padding: 0;
  object-fit: cover;
}

.pin-label {
  position: relative;
  z-index: 1;
  padding-right: 8px;
}

.pin-label b {
  margin-right: 6px;
}

.pin--com .pin-body {
  background: var(--pin-com-bg);
  color: var(--pin-com-ink);
}

.pin.is-empty .pin-body {
  opacity: 0.55;
}

/* Grupo de salas cercanas: un número; al tocarlo se acerca. */
.pin--cluster .pin-body {
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  background: var(--pin-bg);
  color: var(--pin-ink);
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 0 0 3px rgb(var(--shadow, 0 0 0) / 0.18), 0 4px 14px rgb(var(--shadow, 0 0 0) / 0.35);
}

@media (hover: hover) and (pointer: fine) {
  .pin:hover .pin-body {
    transform: scale(1.08);
  }
}

.pin.is-selected .pin-body {
  background: var(--pin-sel-bg);
  color: var(--pin-sel-ink);
  opacity: 1;
  transform: scale(1.06);
}

.me-dot {
  width: 16px;
  height: 16px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #2f80ed;
  box-shadow: 0 0 0 8px rgb(47 128 237 / 0.22);
}

.maplibregl-ctrl-group {
  border-radius: var(--r-md) !important;
}

@media (min-width: 900px) {
  .mapx-panel {
    top: 72px;
    right: auto;
    width: 400px;
    padding-top: 0;
    background: none;
  }

  .mapx-head {
    order: 0;
    padding: 0 16px 12px;
  }

  .mapx-list {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-snap-type: none;
  }

  .vrow {
    flex: none;
    align-self: stretch;
    max-height: none;
    overflow: visible;
  }
}

/* Salidas más rápidas que las entradas: el sistema responde, no hace esperar. */
.sheet:not(.is-open) .sheet-panel {
  transition-duration: var(--dur);
}

.sheet:not(.is-open) .sheet-backdrop,
.toast:not(.is-visible) {
  transition-duration: 140ms;
}

/* Movimiento reducido: sin desplazamientos ni escalas, pero se conservan los fundidos que ayudan a entender. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
  }

  .press:active {
    transform: none;
  }

  .toast,
  .toast.is-visible {
    transform: translateX(-50%);
  }

  .seg-copy {
    transition: none;
  }

  .save svg,
  .save:active svg {
    transform: none;
  }

  .sheet-panel,
  .sheet.is-open .sheet-panel,
  .sheet.is-covered .sheet-panel {
    transform: none;
    opacity: 0;
    transition: opacity var(--dur) linear;
  }

  .sheet.is-open .sheet-panel {
    opacity: 1;
  }
}
