:root {
  --olive: #8f916d;
  --olive-dark: #5f6246;
  --olive-deep: #3f432f;
  --paper: #fbfaf5;
  --ink: #282a20;
  --muted: #777a65;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #e7e7db;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { -webkit-appearance: none; appearance: none; }

.reader {
  height: 100vh;
  height: 100dvh;
  min-height: 520px;
  display: grid;
  grid-template-rows: calc(64px + var(--safe-top)) minmax(0, 1fr) calc(82px + var(--safe-bottom));
  background:
    radial-gradient(circle at 50% 28%, rgba(255,255,255,.8), transparent 46%),
    linear-gradient(180deg, #f0f0e7, #dcdccc);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--safe-top) 16px 0;
  border-bottom: 1px solid rgba(63,67,47,.1);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark, .help-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 48% 48% / 58% 58% 42% 42%;
  color: white;
  background: var(--olive);
  font-family: "Songti SC", STSong, serif;
  font-size: 17px;
}
.brand h1 { margin: 0; font-size: 15px; letter-spacing: .1em; font-weight: 650; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 11px; letter-spacing: .08em; }

.icon-button, .round-button {
  border: 1px solid rgba(63,67,47,.18);
  color: var(--olive-deep);
  background: rgba(255,255,255,.66);
  border-radius: 50%;
  cursor: pointer;
}
.icon-button { width: 34px; height: 34px; font-weight: 700; }

.book-area {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 10px 12px 6px;
  perspective: 1800px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.page {
  position: relative;
  width: min(calc(100vw - 24px), 520px);
  height: auto;
  max-height: 100%;
  aspect-ratio: 595.5 / 842.25;
  background: white;
  border-radius: 2px 6px 6px 2px;
  overflow: hidden;
  transform-style: preserve-3d;
  transform-origin: left center;
  box-shadow: 0 14px 36px rgba(43,45,31,.18), 0 2px 5px rgba(43,45,31,.16);
  z-index: 2;
}

.page::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(55,58,38,.14), rgba(255,255,255,.04));
}

.page img { width: 100%; height: 100%; display: block; object-fit: contain; pointer-events: none; }
.page-sheen {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,.7));
}

.book-shadow {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: min(72vw, 440px);
  height: 22px;
  border-radius: 50%;
  background: rgba(49,52,35,.25);
  filter: blur(16px);
  transform: translateX(-50%);
}

