:root {
  color-scheme: dark;
  --navy: #071a3b;
  --blue: #193f86;
  --line: rgba(255, 255, 255, 0.14);
  font-family: Arial, Helvetica, sans-serif;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #041027;
  color: #fff;
}
button,
a {
  font: inherit;
  color: inherit;
}
.reader {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: radial-gradient(
    circle at 50% 44%,
    #1c3765 0,
    #071a3b 48%,
    #030b1b 100%
  );
}
.topbar,
.bottombar {
  height: 64px;
  padding: 0 max(22px, env(safe-area-inset-left)) 0
    max(22px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 4;
  background: rgba(3, 12, 30, 0.78);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.bottombar {
  height: 58px;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}
.brand-name {
  font-family: Copperplate, "Copperplate Gothic Bold", serif;
  font-size: 18px;
  letter-spacing: 0;
  white-space: nowrap;
}
.brand-logo {
  display: block;
  width: 54px;
  height: 40px;
  overflow: hidden;
  background: #fff;
  border-radius: 2px;
}
.brand-logo img {
  display: block;
  width: 54px;
  height: 54px;
  transform: translateY(-3px);
}
.top-actions {
  display: flex;
  gap: 8px;
}
.tool,
.edge,
.index {
  border: 0;
  background: transparent;
  cursor: pointer;
}
.tool {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 5px;
  font-size: 23px;
}
.download-icon {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 3px;
  font-size: 20px;
  line-height: 1;
  padding-bottom: 1px;
}
.tool:hover,
.edge:hover,
.index:hover {
  background: rgba(255, 255, 255, 0.1);
}
.stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 18px 60px;
}
.book {
  position: relative;
  height: min(84vh, calc(100vh - 150px));
  aspect-ratio: 595.276/841.89;
  max-width: calc(100vw - 120px);
  user-select: none;
  touch-action: none;
  perspective: 1600px;
}
.page,
.page-shadow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  background: #fff;
}
.page.next {
  opacity: 0;
  z-index: 1;
  transform-origin: left center;
  backface-visibility: hidden;
}
.page.current {
  z-index: 2;
  transform-origin: left center;
  backface-visibility: hidden;
}
.book.turn-left .current { animation: bookNext .5s cubic-bezier(.42,0,.58,1) forwards; }
.book.turn-left .next { opacity: 1; }
.book.turn-right .current { z-index: 1; }
.book.turn-right .next { opacity: 1; z-index: 3; animation: bookPrevious .5s cubic-bezier(.42,0,.58,1) forwards; }
.page-shadow {
  filter: blur(15px);
  transform: translateY(12px);
  opacity: 0.5;
  box-shadow: none;
}
.edge {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 100px;
  border-radius: 8px;
  font-size: 54px;
  font-weight: 200;
  color: rgba(255, 255, 255, 0.7);
  z-index: 3;
}
.edge-prev {
  left: 8px;
}
.edge-next {
  right: 8px;
}
.hint {
  position: absolute;
  bottom: 8px;
  opacity: 0.55;
  font-size: 11px;
  letter-spacing: 0.08em;
  transition: opacity .5s;
}
.index {
  white-space: nowrap;
  font-size: 12px;
  padding: 7px 0;
}
.index strong {
  font-size: 18px;
  margin-right: 3px;
}
.progress {
  height: 2px;
  background: var(--line);
  flex: 1;
  max-width: 220px;
}
.progress i {
  display: block;
  height: 100%;
  background: #7fa8ed;
  transition: width 0.3s;
}
.domain {
  opacity: 0.6;
  font-size: 10px;
  letter-spacing: 0.1em;
}
.thumb-panel {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 58px;
  max-height: 38vh;
  overflow: auto;
  padding: 16px 22px;
  background: rgba(3, 12, 30, 0.96);
  border-top: 1px solid var(--line);
  transform: translateY(110%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform .3s, opacity .3s, visibility .3s;
}
.thumb-panel.open {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
#thumbGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
  max-width: 1100px;
  margin: auto;
}
.thumb {
  border: 1px solid transparent;
  background: none;
  padding: 0;
  cursor: pointer;
  opacity: 0.62;
}
.thumb.active {
  border-color: #83abef;
  opacity: 1;
}
.thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 595/842;
  object-fit: cover;
}
dialog {
  background: #0a1d41;
  color: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}
dialog form {
  display: flex;
  gap: 10px;
  align-items: center;
}
dialog input,
dialog button {
  border: 1px solid var(--line);
  background: #102a59;
  color: #fff;
  padding: 8px;
  border-radius: 4px;
}
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  justify-items: center;
  color: #9eb6db;
  background: #fff;
  z-index: 5;
}
.loading span {
  width: 22px;
  height: 22px;
  border: 2px solid #d5deed;
  border-top-color: #21479a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading small {
  font-size: 11px;
  color: #254475;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes bookNext { 45% { box-shadow: 16px 18px 42px rgba(0,0,0,.48); } to { transform: rotateY(-178deg); box-shadow: 28px 18px 48px rgba(0,0,0,.18); } }
@keyframes bookPrevious { from { transform: rotateY(-178deg); box-shadow: 28px 18px 48px rgba(0,0,0,.18); } 55% { box-shadow: 16px 18px 42px rgba(0,0,0,.48); } to { transform: rotateY(0); box-shadow: 0 18px 48px rgba(0,0,0,.38); } }
@media (prefers-reduced-motion: reduce) { .book.turn-left .current, .book.turn-right .current { animation-duration: .01ms; } }
@media (max-width: 600px) {
  .topbar {
    height: 52px;
    padding: 0 14px;
  }
  .brand-logo {
    width: 44px;
    height: 34px;
  }
  .brand-logo img {
    width: 44px;
    height: 44px;
    transform: translateY(-2px);
  }
  .brand-name { font-size: 15px; }
  .stage {
    padding: 10px 12px;
  }
  .book {
    height: min(calc(100dvh - 135px), calc((100vw - 24px) * 1.4147));
    max-width: none;
  }
  .edge {
    width: 35px;
    height: 72px;
    font-size: 42px;
  }
  .edge-prev {
    left: -4px;
  }
  .edge-next {
    right: -4px;
  }
  .bottombar {
    height: 48px;
    padding: 0 14px;
    gap: 10px;
  }
  .domain {
    display: none;
  }
  .hint {
    font-size: 10px;
    bottom: 3px;
  }
  .progress {
    max-width: none;
  }
}
