/* ============================================================
   The Reading Room — Viewer styles
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;0,9..144,900;1,9..144,500&family=Hanken+Grotesk:wght@400;500;600;700&display=swap');

:root {
  --paper: #efe7d9;
  --stage: #2a2520;
  --stage-2: #1d1915;
  --ink: #211c17;
  --paper-card: #fbf8f1;
  --line: rgba(255,255,255,0.14);
  --terracotta: #c9692f;
  --gold: #cfa84e;
  --txt: #ece3d3;
  --txt-soft: #a99f8d;
  --display: 'Fraunces', Georgia, serif;
  --body: 'Hanken Grotesk', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--body);
  color: var(--txt);
  background:
    radial-gradient(120% 80% at 50% -10%, #38312a 0%, var(--stage) 45%, var(--stage-2) 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 14px clamp(12px, 3vw, 26px);
  background: linear-gradient(180deg, rgba(20,17,14,0.65), transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--body); font-size: 14px; font-weight: 600;
  color: var(--txt);
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px; min-height: 40px;
  cursor: pointer; white-space: nowrap;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: background .18s, transform .12s, border-color .18s;
}
.btn:hover { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.3); }
.btn:active { transform: scale(.96); }
.btn svg { width: 18px; height: 18px; }
.btn.icon { padding: 9px; width: 40px; }

.title-block { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.title-block .t-main {
  font-family: var(--display); font-weight: 600; font-size: clamp(15px, 2.3vw, 20px);
  letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title-block .t-sub {
  font-size: 12px; color: var(--txt-soft);
  display: flex; align-items: center; gap: 7px;
}
.title-block .t-sub .views { display: inline-flex; align-items: center; gap: 4px; color: var(--gold); }
.title-block .t-sub .views svg { width: 13px; height: 13px; }
.topbar .controls { display: flex; gap: 8px; }

/* ---------- Stage ---------- */
.stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 78px clamp(8px, 4vw, 60px) 92px;
}
#book { touch-action: pan-y; }

/* page-flip pages */
.page {
  background: var(--paper-card);
  overflow: hidden;
}
.page .page-content {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper-card);
}
.page .page-content img { width: 100%; height: 100%; object-fit: contain; display: block; }
.page .page-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #b9ac95;
}
.page .page-loading .spin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid rgba(0,0,0,0.12); border-top-color: var(--terracotta);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* ---- book realism: drop shadow + center spine gutter ---------------- */
/* the whole spread casts a soft shadow on the stage, like a real book   */
#book .stf__block { box-shadow: 0 14px 36px -8px rgba(0,0,0,0.5); }

/* center spine shadow — shown only while the book is open and still
   (faded out during a flip), and never in single-page / portrait mode   */
#book .stf__block::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 74px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 20;
  opacity: 0;
  transition: opacity .18s ease;
  background: linear-gradient(to right,
    rgba(0,0,0,0)   0%,
    rgba(0,0,0,.16) 44%,
    rgba(0,0,0,.32) 50%,
    rgba(0,0,0,.16) 56%,
    rgba(0,0,0,0)   100%);
}
.stage.book-resting:not(.is-portrait) #book .stf__block::after { opacity: 1; }

/* page-stack edges — fake the physical thickness of the bound book.
   Width is set per-page in JS (thick on the side with more pages).        */
#book .book-stack {
  position: absolute; top: 4px; bottom: 4px; width: 0;
  pointer-events: none; z-index: 4;
  transition: width .28s ease;
  background-color: var(--paper);
}
#book .book-stack.right {
  right: 0; transform: translateX(100%);
  border-radius: 0 2px 2px 0;
  background-image: repeating-linear-gradient(to right,
    rgba(0,0,0,0) 0, rgba(0,0,0,0) 1.5px,
    rgba(0,0,0,.08) 1.5px, rgba(0,0,0,.08) 2px);
  box-shadow: inset -7px 0 9px -6px rgba(0,0,0,.40), 3px 3px 8px -3px rgba(0,0,0,.5);
}
#book .book-stack.left {
  left: 0; transform: translateX(-100%);
  border-radius: 2px 0 0 2px;
  background-image: repeating-linear-gradient(to left,
    rgba(0,0,0,0) 0, rgba(0,0,0,0) 1.5px,
    rgba(0,0,0,.08) 1.5px, rgba(0,0,0,.08) 2px);
  box-shadow: inset 7px 0 9px -6px rgba(0,0,0,.40), -3px 3px 8px -3px rgba(0,0,0,.5);
}
.stage.is-portrait #book .book-stack { display: none; }

/* in-image clickable links: transparent overlay hotspots on the page    */
.hotspot {
  position: absolute; display: block; z-index: 6;
  cursor: pointer; border-radius: 3px;
  /* To position a new link, uncomment the next line, reload, nudge the
     manifest x/y/w/h until the box sits on the link, then comment again: */
  /* outline: 2px solid #ff3b30; background: rgba(255,59,48,.18); */
}

