:root {
  --negro: #030204;
  --ambar: #f2cf7a;
  --papel: #efe3c8;
  --tinta: #1b1410;
  --carmesi: #4a0d1a;
  --carmesi-oscuro: #250610;
  --humo: #9a8f80;
  --acento: var(--ambar);
  --display: "Playfair Display", Georgia, "Times New Roman", serif;
  --texto: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--negro);
  color: var(--papel);
  font-family: var(--texto);
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }

[hidden] { display: none !important; }

#escena {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Capas a pantalla completa */
.capa {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 10;
  overflow-y: auto;
}

/* Negro de inicio: se desvanece solo */
#inicio {
  background: var(--negro);
  transition: opacity 1.8s ease;
  pointer-events: none;
}

#inicio.apagando { opacity: 0; }

/* Rótulo de apertura */
#titulo {
  position: fixed;
  left: 0;
  right: 0;
  top: 10vh;
  z-index: 4;
  margin: 0;
  padding: 0 24px;
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  color: var(--humo);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 1.6s ease, transform 1.6s ease;
  pointer-events: none;
}

#titulo span {
  display: block;
  margin-bottom: 4px;
  font-style: normal;
  font-weight: 500;
  font-size: clamp(1.5rem, 4.4vw, 2.6rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ambar);
  text-shadow: 0 0 28px rgba(242, 207, 122, 0.35);
}

#titulo.visible { opacity: 1; transform: none; }

/* Tarjeta: entrada de teatro en papel crema, con la captura enmarcada */
.tarjeta {
  position: fixed;
  z-index: 5;
  /* Crece con la pantalla; escena.js calcula el mismo ancho para encuadrar */
  font-size: clamp(16px, 1.17vw, 22px);
  width: min(18.75em, calc(100vw - 32px));
  padding: 6px;
  background: var(--papel);
  color: var(--tinta);
  border: 1px solid var(--tinta);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7), 0 0 34px color-mix(in srgb, var(--acento) 28%, transparent);
  transform-origin: 0 35%;
  transform: rotate(-1.5deg) scale(0.6);
  opacity: 0;
  transition: transform 0.45s cubic-bezier(0.2, 1.4, 0.4, 1), opacity 0.3s;
  pointer-events: none;
}

.tarjeta.izquierda {
  transform-origin: 100% 35%;
  transform: rotate(1.5deg) scale(0.6);
}

.tarjeta.visible {
  transform: rotate(-1.5deg) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.tarjeta.izquierda.visible { transform: rotate(1.5deg) scale(1); }

/* En pantallas estrechas la tarjeta se ancla abajo, centrada */
.tarjeta.anclada {
  left: 50% !important;
  top: auto !important;
  bottom: 84px;
  transform-origin: 50% 100%;
  transform: translateX(-50%) rotate(-1deg) scale(0.6);
}

.tarjeta.anclada.visible { transform: translateX(-50%) rotate(-1deg) scale(1); }

.tarjeta-imagen {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 1;
  object-fit: cover;
  border: 1px solid var(--tinta);
  background: var(--tinta);
}

.tarjeta.anclada .tarjeta-imagen { aspect-ratio: 3 / 1; }

.tarjeta-cuerpo {
  position: relative;
  padding: 12px 14px 12px;
  border: 1px solid var(--tinta);
  border-top: 4px solid var(--acento);
}

.tarjeta-imagen:not([hidden]) + .tarjeta-cuerpo { margin-top: 5px; }

.tarjeta-icono {
  float: right;
  /* El tamaño de letra manda (iconos emoji); la caja mide 1.36em = 3.4em de la tarjeta */
  font-size: 2.5em;
  width: 1.36em;
  height: 1.36em;
  margin: 0 0 6px 10px;
  line-height: 1.36em;
  text-align: center;
}

.tarjeta-icono img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 13px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.tarjeta-nombre {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.4em;
  line-height: 1.15;
}

.tarjeta-tipo {
  margin: 3px 0 10px;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.92em;
  color: #5c4d3f;
}

.tarjeta-tipo:empty { display: none; }

.tarjeta-desc {
  clear: both;
  margin: 0 0 12px;
  font-size: 0.95em;
  line-height: 1.4;
}

.tarjeta-meta {
  margin: 0 0 12px;
  font-size: 0.85em;
  color: #5c4d3f;
}

.tarjeta-meta:empty { display: none; }

.tarjeta-abrir {
  display: inline-block;
  padding: 8px 18px;
  background: var(--tinta);
  color: var(--papel);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background 0.2s;
}

.tarjeta-abrir::after { content: " →"; }

.tarjeta-abrir:hover, .tarjeta-abrir:focus-visible {
  background: var(--carmesi);
  outline: none;
}

/* Pantallas bajas (móvil apaisado): tarjeta compacta, sin captura */
@media (max-height: 520px) {
  .tarjeta { width: min(16.25em, calc(100vw - 32px)); }
  .tarjeta-imagen { display: none; }
  .tarjeta-imagen + .tarjeta-cuerpo { margin-top: 0 !important; }
  .tarjeta-cuerpo { padding: 8px 12px 10px; }
  .tarjeta-icono { font-size: 1.85em; }
  .tarjeta-nombre { font-size: 1.15em; }
  .tarjeta-tipo { margin-bottom: 6px; }
  .tarjeta-desc { font-size: 0.85em; margin-bottom: 8px; }
  .tarjeta-abrir { padding: 5px 14px; }
  .tarjeta.anclada { bottom: 56px; }
}

/* HUD inferior */
#hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 6px 10px;
  padding: 16px 20px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
  animation: aparecer 1.6s ease both;
}

