:root {
  color-scheme: dark;
  --bg: #081018;
  --panel: rgba(11, 19, 29, 0.72);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f5f8fb;
  --muted: rgba(245, 248, 251, 0.68);
  --cyan: #58d5ff;
  --violet: #a78bfa;
  --mint: #7ee7c7;
  --paper-shadow: rgba(0, 0, 0, 0.5);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

.app {
  position: relative;
  min-height: 100vh;
  padding: clamp(14px, 2.5vw, 28px);
  background:
    linear-gradient(135deg, rgba(88, 213, 255, 0.16), transparent 32%),
    linear-gradient(315deg, rgba(167, 139, 250, 0.16), transparent 38%),
    linear-gradient(180deg, #09131d 0%, #090f16 54%, #05080d 100%);
  overflow: hidden;
}

.app::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: linear-gradient(to bottom, transparent 0%, black 14%, black 72%, transparent 100%);
  pointer-events: none;
}

.light-ribbon {
  position: absolute;
  width: 72vw;
  height: 22vh;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transform: rotate(-12deg);
  opacity: 0.65;
  pointer-events: none;
}

.ribbon-one {
  top: 7vh;
  left: -22vw;
  background: linear-gradient(90deg, transparent, rgba(88, 213, 255, 0.12), transparent);
}

.ribbon-two {
  right: -28vw;
  bottom: 11vh;
  background: linear-gradient(90deg, transparent, rgba(126, 231, 199, 0.11), transparent);
}

.stage {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(10px, 1.7vh, 18px);
  max-width: 1180px;
  height: calc(100vh - clamp(28px, 5vw, 56px));
  margin: 0 auto;
}

.topbar,
.control-deck {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.24);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(14px, 2.2vw, 24px);
}

.brand {
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--mint);
  font-size: 12px;
  font-weight: 700;
}

.brand-mark::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 18px rgba(126, 231, 199, 0.8);
}

h1 {
  margin: 0;
  font-family: "Cormorant Garamond", "Aptos Display", "Segoe UI Variable Display", "Helvetica Neue", "PingFang SC", "Microsoft YaHei", serif;
  font-size: clamp(21px, 2.7vw, 32px);
  font-weight: 600;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #ffffff 0%, #c7f6ff 42%, #96b7ff 78%, #d7c7ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 18px rgba(88, 213, 255, 0.2), 0 0 36px rgba(167, 139, 250, 0.12);
}

.counter {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#pageNumber {
  font-family: "Cormorant Garamond", "Aptos Display", "Segoe UI Variable Display", "Bahnschrift", "Helvetica Neue", serif;
  font-size: clamp(30px, 4.6vw, 48px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #ffffff 0%, #c7f6ff 46%, #96a9ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 22px rgba(88, 213, 255, 0.2);
}

.counter-total {
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.reader {
  position: relative;
  display: block;
  min-height: 0;
  touch-action: pan-y;
}

.book-shell {
  position: relative;
  justify-self: center;
  width: min(94vw, calc((100vh - 130px) * 1.48), 1220px);
  min-width: 280px;
  aspect-ratio: 1190 / 850;
  margin: 0 auto;
  perspective: 2200px;
}

.book-shell::before {
  content: "";
  position: absolute;
  inset: 2% -4% -3%;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.36);
  filter: blur(28px);
  transform: translateY(18px);
}

.book {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.book-binding {
  position: absolute;
  z-index: 8;
  top: 2.4%;
  bottom: 2.4%;
  left: -9px;
  width: 18px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.02)),
    linear-gradient(180deg, rgba(88, 213, 255, 0.4), rgba(167, 139, 250, 0.34));
  box-shadow: 0 0 24px rgba(88, 213, 255, 0.28);
  pointer-events: none;
}

.page-frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px var(--paper-shadow);
  transform: rotateY(0deg);
  transform-origin: left center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transition:
    transform 1080ms cubic-bezier(0.18, 0.9, 0.14, 1),
    filter 1080ms cubic-bezier(0.18, 0.9, 0.14, 1),
    box-shadow 1080ms cubic-bezier(0.18, 0.9, 0.14, 1);
  will-change: transform;
}

.page-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.2), transparent 9%, transparent 84%, rgba(255, 255, 255, 0.15)),
    linear-gradient(130deg, rgba(88, 213, 255, 0.1), transparent 28%, rgba(167, 139, 250, 0.08) 74%, transparent);
  mix-blend-mode: multiply;
  pointer-events: none;
}

.page-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.page-old {
  z-index: 5;
}

.page-new {
  z-index: 4;
}

