:root {
  --cream: #F2EADC;
  --cream-2: #E9DECB;
  --ink: #202321;
  --muted: #6D6B65;
  --rail: #4D1717;
  --toolbar: #F2EADC;
  --line: rgba(32,35,33,.14);
  --shadow: 0 20px 50px rgba(48,39,28,.22), 0 4px 14px rgba(48,39,28,.12);
  --zoom: 1;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background-color: #F2EADC !important;
  background-image: none !important;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
button, a { font: inherit; }
button { color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

html, body, .viewer, .stage, .book-shell, .topbar, .bottombar { background-image: none !important; }

.topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--toolbar) !important;
  background-image: none !important;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: transparent;
  flex: 0 0 auto;
}
.brand-mark img {
  width: 42px; height: 42px; display: block; object-fit: contain;
  border-radius: 0;
}
.brand-copy { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-copy strong { font-family: Georgia, "Times New Roman", serif; font-size: 17px; letter-spacing: .01em; }
.brand-copy span { font-size: 11.5px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 5px; }
.icon-btn, .footer-btn, .close-btn, .nav-arrow {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; color: #373A36;
  text-decoration: none;
}
.icon-btn:hover, .footer-btn:hover, .close-btn:hover { background: rgba(77,23,23,.07); }
.icon-btn:focus-visible, .footer-btn:focus-visible, .nav-arrow:focus-visible, .close-btn:focus-visible, .thumb-card:focus-visible {
  outline: 2px solid var(--rail); outline-offset: 2px;
}

.viewer {
  height: calc(100vh - 116px);
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(0,1fr) 64px;
  align-items: center;
  background-color: #F2EADC !important;
  background-image: none !important;
}
.stage {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  overflow: auto;
  padding: 22px 18px;
  scrollbar-width: thin;
}
.book-shell {
  width: min(1180px, calc((100vh - 164px) * 1.54545), calc(100vw - 172px));
  aspect-ratio: 2.0 / 1.2941176471;
  transform: scale(var(--zoom));
  transform-origin: center center;
  transition: transform .18s ease;
  flex: 0 0 auto;
}
.book {
  width: 100%; height: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  position: relative;
  perspective: 2600px;
  filter: drop-shadow(0 12px 24px rgba(57,45,30,.10));
}
.page-slot {
  height: 100%;
  background: transparent;
  position: relative;
  overflow: hidden;
}
.page-slot.has-page { background: #fff; box-shadow: var(--shadow); }
.page-left.has-page { border-radius: 4px 0 0 4px; }
.page-right.has-page { border-radius: 0 4px 4px 0; }
.page-slot img {
  width: 100%; height: 100%; object-fit: contain; display: block; background: #fff;
  user-select: none; -webkit-user-drag: none;
}
.page-left.has-page::after,
.page-right.has-page::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 24px; pointer-events: none;
}
.page-left.has-page::after { right: 0; background: linear-gradient(to left, rgba(20,20,20,.13), transparent); }
.page-right.has-page::before { left: 0; background: linear-gradient(to right, rgba(20,20,20,.12), transparent); }
.gutter {
  position: absolute; left: 50%; top: .4%; bottom: .4%; width: 2px; transform: translateX(-1px);
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,.13) 8%, rgba(0,0,0,.13) 92%, transparent);
  box-shadow: 0 0 14px rgba(0,0,0,.08);
  z-index: 5; pointer-events: none;
}