@keyframes aparecer { from { opacity: 0; } }

#puntos {
  grid-column: 1 / -1;
  justify-self: center;
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: auto;
}

/* El botón es más grande que el punto que se ve, para acertar con el dedo */
#puntos button {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
}

#puntos button::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 1px solid var(--humo);
  border-radius: 50%;
  transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}

#puntos li.activo button::before {
  background: var(--ambar);
  border-color: var(--ambar);
  box-shadow: 0 0 10px rgba(242, 207, 122, 0.6);
}

#puntos li.visto button::before { background: var(--humo); }

#puntos button:hover::before, #puntos button:focus-visible::before { border-color: var(--ambar); }
#puntos button:focus-visible { outline: none; }

.hud-izquierda {
  justify-self: start;
  display: flex;
  align-items: baseline;
  gap: 16px;
}

#btn-saltar, #btn-idioma {
  pointer-events: auto;
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(154, 143, 128, 0.4);
  padding: 4px 2px;
  color: var(--humo);
  font-family: var(--display);
  font-style: italic;
  font-size: 0.95rem;
  transition: color 0.3s, border-color 0.3s;
}

#btn-saltar:hover, #btn-saltar:focus-visible,
#btn-idioma:hover, #btn-idioma:focus-visible { color: var(--ambar); border-color: var(--ambar); outline: none; }

#pista {
  margin: 0;
  text-align: right;
  font-size: 0.85rem;
  color: var(--humo);
  opacity: 0;
  transition: opacity 0.6s;
}

#pista.visible { opacity: 0.85; }

#btn-sonido {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 38px;
  height: 38px;
  background: none;
  border: 1px solid transparent;
  border-radius: 19px;
  padding: 0 8px;
  color: var(--humo);
  transition: color 0.3s, background 0.3s, border-color 0.3s;
}

/* Etiqueta del botón: solo se lee cuando hace falta el toque para activar el sonido */
.btn-sonido-texto {
  display: none;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
}

#btn-sonido:not(.esperando) .btn-sonido-texto {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#btn-sonido:hover, #btn-sonido:focus-visible { color: var(--ambar); outline: none; }

#btn-sonido .tachado { display: none; }
#btn-sonido[aria-pressed="false"] .ondas { display: none; }
#btn-sonido[aria-pressed="false"] .tachado { display: block; }

/* A la espera del primer toque para poder sonar: botón ámbar que late para llamar la atención */
#btn-sonido.esperando {
  color: var(--tinta);
  background: var(--ambar);
  border-color: var(--ambar);
  padding: 0 16px 0 12px;
  animation: latir 1.8s ease-in-out infinite;
}

#btn-sonido.esperando .btn-sonido-texto { display: inline; }

#btn-sonido.esperando:hover, #btn-sonido.esperando:focus-visible { background: #ffe09a; color: var(--tinta); }

