/* ==========================================================================
   Digital catalogue reader
   --------------------------------------------------------------------------
   Layout is a three row grid: top bar / stage / bottom bar. Only the stage
   ever changes size, so the book can be told exactly how much room it has.
   ========================================================================== */

:root {
  --bg:            #0e1015;
  --bg-2:          #171a22;
  --surface:       rgba(28, 32, 42, .82);
  --surface-solid: #1c202a;
  --line:          rgba(255, 255, 255, .10);
  --ink:           #e8eaf0;
  --ink-dim:       #9aa1b2;
  --accent:        #8ec63f;
  --accent-ink:    #0e1015;
  --paper:         #f2f0ec;

  --bar-h:  clamp(48px, 7vh, 60px);
  --radius: 10px;
  --ease:   cubic-bezier(.22, .61, .36, 1);

  /* Safe area on notched phones. */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;                 /* the reader owns the viewport */
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.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;
}

/* --------------------------------------------------------------------------
   Boot screen
   -------------------------------------------------------------------------- */

.boot {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(120% 90% at 50% 40%, var(--bg-2) 0%, var(--bg) 70%);
  transition: opacity .45s var(--ease);
}
.boot.is-done { opacity: 0; pointer-events: none; }

/* Three sheets fanning open, purely CSS so nothing extra loads. */
.boot__book { position: relative; width: 72px; height: 52px; perspective: 400px; }
.boot__book span {
  position: absolute; inset: 0 0 0 50%;
  background: linear-gradient(100deg, #cfd3dc, #f4f5f8);
  border-radius: 0 3px 3px 0;
  transform-origin: left center;
  animation: bootflip 1.8s var(--ease) infinite;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, .45);
}
.boot__book span:nth-child(2) { animation-delay: .22s; }
.boot__book span:nth-child(3) { animation-delay: .44s; }
@keyframes bootflip {
  0%        { transform: rotateY(0deg);    opacity: 1; }
  55%, 100% { transform: rotateY(-170deg); opacity: .25; }
}

.boot__label { margin: 0; color: var(--ink-dim); font-size: 13px; letter-spacing: .04em; }
.boot__bar   { width: min(240px, 55vw); height: 3px; border-radius: 3px; background: rgba(255,255,255,.10); overflow: hidden; }
.boot__bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s var(--ease); }

@media (prefers-reduced-motion: reduce) {
  .boot__book span { animation: none; }
}

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */

.reader {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: var(--safe-t) 0 var(--safe-b);
  background:
    radial-gradient(130% 100% at 50% 45%, #1b1f29 0%, var(--bg) 72%);
}
.reader[hidden] { display: none; }

.bar {
  display: flex; align-items: center; gap: 6px;
  height: var(--bar-h);
  padding: 0 10px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 20;
}
.bar--top    { border-bottom: 1px solid var(--line); justify-content: space-between; }
.bar--bottom { border-top: 1px solid var(--line);    justify-content: center; }

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

.title {
  margin: 0 8px;
  font-size: 14px; font-weight: 600; letter-spacing: .01em;
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 46vw;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; height: 38px; padding: 0 8px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--ink);
  font: inherit; font-size: 13px; font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .16s var(--ease), color .16s var(--ease), opacity .16s;
  text-decoration: none;
}
.btn:hover  { background: rgba(255, 255, 255, .09); }
.btn:active { background: rgba(255, 255, 255, .14); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .3; pointer-events: none; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.btn--wide  { min-width: 56px; }
.btn--ghost { min-width: 32px; height: 32px; }

.btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* Fullscreen button swaps its glyph based on state. */
#btnFullscreen .ico-collapse { display: none; }
#btnFullscreen[aria-pressed="true"] .ico-expand   { display: none; }
#btnFullscreen[aria-pressed="true"] .ico-collapse { display: block; }
#btnFullscreen[aria-pressed="true"] { background: transparent; color: var(--ink); }
#btnFullscreen[aria-pressed="true"]:hover { background: rgba(255,255,255,.09); }

/* --------------------------------------------------------------------------
   Stage + book
   -------------------------------------------------------------------------- */

.stage {
  position: relative;
  overflow: hidden;                 /* clips the book once it is zoomed */
  display: flex; align-items: center; justify-content: center;
  padding: clamp(8px, 2.2vmin, 26px);
  min-height: 0;                    /* lets the grid row actually shrink */
  touch-action: none;
}

/* Carries the zoom transform. Kept separate from .book so the flip engine
   never has to reason about a scaled ancestor while at 100%. */
.stage__zoom {
  width: 100%; height: 100%;
  transform-origin: 50% 50%;
  will-change: transform;
}
.stage__zoom.is-animating { transition: transform .28s var(--ease); }

.book {
  width: 100%; height: 100%;
  /* Book.centreOffset slides a lone cover into the middle of the stage. A
     translation is transparent to the flip engine's pointer maths. */
  transition: transform .5s var(--ease);
}

/* StPageFlip writes inline min-width/min-height onto its root element, sized
   from the `minWidth` setting. That setting also decides the single page
   breakpoint, so it has to stay fairly large -- but as a CSS floor it would
   overflow small phones. The engine reads the setting, not the style, so
   clearing it here is safe. */
.stf__parent {
  width: 100%; height: 100%;
  min-width: 0 !important;
  min-height: 0 !important;
  touch-action: none;
}

/* The shipped stylesheet misspells this selector (.sft__wrapper), so the
   wrapper never gets its rules. Declared here instead. */
.stf__wrapper {
  position: relative;
  width: 100%; height: 100%;
}

/* One page. Hard pages (cover, back) get a slightly different treatment. */
.page {
  background: var(--paper);
  overflow: hidden;
  backface-visibility: hidden;
  transform: translateZ(0);
  /* Lifts the sheet off the backdrop. Carried by the page rather than the
     container so it tracks the paper exactly, including mid turn. */
  box-shadow: 0 16px 38px -14px rgba(0, 0, 0, .75);
}
.page.--left  { box-shadow: inset -14px 0 26px -14px rgba(0, 0, 0, .45); }
.page.--right { box-shadow: inset  14px 0 26px -14px rgba(0, 0, 0, .45); }
.page.--hard  { background: #e6e3dd; }

.page__img {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;
  user-select: none; -webkit-user-drag: none;
  pointer-events: none;             /* drags belong to the flip engine */
}
.page__img[data-loaded="false"] { opacity: 0; }
.page__img { transition: opacity .2s linear; }

/* Folio number, hidden on the two hard covers. */
.page__folio {
  position: absolute; bottom: 6px;
  font-size: 10px; letter-spacing: .08em;
  color: rgba(0, 0, 0, .38);
  pointer-events: none;
}
.page.--left  .page__folio { left: 12px; }
.page.--right .page__folio { right: 12px; }
.page.--hard  .page__folio { display: none; }

/* --------------------------------------------------------------------------
   Pan layer -- live only while zoomed
   -------------------------------------------------------------------------- */

.pan-layer {
  position: absolute; inset: 0; z-index: 8;
  display: none;
  cursor: grab;
  touch-action: none;
}
.stage.is-zoomed .pan-layer { display: block; }
.pan-layer.is-panning { cursor: grabbing; }

/* --------------------------------------------------------------------------
   Edge arrows
   -------------------------------------------------------------------------- */

.nav-arrow {
  position: absolute; top: 50%; z-index: 10;
  transform: translateY(-50%);
  width: 44px; height: 68px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 10px;
  background: rgba(14, 16, 21, .5);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  color: var(--ink);
  cursor: pointer; opacity: 0;
  transition: opacity .22s var(--ease), background .16s var(--ease);
}
.nav-arrow--prev { left: 6px; }
.nav-arrow--next { right: 6px; }
.nav-arrow svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stage:hover .nav-arrow, .nav-arrow:focus-visible { opacity: 1; }
.nav-arrow:hover { background: rgba(14, 16, 21, .78); }
.nav-arrow[disabled] { opacity: 0 !important; pointer-events: none; }
.stage.is-zoomed .nav-arrow { display: none; }

/* Touch devices have no hover, and swiping already covers this. */
@media (hover: none) { .nav-arrow { display: none; } }

/* --------------------------------------------------------------------------
   Thumbnails
   -------------------------------------------------------------------------- */

.thumbs {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 15;
  width: 190px;
  display: flex; flex-direction: column;
  background: var(--surface-solid);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  /* Hidden from pointers and the tab order while parked off screen, but only
     after the slide-out finishes. */
  visibility: hidden;
  transition: transform .28s var(--ease), visibility 0s .28s;
}
.thumbs.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform .28s var(--ease);
}

.thumbs__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-dim);
}

.thumbs__list {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 10px; display: grid; gap: 10px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent;
}
.thumbs__list::-webkit-scrollbar { width: 8px; }
.thumbs__list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 8px; }

.thumb {
  position: relative;
  display: block; width: 100%; padding: 0;
  border: 2px solid transparent; border-radius: 6px;
  background: #23262f; cursor: pointer; overflow: hidden;
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.thumb:hover { transform: translateY(-2px); }
.thumb.is-current { border-color: var(--accent); }
.thumb img { display: block; width: 100%; height: auto; }
.thumb__no {
  position: absolute; right: 4px; bottom: 4px;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(0, 0, 0, .62);
  font-size: 10px; color: #fff; font-variant-numeric: tabular-nums;
}
.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --------------------------------------------------------------------------
   Pager
   -------------------------------------------------------------------------- */

.pager {
  display: flex; align-items: center; gap: 6px;
  margin: 0 6px; padding: 0 10px; height: 34px;
  border: 1px solid var(--line); border-radius: 9px;
  background: rgba(255, 255, 255, .04);
  font-size: 13px; color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.pager__input {
  width: 3.2ch; padding: 0; border: 0; background: transparent;
  color: var(--ink); font: inherit; font-weight: 600; text-align: right;
  -moz-appearance: textfield;
}
.pager__input:focus { outline: none; color: var(--accent); }
.pager__input::-webkit-outer-spin-button,
.pager__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; z-index: 40;
  bottom: calc(var(--bar-h) + var(--safe-b) + 14px);
  transform: translate(-50%, 8px);
  max-width: min(420px, 88vw);
  padding: 9px 16px; border-radius: 999px;
  background: rgba(20, 23, 30, .94);
  border: 1px solid var(--line);
  font-size: 13px; color: var(--ink);
  opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast[hidden] { display: none; }

/* --------------------------------------------------------------------------
   noscript
   -------------------------------------------------------------------------- */

.noscript {
  position: fixed; inset: 0; display: grid; place-content: center;
  gap: 10px; text-align: center; padding: 24px; background: var(--bg);
}
.noscript a { color: var(--accent); }

/* --------------------------------------------------------------------------
   Small screens
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
  .title       { max-width: 38vw; font-size: 13px; }
  .btn         { min-width: 36px; height: 36px; padding: 0 6px; }
  .btn svg     { width: 19px; height: 19px; }
  .stage       { padding: 8px; }
  #btnZoomOut, #btnZoomLevel { display: none; }   /* pinch covers this */

  .thumbs {
    top: auto; left: 0; width: 100%; height: 42vh;
    border-left: 0; border-top: 1px solid var(--line);
    transform: translateY(100%);
  }
  .thumbs.is-open { transform: translateY(0); }
  .thumbs__list   { grid-template-columns: repeat(3, 1fr); }
}

/* Short landscape phones: reclaim vertical space. */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --bar-h: 44px; }
  .title { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stage__zoom.is-animating,
  .thumbs, .toast, .nav-arrow { transition-duration: .01ms; }
}
