:root {
  --noche: #0e1530;
  --noche-media: #1a2447;
  --horizonte: #2b3562;
  --bruma: #aab3d4;
  --texto: #ecebf4;
  --luz: #f0c27b;
  --luz-rgb: 240, 194, 123;
  --luz-tenue: rgba(var(--luz-rgb), 0.16);
  --linea: rgba(236, 235, 244, 0.16);
  --radio: 12px;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--texto);
  background: var(--noche);
  overflow-x: hidden;
}

/* Fondo fijo: cielo de atardecer */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(120% 55% at 50% 108%, rgba(var(--luz-rgb), 0.26), transparent 62%),
    linear-gradient(180deg, var(--noche) 0%, var(--noche-media) 62%, var(--horizonte) 100%);
}

#luces {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

a { color: var(--luz); text-underline-offset: 3px; }

:focus-visible {
  outline: 2px solid var(--luz);
  outline-offset: 3px;
  border-radius: 6px;
}

.visualmente-oculto {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Botones ---------- */
.boton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 2rem;
  font: 600 1rem/1 var(--sans);
  letter-spacing: 0.01em;
  color: #1b1630;
  background: var(--luz);
  border: 0;
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 0 0 0 var(--luz-tenue);
}
.boton:hover { background: #f6d196; box-shadow: 0 0 0 6px var(--luz-tenue); }
.boton:active { transform: translateY(1px); }
.boton[disabled] { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.enlace {
  color: var(--bruma);
  text-decoration: none;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid transparent;
}
.enlace:hover { color: var(--texto); border-bottom-color: var(--bruma); }

/* ---------- Botón de música ---------- */
.musica {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1rem;
  font: 500 0.875rem/1 var(--sans);
  color: var(--texto);
  background: rgba(14, 21, 48, 0.55);
  border: 1px solid var(--linea);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.musica:hover { border-color: var(--luz); }
.musica[aria-pressed="true"] { color: var(--luz); border-color: var(--luz); }

/* ---------- Portada ---------- */
.portada {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 4.25rem 1.5rem 1.75rem;
}

/* El retrato ocupa todo el espacio que queda libre sobre el texto, de modo que
   la portada completa (retrato, nombre y botones) cabe en cualquier pantalla. */
.retrato-caja {
  flex: 1 1 0;
  min-height: 150px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: clamp(1rem, 3vh, 2rem);
}
.portada-texto { flex: none; display: flex; flex-direction: column; align-items: center; }

.retrato {
  height: clamp(150px, 30vh, 420px); /* respaldo para navegadores sin unidades de contenedor */
  aspect-ratio: 1;
  border-radius: 50%;
  position: relative;
  background: radial-gradient(circle at 50% 45%, #fff3d6 0%, var(--luz) 28%, rgba(var(--luz-rgb), 0.28) 55%, transparent 72%);
  filter: blur(0.3px);
}
@supports (height: 1cqh) {
  .retrato-caja { container-type: size; }
  .retrato { height: min(calc(100cqh - 24px), 420px, 74vw); }
}

/* Pantallas anchas: el retrato a un lado del texto, mucho más grande */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  .portada { flex-direction: row; justify-content: center; gap: clamp(2rem, 6vw, 6rem); padding: 3rem 4vw; }
  .retrato-caja { flex: 0 0 auto; width: auto; min-height: 0; margin: 0; container-type: normal; }
  .retrato { height: auto; width: min(40vw, 72vh, 540px); }
  .portada-texto { align-items: flex-start; text-align: left; max-width: 36rem; }
  .acciones { justify-content: flex-start; }
}
.retrato.con-foto {
  background: none;
  filter: none;
  border: 1px solid rgba(var(--luz-rgb), 0.55);
  box-shadow: 0 0 0 10px var(--luz-tenue), 0 0 90px rgba(var(--luz-rgb), 0.34);
  overflow: hidden;
}
.retrato img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; display: block; }

.en-memoria {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--bruma);
  letter-spacing: 0.04em;
}

.nombre { margin: 0; font-family: var(--serif); font-weight: 300; line-height: 0.95; }
.nombre-pila {
  display: block;
  font-size: clamp(3.5rem, min(17vw, 10.5vh), 8.5rem);
  letter-spacing: -0.01em;
  animation: aparecer 2.4s ease-out both;
}
.nombre-apellidos {
  display: block;
  margin-top: 0.6rem;
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  font-weight: 400;
  font-style: italic;
  color: var(--luz);
  animation: aparecer 2.4s 0.6s ease-out both;
}

@keyframes aparecer {
  from { opacity: 0; filter: blur(6px); }
  to   { opacity: 1; filter: blur(0); }
}

.fechas { margin: 1.25rem 0 0; color: var(--bruma); font-size: 1rem; }

.frase {
  max-width: 30rem;
  margin: clamp(1rem, 2.6vh, 2rem) 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1.35rem, 3.6vw, 1.75rem);
  line-height: 1.4;
  color: var(--texto);
}

