#viewer {
  display: inline-block;
  position: relative;
  max-width: 90%;
  line-height: 0;
}

#viewer-wrap {
  text-align: center;
}

#viewer:fullscreen,
#viewer.is-fullscreen {
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: #000;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
}

#viewer.is-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99999;
}

#viewer canvas {
  display: block;
  max-width: 100%;
  transition: opacity 0.3s ease, transform 0.3s ease;
  image-rendering: auto;
  -webkit-image-rendering: auto;
  border: 5px solid #d0d0d0;
  height: auto !important;
}

#viewer:fullscreen canvas,
#viewer.is-fullscreen canvas {
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  border: none;
}

#viewer canvas.page-exit-left {
  opacity: 0;
  transform: translateX(-30px);
}

#viewer canvas.page-exit-right {
  opacity: 0;
  transform: translateX(30px);
}

#viewer canvas.page-enter {
  opacity: 0;
  transition: none;
}

#viewer canvas.page-enter-active {
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.nav-btn {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
  background: rgba(30, 30, 30, 0.7);
  backdrop-filter: blur(8px);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  opacity: 0.7;
}

.nav-btn:hover {
  background: rgba(30, 30, 30, 0.9);
  opacity: 1;
}

#prev { left: 12px; }
#next { right: 12px; }

#bottom-bar {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(30, 30, 30, 0.85);
  backdrop-filter: blur(8px);
  color: white;
  padding: 8px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  width: fit-content;
}

#bottom-bar button {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: white;
  padding: 6px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

#bottom-bar button:hover {
  background: rgba(255, 255, 255, 0.25);
}

#bottom-bar span {
  font-size: 14px;
  white-space: nowrap;
  line-height: normal;
}

.page-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#page_num {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  color: white;
  font-size: 14px;
  min-width: 2.5ch;
  text-align: center;
  padding: 4px 8px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  line-height: normal;
}

#page_num:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

#page-select {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

#page-list {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 25%;
  transform: translateX(-50%);
  background: rgba(30, 30, 30, 0.95);
  backdrop-filter: blur(12px);
  border-radius: 8px;
  padding: 4px;
  overflow-y: auto;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  flex-direction: column;
}

#page-list.open {
  display: flex;
}

#page-list button {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  padding: 6px 16px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  text-align: center;
  line-height: normal;
  white-space: nowrap;
}

#page-list button:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

#page-list button.highlight {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

#page-list button.active {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-weight: 600;
}
