* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: #f1f1f1;
  font-family: Arial, Helvetica, sans-serif;
  color: #222;
}

a {
  text-decoration: none;
}

/* HOME */

.home {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
}

.home-card {
  width: 100%;
  max-width: 1000px;
  background: #ffffff;
  padding: 40px;
  border-radius: 24px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.08);
  text-align: center;
}

.home-card h1 {
  margin: 0;
  color: #0a5e61;
  font-size: 38px;
}

.home-card p {
  color: #555;
  margin: 12px 0 30px;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.home-book {
  background: #f7f7f7;
  border: 1px solid #ddd;
  border-radius: 18px;
  padding: 28px 20px;
  color: #222;
  transition: 0.2s ease;
}

.home-book:hover {
  transform: translateY(-4px);
  border-color: #0a5e61;
  background: #e3f6f3;
}

.home-book span {
  display: block;
  color: #0a5e61;
  font-weight: bold;
  margin-bottom: 8px;
}

.home-book strong {
  font-size: 20px;
}

/* PÁGINA DEL LIBRO */

.main {
  min-height: 100vh;
  padding: 24px 20px 40px;
  text-align: center;
}

.header {
  position: relative;
}

.back-home {
  display: inline-block;
  margin-bottom: 12px;
  color: #0a5e61;
  font-weight: bold;
}

.header h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  color: #0a5e61;
}

.header p {
  margin: 8px 0 20px;
  color: #555;
}

/* MENÚ SUPERIOR RESPONSIVE */

.books-menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 10px 0 18px;
  margin: 0 auto 10px;
  max-width: 1100px;
  width: 100%;
}

.book-tab {
  border: 1px solid #0a5e61;
  background: #ffffff;
  color: #0a5e61;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: bold;
  white-space: nowrap;
  transition: 0.2s ease;
  font-size: 15px;
}

.book-tab:hover {
  background: #e3f6f3;
}

.book-tab.active {
  background: #0a5e61;
  color: #ffffff;
}

/* INFO */

.book-info {
  margin-bottom: 18px;
}

#pageInfo {
  display: inline-block;
  font-weight: bold;
  color: #555;
}

/* VISOR */

.viewer-area {
  position: relative;
  display: grid;
  grid-template-columns: 56px minmax(0, 980px) 56px;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
}

.book-wrapper {
  width: 100%;
  max-width: 980px;
  height: 660px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
}

#book {
  width: 900px;
  height: 620px;
  min-width: 900px;
  min-height: 620px;
}

.page {
  background: #ffffff;
  overflow: hidden;
  border: 1px solid #ddd;
}

.page canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* FLECHAS */

.side-btn {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: #0a5e61;
  color: #ffffff;
  font-size: 46px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 6px;
  transition: 0.2s ease;
  z-index: 10;
  flex-shrink: 0;
}

.side-btn:hover {
  background: #25b79b;
  transform: scale(1.05);
}

.side-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* CARGA / ERROR */

.loading-box {
  background: #ffffff;
  padding: 30px;
  border-radius: 14px;
  max-width: 620px;
  margin: auto;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}

/* TABLET */

@media (max-width: 1050px) {
  .main {
    padding: 22px 14px 36px;
  }

  .viewer-area {
    grid-template-columns: 48px minmax(0, 760px) 48px;
    gap: 10px;
  }

  .book-wrapper {
    max-width: 760px;
    height: 560px;
  }

  #book {
    width: 760px;
    height: 540px;
    min-width: 760px;
    min-height: 540px;
  }

  .side-btn {
    width: 48px;
    height: 48px;
    font-size: 38px;
  }
}

/* CELULAR */

@media (max-width: 700px) {
  .main {
    padding: 18px 10px 28px;
  }

  .header h1 {
    font-size: 25px;
  }

  .header p {
    font-size: 14px;
  }

  .books-menu {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 10px 4px 16px;
    margin-bottom: 8px;
    scrollbar-width: thin;
  }

  .book-tab {
    padding: 9px 14px;
    font-size: 14px;
    flex: 0 0 auto;
  }

  .book-info {
    margin-bottom: 12px;
  }

  #pageInfo {
    font-size: 14px;
  }

  .viewer-area {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    gap: 6px;
    width: 100%;
  }

  .book-wrapper {
    max-width: 100%;
    height: 520px;
    overflow: visible;
  }

  #book {
    width: 78vw;
    height: 500px;
    min-width: 78vw;
    min-height: 500px;
  }

  .side-btn {
    width: 42px;
    height: 42px;
    font-size: 34px;
    padding-bottom: 5px;
  }

  .home {
    padding: 20px;
  }

  .home-card {
    padding: 28px 20px;
  }

  .home-card h1 {
    font-size: 28px;
  }

  .home-grid {
    grid-template-columns: 1fr;
  }
}

/* CELULAR PEQUEÑO */

@media (max-width: 430px) {
  .main {
    padding-left: 8px;
    padding-right: 8px;
  }

  .viewer-area {
    grid-template-columns: 36px minmax(0, 1fr) 36px;
    gap: 4px;
  }

  .book-wrapper {
    height: 470px;
  }

  #book {
    width: 76vw;
    height: 450px;
    min-width: 76vw;
    min-height: 450px;
  }

  .side-btn {
    width: 36px;
    height: 36px;
    font-size: 30px;
  }

  .book-tab {
    font-size: 13px;
    padding: 8px 12px;
  }
}

/* CELULAR MUY PEQUEÑO */

@media (max-width: 360px) {
  .viewer-area {
    grid-template-columns: 32px minmax(0, 1fr) 32px;
  }

  .book-wrapper {
    height: 430px;
  }

  #book {
    width: 74vw;
    height: 410px;
    min-width: 74vw;
    min-height: 410px;
  }

  .side-btn {
    width: 32px;
    height: 32px;
    font-size: 27px;
  }
  
}