.acciones {
  margin-top: clamp(1.25rem, 3.6vh, 2.5rem);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: center;
  justify-content: center;
}

/* ---------- Mensaje ---------- */
.mensaje {
  max-width: 34rem;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
  text-align: center;
  font-family: var(--serif);
  font-size: clamp(1.25rem, 3vw, 1.45rem);
  line-height: 1.7;
  font-weight: 400;
}
.mensaje p { margin: 0 0 1.25rem; }

/* ---------- Galería ---------- */
.recuerdos {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
  scroll-margin-top: 1rem;
}
.recuerdos h2 {
  margin: 0;
  text-align: center;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 3rem);
}
.conteo { text-align: center; color: var(--bruma); margin: 0.5rem 0 2.5rem; }
.vacio { text-align: center; color: var(--bruma); max-width: 26rem; margin: 1.5rem auto 0; }

.galeria {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2 140px;
  column-gap: 12px;
}
@media (min-width: 640px)  { .galeria { columns: 3 200px; column-gap: 16px; } }
@media (min-width: 1000px) { .galeria { columns: 4 240px; } }

.galeria li { break-inside: avoid; margin: 0 0 12px; }
@media (min-width: 640px) { .galeria li { margin-bottom: 16px; } }

.tile {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  overflow: hidden;
  background: var(--noche-media);
  cursor: pointer;
  transition: border-color 0.2s;
}
.tile:hover { border-color: var(--luz); }
.tile img, .tile video { display: block; width: 100%; height: auto; min-height: 90px; object-fit: cover; }
.tile .play {
  position: absolute;
  right: 10px; bottom: 10px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: #1b1630;
  background: var(--luz);
  border-radius: 50%;
}

/* ---------- Mensajes escritos ---------- */
.mensajes-sec { padding-bottom: 1rem; }
.mensajes {
  list-style: none;
  margin: 2rem auto 0;
  padding: 0;
  max-width: 40rem;
  display: grid;
  gap: 1.25rem;
}
.mensajes li {
  padding: 1.5rem 1.5rem 1.25rem;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: rgba(14, 21, 48, 0.5);
}
.mensajes blockquote {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.2rem, 3vw, 1.4rem);
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.mensaje-autor { margin: 1rem 0 0; text-align: right; color: var(--luz); font-style: italic; font-family: var(--serif); font-size: 1.1rem; }

.pie { padding: 2rem 1.5rem 3rem; text-align: center; color: var(--bruma); font-family: var(--serif); font-style: italic; font-size: 1.2rem; }
.pie p { margin: 0; }

