:root {
  color-scheme: dark;
  --navy: #031d2b;
  --emerald: #073f40;
  --gold: #e2b75b;
  --gold-soft: #f4d98f;
  --ivory: #fff8e8;
  --ink: #1f201d;
  --toolbar: rgba(4, 30, 40, 0.86);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ivory);
  background:
    radial-gradient(circle at 50% 36%, rgba(223, 176, 77, 0.16), transparent 30%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 44px 44px,
    linear-gradient(225deg, rgba(255, 255, 255, 0.02) 25%, transparent 25%) 0 0 / 44px 44px,
    linear-gradient(145deg, #061b25, #0b4b49 56%, #04151f);
}

button, input { font: inherit; }
button { color: inherit; }

.reader {
  position: relative;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: max(12px, env(safe-area-inset-top)) clamp(12px, 2.5vw, 34px) max(14px, env(safe-area-inset-bottom));
}

.reader::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.55;
  background-image: radial-gradient(rgba(255, 255, 255, 0.05) 0.8px, transparent 0.8px);
  background-size: 8px 8px;
  mask-image: linear-gradient(to bottom, black, transparent 84%);
}

.toolbar {
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
}

.brand-button,
.icon-button,
.speed-button,
.home-button,
.language-pill {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--toolbar);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px);
}

.brand-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  padding: 7px 16px 7px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.brand-button img { width: 60px; height: 40px; object-fit: contain; }
.brand-button span { font-size: 0.95rem; font-weight: 700; letter-spacing: 0.01em; }

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

