/* ===========================================================
   Lector de cómic — estilos
   Tema oscuro, responsive y pensado para leer cómodo.
   =========================================================== */

:root {
  --bg: #0d0d12;
  --bg-stage: #08080b;
  --surface: #16161f;
  --surface-hover: #21212e;
  --border: #2a2a38;
  --text: #e8e8f0;
  --text-dim: #9a9aae;
  --accent: #6c8cff;
  --topbar-h: 56px;
  --gap-pages: 4px;          /* separación entre las dos páginas en modo doble */
  --turn-ms: 320ms;          /* duración de la animación de pase de página */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------------- Barra superior ---------------- */
.topbar {
  flex: 0 0 var(--topbar-h);
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.topbar__left  { justify-self: start;  min-width: 0; }
.topbar__center{ justify-self: center; min-width: 0; }
.topbar__right { justify-self: end; display: flex; align-items: center; gap: 10px; }

.topbar__title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 38vw;
}

.chapter-select {
  appearance: none;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%239a9aae' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 32px 8px 12px;
  font-size: 0.9rem;
  max-width: min(60vw, 360px);
  cursor: pointer;
  text-overflow: ellipsis;
}
.chapter-select:hover { background-color: var(--surface-hover); }
.chapter-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.page-counter {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------- Zona de lectura ---------------- */
.reader {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--bg-stage);
  overflow: hidden;
  touch-action: pan-y;
}

/* Contenedor donde se montan las páginas */
.stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-pages);
  padding: 10px;
}

/* Cada página del cómic */
.page-img {
  max-height: 100%;
  max-width: 100%;
  height: auto;
  width: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  background: #000;
  box-shadow: 0 6px 30px rgba(0, 0, 0, .5);
  border-radius: 2px;
}

/* En modo doble, cada página ocupa como mucho la mitad */
.stage--double .page-img { max-width: calc(50% - var(--gap-pages)); }

/* ----- Animación de pase de página ----- */
@media (prefers-reduced-motion: no-preference) {
  .stage.is-turning-next { animation: turn-next var(--turn-ms) ease; }
  .stage.is-turning-prev { animation: turn-prev var(--turn-ms) ease; }
}

@keyframes turn-next {
  0%   { opacity: 0; transform: translateX(7%)  scale(.985); }
  100% { opacity: 1; transform: translateX(0)    scale(1); }
}
@keyframes turn-prev {
  0%   { opacity: 0; transform: translateX(-7%) scale(.985); }
  100% { opacity: 1; transform: translateX(0)    scale(1); }
}

/* ---------------- Navegación ---------------- */
.nav-zone {
  position: absolute;
  top: 0; bottom: 0;
  width: 30%;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}
.nav-zone--prev { left: 0; }
.nav-zone--next { right: 0; }
.nav-zone:focus-visible { outline: none; }

.arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px; height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(22, 22, 31, .55);
  color: var(--text);
  cursor: pointer;
  z-index: 15;
  opacity: 0;
  transition: opacity .2s ease, background .2s ease;
  backdrop-filter: blur(4px);
}
.arrow--prev { left: 12px; }
.arrow--next { right: 12px; }
.reader:hover .arrow { opacity: .75; }
.arrow:hover { opacity: 1 !important; background: rgba(40, 40, 56, .8); }
.arrow:disabled { opacity: 0 !important; pointer-events: none; }

/* En táctil mostramos las flechas siempre tenues */
@media (hover: none) {
  .arrow { opacity: .55; }
}

/* ---------------- Overlay (carga / error) ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 11, .9);
  color: var(--text-dim);
  font-size: .95rem;
  text-align: center;
  padding: 24px;
  z-index: 50;
}
.overlay[hidden] { display: none; }

/* ---------------- Móvil ---------------- */
@media (max-width: 640px) {
  .topbar__title { display: none; }
  .topbar { grid-template-columns: auto 1fr auto; }
  .chapter-select { max-width: 52vw; }
}