.page-old.turn-out-next {
  transform: rotateY(-112deg);
  filter: brightness(0.86) saturate(0.86);
  box-shadow: -22px 22px 80px rgba(0, 0, 0, 0.45);
}

.page-new.pre-turn-prev {
  z-index: 6;
  transform: rotateY(-112deg);
  filter: brightness(0.86) saturate(0.9);
}

.page-new.turn-in-prev {
  transform: rotateY(0deg);
  filter: brightness(1) saturate(1);
}

.page-spread {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 24px 80px var(--paper-shadow);
  transform: translateZ(0);
  transform-style: preserve-3d;
  will-change: opacity, transform, filter;
}

.page-spread::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08), transparent 10%, transparent 49.2%, rgba(0, 0, 0, 0.12) 50%, transparent 50.8%, transparent 90%, rgba(255, 255, 255, 0.05)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.08));
  pointer-events: none;
  z-index: 2;
}

.spread-page {
  position: relative;
  inset: auto;
  transform: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.spread-page img {
  object-position: center;
}

.spread-left {
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.spread-right {
  border-left: 1px solid rgba(255, 255, 255, 0.16);
}

.spread-current {
  z-index: 1;
  transition: opacity 180ms ease, filter 180ms ease, transform 180ms ease;
}

.spread-current.is-dimming {
  opacity: 0.18;
  filter: brightness(0.82) saturate(0.9);
  transform: scale(0.994) translateZ(0);
}

.spread-target {
  z-index: 3;
  opacity: 0;
  filter: brightness(0.94) saturate(0.96);
  transform: scale(1.006) translateZ(0);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    filter 180ms ease;
}

.spread-target.is-visible {
  opacity: 1;
  filter: brightness(1) saturate(1);
  transform: scale(1) translateZ(0);
}

.turn-leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 10;
  transform-style: preserve-3d;
  transition:
    transform 460ms cubic-bezier(0.18, 0.9, 0.18, 1),
    box-shadow 460ms cubic-bezier(0.18, 0.9, 0.18, 1);
  will-change: transform, box-shadow;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.2));
}

.turn-forward {
  left: 50%;
  transform-origin: left center;
}

.turn-backward {
  left: 0;
  transform-origin: right center;
}

.turn-leaf::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.42), transparent 12%, transparent 72%, rgba(0, 0, 0, 0.28)),
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.24), transparent 34%),
    linear-gradient(135deg, rgba(88, 213, 255, 0.08), transparent 42%, rgba(167, 139, 250, 0.1));
  pointer-events: none;
  z-index: 3;
  opacity: 0.9;
  transition: opacity 460ms ease;
}

.turn-leaf::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 16%;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.3), transparent 70%);
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 460ms ease;
}

.turn-forward::after {
  left: 0;
}

.turn-backward::after {
  right: 0;
  transform: scaleX(-1);
}

.turn-leaf.is-turning.turn-forward {
  transform: rotateY(-180deg);
  box-shadow: -18px 14px 56px rgba(0, 0, 0, 0.38);
}

.turn-leaf.is-turning.turn-backward {
  transform: rotateY(180deg);
  box-shadow: 18px 14px 56px rgba(0, 0, 0, 0.38);
}

.turn-leaf.is-turning::before {
  opacity: 0.64;
}

.turn-leaf.is-turning::after {
  opacity: 1;
}

.turn-sheet {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transition: transform 460ms cubic-bezier(0.18, 0.9, 0.18, 1);
}

.turn-forward .turn-sheet {
  transform-origin: left center;
}

.turn-backward .turn-sheet {
  transform-origin: right center;
}

.turn-leaf.is-turning .turn-sheet {
  transform:
    translateX(0)
    scaleX(0.985)
    skewY(-1deg);
}

.turn-leaf.is-turning.turn-forward .turn-sheet {
  transform:
    translateX(-0.8%)
    scaleX(0.965)
    skewY(1.4deg);
}

.turn-leaf.is-turning.turn-backward .turn-sheet {
  transform:
    translateX(0.8%)
    scaleX(0.965)
    skewY(-1.4deg);
}

.turn-front::before,
.turn-backface::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.turn-front::before {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), transparent 26%, transparent 72%, rgba(0, 0, 0, 0.12)),
    radial-gradient(circle at 100% 50%, rgba(0, 0, 0, 0.28), transparent 34%);
  opacity: 0.82;
}

.turn-backface::before {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.16), transparent 22%, transparent 76%, rgba(255, 255, 255, 0.12)),
    radial-gradient(circle at 0% 50%, rgba(0, 0, 0, 0.2), transparent 34%);
  opacity: 0.88;
}

