:root {
  --color-bg: #1f243d;
  --color-surface: rgba(48, 54, 73, 0.9);
  --color-surface-strong: rgba(10, 15, 33, 0.72);
  --color-text: #f3f6ff;
  --color-muted: rgba(243, 246, 255, 0.68);
  --color-active: #ffffff;
  --book-ratio: 0.7325;
  --book-height: min(68dvh, 720px);
  --book-gap: 0px;
  --book-zoom: 1;
  --book-drag-offset: 0px;
  --book-pan-x: 0px;
  --book-pan-y: 0px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 20% 20%, rgba(59, 88, 168, 0.18) 0%, rgba(31, 36, 61, 0) 40%),
    radial-gradient(circle at 90% 100%, rgba(112, 155, 220, 0.16) 0%, rgba(31, 36, 61, 0) 55%),
    var(--color-bg);
  color: var(--color-text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.reader {
  overflow-x: clip;
}

.reader__main {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem;
}

.reader__header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

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

/* ---- Toolbar ---- */

.toolbar {
  margin: 0 auto;
  width: min(100%, 38rem);
  /* min-height: 2.9rem; */
  padding: 0.26rem 0.34rem;
  border-radius: 999px;
  background: var(--color-surface);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.06rem;
  flex-wrap: wrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.toolbar__button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  min-width: 2.25rem;
  height: 1.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease; */
}

.toolbar__button:hover,
.toolbar__button:focus-visible {
  outline: 0;
  /* background: rgba(255, 255, 255, 0.11); */
  color: var(--color-active);
}

.toolbar__button--active {
  /* background: rgba(255, 255, 255, 0.15); */
  color: var(--color-active);
}

.toolbar__button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.toolbar__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

/* -- Mobile: hide secondary, show more -- */
.toolbar__button--secondary {
  display: none;
}

.toolbar--expanded .toolbar__button--secondary {
  display: inline-flex;
}

.toolbar--expanded .toolbar__more {
  display: none;
}

/* ---- Zoom Bar ---- */

.zoombar {
  margin: 0 auto;
  width: min(100%, 22rem);
  min-height: 2.5rem;
  padding: 0.2rem 0.4rem;
  border-radius: 999px;
  background: rgba(180, 185, 200, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}

.zoombar[hidden] {
  display: none;
}

.zoombar__button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(50, 55, 70, 0.85);
  min-width: 2rem;
  height: 2rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.zoombar__button:hover,
.zoombar__button:focus-visible {
  outline: 0;
  background: rgba(255, 255, 255, 0.35);
  color: rgba(30, 35, 50, 0.95);
}

.zoombar__button--active {
  background: rgba(255, 255, 255, 0.3);
}

/* ---- Jump (hidden on mobile) ---- */

.jump {
  display: none;
}

.jump__label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
}

.jump__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: #5d6168;
  color: #3b3d41;
  text-align: right;
  padding: 0 0.4rem 0 1rem;
  border-radius: 999px 0 0 999px;
}

.jump__input::placeholder {
  color: rgba(140, 144, 150, 0.5);
}

.jump__input:focus {
  outline: 0;
}

.jump__button {
  border: 0;
  padding: 0 1.25rem 0 0.7rem;
  color: #a8a5a5;
  background: #33353a;
  cursor: pointer;
  border-radius: 0 999px 999px 0;
  display: flex;
  align-items: center;
  transition: opacity 0.15s ease;
}

.jump__button:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ---- Stage ---- */

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.8rem;
  overflow: hidden;
}

.stage__nav {
  border: 0;
  width: 2.5rem;
  height: 2.5rem;
  aspect-ratio: 1;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(10, 16, 30, 0.62);
  backdrop-filter: blur(3px);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, visibility 0.2s ease;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stage__nav:hover,
.stage__nav:focus-visible {
  outline: 0;
  transform: scale(1.05);
  background: rgba(5, 9, 24, 0.55);
}

.stage__arrow {
  display: block;
  line-height: 0;
  color: #c8c8c8;
}

.stage__nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stage__nav--hidden {
  visibility: hidden;
  pointer-events: none;
}

/* ---- Book ---- */

.book {
  --spread-factor: 1;
  margin: 0 auto;
  position: relative;
  width: calc(var(--book-height) * var(--book-ratio) * var(--spread-factor));
  height: var(--book-height);
  transform: translateX(calc(var(--book-drag-offset) + var(--book-pan-x))) translateY(var(--book-pan-y)) scale(var(--book-zoom));
  transform-origin: center center;
  transition: width 0.3s ease, transform 0.25s ease;
  display: flex;
  gap: var(--book-gap);
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.45));
  cursor: grab;
  touch-action: pan-y;
}

