:root {
  --forest-950: #03271d;
  --forest-900: #063e2e;
  --forest-800: #07533c;
  --forest-700: #0a684a;
  --gold: #efc44f;
  --gold-deep: #b98d25;
  --paper: #fffdf7;
  --ink: #eff8f3;
  --muted: #b8cdc3;
  --shadow: 0 26px 70px rgba(0, 0, 0, .42);
  --page-ratio: 2 / 3;
  --zoom: 1;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 50% -20%, rgba(239, 196, 79, .16), transparent 38rem),
    linear-gradient(135deg, var(--forest-950), #041c16 70%);
  overflow-x: hidden;
}

button, input, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  min-height: 76px;
  padding: 12px clamp(14px, 3vw, 38px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(3, 39, 29, .9);
  border-bottom: 1px solid rgba(239, 196, 79, .45);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 20;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid var(--gold);
  outline: 1px solid rgba(255, 255, 255, .55);
  outline-offset: -6px;
  color: var(--gold);
  font: 700 15px Georgia, serif;
  letter-spacing: .08em;
  background: var(--forest-800);
}

.brand-copy { display: flex; flex-direction: column; min-width: 0; }
.brand-copy strong { font-family: Georgia, serif; font-size: clamp(1rem, 2.2vw, 1.25rem); letter-spacing: .03em; }
.brand-copy small { color: var(--gold); font-size: .78rem; letter-spacing: .11em; text-transform: uppercase; margin-top: 3px; }

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

.icon-button {
  min-height: 44px;
  padding: 8px 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 9px;
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .2s;
}

.icon-button:hover { background: rgba(239, 196, 79, .12); border-color: rgba(239, 196, 79, .7); }
.icon-button:active { transform: translateY(1px); }
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button span { font-size: .88rem; }

.viewer { flex: 1; min-height: 0; position: relative; }

.reader {
  min-height: calc(100vh - 76px);
  min-height: calc(100dvh - 76px);
  padding: clamp(18px, 3vh, 34px) clamp(12px, 4vw, 56px) 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.book-wrap {
  width: min(100%, 1240px);
  min-height: 0;
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) 50px;
  align-items: center;
  gap: clamp(4px, 1.2vw, 16px);
}

.book {
  width: min(100%, calc((100vh - 235px) * 4 / 3));
  width: min(100%, calc((100dvh - 235px) * 4 / 3));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 0 1fr;
  align-items: stretch;
  justify-content: center;
  perspective: 1800px;
  transform: scale(var(--zoom));
  transform-origin: center center;
  transition: transform .22s ease;
}

.book.cover-mode, .book.back-mode {
  width: min(100%, calc((100vh - 235px) * 2 / 3));
  width: min(100%, calc((100dvh - 235px) * 2 / 3));
  grid-template-columns: 1fr;
}

.book.cover-mode .page-slot--right, .book.back-mode .page-slot--left { box-shadow: var(--shadow); }
.book.cover-mode .book-gutter, .book.back-mode .book-gutter { display: none; }

.page-slot {
  position: relative;
  aspect-ratio: var(--page-ratio);
  background: var(--paper);
  overflow: hidden;
  box-shadow: 0 20px 55px rgba(0, 0, 0, .34);
  backface-visibility: hidden;
  will-change: transform, filter;
}

.page-slot--left { border-radius: 8px 2px 2px 8px; transform-origin: right center; }
.page-slot--right { border-radius: 2px 8px 8px 2px; transform-origin: left center; }
.page-slot img { width: 100%; height: 100%; display: block; object-fit: contain; background: var(--paper); user-select: none; -webkit-user-drag: none; }

.page-slot--left::after, .page-slot--right::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.page-slot--left::after { background: linear-gradient(90deg, transparent 84%, rgba(0, 0, 0, .12)); }
.page-slot--right::after { background: linear-gradient(90deg, rgba(0, 0, 0, .13), transparent 16%); }
.cover-mode .page-slot--right::after { background: linear-gradient(90deg, rgba(0,0,0,.08), transparent 10%, transparent 90%, rgba(0,0,0,.06)); }

.book-gutter {
  width: 0;
  position: relative;
  z-index: 3;
}

.book-gutter::after {
  content: "";
  position: absolute;
  width: 28px;
  left: -14px;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.24), transparent);
  pointer-events: none;
}

.page-number {
  position: absolute;
  bottom: 8px;
  min-width: 28px;
  padding: 4px 7px;
  color: white;
  background: rgba(3, 39, 29, .74);
  border: 1px solid rgba(239, 196, 79, .5);
  border-radius: 999px;
  font-size: .72rem;
  line-height: 1;
  text-align: center;
  z-index: 2;
  opacity: .88;
}

.page-number--left { left: 8px; }
.page-number--right { right: 8px; }

.book.turn-next .page-slot--right { animation: turnNext .5s cubic-bezier(.52, .08, .35, .96); }
.book.turn-previous .page-slot--left { animation: turnPrevious .5s cubic-bezier(.52, .08, .35, .96); }

@keyframes turnNext {
  0% { transform: rotateY(0); filter: brightness(1); }
  48% { transform: rotateY(-82deg); filter: brightness(.72); }
  52% { transform: rotateY(-82deg); filter: brightness(.72); }
  100% { transform: rotateY(0); filter: brightness(1); }
}