.turn-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

.turn-front {
  z-index: 1;
}

.turn-backface {
  transform: rotateY(180deg);
}

.nav-button {
  display: grid;
  place-items: center;
  position: absolute;
  z-index: 20;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease, opacity 180ms ease;
}

.nav-button svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.nav-button:hover:not(:disabled) {
  transform: translateY(-50%) scale(1.06);
  background: rgba(88, 213, 255, 0.18);
  border-color: rgba(88, 213, 255, 0.55);
}

.nav-button:disabled {
  cursor: default;
  opacity: 0.36;
}

.control-deck {
  padding: 12px;
}

@media (min-width: 761px) {
  .stage {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .control-deck {
    display: none;
  }

  .nav-prev {
    left: clamp(8px, 2vw, 24px);
  }

  .nav-next {
    right: clamp(8px, 2vw, 24px);
  }
}

.progress {
  height: 4px;
  margin: 0 2px 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.progress span {
  display: block;
  width: 8.3333%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--violet), var(--mint));
  box-shadow: 0 0 18px rgba(88, 213, 255, 0.62);
  transition: width 320ms ease;
}

.thumb-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(50px, 58px);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}

.thumb-button {
  position: relative;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  aspect-ratio: 595 / 850;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.thumb-button img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.thumb-button span {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 22px;
  padding: 3px 5px;
  border-radius: 999px;
  background: rgba(3, 7, 12, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.thumb-button:hover,
.thumb-button.is-active {
  transform: translateY(-2px);
  border-color: rgba(126, 231, 199, 0.74);
  box-shadow: 0 0 0 2px rgba(126, 231, 199, 0.14), 0 12px 28px rgba(0, 0, 0, 0.28);
}

@media (max-width: 760px) {
  body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app {
    min-height: 100svh;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .app::before {
    background-size: 36px 36px;
  }

  .light-ribbon {
    width: 110vw;
    height: 16vh;
  }

  .ribbon-one {
    top: 3vh;
    left: -35vw;
  }

  .ribbon-two {
    right: -40vw;
    bottom: 6vh;
  }

  .stage {
    height: auto;
    min-height: calc(100svh - 20px);
    gap: 10px;
  }

  .topbar {
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .brand-mark {
    font-size: 10px;
    margin-bottom: 3px;
  }

  h1 {
    letter-spacing: 0.04em;
  }

  #pageNumber {
    font-size: 26px;
  }

  .counter-total {
    font-size: 13px;
  }

  .reader {
    display: block;
    gap: 10px;
    position: relative;
    flex: 1;
    min-height: 0;
  }

  .book-shell {
    width: min(92vw, 440px);
    min-width: 0;
    aspect-ratio: auto;
    max-height: calc(100svh - 210px);
    order: 1;
    margin: 0 auto;
  }

  .book-shell::before {
    filter: blur(16px);
    transform: translateY(10px);
  }

  .book {
    position: relative;
    width: 100%;
    aspect-ratio: 595 / 850;
    max-height: calc(100svh - 210px);
  }

  .book-binding {
    display: none;
  }

  .page-frame {
    border-radius: 6px;
    position: relative;
    aspect-ratio: 595 / 850;
  }

  .page-frame::after {
    border-radius: 6px;
  }

  .page-frame img {
    border-radius: 6px;
  }

  .nav-button {
    position: absolute;
    z-index: 10;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
  }

  .nav-button svg {
    width: 22px;
    height: 22px;
    stroke-width: 2.6;
  }

  .nav-prev {
    left: 2px;
  }

  .nav-next {
    right: 2px;
  }

  .nav-button:hover:not(:disabled) {
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.12);
  }

  .nav-button:active:not(:disabled) {
    background: rgba(88, 213, 255, 0.28);
    border-color: rgba(88, 213, 255, 0.5);
    transform: translateY(-50%) scale(0.94);
  }

  .control-deck {
    padding: 10px;
    border-radius: 8px;
  }

  .progress {
    height: 3px;
    margin: 0 2px 10px;
  }

  .thumb-strip {
    grid-auto-columns: minmax(40px, 52px);
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .thumb-strip::-webkit-scrollbar {
    display: none;
  }

  .thumb-button {
    border-radius: 6px;
  }

  .thumb-button span {
    right: 2px;
    bottom: 2px;
    min-width: 18px;
    padding: 2px 4px;
    font-size: 9px;
  }

  .thumb-button.is-active {
    transform: translateY(-1px);
    box-shadow: 0 0 0 1.5px rgba(126, 231, 199, 0.6), 0 6px 16px rgba(0, 0, 0, 0.3);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}