.book--spread {
  --spread-factor: 2;
}

.book--dragging {
  cursor: grabbing;
  transition: width 0.3s ease;
}

.book::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.book--turn-next::after {
  background: linear-gradient(100deg,
      rgba(255, 255, 255, 0) 25%,
      rgba(255, 255, 255, 0.14) 45%,
      rgba(255, 255, 255, 0) 65%);
  animation: flip-next 0.52s ease;
}

.book--turn-prev::after {
  background: linear-gradient(260deg,
      rgba(255, 255, 255, 0) 25%,
      rgba(255, 255, 255, 0.14) 45%,
      rgba(255, 255, 255, 0) 65%);
  animation: flip-prev 0.52s ease;
}

.book__sheet {
  margin: 0;
  flex: 1;
  background: #05122f;
  overflow: hidden;
  border-radius: 2px;
  position: relative;
}

.book__sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(95deg, rgba(0, 0, 0, 0.34), rgba(255, 255, 255, 0) 45%);
  opacity: 0.4;
  pointer-events: none;
}

.book__sheet--left {
  box-shadow: inset -2px 0 8px rgba(0, 0, 0, 0.38);
}

.book__sheet--right {
  box-shadow: inset 2px 0 8px rgba(0, 0, 0, 0.38);
}

.book__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.book--cover .book__sheet--left {
  display: none;
}

/* ---- Pager ---- */

.pager {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.5rem;
}


.pager__edge {
  flex: 0 0 auto;
  border: 0;
  min-width: 5rem;
  min-height: 2.6rem;
  padding: 0 1rem;
  border-radius: 999px;
  background: rgba(38, 25, 40, 0.45);
  color: var(--color-text);
  text-align: center;
  cursor: pointer;
}

.pager__edge--empty {
  cursor: default;
  opacity: 0.5;
}

.pager__edge:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.pager__dots {
  flex: 1;
  min-width: 0;
  min-height: 2.8rem;
  border-radius: 999px;
  background: rgba(38, 25, 40, 0.45);
  padding: 0.5rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.pager__dots::-webkit-scrollbar {
  display: none;
}

.pager__dot {
  flex: 0 0 auto;
  border: 0;
  width: 0.82rem;
  height: 0.82rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.38);
  cursor: pointer;
}

.pager__dot--active {
  background: #ffffff;
}

/* ---- Sidebar (TOC) ---- */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  width: min(80vw, 26rem);
  background: #fff;
  color: #222;
  transform: translateX(-100%);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
}

.sidebar[hidden] {
  display: flex;
}

.sidebar--open {
  transform: translateX(0);
}

.sidebar__header {
  min-height: 3.2rem;
  padding: 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(30, 35, 55, 0.95);
  color: #fff;
}

.sidebar__icon {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}

.sidebar__title {
  margin: 0;
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
}