@keyframes turnPrevious {
  0% { transform: rotateY(0); filter: brightness(1); }
  48% { transform: rotateY(82deg); filter: brightness(.72); }
  52% { transform: rotateY(82deg); filter: brightness(.72); }
  100% { transform: rotateY(0); filter: brightness(1); }
}

.turn-control {
  width: 48px;
  height: 74px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(239, 196, 79, .55);
  border-radius: 999px;
  color: var(--gold);
  background: rgba(3, 39, 29, .78);
  box-shadow: 0 12px 28px rgba(0,0,0,.25);
  cursor: pointer;
  transition: background .2s, transform .2s, opacity .2s;
}

.turn-control:hover:not(:disabled) { background: var(--forest-700); transform: scale(1.04); }
.turn-control:disabled { opacity: .26; cursor: default; }
.turn-control svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.reader-controls {
  margin-top: clamp(15px, 2.4vh, 24px);
  min-height: 48px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 12px;
  background: rgba(3, 39, 29, .8);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  backdrop-filter: blur(10px);
}

.compact-button {
  width: 38px;
  height: 36px;
  border: 0;
  border-radius: 7px;
  color: var(--ink);
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.compact-button:hover:not(:disabled) { color: var(--forest-950); background: var(--gold); }
.compact-button:disabled { opacity: .28; cursor: default; }
.compact-button--wide { font-size: 1.25rem; font-weight: 700; }

.page-jump { display: flex; align-items: center; gap: 6px; padding: 0 8px; color: var(--muted); font-size: .86rem; }
.page-jump label { color: var(--ink); }
.page-jump input {
  width: 58px;
  height: 34px;
  border: 1px solid rgba(239,196,79,.54);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255,255,255,.08);
  text-align: center;
  outline: 0;
}
.page-jump input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(239,196,79,.16); }
.control-divider { width: 1px; height: 24px; background: rgba(255,255,255,.18); margin: 0 4px; }
#zoomLabel { width: 46px; color: var(--muted); font-size: .78rem; text-align: center; }
.reader-hint { margin: 9px 0 0; color: var(--muted); font-size: .78rem; text-align: center; }

.thumbnail-panel {
  position: fixed;
  z-index: 30;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(370px, 92vw);
  padding: 16px;
  background: rgba(3, 39, 29, .985);
  border-right: 1px solid rgba(239,196,79,.5);
  box-shadow: 24px 0 60px rgba(0,0,0,.45);
  transform: translateX(-102%);
  transition: transform .26s ease;
  overflow: hidden;
}

.thumbnail-panel.is-open { transform: translateX(0); }
.panel-heading { height: 44px; display: flex; align-items: center; justify-content: space-between; color: var(--gold); font-family: Georgia, serif; font-size: 1.08rem; }
.close-button { width: 38px; height: 38px; border: 0; border-radius: 8px; color: white; background: rgba(255,255,255,.08); font-size: 1.65rem; line-height: 1; cursor: pointer; }
.thumbnail-grid {
  height: calc(100% - 44px);
  padding: 10px 4px 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 12px;
  overflow-y: auto;
  scrollbar-color: var(--gold-deep) transparent;
}

.thumbnail {
  padding: 0;
  color: var(--ink);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 6px;
  background: rgba(255,255,255,.04);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .2s, transform .2s;
}
.thumbnail:hover { border-color: var(--gold); transform: translateY(-2px); }
.thumbnail[aria-current="page"] { border: 2px solid var(--gold); box-shadow: 0 0 0 3px rgba(239,196,79,.14); }
.thumbnail img { width: 100%; aspect-ratio: var(--page-ratio); display: block; object-fit: cover; background: var(--paper); }
.thumbnail span { display: block; padding: 7px; font-size: .76rem; text-align: center; }

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

@media (max-width: 820px) {
  .topbar { min-height: 68px; }
  .brand-copy small { display: none; }
  .icon-button span { display: none; }
  .icon-button { width: 42px; padding: 7px; }
  .reader { min-height: calc(100dvh - 68px); padding: 14px 8px 18px; }
  .book-wrap { grid-template-columns: 42px minmax(0, 1fr) 42px; gap: 2px; }
  .book, .book.cover-mode, .book.back-mode {
    width: min(100%, calc((100dvh - 205px) * 2 / 3));
    grid-template-columns: 1fr;
  }
  .book-gutter { display: none; }
  .page-slot { border-radius: 7px; box-shadow: var(--shadow); }
  .page-slot--left::after, .page-slot--right::after { background: linear-gradient(90deg, rgba(0,0,0,.06), transparent 10%, transparent 90%, rgba(0,0,0,.06)); }
  .turn-control { width: 40px; height: 64px; }
  .turn-control svg { width: 24px; height: 24px; }
  .reader-controls { max-width: 100%; }
  .reader-controls .compact-button:first-child,
  .reader-controls .compact-button:nth-of-type(4),
  .control-divider,
  #zoomOut, #zoomIn, #zoomLabel { display: none; }
  .reader-hint { font-size: .74rem; }
}

@media (max-width: 430px) {
  .brand-mark { width: 40px; height: 40px; font-size: .78rem; }
  .brand-copy strong { font-size: .94rem; }
  .top-actions { gap: 4px; }
  .book-wrap { grid-template-columns: 34px minmax(0, 1fr) 34px; }
  .turn-control { width: 32px; height: 56px; border-color: rgba(239,196,79,.4); }
  .page-jump { padding: 0 3px; }
}

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