.flip-sheet {
  position: absolute;
  top: 0;
  width: 50%; height: 100%;
  z-index: 20;
  transform-style: preserve-3d;
  pointer-events: none;
}
.flip-sheet.next { left: 50%; transform-origin: left center; animation: flipNext .72s cubic-bezier(.2,.72,.18,1) forwards; }
.flip-sheet.prev { left: 0; transform-origin: right center; animation: flipPrev .72s cubic-bezier(.2,.72,.18,1) forwards; }
.flip-face {
  position: absolute; inset: 0;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 14px 34px rgba(48,39,28,.22);
}
.flip-face img { width: 100%; height: 100%; object-fit: contain; display: block; background: #fff; }
.flip-sheet.next .flip-back, .flip-sheet.prev .flip-back { transform: rotateY(180deg); }
.flip-sheet.next::after, .flip-sheet.prev::after {
  content:""; position:absolute; inset:0; pointer-events:none; z-index:5;
  background: linear-gradient(90deg, rgba(0,0,0,.20), transparent 22%, transparent 72%, rgba(0,0,0,.10));
  opacity: .0; animation: pageShade .72s ease-in-out;
}
@keyframes flipNext { from { transform: rotateY(0deg); } to { transform: rotateY(-180deg); } }
@keyframes flipPrev { from { transform: rotateY(0deg); } to { transform: rotateY(180deg); } }
@keyframes pageShade { 0%,100% { opacity: .05; } 48% { opacity: .85; } }

.nav-arrow {
  width: 48px; height: 84px; border-radius: 14px;
  color: rgba(32,35,33,.58);
  transition: background .15s ease, color .15s ease, opacity .15s ease;
  z-index: 10;
}
.nav-arrow svg { width: 34px; height: 34px; stroke-width: 1.4; }
.nav-arrow:hover { color: var(--rail); background: rgba(255,255,255,.38); }
.nav-arrow:disabled { opacity: .16; cursor: default; background: none; }
.nav-prev { justify-self: end; }
.nav-next { justify-self: start; }

.bottombar {
  height: 54px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--toolbar) !important;
  background-image: none !important;
  border-top: 1px solid var(--line);
  position: relative; z-index: 30;
}
.footer-btn { width: 38px; height: 38px; border-radius: 9px; }
.footer-btn svg { width: 19px; height: 19px; }
.footer-btn:disabled { opacity: .26; cursor: default; background: transparent; }
.page-counter {
  min-width: 92px; height: 32px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 8px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.44);
  font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums;
  margin: 0 3px;
}

.thumb-panel {
  position: fixed; top: 62px; left: 0; bottom: 54px; width: min(330px, 88vw);
  background: #FBF7EF;
  z-index: 60;
  box-shadow: 14px 0 40px rgba(48,39,28,.18);
  transform: translateX(-104%);
  transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.thumb-panel.open { transform: translateX(0); }
.thumb-head { height: 54px; display:flex; align-items:center; justify-content:space-between; padding:0 14px 0 18px; border-bottom:1px solid var(--line); }
.thumb-head strong { font-family: Georgia, serif; }
.close-btn { width:36px; height:36px; border-radius:8px; font-size:26px; line-height:1; }
.thumb-grid { padding: 14px; overflow-y: auto; display:grid; grid-template-columns:1fr 1fr; gap: 12px; }
.thumb-card { border:1px solid transparent; background:transparent; border-radius:9px; padding:7px; cursor:pointer; text-align:center; color:var(--muted); }
.thumb-card img { width:100%; display:block; border-radius:3px; box-shadow:0 5px 14px rgba(0,0,0,.13); background:white; }
.thumb-card span { display:block; margin-top:6px; font-size:11px; font-weight:600; }
.thumb-card:hover { background:rgba(77,23,23,.05); }
.thumb-card.active { border-color:rgba(77,23,23,.45); background:rgba(77,23,23,.07); color:var(--rail); }
.scrim { position:fixed; inset:62px 0 54px 0; background:rgba(35,31,24,.20); z-index:50; }

@media (max-width: 780px) {
  .topbar { height: 56px; padding: 0 10px; }
  .brand-mark, .brand-mark img { width: 36px; height: 36px; }
  .brand-copy strong { font-size: 15px; }
  .brand-copy span { display: none; }
  .top-actions { gap: 0; }
  .icon-btn { width: 36px; height: 36px; }
  .icon-btn svg { width: 20px; height: 20px; }
  .viewer { height: calc(100vh - 106px); grid-template-columns: 42px minmax(0,1fr) 42px; }
  .stage { padding: 14px 4px; }
  .book-shell {
    width: min(calc(100vw - 92px), calc((100vh - 142px) * .77272727));
    aspect-ratio: .77272727 / 1;
  }
  .book { display:block; }
  .page-slot { position:absolute; inset:0; width:100%; height:100%; }
  .page-left { display:none; }
  .page-right.has-page { border-radius:4px; }
  .page-right.has-page::before { display:none; }
  .gutter { display:none; }
  .flip-sheet, .flip-sheet.next, .flip-sheet.prev { left:0; width:100%; transform-origin:left center; }
  .flip-sheet.prev { transform-origin:right center; }
  .nav-arrow { width:38px; height:72px; }
  .nav-arrow svg { width:27px; height:27px; }
  .bottombar { height: 50px; }
  .thumb-panel { top:56px; bottom:50px; }
  .scrim { inset:56px 0 50px 0; }
}

@media (prefers-reduced-motion: reduce) {
  .flip-sheet.next, .flip-sheet.prev { animation-duration: .01ms; }
  .flip-sheet.next::after, .flip-sheet.prev::after { animation-duration: .01ms; }
  .book-shell, .thumb-panel { transition: none; }
}
