/* Paleta medida del logo de Guyunusa */
:root {
  --negro: #000000;
  --violeta: #8259cf;
  --violeta-claro: #e9e1fa;
  --amarillo: #e6be1d;
  --amarillo-claro: #fbf0c6;
  --fondo: #faf7f1;
  --papel: #ffffff;
  --gris: #6d675f;
  --linea: #e7e1d6;
  --error: #b3261e;
  --sombra: 0 24px 60px -18px rgba(0, 0, 0, .45), 0 6px 18px -8px rgba(0, 0, 0, .25);
  --alto-tapa: min(62vh, 560px);
  --ancho-ficha: min(46vw, 660px);
  --hueco: clamp(32px, 4vw, 64px);
  --solape: calc(var(--hueco) + 90px);   /* cuánto de la ficha queda escondido detrás de la tapa */
  --suave: cubic-bezier(.22, .9, .25, 1);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--fondo);
  color: var(--negro);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto;
}
/* Círculos de fondo, como el del logo, muy tenues */
body::before, body::after { content: ""; position: fixed; border-radius: 50%; pointer-events: none; z-index: 0; }
body::before { width: 70vmax; height: 70vmax; right: -24vmax; top: -30vmax; background: var(--violeta-claro); opacity: .55; }
body::after { width: 38vmax; height: 38vmax; left: -14vmax; bottom: -20vmax; background: var(--amarillo-claro); opacity: .7; }
.defs { position: absolute; }

/* ---------- Intro ---------- */
.intro {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--fondo);
  transition: opacity .8s var(--suave), visibility .8s;
}
.intro.chau { opacity: 0; visibility: hidden; }
.intro.chau .logo-grande { transform: scale(.94) translateY(-10px); }
.logo-grande { width: min(58vh, 540px); height: auto; overflow: visible; transition: transform .8s var(--suave); }
.logo-grande g { transform-box: fill-box; }
/* el orden (--i) de letras, puntitos y "libros" lo pone app.js */
.logo-grande .circulo { transform-origin: center; animation: aparecer-circulo 1s cubic-bezier(.2, .8, .25, 1) both; }
.logo-grande .libro { transform-origin: 50% 100%; animation: crecer-libro 1s cubic-bezier(.25, .75, .3, 1) both; }
.logo-grande .l1 { animation-delay: .45s; }
.logo-grande .l2 { animation-delay: .58s; }
.logo-grande .l3 { animation-delay: .71s; }
.logo-grande .punto-dos { transform-origin: center; animation: saltar .85s both; }
.logo-grande .p1 { animation-delay: 1.15s; }
.logo-grande .p2 { animation-delay: 1.27s; }
.logo-grande .letra { clip-path: inset(0 0 100% 0); animation: tinta .6s cubic-bezier(.55, .1, .35, 1) both; animation-delay: calc(1.15s + var(--i, 0) * .16s); }
.logo-grande .puntitos g { transform-origin: center; animation: saltar .7s both; animation-delay: calc(2.35s + var(--i, 0) * .07s); }
.logo-grande .libros g { animation: subir-letra .5s var(--suave) both; animation-delay: calc(2.85s + var(--i, 0) * .06s); }

.cargador { display: flex; gap: 8px; align-items: flex-end; height: 34px; margin-top: 22px; opacity: 0; transform: translateY(8px); transition: opacity .6s var(--suave), transform .6s var(--suave); }
.intro.cargando .cargador { opacity: 1; transform: none; }
.intro.listo .cargador { opacity: 0; transform: translateY(6px); }
.cargador span { width: 9px; height: 34px; border-radius: 3px; background: var(--violeta); transform-origin: bottom; animation: estante 1.1s ease-in-out infinite; }
.cargador span:nth-child(2) { animation-delay: .14s; }
.cargador span:nth-child(3) { background: var(--amarillo); animation-delay: .28s; }
.intro-estado { min-height: 1.4em; margin: 18px 0 0; color: var(--gris); font-size: 1.05rem; }