/* ---------- Loading overlay ---------- */
.loader {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; background: radial-gradient(80% 60% at 50% 40%, #322b24, var(--stage-2));
  transition: opacity .5s; text-align: center; padding: 24px;
}
.loader.hide { opacity: 0; pointer-events: none; }
.loader .glyph { font-family: var(--display); font-weight: 900; font-size: 64px; color: var(--gold); }
.loader .lbl { font-size: 14px; letter-spacing: 0.04em; color: var(--txt-soft); }
.loader .bar { width: min(280px, 70vw); height: 4px; border-radius: 4px; background: rgba(255,255,255,0.1); overflow: hidden; }
.loader .bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--terracotta), var(--gold)); transition: width .25s; }
.loader.error .glyph { color: var(--terracotta); }

/* ---------- Bottom nav ---------- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; background: linear-gradient(0deg, rgba(20,17,14,0.6), transparent);
  pointer-events: none;
}
.bottombar > * { pointer-events: auto; }
.pageind {
  display: inline-flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px;
  background: rgba(255,255,255,0.07); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 16px; min-height: 40px;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  cursor: pointer;
}
.pageind input {
  width: 3ch; background: transparent; border: none; color: var(--gold);
  font: inherit; text-align: right; outline: none; -moz-appearance: textfield;
}
.pageind input::-webkit-outer-spin-button, .pageind input::-webkit-inner-spin-button { -webkit-appearance: none; }
.pageind .sep { color: var(--txt-soft); }
.btn[disabled] { opacity: .3; cursor: default; }

/* ---------- TOC panel ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 70; background: rgba(10,8,6,0.5);
  opacity: 0; pointer-events: none; transition: opacity .3s;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.scrim.open { opacity: 1; pointer-events: auto; }
.toc {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 80;
  width: min(380px, 86vw);
  background: #211c17; border-right: 1px solid var(--line);
  transform: translateX(-101%); transition: transform .34s cubic-bezier(.3,.8,.25,1);
  display: flex; flex-direction: column;
  box-shadow: 30px 0 60px -20px rgba(0,0,0,0.6);
}
.toc.open { transform: none; }
.toc header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 14px; border-bottom: 1px solid var(--line);
}
.toc header h2 { font-family: var(--display); font-weight: 600; font-size: 22px; }
.toc .tabs { display: flex; gap: 6px; padding: 12px 16px 4px; }
.toc .tab {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--txt-soft);
  background: transparent; border: none; padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.toc .tab[aria-selected="true"] { background: rgba(255,255,255,0.08); color: var(--txt); }
.toc .panel { flex: 1; overflow-y: auto; padding: 8px 12px 24px; }
.toc .panel[hidden] { display: none; }

.toc .outline a {
  display: flex; gap: 12px; align-items: baseline;
  padding: 11px 12px; border-radius: 8px; text-decoration: none; color: var(--txt);
  font-size: 14.5px; transition: background .15s;
}
.toc .outline a:hover { background: rgba(255,255,255,0.06); }
.toc .outline a .pg { color: var(--gold); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12px; min-width: 2ch; }
.toc .outline a.lvl-1 { padding-left: 28px; font-size: 13.5px; color: var(--txt-soft); }
.toc .outline a.lvl-2 { padding-left: 44px; font-size: 13px; color: var(--txt-soft); }

.toc .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.toc .grid button {
  border: 1px solid var(--line); background: #1a1611; border-radius: 6px; overflow: hidden;
  cursor: pointer; padding: 0; aspect-ratio: 3/4; position: relative; transition: border-color .15s, transform .15s;
}
.toc .grid button:hover { border-color: var(--gold); transform: translateY(-2px); }
.toc .grid button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.toc .grid button .n {
  position: absolute; bottom: 0; left: 0; right: 0; font-size: 10px; font-weight: 700;
  background: linear-gradient(0deg, rgba(0,0,0,0.7), transparent); color: #fff; padding: 8px 5px 3px; text-align: center;
}
.toc .grid button .ph { position: absolute; inset: 0; background: #161310; }

/* ---------- Zoom lightbox ---------- */
.zoom {
  position: fixed; inset: 0; z-index: 90; background: rgba(12,10,8,0.94);
  display: none; align-items: center; justify-content: center; cursor: zoom-out;
  overflow: hidden; touch-action: none;
}
.zoom.open { display: flex; }
.zoom img {
  max-width: none; transform-origin: center center; will-change: transform;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6); background: #fff;
}
.zoom .zclose { position: fixed; top: 16px; right: 16px; z-index: 2; }
.zoom .zhint { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--txt-soft); }

/* hide hover-only chrome on touch by keeping it always visible (mobile friendly) */
@media (max-width: 640px) {
  .stage { padding: 70px 4px 84px; }
  .btn .lbl-text { display: none; }
  .btn.back .lbl-text { display: none; }
  .title-block .t-main { font-size: 15px; }
}
@media (min-width: 641px) {
  .btn.icon-md { width: 40px; padding: 9px; }
}

.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }
