:root {
  color-scheme: dark;
  --plum: #160822;
  --plum-2: #2a0a38;
  --ink: #071c34;
  --gold: #ffc516;
  --cream: #f8f3e8;
  --muted: #cabfd1;
  --toolbar-height: 72px;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 76% 16%, rgba(255, 197, 22, .13), transparent 26rem),
    radial-gradient(circle at 14% 100%, rgba(103, 36, 118, .42), transparent 32rem),
    linear-gradient(145deg, var(--plum), #08040d 68%);
  color: #fff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.toolbar {
  min-height: var(--toolbar-height);
  padding: 10px clamp(14px, 2.5vw, 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  background: rgba(9, 3, 15, .76);
  backdrop-filter: blur(16px);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 9px; height: 39px; flex: 0 0 auto; border-radius: 8px;
  background: linear-gradient(180deg, var(--gold), #f28a22);
  box-shadow: 0 0 26px rgba(255, 197, 22, .35);
}
.brand-copy { display: grid; line-height: 1.08; min-width: 0; }
.brand-copy strong { font-size: clamp(.98rem, 2vw, 1.15rem); letter-spacing: .015em; }
.brand-copy small { color: var(--muted); font-size: .77rem; margin-top: 5px; }

.toolbar-actions { display: flex; align-items: center; gap: 6px; }
.icon-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 11px;
  background: rgba(255,255,255,.06);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.icon-button:hover { background: rgba(255,255,255,.12); border-color: rgba(255,197,22,.55); }
.icon-button:active { transform: translateY(1px); }
.icon-button:focus-visible, .page-arrow:focus-visible, .thumbnail:focus-visible, #closeThumbs:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 3px;
}
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:first-child svg { fill: currentColor; stroke: none; }

.viewer-shell { height: calc(100vh - var(--toolbar-height)); position: relative; }
.viewer { height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) 38px; }
.book-stage {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(16px, 2.5vh, 28px) clamp(48px, 5vw, 76px) 10px;
  perspective: 1800px;
}
.book {
  height: 100%;
  max-height: 760px;
  max-width: 1120px;
  aspect-ratio: 1.414 / 1;
  display: flex;
  justify-content: center;
  align-items: center;
  filter: drop-shadow(0 24px 38px rgba(0,0,0,.42));
  transform-style: preserve-3d;
}
.book.single { aspect-ratio: .707 / 1; }

.page {
  height: 100%;
  min-width: 0;
  position: relative;
  overflow: hidden;
  background: #fff;
  transform-origin: center center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.book:not(.single) .page { width: 50%; }
.book.single .page { width: 100%; }
.book:not(.single) .page:first-child { box-shadow: inset -10px 0 20px -20px rgba(0,0,0,.75), inset 0 0 0 1px rgba(0,0,0,.06); }
.book:not(.single) .page:last-child { box-shadow: inset 10px 0 20px -20px rgba(0,0,0,.75), inset 0 0 0 1px rgba(0,0,0,.06); }
.page img { display: block; width: 100%; height: 100%; object-fit: contain; background: #fff; user-select: none; -webkit-user-drag: none; }
.page-link { position: absolute; display: block; z-index: 4; border-radius: 2px; }
.page-link:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; background: rgba(255,197,22,.18); }
.page-link:hover { background: rgba(255,197,22,.12); box-shadow: inset 0 0 0 1px rgba(255,197,22,.35); }

.book.turn-next { animation: turnNext .24s ease-out; }
.book.turn-previous { animation: turnPrevious .24s ease-out; }
@keyframes turnNext { 0% { transform: rotateY(0); opacity: 1; } 48% { transform: rotateY(-5deg) scale(.985); opacity: .72; } 100% { transform: rotateY(0); opacity: 1; } }
@keyframes turnPrevious { 0% { transform: rotateY(0); opacity: 1; } 48% { transform: rotateY(5deg) scale(.985); opacity: .72; } 100% { transform: rotateY(0); opacity: 1; } }

.page-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 14px;
  background: rgba(255,255,255,.07);
  cursor: pointer;
  z-index: 8;
  transition: background .18s ease, opacity .18s ease;
}
.page-arrow:hover:not(:disabled) { background: rgba(255,197,22,.19); }
.page-arrow:disabled { opacity: .22; cursor: default; }
.page-arrow.previous { left: clamp(7px, 1.6vw, 24px); }
.page-arrow.next { right: clamp(7px, 1.6vw, 24px); }
.page-arrow svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.viewer-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 16px 10px;
  color: #fff;
  font-size: .82rem;
}
#pageStatus { min-width: 9rem; text-align: right; font-weight: 700; }
.hint { color: var(--muted); border-left: 1px solid rgba(255,255,255,.2); padding-left: 16px; }

.thumbnail-panel {
  position: absolute;
  inset: 0 auto 0 0;
  width: min(410px, 88vw);
  z-index: 30;
  overflow: auto;
  padding: 18px;
  background: rgba(12, 5, 19, .97);
  border-right: 1px solid rgba(255,255,255,.13);
  box-shadow: 18px 0 46px rgba(0,0,0,.4);
}
.thumbnail-panel[hidden] { display: none; }
.thumbnail-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; font-size: 1.05rem; }
#closeThumbs { width: 42px; height: 42px; border: 0; background: transparent; color: #fff; font-size: 1.8rem; cursor: pointer; border-radius: 8px; }
.thumbnail-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.thumbnail { border: 1px solid rgba(255,255,255,.15); border-radius: 7px; padding: 0; overflow: hidden; background: #fff; cursor: pointer; position: relative; }
.thumbnail img { width: 100%; display: block; }
.thumbnail span { position: absolute; right: 5px; bottom: 5px; min-width: 24px; height: 24px; padding: 0 5px; display: grid; place-items: center; border-radius: 12px; background: rgba(15,5,22,.88); color: #fff; font-size: .7rem; font-weight: 700; }
.thumbnail.active { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }

noscript { display: block; padding: 20px; background: #fff; color: #111; }

@media (max-width: 760px) {
  :root { --toolbar-height: 64px; }
  .brand-copy small { display: none; }
  .icon-button { width: 44px; padding: 8px; }
  .icon-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .book-stage { padding: 12px 38px 4px; }
  .book, .book.single { width: 100%; max-width: 500px; height: auto; max-height: 100%; aspect-ratio: .707 / 1; }
  .book:not(.single) .page, .book.single .page { width: 100%; }
  .page-arrow { width: 34px; height: 54px; border-radius: 10px; }
  .page-arrow.previous { left: 3px; }
  .page-arrow.next { right: 3px; }
  .viewer-footer { font-size: .76rem; }
  #pageStatus { min-width: auto; text-align: center; }
  .hint { display: none; }
  .thumbnail-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-height: 600px) and (min-width: 761px) {
  :root { --toolbar-height: 58px; }
  .toolbar { padding-top: 6px; padding-bottom: 6px; }
  .book-stage { padding-top: 10px; }
}

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