* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #111827;
  color: #e5e7eb;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(17, 24, 39, 0.95);
  border-bottom: 1px solid #374151;
  padding: 6px 8px 5px;
  backdrop-filter: blur(4px);
}

.toolbar-row {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
  scrollbar-width: thin;
}

.btn {
  border: 1px solid #4b5563;
  background: #1f2937;
  color: #e5e7eb;
  border-radius: 10px;
  height: 32px;
  padding: 0 9px;
  cursor: pointer;
  font-size: 13px;
  flex: 0 0 auto;
}

.btn:hover {
  background: #374151;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  background: #1f2937;
}

.btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.btn.primary:hover {
  background: #1d4ed8;
}

.icon-btn {
  min-width: 32px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#page-input,
#search-input {
  height: 32px;
  border: 1px solid #4b5563;
  border-radius: 10px;
  padding: 0 9px;
  outline: none;
  background: #111827;
  color: #f9fafb;
  flex: 0 0 auto;
}

#page-input {
  width: 64px;
}

#search-input {
  width: min(240px, 46vw);
  background: #ffffff;
  color: #111827;
  border: 1px solid #cbd5e1;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18);
  font-weight: 600;
}

#page-input:focus,
#search-input:focus {
  border-color: #2563eb;
}

.status {
  font-size: 12px;
  color: #9ca3af;
  margin: 0;
  white-space: nowrap;
}

.status.compact {
  font-size: 12px;
}

.viewer-wrapper {
  flex: 1;
  min-height: 0;
  padding: 4px 7px 7px;
  display: flex;
}

.page-stage {
  position: relative;
  flex: 1;
  border-radius: 10px;
  background: radial-gradient(circle at center, #1f2937 0%, #0b1220 70%);
  border: 1px solid #1f2937;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 6px;
}

.side-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 88px;
  border: 0;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.35);
  color: rgba(255, 255, 255, 0.85);
  font-size: 20px;
  cursor: pointer;
  z-index: 4;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.side-nav:hover {
  background: rgba(15, 23, 42, 0.6);
}

.side-nav:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.side-nav.hidden {
  opacity: 0;
  pointer-events: none;
}

.side-prev {
  left: 8px;
}

.side-next {
  right: 8px;
}

.inner-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(17, 24, 39, 0.84);
  color: #f9fafb;
  font-size: 13px;
  border: 1px solid #4b5563;
  border-radius: 999px;
  padding: 8px 14px;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.inner-loading.show {
  opacity: 1;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.cover-view {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 8px;
}

#cover-image {
  max-width: min(560px, 92vw);
  max-height: calc(100vh - 120px);
  width: auto;
  height: auto;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
}

.book-spread {
  position: relative;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px;
}

.book-spread.ready {
  display: inline-flex;
}

.book-spine {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 50%;
  width: 8px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.45) 0%,
    rgba(255, 255, 255, 0.18) 50%,
    rgba(0, 0, 0, 0.45) 100%
  );
  pointer-events: none;
}

.page-sheet {
  display: none;
  background: #fff;
  border-radius: 2px;
  border: 1px solid #d1d5db;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (max-width: 768px) {
  .toolbar {
    padding: 4px 6px 2px;
  }

  .toolbar-row {
    gap: 6px;
    margin-bottom: 1px;
  }

  .btn,
  #page-input,
  #search-input {
    height: 30px;
    font-size: 12px;
  }

  .icon-btn {
    min-width: 30px;
  }

  #search-input {
    width: min(160px, 38vw);
  }

  .viewer-wrapper {
    padding: 0 6px 6px;
    margin-top: -6px;
  }

  #load-status {
    display: none;
  }

  .page-stage {
    padding: 4px;
  }

  .side-nav {
    width: 32px;
    height: 72px;
    font-size: 18px;
  }

  .side-prev {
    left: 4px;
  }

  .side-next {
    right: 4px;
  }

  .book-spread {
    gap: 10px;
    padding: 4px;
  }

  #cover-image {
    max-width: 94vw;
    max-height: calc(100vh - 96px);
  }

  .book-spine {
    width: 6px;
  }
}

/* Template skin overrides */
body {
  background: #d7dee8;
}

.app {
  background: url("./img/bg.jpg") center/cover no-repeat;
}

.toolbar {
  position: static;
  background: transparent;
  border-bottom: 0;
  padding: 16px 18px 8px;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-box {
  flex: 1;
  height: 40px;
  background: url("./img/search-box.png") center/100% 100% no-repeat;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 106px 0 14px;
}

#search-input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  color: #7d8390;
  font-size: 14px;
  font-weight: 600;
  box-shadow: none;
}

.image-btn {
  border: 0;
  background: transparent no-repeat center/100% 100%;
  padding: 0;
  cursor: pointer;
}

.clear-btn {
  position: absolute;
  right: 96px;
  width: 18px;
  height: 18px;
  background-image: url("./img/search-clear.png");
  opacity: 0.7;
}

.search-btn {
  position: absolute;
  right: 4px;
  top: 2px;
  width: 80px;
  height: 36px;
  background-image: url("./img/search-btn.png");
}

.search-btn:disabled,
.clear-btn:disabled {
  opacity: 0.4;
}

.hidden-controls,
.hidden-status {
  display: none;
}

.viewer-wrapper {
  padding: 6px 18px 0;
  margin-top: 0;
}

.page-stage {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  touch-action: pan-y;
}

.side-nav {
  width: 24px;
  height: 62px;
  background-color: transparent;
}

.side-prev {
  left: -2px;
  background-image: url("./img/side-prev.png");
}

.side-next {
  right: -2px;
  background-image: url("./img/side-next.png");
}

.cover-view {
  padding: 0;
}

#cover-image {
  max-width: 100%;
  max-height: 100%;
}

.page-sheet {
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.flip-layer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 7;
  pointer-events: none;
  border: 0;
  box-shadow: none;
  backface-visibility: hidden;
  will-change: transform, opacity;
}

.flip-shadow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(80vw, 360px);
  height: min(70vh, 560px);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  display: none;
  will-change: opacity;
}

.book-spine {
  display: none;
}

.bottom-controls {
  position: relative;
  height: 112px;
  padding-bottom: 30px;
}

.nav-btn,
.zoom-btn {
  position: absolute;
  bottom: 30px;
  width: 42px;
  height: 42px;
}

#prev-page {
  left: 14%;
  background-image: url("./img/bottom-prev.png");
}

#next-page {
  left: 78%;
  background-image: url("./img/bottom-next.png");
}

#zoom-in {
  left: 57%;
  background-image: url("./img/zoom-in.png");
}

#zoom-out {
  left: 35%;
  background-image: url("./img/zoom-out.png");
}

.bottom-controls .image-btn:disabled {
  opacity: 0.35;
}

@media (max-width: 768px) {
  .toolbar {
    padding: 16px 18px 8px;
  }

  .viewer-wrapper {
    padding: 6px 18px 0;
  }

  .search-box {
    height: 38px;
    padding-right: 102px;
  }

  .search-btn {
    width: 76px;
    height: 34px;
    top: 2px;
  }

  .clear-btn {
    right: 90px;
  }

  .bottom-controls {
    height: 106px;
  }

  .nav-btn,
  .zoom-btn {
    width: 40px;
    height: 40px;
    bottom: 28px;
  }
}