@keyframes latir {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242, 207, 122, 0.55); }
  60% { box-shadow: 0 0 0 12px rgba(242, 207, 122, 0); }
}

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

/* Telón final: pliegues carmesí */
#final, #sin-webgl {
  background-color: var(--carmesi-oscuro);
  background-image:
    linear-gradient(180deg, rgba(0,0,0,0.55), rgba(0,0,0,0.15) 40%, rgba(0,0,0,0.6)),
    repeating-linear-gradient(90deg, var(--carmesi) 0 48px, var(--carmesi-oscuro) 48px 96px);
  opacity: 0;
  transition: opacity 1.4s ease;
}

#final.visible, #sin-webgl.visible { opacity: 1; }

.final-contenido {
  width: 100%;
  max-width: 640px;
  text-align: center;
}

.final-contenido h1 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2rem, 6vw, 3.2rem);
  color: var(--ambar);
}

.final-contenido p {
  margin: 0 0 26px;
  color: rgba(239, 227, 200, 0.8);
  line-height: 1.5;
}

/* Programa: una entrada por proyecto */
#programa {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

#programa:empty { display: none; }

#programa a {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 18px 12px 16px;
  background: var(--papel);
  color: var(--tinta);
  text-decoration: none;
  border-top: 4px solid var(--acento);
  box-shadow: inset 0 0 0 3px var(--papel), inset 0 0 0 4px var(--tinta), 0 12px 26px rgba(0, 0, 0, 0.45);
  transition: transform 0.25s cubic-bezier(0.2, 1.4, 0.4, 1), background 0.2s;
}

#programa a:hover, #programa a:focus-visible {
  transform: translateY(-4px) rotate(-1deg);
  background: #fbf2dc;
  outline: none;
}

.programa-icono {
  width: 64px;
  height: 64px;
  margin-bottom: 6px;
  font-size: 46px;
  line-height: 64px;
}

.programa-icono img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

#programa strong {
  font-family: var(--display);
  font-size: 1.15rem;
  line-height: 1.2;
}

#programa a > span:last-child {
  font-size: 0.82rem;
  color: #5c4d3f;
  line-height: 1.3;
}

#enlaces, #enlaces-simple {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
}

#enlaces a, #enlaces-simple a {
  display: inline-block;
  padding: 8px 18px;
  color: var(--papel);
  text-decoration: none;
  font-weight: 600;
  border: 1px solid rgba(239, 227, 200, 0.5);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

#lista-simple a {
  display: inline-block;
  padding: 10px 20px;
  background: var(--papel);
  color: var(--tinta);
  text-decoration: none;
  font-weight: 600;
  box-shadow: inset 0 0 0 3px var(--papel), inset 0 0 0 4px var(--tinta);
}

#enlaces a:hover, #enlaces a:focus-visible,
#enlaces-simple a:hover, #enlaces-simple a:focus-visible,
#lista-simple a:hover, #lista-simple a:focus-visible {
  background: var(--ambar);
  border-color: var(--ambar);
  color: var(--tinta);
  outline: none;
}

.final-acciones {
  display: flex;
  justify-content: center;
  gap: 24px;
}

#btn-repetir, #btn-idioma-final {
  background: none;
  border: 0;
  border-bottom: 1px solid var(--humo);
  color: var(--humo);
  font-family: var(--display);
  font-style: italic;
  font-size: 1.05rem;
  padding: 6px 4px;
}

#btn-repetir:hover, #btn-repetir:focus-visible,
#btn-idioma-final:hover, #btn-idioma-final:focus-visible { color: var(--ambar); border-color: var(--ambar); outline: none; }

#lista-simple {
  list-style: none;
  padding: 0;
  margin: 0 0 28px;
  display: grid;
  gap: 10px;
}

#lista-simple li span { display: block; margin-top: 6px; color: rgba(239, 227, 200, 0.8); font-size: 0.95rem; }

@media (prefers-reduced-motion: reduce) {
  .tarjeta, #inicio, #titulo, #final, #sin-webgl, #pista, #puntos button::before, #programa a, #btn-sonido { transition: none; }
  #hud, #btn-sonido.esperando { animation: none; }
}