.icon-button,
.speed-button,
.language-pill {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.icon-button, .speed-button { cursor: pointer; }
.speed-button { width: 58px; font-size: 0.9rem; font-weight: 800; }
.language-pill { width: 70px; border-radius: 24px; font-size: 0.78rem; font-weight: 800; color: var(--gold-soft); }
.icon-button svg, .home-button svg, .page-nav svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:hover, .speed-button:hover, .brand-button:hover, .home-button:hover { border-color: rgba(226, 183, 91, 0.7); background: rgba(6, 49, 56, 0.96); }
.icon-button.is-active { color: #112b2f; background: var(--gold); border-color: var(--gold); }

.book-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(54px, 0.18fr) minmax(0, 1400px) minmax(54px, 0.18fr);
  align-items: center;
  gap: clamp(8px, 1.8vw, 28px);
  padding: 10px 0 8px;
}

.book-wrap { min-width: 0; display: grid; place-items: center; position: relative; }

.book {
  position: relative;
  width: min(100%, calc((100dvh - 196px) * 1.42));
  aspect-ratio: 1.42 / 1;
  max-height: calc(100dvh - 196px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  perspective: 2200px;
  filter: drop-shadow(0 28px 32px rgba(0, 0, 0, 0.32));
  touch-action: pan-y;
}

.book::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 1.1% -1.2% -1.6%;
  border-radius: 5px 5px 16px 16px;
  background: linear-gradient(90deg, #b8aa8b, #f7efd9 6%, #f7efd9 94%, #aa9b7f);
  box-shadow: var(--shadow);
}

.paper {
  position: relative;
  min-width: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #f7f3e9;
  backface-visibility: hidden;
}

.paper-left { border-radius: 8px 1px 1px 8px; box-shadow: inset -24px 0 34px -32px rgba(0, 0, 0, 0.55); }
.paper-right { border-radius: 1px 8px 8px 1px; box-shadow: inset 24px 0 34px -32px rgba(0, 0, 0, 0.55); }
.paper.is-empty { background: linear-gradient(100deg, #eee7d9, #fbf7ec); }
.paper.is-empty img, .paper.is-empty .page-number { display: none; }

.paper img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #f7f3e9;
  user-select: none;
}

.paper.is-cover {
  grid-column: 1 / 3;
  width: 50%;
  justify-self: center;
  border-radius: 7px;
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.36);
}

.paper.is-cover img { object-fit: cover; }
.paper.is-cover + .book-spine, .paper.is-cover ~ .paper-right { display: none; }

.page-number {
  position: absolute;
  bottom: 1.6%;
  left: 50%;
  translate: -50% 0;
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 26px;
  padding: 0 8px;
  border-radius: 13px;
  color: #75571b;
  background: rgba(255, 249, 232, 0.88);
  font: 700 0.78rem/1 Georgia, serif;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.book-spine {
  position: absolute;
  z-index: 5;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 34px;
  translate: -50% 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(44, 35, 25, 0.18), rgba(255, 255, 255, 0.32), rgba(44, 35, 25, 0.15), transparent);
}

.turn-sheet {
  position: absolute;
  z-index: 8;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  border-radius: 2px 8px 8px 2px;
  pointer-events: none;
  opacity: 0;
  transform-origin: left center;
  background: linear-gradient(90deg, #d9d1c1, #fffdf5 12%, #f7f1e5 84%, #c8bdab);
  box-shadow: -18px 0 24px rgba(0, 0, 0, 0.2);
}

.book.turn-next .turn-sheet { animation: turn-next 480ms cubic-bezier(.55, .02, .22, 1) both; }
.book.turn-prev .turn-sheet { left: 0; transform-origin: right center; animation: turn-prev 480ms cubic-bezier(.55, .02, .22, 1) both; }
@keyframes turn-next { 0% { opacity: .95; transform: rotateY(0); } 100% { opacity: .18; transform: rotateY(-178deg); } }
@keyframes turn-prev { 0% { opacity: .18; transform: rotateY(178deg); } 100% { opacity: .95; transform: rotateY(0); } }

.page-nav {
  justify-self: center;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(2, 24, 32, 0.48);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: transform 160ms ease, color 160ms ease, background 160ms ease;
}

.page-nav:hover:not(:disabled) { transform: scale(1.07); color: #102d31; background: var(--gold); }
.page-nav:disabled { opacity: 0.24; cursor: not-allowed; }

.gesture-hint {
  position: absolute;
  left: 50%;
  bottom: 1.9%;
  translate: -50% 0;
  z-index: 11;
  margin: 0;
  padding: 9px 14px;
  border-radius: 999px;
  color: rgba(255, 250, 235, 0.88);
  background: rgba(2, 23, 30, 0.72);
  font-size: 0.8rem;
  pointer-events: none;
  transition: opacity 300ms ease;
}
.gesture-hint.is-hidden { opacity: 0; }

.read-caption {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 3.4%;
  translate: -50% 0;
  width: min(92%, 860px);
  padding: 12px 18px;
  border: 1px solid rgba(226, 183, 91, 0.45);
  border-radius: 14px;
  color: #fff8e7;
  background: rgba(3, 27, 39, 0.92);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  font-size: clamp(0.9rem, 1.5vw, 1.05rem);
  line-height: 1.5;
  text-align: center;
}

.caption-dot { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 5px rgba(226, 183, 91, 0.14); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.42; transform: scale(.8); } }

.progress-bar {
  z-index: 20;
  width: min(760px, 96%);
  min-height: 54px;
  justify-self: center;
  align-self: end;
  display: grid;
  grid-template-columns: 46px minmax(100px, 1fr) minmax(78px, auto);
  align-items: center;
  gap: 13px;
  padding: 7px 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(2, 23, 30, 0.9);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(18px);
}

.home-button { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.progress-bar input { width: 100%; accent-color: var(--gold); cursor: pointer; }
.page-status { min-width: 84px; color: var(--gold-soft); font-size: 0.9rem; font-weight: 750; letter-spacing: 0.03em; text-align: center; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  top: 84px;
  translate: -50% -14px;
  max-width: min(90vw, 620px);
  padding: 12px 18px;
  border-radius: 12px;
  color: #10282c;
  background: var(--gold-soft);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.28);
  font-size: 0.92rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: 220ms ease;
}
.toast.is-visible { opacity: 1; translate: -50% 0; }

button:focus-visible, input:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.reader.is-locked { visibility: hidden; }
.access-gate {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(circle at 50% 12%, rgba(226, 183, 91, .22), transparent 36%),
    linear-gradient(145deg, #041f29, #083946 58%, #03171f);
}
.access-gate[hidden] { display: none; }
.access-card {
  width: min(100%, 500px);
  padding: clamp(28px, 6vw, 48px);
  border: 1px solid rgba(226, 183, 91, .5);
  border-radius: 24px;
  color: #fff8e7;
  background: rgba(3, 29, 38, .94);
  box-shadow: 0 28px 90px rgba(0, 0, 0, .45);
  text-align: center;
}
.access-card > img { width: 128px; height: auto; margin-bottom: 18px; }
.access-kicker { margin: 0 0 10px; color: var(--gold); font-size: .82rem; font-weight: 800; letter-spacing: .14em; }
.access-card h1 { margin: 0; color: #fff; font-family: Georgia, serif; font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.14; }
.access-card > p:not(.access-kicker) { margin: 16px auto 24px; color: rgba(255, 248, 231, .78); line-height: 1.6; }
.access-card form { text-align: left; }
.access-card label { display: block; margin-bottom: 8px; color: #fff; font-size: .92rem; font-weight: 750; }
.password-row { display: grid; grid-template-columns: 1fr 64px; gap: 8px; }
.password-row input { min-width: 0; height: 52px; padding: 0 15px; border: 1px solid rgba(255,255,255,.24); border-radius: 12px; color: #10282c; background: #fff; font-size: 1rem; }
.password-row button, .lock-button { border: 1px solid rgba(226, 183, 91, .45); border-radius: 12px; color: var(--gold-soft); background: rgba(255,255,255,.08); font-weight: 750; cursor: pointer; }
.access-error { min-height: 24px; margin: 8px 0 2px; color: #ffd5c9; font-size: .88rem; }
.unlock-button { width: 100%; min-height: 52px; border: 0; border-radius: 12px; color: #082b33; background: linear-gradient(135deg, #f8dfa2, #d9a83e); font-size: 1rem; font-weight: 850; cursor: pointer; box-shadow: 0 12px 32px rgba(217, 168, 62, .24); }
.access-card small { display: block; margin-top: 16px; color: rgba(255,255,255,.56); font-size: .78rem; }
.lock-button { height: 42px; padding: 0 12px; }

@media (max-width: 760px) {
  body { overflow: auto; }
  .reader { min-height: 100dvh; padding-inline: 10px; }
  .toolbar { min-height: 56px; }
  .brand-button { width: 50px; padding: 5px; justify-content: center; }
  .brand-button img { width: 42px; height: 36px; }
  .brand-button span { display: none; }
  .toolbar-actions { gap: 5px; }
  .icon-button { width: 41px; height: 41px; }
  .language-pill { width: 56px; height: 41px; font-size: 0.68rem; }
  .speed-button { width: 49px; height: 41px; border-radius: 21px; font-size: 0.78rem; }
  .lock-button { display: none; }
  .book-stage { grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 4px; }
  .book { width: min(100%, calc((100dvh - 178px) * .707)); max-height: calc(100dvh - 178px); aspect-ratio: .707 / 1; grid-template-columns: 1fr; }
  .paper-left, .paper-right { grid-column: 1; grid-row: 1; border-radius: 7px; box-shadow: 0 18px 45px rgba(0, 0, 0, .28); }
  .paper-left.is-empty { display: none; }
  .paper-right { display: none; }
  .paper.is-cover { grid-column: 1; width: 100%; }
  .book-spine { display: none; }
  .turn-sheet { left: 0; width: 100%; }
  .page-nav { width: 42px; height: 42px; }
  .page-nav svg { width: 20px; height: 20px; }
  .gesture-hint { display: none; }
  .read-caption { bottom: 2.5%; padding: 10px 13px; max-height: 90px; overflow: hidden; }
  .progress-bar { width: 100%; grid-template-columns: 42px 1fr 76px; }
}

@media (max-height: 620px) and (min-width: 761px) {
  .brand-button { height: 46px; }
  .icon-button, .speed-button, .language-pill { height: 42px; width: 42px; }
  .book { max-height: calc(100dvh - 162px); width: min(100%, calc((100dvh - 162px) * 1.42)); }
  .progress-bar { min-height: 46px; }
}

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