@keyframes aparecer-circulo { from { opacity: 0; transform: scale(.6) rotate(-8deg); } to { opacity: 1; transform: none; } }
@keyframes crecer-libro { from { opacity: 0; transform: scaleY(0); } to { opacity: 1; transform: scaleY(1); } }
@keyframes saltar {
  0% { opacity: 0; transform: scale(0); animation-timing-function: cubic-bezier(.3, .7, .4, 1); }
  45% { opacity: 1; transform: scale(1.28); animation-timing-function: cubic-bezier(.45, 0, .25, 1); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes tinta { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 -2% 0); } }
@keyframes subir-letra { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes estante { 0%, 100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }

/* ---------- Escenario ---------- */
.escenario { position: relative; z-index: 1; display: grid; place-items: center; min-height: 0; padding: 0 40px; }

.espera { text-align: center; animation: aparecer .7s var(--suave) both; }
.espera-logo { width: min(34vh, 280px); height: auto; animation: respirar 4s ease-in-out infinite; }
.espera-texto { display: flex; align-items: center; justify-content: center; gap: .6em; font-size: clamp(1.6rem, 3vw, 2.4rem); color: var(--gris); margin: 28px 0 0; white-space: nowrap; }
.espera-texto svg { width: 1.6em; height: 1em; color: var(--negro); flex: none; }
@keyframes respirar { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
@keyframes aparecer { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* Un libro: tapa + ficha. Los movimientos de la tapa los anima app.js (trayectorias calculadas);
   la ficha se abre y se cierra por CSS, siempre desde atrás de la tapa. */
.escena {
  position: relative;   /* referencia de offsetLeft para medir la tapa */
  display: grid;
  grid-template-columns: auto var(--ancho-ficha);
  gap: var(--hueco);
  align-items: center;
}
.tapa-caja {
  position: relative; z-index: 2;
  height: var(--alto-tapa);
  display: grid; place-items: center;
  opacity: 0;
  will-change: transform;   /* capa fija: sin redibujo al terminar cada animación */
}
.tapa {
  display: block;
  height: min(var(--alto-tapa), var(--alto-maximo, 100vh)); width: auto;   /* --alto-maximo: imágenes chicas, sin pixelarse */
  border-radius: 3px 6px 6px 3px;
  box-shadow: var(--sombra);
}
.tapa.ancha { width: calc(var(--alto-tapa) * .9); height: auto; }   /* más ancha que alta: manda el ancho */
.sin-tapa {
  height: var(--alto-tapa);
  aspect-ratio: 2 / 3;
  border-radius: 3px 6px 6px 3px;
  box-shadow: var(--sombra);
  background: var(--negro);
  color: rgba(255, 255, 255, .72);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px;
  padding: 32px; text-align: center;
  font-size: clamp(1rem, 1.9vh, 1.35rem); font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  position: relative; overflow: hidden;
}
.sin-tapa svg { width: 46%; height: auto; }
.sin-tapa::after { content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, .12); }

/* La ficha se despliega con dos desplazamientos opuestos (los anima app.js, por la placa de video):
   .ficha recorta (overflow) y se corre hacia atrás de la tapa; .ficha-carta se corre lo mismo al revés,
   así el contenido queda quieto y se ve solo la parte desplegada. Cerrada: -100% / 100%. */
.ficha {
  position: relative; z-index: 1;
  margin-left: calc(var(--solape) * -1);
  border-radius: 0 22px 22px 0;
  overflow: hidden;
  transform: translateX(-100%);
  will-change: transform;
}
.ficha-carta {
  position: relative;
  padding: clamp(28px, 4vh, 48px) clamp(34px, 3.4vw, 58px) clamp(28px, 4vh, 48px) calc(var(--solape) + clamp(20px, 2.4vw, 40px));
  background: var(--papel);
  transform: translateX(100%);
  will-change: transform;
}
.ficha-carta::after { /* las tres franjas del logo en el borde derecho */
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 10px;
  background: linear-gradient(var(--violeta) 0 38%, var(--negro) 38% 44%, var(--violeta) 44% 72%, var(--amarillo) 72%);
}
.ficha-carta > * { opacity: 0; transform: translateY(14px); transition: opacity .18s ease, transform .18s ease; }
.ficha-titulo { font-size: clamp(1.9rem, 3.4vw, 3.3rem); line-height: 1.08; margin: 0 0 12px; font-weight: 800; letter-spacing: -.01em; text-wrap: balance; }
.ficha-autor { font-size: clamp(1.1rem, 1.8vw, 1.6rem); color: var(--violeta); font-weight: 600; margin: 0 0 clamp(20px, 4vh, 40px); }
.ficha-autor:empty { display: none; }
.ficha-precio {
  margin: 0;
  font-size: clamp(3.6rem, 8vw, 7.2rem); font-weight: 900; line-height: 1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; display: inline-block; position: relative;
}
.ficha-precio::after { /* subrayado amarillo debajo de los números, que se dibuja */
  content: ""; position: absolute; left: 0; right: 0; bottom: .03em; height: .07em; border-radius: 99px;   /* al pie de los números */
  background: var(--amarillo); transform: scaleX(0); transform-origin: left;
}
.ficha-precio.sin-precio { font-size: clamp(1.8rem, 3vw, 2.6rem); }
.ficha-precio.sin-precio .moneda { display: none; }
.moneda { font-size: .45em; font-weight: 700; margin-right: .12em; vertical-align: .9em; }

/* Abierta: aparecen los textos. --demora la pone app.js (vidriera más pausada, consulta casi inmediata). */
.escena.abierta .ficha-carta > * { opacity: 1; transform: none; transition: opacity .45s ease, transform .55s var(--suave); }
.escena.abierta .ficha-carta > :nth-child(1) { transition-delay: calc(var(--demora, .3s) + .25s); }
.escena.abierta .ficha-carta > :nth-child(2) { transition-delay: calc(var(--demora, .3s) + .33s); }
.escena.abierta .ficha-carta > :nth-child(3) { transition-delay: calc(var(--demora, .3s) + .42s); }
.escena.abierta .ficha-precio::after { transform: scaleX(1); transition: transform .55s var(--suave) calc(var(--demora, .3s) + .7s); }

/* Reinicio: los textos de la ficha vuelven a ocultos al instante antes de un libro nuevo. */
.escena.reinicio .ficha-carta > * { transition: none; }

/* ---------- Avisos ---------- */
.aviso { text-align: center; font-size: clamp(1.8rem, 3.4vw, 2.8rem); font-weight: 700; max-width: 24ch; line-height: 1.2; animation: aparecer .5s var(--suave) both; }
.aviso p { margin: 0; }

/* ---------- Pie ---------- */
.pie { position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; padding: 18px 36px 26px; min-height: 76px; }
.pista { display: inline-flex; align-items: center; gap: 12px; color: var(--gris); font-size: 1.1rem; opacity: 0; transition: opacity .6s; }
.pista svg { width: 40px; height: 25px; color: var(--negro); }
body.con-vidriera .pista { opacity: 1; }
.pastilla {
  position: fixed; bottom: 34px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: inline-flex; align-items: center; gap: 14px;
  background: var(--negro); color: #fff; padding: 12px 24px; border-radius: 999px;
  font-size: 1.4rem; font-variant-numeric: tabular-nums; letter-spacing: .08em;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, .5);
  animation: pastilla .3s var(--suave) both;
}
.pastilla .libritos { display: none; gap: 5px; align-items: flex-end; height: 22px; }
.pastilla.buscando .libritos { display: inline-flex; }
.pastilla .libritos i { width: 6px; height: 22px; border-radius: 2px; background: var(--violeta); transform-origin: bottom; animation: estante .8s ease-in-out infinite; }
.pastilla .libritos i:nth-child(2) { animation-delay: .1s; }
.pastilla .libritos i:nth-child(3) { background: var(--amarillo); animation-delay: .2s; }
@keyframes pastilla { from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(.95); } to { opacity: 1; transform: translateX(-50%); } }
.tiempo { position: absolute; left: 0; right: 0; bottom: 0; height: 15px; }
.tiempo span { display: block; height: 100%; background: linear-gradient(90deg, var(--violeta), var(--amarillo)); transform-origin: left; }

