:root {
  --ink: #0c2927;
  --deep: #0b312d;
  --green: #123f39;
  --green-2: #174b44;
  --gold: #d7ad61;
  --gold-soft: #ead4a8;
  --paper: #f5efe4;
  --white: #fffdf8;
  --ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  background: #061d1b;
  color: var(--white);
  font-family: var(--ui);
}

button, a { font: inherit; }

button { color: inherit; }

.ambient {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 50% 18%, rgba(53, 112, 100, .48), transparent 34rem),
    radial-gradient(circle at 12% 72%, rgba(215, 173, 97, .10), transparent 28rem),
    linear-gradient(145deg, #0b322e 0%, #071f1d 48%, #031514 100%);
}

.ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .17;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
  pointer-events: none;
}

.topbar {
  position: relative;
  z-index: 20;
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(18px, 3vw, 46px);
  border-bottom: 1px solid rgba(234, 212, 168, .2);
  background: rgba(4, 24, 22, .74);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(234, 212, 168, .65);
  border-radius: 50%;
  color: var(--gold-soft);
  font: 700 16px/1 var(--serif);
  letter-spacing: .08em;
  box-shadow: inset 0 0 0 4px rgba(215, 173, 97, .06);
}

.brand strong {
  display: block;
  color: var(--white);
  font: 500 clamp(19px, 2vw, 25px)/1.05 var(--serif);
  letter-spacing: .01em;
}

