:root {
  color-scheme: dark;
  --ink: #f5f1e7;
  --muted: #bcc8bf;
  --green: #173d2a;
  --green-2: #0d2b1c;
  --gold: #d9b86c;
  --zoom: 1;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 15%, rgba(92, 128, 88, .22), transparent 42%),
    linear-gradient(145deg, #0a1f15, var(--green-2) 55%, #081a12);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button { font: inherit; }

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.reader {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.brandbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .22em;
}

h1 {
  margin: 0;
  font-size: clamp(19px, 2vw, 28px);
  letter-spacing: .04em;
}

h1 span {
  color: var(--muted);
  font-size: .64em;
  font-weight: 500;
}

.hint {
  margin: 0 6px 3px 0;
  color: var(--muted);
  font-size: 12px;
}

.stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.stage.is-zoomed {
  display: block;
  cursor: grab;
}

.stage.is-zoomed:active { cursor: grabbing; }

.book-zoom {
  width: min(100%, 1680px);
  zoom: var(--zoom);
  transition: zoom .16s ease;
}

.stage.is-zoomed .book-zoom { margin: 0; }

#book {
  margin: auto;
  filter: drop-shadow(0 24px 34px rgba(0, 0, 0, .38));
  cursor: zoom-in;
}

.stage.is-zoomed #book { cursor: inherit; }
.stage.is-zoomed .turn { display: none; }

.page {
  overflow: hidden;
  background: #fff;
  border: 0;
}

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

.loading {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(8, 27, 18, .92);
  transition: opacity .3s ease, visibility .3s ease;
}

.loading.done { opacity: 0; visibility: hidden; }

.loading span {
  width: 34px;
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, .2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.loading p { margin: 0; color: var(--muted); font-size: 13px; }

@keyframes spin { to { transform: rotate(360deg); } }

.turn {
  position: fixed;
  top: 50%;
  z-index: 30;
  width: 46px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 14px;
  background: rgba(8, 28, 18, .74);
  color: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transform: translateY(-50%);
  transition: background .15s ease, opacity .15s ease;
}

.turn:hover { background: rgba(54, 91, 59, .9); }
.turn:disabled { opacity: .28; cursor: default; }
.turn-prev { left: max(16px, env(safe-area-inset-left)); }
.turn-next { right: max(16px, env(safe-area-inset-right)); }

.turn svg, .toolbar svg {
  width: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: max-content;
  margin: 0 auto;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 15px;
  background: rgba(8, 28, 18, .78);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .24);
  backdrop-filter: blur(12px);
}

.toolbar button {
  width: 36px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.toolbar button:hover { background: rgba(255, 255, 255, .09); }
.toolbar button:disabled { opacity: .35; cursor: default; }

.toolbar output {
  min-width: 56px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#pageNumber { color: var(--ink); font-weight: 650; }

.divider { width: 1px; height: 20px; background: rgba(255, 255, 255, .14); }

noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
  background: var(--green-2);
}

@media (pointer: coarse) {
  .book-zoom { max-width: 520px; }
}

@media (max-width: 700px) {
  .reader { gap: 8px; padding: max(10px, env(safe-area-inset-top)) 8px max(9px, env(safe-area-inset-bottom)); }
  .brandbar { padding: 0 6px; }
  .eyebrow { font-size: 8px; }
  h1 { font-size: 17px; }
  .hint { max-width: 132px; text-align: right; font-size: 10px; line-height: 1.35; }
  .turn { top: auto; bottom: 14px; width: 42px; height: 42px; border-radius: 50%; transform: none; }
  .turn-prev { left: 12px; }
  .turn-next { right: 12px; }
  .toolbar { min-height: 42px; padding: 3px 5px; }
  .toolbar button { width: 38px; height: 36px; }
  .toolbar output { min-width: 55px; font-size: 13px; }
}

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