/* El campo que recibe el lector queda fuera de la vista */
.lector { position: fixed; left: -9999px; top: 0; }

/* ---------- Editor de la vidriera ---------- */
.editor {
  border: none; border-radius: 22px; padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto;
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, .5); color: var(--negro);
}
.editor::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(3px); }
.editor form { padding: 28px 30px 24px; display: grid; gap: 14px; }
.editor-cabecera { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-right: -8px; }
.editor h2 { margin: 0; font-size: 1.6rem; }
.boton-icono.cerrar { width: 38px; height: 38px; }
.boton-icono.cerrar svg { width: 18px; height: 18px; }
.editor input {
  font: inherit; font-size: 1.05rem; width: 100%;
  border: 1.5px solid var(--linea); border-radius: 12px; padding: 12px 14px; background: var(--fondo); color: var(--negro);
}
.editor input:focus { outline: none; border-color: var(--violeta); }
.editor-agregar { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.editor-aviso { margin: 0; color: var(--error); font-weight: 600; }
.editor-lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 36vh; overflow: auto; }
.editor-vacia { margin: 0; padding: 18px; border: 1.5px dashed var(--linea); border-radius: 12px; color: var(--gris); text-align: center; }
.fila {
  display: grid; grid-template-columns: 18px 40px 1fr auto auto; align-items: center; gap: 12px;
  padding: 8px 10px; border: 1.5px solid var(--linea); border-radius: 12px; background: var(--papel);
}
.fila.arrastrando { opacity: .4; }
.fila.falta { border-color: #f1c4c0; background: #fdf3f2; }
.fila-asa { color: #b9b2a7; cursor: grab; display: grid; place-items: center; }
.fila-asa svg { width: 10px; height: 16px; }
.fila-tapa { width: 40px; height: 56px; border-radius: 3px; background: var(--negro) center / cover no-repeat; }
.fila-tapa.vacia { display: grid; place-items: center; }
.fila-tapa.vacia::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--amarillo); }
.fila-datos { display: grid; min-width: 0; }
.fila-titulo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila-codigo { color: var(--gris); font-variant-numeric: tabular-nums; }
.fila.falta .fila-codigo { color: var(--error); }
.fila-precio { font-weight: 800; font-variant-numeric: tabular-nums; }
.fila-acciones { display: flex; gap: 2px; }
.boton-icono {
  width: 32px; height: 32px; display: grid; place-items: center; padding: 0;
  border: none; border-radius: 8px; background: transparent; color: var(--gris); cursor: pointer;
}
.boton-icono svg { width: 16px; height: 16px; }
.boton-icono:hover { background: var(--fondo); color: var(--negro); }
.boton-icono.quitar:hover { color: var(--error); }
.boton-icono:disabled { opacity: .25; cursor: default; background: transparent; }
.editor-botones { display: flex; justify-content: flex-end; gap: 10px; }
.boton { font: inherit; font-weight: 700; border-radius: 999px; padding: 11px 22px; cursor: pointer; border: 2px solid var(--negro); }
.boton { background: var(--negro); color: #fff; }
.boton-secundario { font: inherit; font-weight: 700; border-radius: 999px; padding: 11px 22px; cursor: pointer; border: 2px solid var(--linea); background: transparent; color: var(--negro); }
.boton-secundario:hover { border-color: var(--negro); }

/* Ventanita de cambios sin guardar */
.confirmar { border: none; border-radius: 18px; padding: 22px 24px 18px; width: min(460px, calc(100vw - 32px)); box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .5); color: var(--negro); }
.confirmar::backdrop { background: rgba(0, 0, 0, .25); }
.confirmar p { margin: 0 0 18px; font-size: 1.15rem; font-weight: 600; text-align: center; }
.confirmar .editor-botones { display: grid; grid-template-columns: 1fr 1fr; }   /* los dos botones del mismo ancho */
.confirmar button { white-space: nowrap; }
.boton:hover:not(:disabled) { background: #2c2c2c; }
.boton:disabled { opacity: .35; cursor: default; }

/* ---------- Pantallas angostas ---------- */
@media (max-width: 820px) {
  :root { --alto-tapa: 34vh; --ancho-ficha: calc(100vw - 32px); --hueco: 20px; }
  .escenario { padding: 0 16px; }
  .escena { grid-template-columns: 1fr; justify-items: center; }
  .ficha { margin-left: 0; border-radius: 22px; }
  .ficha-carta { padding: 24px 28px; text-align: center; }
  .pie { padding: 12px 16px 18px; }
  .pista { font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; transition-delay: 0s !important; }
}