.sidebar__close {
  border: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: #fff;
  font-size: 1.3rem;
  background: rgba(255, 255, 255, 0.15);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar__close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.sidebar__list {
  flex: 1;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

.sidebar__item {
  border: 0;
  width: 100%;
  text-align: left;
  background: transparent;
  color: #333;
  font-size: 1rem;
  padding: 1rem 1.1rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  transition: background 0.15s ease;
}

.sidebar__item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar__item--active {
  background: rgba(59, 130, 246, 0.08);
  color: #1a56db;
  font-weight: 600;
}

.sidebar__backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.32s ease;
  pointer-events: none;
}

.sidebar__backdrop--visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- Share Modal ---- */

.share-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.share-modal[hidden] {
  display: flex;
}

.share-modal--open {
  opacity: 1;
  pointer-events: auto;
}

.share-modal__content {
  position: relative;
  width: fit-content;
  max-width: 90vw;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  transform: translateY(1rem) scale(0.95);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.share-modal--open .share-modal__content {
  transform: translateY(0) scale(1);
}

.share-modal__header {
  display: flex;
  align-items: center;
  padding: 0.8rem 1.2rem;
  background: #181818;
  color: #fff;
}

.share-modal__icon {
  display: inline-flex;
  margin-right: 0.5rem;
}

.share-modal__title {
  margin: 0;
  flex: 1;
  font-size: 1.15rem;
  font-weight: 500;
}

.share-modal__close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.5rem;
}

.share-modal__close:hover {
  opacity: 0.8;
}

.share-modal__body {
  display: flex;
  flex-direction: column;
  padding: 1.5rem 2.5rem 2rem;
  gap: 1.8rem;
}

.share-modal__main {
  display: flex;
  gap: 2rem;
  flex-wrap: nowrap;
}

.share-modal__qr-col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.share-modal__qr-box {
  width: 9.5rem;
  height: 9.5rem;
  margin-bottom: 0.8rem;
  border: 1px solid #eee;
  padding: 0.5rem;
  background: #fff;
  border-radius: 4px;
}

.share-modal__qr-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.share-modal__qr-tabs {
  display: flex;
  background: #f5f5f5;
  padding: 2px;
  border-radius: 4px;
}

.share-modal__tab {
  border: 0;
  background: transparent;
  color: #666;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 2px;
  line-height: 1.2;
}

.share-modal__tab--active {
  background: #332a2a;
  color: #fff;
}

.share-modal__qr-copy {
  border: 0;
  background: transparent;
  color: #666;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 2px;
  line-height: 1.2;
  margin-left: auto;
  transition: color 0.2s, background 0.2s;
}

.share-modal__qr-copy:hover {
  background: #e0e0e0;
  color: #333;
}

.share-modal__platforms {
  flex: 0 0 auto;
}

.share-modal__subtitle {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 500;
  color: #333;
}

.share-modal__icons {
  display: grid;
  grid-template-columns: repeat(3, 75px);
  gap: 1.2rem 0.5rem;
}

.share-btn {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  transition: transform 0.2s ease;
}

.share-btn:hover {
  transform: translateY(-2px);
}

.share-btn__icon {
  display: block;
  width: 42px;
  height: 42px;
}

.share-btn-icon {
  display: block;
  width: 100%;
  height: 100%;
}

.share-btn__text {
  font-size: 0.75rem;
  color: #666;
  white-space: nowrap;
}

.share-modal__link-row {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.share-modal__checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: #777;
  cursor: pointer;
}

.share-modal__copy-box {
  display: flex;
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
}

.share-modal__url {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  color: #333;
  background: #fafafa;
}

.share-modal__url:focus {
  outline: 0;
}

.share-modal__copy-btn {
  border: 0;
  background: #332a2a;
  color: #fff;
  padding: 0 1.2rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.share-modal__copy-btn:hover {
  background: #4a3e3e;
}

@media (max-width: 639px) {
  .share-modal__body {
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.2rem;
  }
}

/* ---- Animations ---- */

@keyframes flip-next {
  0% {
    opacity: 0;
    transform: translateX(-14%);
  }

  40% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateX(14%);
  }
}

@keyframes flip-prev {
  0% {
    opacity: 0;
    transform: translateX(14%);
  }

  40% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateX(-14%);
  }
}

/* ---- Responsive ---- */

@media (min-width: 640px) {
  .reader__main {
    padding: 0.75rem 1rem 1rem;
  }

  .stage {
    gap: 0.9rem;
  }

  .stage__nav {
    width: 2.75rem;
    height: 2.75rem;
  }
}

@media (min-width: 980px) {
  :root {
    --book-height: min(72dvh, 760px);
  }

  .reader__main {
    padding: 0.35rem 0.85rem 0.85rem;
    gap: 0.55rem;
  }

  .stage {
    gap: 1rem;
  }

  .stage__nav {
    width: 3.25rem;
    height: 3.25rem;
  }

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

  .toolbar__button--secondary {
    display: inline-flex;
  }

  .toolbar__more {
    display: none;
  }

  .jump {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    width: 8rem;
    height: 1.75rem;
    border-radius: 999px;
    background: transparent;
  }

  .pager {
    gap: 0.85rem;
    padding: 0;
    max-width: 52rem;
    margin: 0 auto;
  }

  .pager__edge {
    min-width: 6rem;
  }

  .pager__dots {
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    transition-duration: 0.01ms;
  }
}