/* ---------- Visor ---------- */
.visor {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 22, 0.94);
  padding: 3.5rem 1rem 3.5rem;
}
.visor[hidden] { display: none; }
.visor-contenido { max-width: min(1100px, 100%); max-height: 100%; display: flex; }
.visor-contenido img, .visor-contenido video {
  max-width: 100%;
  max-height: calc(100vh - 7.5rem);
  max-height: calc(100dvh - 7.5rem);
  border-radius: var(--radio);
  background: #000;
}
.visor-cerrar, .visor-nav {
  position: absolute;
  display: grid; place-items: center;
  width: 48px; height: 48px;
  font: 300 2rem/1 var(--sans);
  color: var(--texto);
  background: rgba(236, 235, 244, 0.08);
  border: 1px solid var(--linea);
  border-radius: 50%;
  cursor: pointer;
}
.visor-cerrar:hover, .visor-nav:hover { border-color: var(--luz); color: var(--luz); }
.visor-cerrar { top: max(12px, env(safe-area-inset-top)); right: 12px; }
.visor-nav { top: 50%; transform: translateY(-50%); }
.visor-prev { left: 10px; }
.visor-next { right: 10px; }
.visor-nav[hidden] { display: none; }
.visor-autor {
  position: absolute;
  left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  color: var(--bruma);
  font-size: 0.9375rem;
}

/* ---------- Página de subida ---------- */
.subir {
  max-width: 32rem;
  margin: 0 auto;
  padding: max(2rem, env(safe-area-inset-top)) 1.25rem 4rem;
}
.volver { display: inline-block; margin-bottom: 2rem; color: var(--bruma); text-decoration: none; padding: 0.5rem 0; }
.volver:hover { color: var(--texto); }

.subir-titulo {
  margin: 0 0 0.75rem;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.2rem, 8vw, 3rem);
  line-height: 1.1;
}
.subir-intro { margin: 0 0 2rem; color: var(--bruma); }

.elegir {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 2.25rem 1rem;
  text-align: center;
  font-weight: 500;
  color: var(--luz);
  border: 1.5px dashed rgba(var(--luz-rgb), 0.5);
  border-radius: var(--radio);
  background: rgba(var(--luz-rgb), 0.05);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}
.elegir:hover, .elegir.arrastrando { background: var(--luz-tenue); border-color: var(--luz); }
#archivos:focus-visible + .elegir { outline: 2px solid var(--luz); outline-offset: 3px; }