.tap-zone {
  position: absolute;
  z-index: 4;
  top: 10px;
  bottom: 6px;
  width: 36%;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.tap-prev { left: 0; }
.tap-next { right: 0; }
.tap-zone:disabled { cursor: default; }

.swipe-hint {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 18px;
  color: white;
  background: rgba(50,54,36,.78);
  box-shadow: 0 5px 18px rgba(0,0,0,.16);
  font-size: 12px;
  letter-spacing: .04em;
  white-space: nowrap;
  animation: hint-out .5s ease 3s forwards;
}
.swipe-hint span { color: #e4e5cf; font-size: 15px; }
@keyframes hint-out { to { opacity: 0; transform: translate(-50%, 8px); visibility: hidden; } }

.page.turn-next { animation: turn-next .42s cubic-bezier(.5,.05,.25,1); }
.page.turn-prev { animation: turn-prev .42s cubic-bezier(.5,.05,.25,1); transform-origin: right center; }
.page.turn-next .page-sheen, .page.turn-prev .page-sheen { animation: sheen .42s ease; }
@keyframes turn-next {
  0% { transform: rotateY(0) translateX(0); filter: brightness(1); }
  48% { transform: rotateY(-34deg) translateX(-2%); filter: brightness(.82); }
  49% { opacity: .4; }
  50% { transform: rotateY(24deg) translateX(2%); opacity: .15; }
  100% { transform: rotateY(0) translateX(0); opacity: 1; filter: brightness(1); }
}
@keyframes turn-prev {
  0% { transform: rotateY(0) translateX(0); filter: brightness(1); }
  48% { transform: rotateY(34deg) translateX(2%); filter: brightness(.82); }
  49% { opacity: .4; }
  50% { transform: rotateY(-24deg) translateX(-2%); opacity: .15; }
  100% { transform: rotateY(0) translateX(0); opacity: 1; filter: brightness(1); }
}
@keyframes sheen { 0%,100% { opacity: 0; } 45%,55% { opacity: .8; } }

.controls {
  display: grid;
  grid-template-columns: 44px minmax(110px, 1fr) 44px auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: rgba(250,250,245,.92);
  border-top: 1px solid rgba(63,67,47,.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.round-button { width: 44px; height: 44px; font-size: 28px; line-height: 1; }
.round-button:disabled { opacity: .28; }
.progress-wrap { min-width: 0; display: grid; gap: 3px; }
.page-count { display: flex; align-items: baseline; justify-content: center; gap: 4px; color: var(--muted); font-size: 11px; }
.page-count strong { color: var(--olive-deep); font-size: 17px; }
input[type="range"] { width: 100%; accent-color: var(--olive); height: 18px; }
.zoom-button {
  min-width: 66px;
  height: 42px;
  padding: 0 11px;
  border: 0;
  border-radius: 22px;
  color: white;
  background: var(--olive-dark);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.zoom-button span { font-size: 17px; vertical-align: -1px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(27,29,20,.94);
}
.modal[hidden] { display: none; }
.modal-close {
  position: fixed;
  z-index: 55;
  top: calc(12px + var(--safe-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: rgba(0,0,0,.55);
  font-size: 28px;
  line-height: 1;
}
.zoom-scroller {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: calc(68px + var(--safe-top)) 18px calc(28px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
  text-align: center;
}
.zoom-scroller img {
  display: inline-block;
  width: min(200vw, 980px);
  max-width: none;
  height: auto;
  background: white;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
}

.help-modal { display: grid; place-items: center; padding: 24px; background: rgba(41,44,30,.72); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.help-card {
  position: relative;
  width: min(100%, 360px);
  padding: 34px 26px 24px;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 22px 70px rgba(0,0,0,.28);
}
.help-close { position: absolute; top: 10px; right: 10px; color: var(--olive-deep); background: transparent; }
.help-mark { width: 48px; height: 48px; font-size: 22px; }
.help-card h2 { margin: 18px 0 16px; color: var(--olive-deep); font-family: "Songti SC", STSong, serif; font-weight: 500; }
.help-card ul { margin: 0; padding-left: 1.2em; color: #515441; font-size: 14px; line-height: 1.9; }
.primary-button { width: 100%; height: 46px; margin-top: 20px; border: 0; border-radius: 24px; color: white; background: var(--olive-dark); font-weight: 650; }

@media (min-width: 700px) {
  .reader { grid-template-rows: calc(72px + var(--safe-top)) minmax(0, 1fr) calc(88px + var(--safe-bottom)); }
  .topbar, .controls { padding-left: max(24px, calc((100vw - 820px)/2)); padding-right: max(24px, calc((100vw - 820px)/2)); }
  .page { border-radius: 3px 8px 8px 3px; }
  .tap-zone { width: calc(50% - 130px); }
}

@media (max-height: 620px) {
  .reader { grid-template-rows: calc(52px + var(--safe-top)) minmax(0, 1fr) calc(70px + var(--safe-bottom)); }
  .brand-mark { width: 30px; height: 30px; }
  .brand p { display: none; }
  .controls { padding-top: 5px; padding-bottom: calc(5px + var(--safe-bottom)); }
  .round-button { width: 38px; height: 38px; }
  .zoom-button { height: 38px; }
}

@media (max-width: 360px) {
  .controls {
    grid-template-columns: 38px minmax(80px, 1fr) 38px 66px;
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .round-button { width: 38px; height: 38px; }
  .zoom-button { min-width: 0; width: 66px; padding: 0 7px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