.brand span:not(.brand-mark) {
  display: block;
  margin-top: 5px;
  color: rgba(255, 253, 248, .58);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.top-actions { display: flex; align-items: center; gap: 9px; }

.action,
.contents-toggle,
.footer-control,
.page-arrow {
  border: 1px solid rgba(234, 212, 168, .24);
  background: rgba(255, 255, 255, .055);
  color: var(--white);
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, transform .2s ease, opacity .2s ease;
}

.action:hover,
.contents-toggle:hover,
.footer-control:hover,
.page-arrow:hover:not(:disabled) {
  border-color: rgba(234, 212, 168, .62);
  background: rgba(215, 173, 97, .14);
}

.action:focus-visible,
.contents-toggle:focus-visible,
.footer-control:focus-visible,
.page-arrow:focus-visible,
.thumb:focus-visible {
  outline: 3px solid rgba(234, 212, 168, .88);
  outline-offset: 3px;
}

.action {
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  text-decoration: none;
}

.text-action { padding: 0 17px; font-size: 14px; font-weight: 650; letter-spacing: .03em; }
.icon-action { width: 42px; padding: 0; }
.icon-action svg, .page-arrow svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.reader-shell {
  height: calc(100vh - 82px);
  min-height: 610px;
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
}

.contents {
  position: relative;
  z-index: 12;
  min-height: 0;
  padding: 18px 14px 28px;
  border-right: 1px solid rgba(234, 212, 168, .18);
  background: rgba(3, 22, 20, .52);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(215, 173, 97, .35) transparent;
}

.contents-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 2px 2px 14px;
  color: var(--gold-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

#closeContents { display: none; border: 0; background: transparent; color: var(--gold-soft); font-size: 29px; cursor: pointer; }

#thumbnailList { display: grid; gap: 13px; }

.thumb {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.thumb-image {
  position: relative;
  display: block;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 3px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .24);
  transition: border-color .22s ease, transform .22s ease, box-shadow .22s ease;
}

.thumb-image img { display: block; width: 100%; height: auto; }
.thumb:hover .thumb-image { transform: translateY(-2px); border-color: rgba(234, 212, 168, .55); }
.thumb.active .thumb-image { border-color: var(--gold); box-shadow: 0 6px 22px rgba(215, 173, 97, .25); }

.thumb-number {
  position: absolute;
  right: 5px;
  bottom: 5px;
  min-width: 23px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(5, 27, 25, .85);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
}

.thumb-title {
  display: block;
  margin-top: 6px;
  color: rgba(255, 253, 248, .62);
  font-size: 10px;
  line-height: 1.25;
}
.thumb.active .thumb-title { color: var(--gold-soft); }

.reader {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr) 42px 24px;
  gap: 8px;
  padding: 14px clamp(14px, 3vw, 48px) 10px;
}

.reader-meta {
  width: min(100%, 830px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}

.contents-toggle {
  justify-self: start;
  display: none;
  height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 13px;
}

.current-title {
  grid-column: 2;
  overflow: hidden;
  color: var(--gold-soft);
  font-family: var(--serif);
  font-size: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.page-count { justify-self: end; color: rgba(255,255,255,.68); font-size: 13px; font-variant-numeric: tabular-nums; }

.book-zone {
  min-height: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  align-items: center;
  gap: clamp(8px, 2vw, 24px);
}

.book {
  position: relative;
  justify-self: center;
  height: 100%;
  max-height: 100%;
  aspect-ratio: 9 / 16;
  max-width: 100%;
  perspective: 2200px;
  transform-style: preserve-3d;
  touch-action: pan-y;
  user-select: none;
  filter: drop-shadow(0 22px 28px rgba(0, 0, 0, .38));
}

.page-display,
.page-underlay,
.turning-sheet {
  position: absolute;
  inset: 0;
  border-radius: 2px 7px 7px 2px;
  overflow: hidden;
  background: var(--paper);
}

.page-display img,
.page-underlay img,
.sheet-face img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

.page-display::after,
.page-underlay::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 11px 0 18px -16px rgba(0, 0, 0, .55), inset -2px 0 1px rgba(255,255,255,.25);
}

.page-underlay { transform: translate(5px, 5px); background: #d9d0c1; }

.page-underlay::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: inherit;
}

.page-edge {
  position: absolute;
  z-index: 8;
  top: 1.5%;
  right: -5px;
  width: 7px;
  height: 97%;
  border-radius: 0 5px 5px 0;
  background: repeating-linear-gradient(to right, #d8d0c2 0 1px, #f7f1e7 1px 2px);
  box-shadow: 2px 1px 5px rgba(0,0,0,.28);
  pointer-events: none;
}

.turning-sheet {
  z-index: 7;
  transform-style: preserve-3d;
  will-change: transform;
  overflow: visible;
}

.sheet-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 2px 7px 7px 2px;
  background: var(--paper);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.sheet-face.back { transform: rotateY(180deg); }

.sheet-face::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: var(--shade, 0);
  background: linear-gradient(90deg, rgba(0,0,0,.35), transparent 22%, transparent 76%, rgba(0,0,0,.18));
  pointer-events: none;
}

.turning-sheet.forward { transform-origin: left center; }
.turning-sheet.backward { transform-origin: left center; }
.turning-sheet.animating { transition: transform 760ms cubic-bezier(.22, .68, .22, 1), filter 760ms ease; }
.turning-sheet.settling { transition: transform 320ms cubic-bezier(.33, 1, .68, 1); }

.page-arrow {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  box-shadow: 0 10px 24px rgba(0,0,0,.14);
}
.page-arrow:hover:not(:disabled) { transform: scale(1.04); }
.page-arrow:disabled { opacity: .22; cursor: default; }

.reader-footer {
  width: min(100%, 830px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.footer-control {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  display: none;
}
.footer-control:disabled { opacity: .3; cursor: default; }

.progress-track { height: 2px; overflow: hidden; border-radius: 3px; background: rgba(255,255,255,.15); }
.progress-track span { display: block; width: 5%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); transition: width .35s ease; }

.reader-hint { margin: 0; color: rgba(255,255,255,.42); font-size: 12px; text-align: center; }

.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0, 14, 13, .72); backdrop-filter: blur(4px); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

body.page-zoomed .book { cursor: zoom-out; }
body.page-zoomed .book-zone { overflow: auto; align-items: start; }
body.page-zoomed .book { height: auto; width: min(900px, 96vw); max-width: none; aspect-ratio: 9/16; }

@media (max-width: 900px) {
  .reader-shell { grid-template-columns: 1fr; }
  .contents {
    position: fixed;
    z-index: 40;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(330px, 84vw);
    padding: 22px 18px 34px;
    border-right-color: rgba(234,212,168,.35);
    background: rgba(5, 31, 28, .98);
    transform: translateX(-104%);
    transition: transform .3s cubic-bezier(.22,.61,.36,1);
    box-shadow: 20px 0 50px rgba(0,0,0,.35);
  }
  body.contents-open .contents { transform: translateX(0); }
  body.contents-open .scrim { display: block; }
  #thumbnailList { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .contents-heading { font-size: 13px; }
  #closeContents { display: block; }
  .contents-toggle { display: inline-flex; align-items: center; gap: 8px; }
  .reader-meta { grid-template-columns: 1fr minmax(0, auto) 1fr; }
  .current-title { max-width: 38vw; }
}

@media (max-width: 620px) {
  .topbar { height: 68px; padding: 0 14px; }
  .brand-mark { width: 39px; height: 39px; flex-basis: 39px; font-size: 13px; }
  .brand strong { font-size: 18px; }
  .brand span:not(.brand-mark) { display: none; }
  .text-action { width: 42px; padding: 0; font-size: 0; }
  .text-action span { font-size: 20px; }
  .reader-shell { height: calc(100dvh - 68px); min-height: 540px; }
  .reader { grid-template-rows: 38px minmax(0, 1fr) 44px 18px; padding: 8px 8px max(8px, env(safe-area-inset-bottom)); gap: 5px; }
  .reader-meta { padding: 0 5px; }
  .current-title { font-size: 14px; max-width: 34vw; }
  .page-count { font-size: 12px; }
  .contents-toggle { height: 33px; padding: 0 10px; font-size: 12px; }
  .book-zone { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .book { max-width: calc(100vw - 18px); }
  .page-arrow { display: none; }
  .footer-control { display: inline-flex; align-items: center; gap: 6px; }
  .reader-footer { gap: 10px; padding: 0 4px; }
  .reader-hint { font-size: 10px; }
}

@media (max-height: 700px) and (min-width: 621px) {
  .topbar { height: 66px; }
  .reader-shell { height: calc(100vh - 66px); min-height: 500px; }
  .reader { padding-top: 8px; }
  .brand span:not(.brand-mark) { display: none; }
}

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