:root {
  --navbar-height: 64px;
  --floating-nav-space: 72px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: #f9f9f9;
  font-family: sans-serif;
}

.navbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* columna para centrado */
  align-items: center;
  height: 64px;
  padding: 0 1rem;
  background-color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 50;
}

.logo {
  height: clamp(44px, 7vw, 60px);
  width: auto;
  max-width: 100%;
}

.titulo {
  grid-column: 2; /* centra el texto en la columna del medio */
  text-align: center;
  font-size: 1.5rem;
  font-weight: bold;
  line-height: 1.2;
}

.boton-volver {
  grid-column: 3;
  justify-self: end;
  padding: 8px 14px;
  background-color: #000294;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: background 0.3s;
}

.boton-volver:hover {
  background-color: #1b3ed0;
}

#loader {
  text-align: center;
  font-size: 1.2rem;
  color: #666;
  background: #f9f9f9;
  margin-top: 2rem;
}

.container {
  display: flex;
  justify-content: center;
  position: relative;
}

.viewer-area {
  width: 100%;
  display: flex;
  justify-content: center;
  position: relative;
}

.viewer-area.is-zoomed {
  touch-action: none;
}

.viewer-area.is-zoomed #flipbook {
  cursor: grab;
}

.viewer-area.is-panning #flipbook {
  cursor: grabbing;
}

#flipbook {
  width: 60%;
  height: calc(100dvh - var(--navbar-height));
  display: none;
  justify-content: center;
  align-items: center;
  padding: 0.3rem 0 0.8rem;
}

.page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.reading-nav {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translate(-50%, 12px);
  width: min(1120px, calc(100% - 12px));
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  z-index: 40;
}

.viewer-area:hover .reading-nav,
.viewer-area.search-active .reading-nav {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.reading-nav-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: 8px auto;
  column-gap: 10px;
  row-gap: 12px;
  align-items: center;
  background: rgba(20, 24, 32, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  padding: 8px 12px 10px;
}

.reading-progress-track {
  grid-column: 1 / -1;
  grid-row: 1;
  position: relative;
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  overflow: visible;
  cursor: pointer;
}

.reading-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3613d3, #572ce6);
  transition: width 0.2s ease;
}

.reading-progress-knob {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 17px;
  height: 17px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(16, 20, 30, 0.55);
  border-radius: 50%;
  background: #f8fafc;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: grab;
}

.reading-progress-track.is-seeking .reading-progress-knob {
  cursor: grabbing;
}

.reading-progress-label {
  grid-column: 1;
  grid-row: 2;
  font-size: 0.88rem;
  color: rgba(241, 245, 249, 0.95);
  font-weight: 600;
  white-space: nowrap;
}

.reading-controls {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(241, 245, 249, 0.96);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.zoom-slider {
  width: 82px;
  height: 4px;
  accent-color: #a78bfa;
  cursor: pointer;
}

.search-toggle {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: rgba(241, 245, 249, 0.94);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.search-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.search-panel {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.18);
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.search-panel.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.search-panel input {
  width: 100%;
  border: 1px solid #ccd4de;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.95rem;
  outline: none;
}

.search-panel input:focus {
  border-color: #2f4ce1;
  box-shadow: 0 0 0 2px rgba(47, 76, 225, 0.15);
}

.search-results {
  list-style: none;
  max-height: 220px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-result-item {
  width: 100%;
  text-align: left;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-result-item:hover {
  background: #f8faff;
  border-color: #c9d7ff;
}

.search-result-item strong {
  font-size: 0.85rem;
  color: #1f2a44;
}

.search-result-item span {
  font-size: 0.82rem;
  color: #4b5563;
}

.search-empty {
  color: #4b5563;
  font-size: 0.87rem;
  padding: 2px 2px 6px;
}

/*
Loader
*/
.loader-container {
  height: calc(100dvh - var(--navbar-height));
  display: flex;
  justify-content: center;
  background: #f9f9f9;
  transition: opacity 0.5s ease;
}

#loader-percent {
  font-family: sans-serif;
}

.loader-path {
  transition: stroke-dashoffset 0.1s ease-out;
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

@media (max-width: 1024px) {
  #flipbook {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .navbar {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto;
    padding: 0.45rem 0.7rem;
    column-gap: 0.5rem;
    height: auto;
  }

  .logo {
    grid-column: 1;
    grid-row: 1;
    height: 34px;
    align-self: center;
  }

  .titulo {
    grid-column: 2;
    grid-row: 1;
    font-size: 0.95rem;
    line-height: 1.1;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .titulo br {
    display: none;
  }

  .boton-volver {
    display: none;
  }

  #loader {
    margin-top: 0.6rem;
    font-size: 1rem;
  }

  #flipbook {
    height: calc(100dvh - var(--navbar-height));
    align-items: flex-start;
    padding: 0.1rem 0 0.45rem;
  }

  .reading-nav {
    width: calc(100% - 12px);
    bottom: 8px;
  }

  .reading-nav-bar {
    grid-template-columns: 1fr auto;
    grid-template-rows: 7px auto;
    column-gap: 8px;
    row-gap: 10px;
    padding: 7px 9px 8px;
  }

  .reading-progress-label {
    font-size: 0.74rem;
    white-space: nowrap;
  }

  .reading-controls {
    gap: 6px;
  }

  .zoom-controls {
    gap: 5px;
  }

  .zoom-btn {
    width: 24px;
    height: 24px;
    font-size: 1rem;
  }

  .zoom-slider {
    width: 62px;
  }

  .search-toggle {
    width: 28px;
    height: 28px;
    font-size: 1.1rem;
  }
}