.lista-archivos { list-style: none; margin: 1.25rem 0 0; padding: 0; display: grid; gap: 0.6rem; }
.archivo {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: rgba(14, 21, 48, 0.5);
}
.archivo .mini { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--noche-media); display: grid; place-items: center; color: var(--bruma); font-size: 0.75rem; }
.archivo .nom { min-width: 0; }
.archivo .nom b { display: block; font-weight: 500; font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archivo .nom small { color: var(--bruma); font-size: 0.8125rem; }
.archivo .barra { height: 4px; margin-top: 0.4rem; border-radius: 4px; background: var(--linea); overflow: hidden; }
.archivo .barra i { display: block; height: 100%; width: 0; background: var(--luz); transition: width 0.15s; }
.archivo .quitar { width: 40px; height: 40px; font-size: 1.4rem; line-height: 1; color: var(--bruma); background: none; border: 0; cursor: pointer; border-radius: 50%; }
.archivo .quitar:hover { color: var(--texto); }
.archivo.listo small { color: var(--luz); }
.archivo.error small { color: #ff9d9d; }

.campo { margin: 1.75rem 0; }
.campo label { display: block; margin-bottom: 0.4rem; font-weight: 500; }
.campo .opcional { color: var(--bruma); font-weight: 400; }
.campo input {
  width: 100%;
  min-height: 52px;
  padding: 0 1rem;
  font: inherit;
  color: var(--texto);
  background: rgba(14, 21, 48, 0.6);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
}
.campo textarea {
  width: 100%;
  min-height: 130px;
  padding: 0.85rem 1rem;
  font: inherit;
  line-height: 1.5;
  color: var(--texto);
  background: rgba(14, 21, 48, 0.6);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  resize: vertical;
}
.campo-mensaje { margin-top: 0; }
.campo input::placeholder, .campo textarea::placeholder { color: rgba(170, 179, 212, 0.7); }
.campo textarea:focus, .campo input:focus { outline: 2px solid var(--luz); outline-offset: 2px; border-color: transparent; }

.subir-form .boton { width: 100%; }
.estado { min-height: 1.6em; margin: 1rem 0 0; text-align: center; color: var(--bruma); }
.estado.ok { color: var(--luz); font-family: var(--serif); font-size: 1.4rem; line-height: 1.35; }
.estado.mal { color: #ff9d9d; }
.nota { margin-top: 2.5rem; font-size: 0.875rem; color: var(--bruma); }

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .nombre-pila, .nombre-apellidos { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* ---------- Fechas especiales: temas de color ---------- */
/* Se aplican con <html class="tema-..."> (ver 'fechas_especiales' en config.php). */
html.tema-calido  { --noche: #1b1233; --noche-media: #3b2150; --horizonte: #7a4358; --bruma: #d1b8d8; --luz: #ffd08a; --luz-rgb: 255, 208, 138; }
html.tema-rosa    { --noche: #20142b; --noche-media: #3d1f43; --horizonte: #6b3050; --bruma: #cdb3cc; --luz: #f4a7b9; --luz-rgb: 244, 167, 185; }
html.tema-sereno  { --noche: #0b1020; --noche-media: #131a2e; --horizonte: #1e2840; --bruma: #98a1bd; --luz: #e9e4d6; --luz-rgb: 233, 228, 214; }
html.tema-ambar   { --noche: #1c1210; --noche-media: #3a2012; --horizonte: #6b3a14; --bruma: #d9b99a; --luz: #ffa63d; --luz-rgb: 255, 166, 61; }
body, body::before { transition: background-color 0.6s; }

.fecha-especial {
  margin: 0 0 1.5rem;
  padding: 0.45rem 1.1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--luz);
  border: 1px solid rgba(var(--luz-rgb), 0.5);
  border-radius: 999px;
  background: rgba(var(--luz-rgb), 0.1);
  box-shadow: 0 0 24px rgba(var(--luz-rgb), 0.2);
  animation: aparecer 2s ease-out both;
}
.page-subir .fecha-especial { display: inline-block; margin: 0 0 1rem; }

/* ---------- Vista previa de fechas (PROVISIONAL) ---------- */
.vista-previa {
  position: fixed;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(300px, calc(100vw - 24px));
  font-size: 0.875rem;
  color: var(--texto);
  background: rgba(14, 21, 48, 0.88);
  border: 1px dashed var(--luz);
  border-radius: var(--radio);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.vista-previa summary { padding: 0.6rem 0.9rem; cursor: pointer; font-weight: 600; color: var(--luz); }
.vista-previa p { margin: 0; padding: 0 0.9rem 0.5rem; color: var(--bruma); font-size: 0.8125rem; }
.vista-previa ul { list-style: none; margin: 0; padding: 0 0.4rem 0.5rem; max-height: 55vh; overflow: auto; }
.vista-previa a { display: block; padding: 0.5rem 0.6rem; color: var(--texto); text-decoration: none; border-radius: 8px; }
.vista-previa a:hover { background: var(--luz-tenue); }
.vista-previa a[aria-current="true"] { color: var(--luz); font-weight: 600; background: var(--luz-tenue); }
.vista-previa[open] { max-height: 72vh; overflow: auto; }
.vista-previa ul { max-height: none; overflow: visible; }
.vista-previa h3 { margin: 0.4rem 0.9rem 0.2rem; font: 600 0.75rem/1.3 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--bruma); }

/* Teléfonos: bloque de texto más compacto para dejarle más lugar al retrato */
@media (max-width: 480px) {
  .portada { padding-top: 3.75rem; padding-bottom: 1.25rem; }
  .frase { font-size: 1.2rem; line-height: 1.35; }
  .fecha-especial { margin-bottom: 0.9rem; padding: 0.35rem 0.9rem; font-size: 0.875rem; }
  .fechas { margin-top: 0.75rem; font-size: 0.9375rem; }
  .boton { min-height: 48px; }
  .enlace { padding: 0.4rem 0.5rem; }
}
@media (max-width: 480px) and (max-height: 700px) {
  .portada { padding-top: 3.25rem; }
  .nombre-apellidos { margin-top: 0.3rem; }
  .en-memoria { margin-bottom: 0.25rem; }
  .acciones { gap: 0.25rem 1rem; }
}
