:root {
  --ink: #2b2420;
  --muted: #6b6158;
  --paper: #f6f3ee;
  --line: #d8d0c6;
  --accent: #c4785a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.name { font-size: 1.15rem; letter-spacing: 0.04em; font-weight: 600; }
.rule { width: 28px; height: 1px; background: var(--ink); align-self: center; }
.role { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.tools { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.tools label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.tools select {
  font: inherit; font-size: 0.85rem; text-transform: none; letter-spacing: 0;
  color: var(--ink); border: 1px solid var(--line); background: #fff; padding: 0.25rem 0.4rem; border-radius: 4px;
}
.btn, footer a {
  color: #fff; background: var(--ink); text-decoration: none;
  font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.45rem 0.75rem; border-radius: 4px;
}
footer a { background: transparent; color: var(--ink); padding: 0; text-decoration: underline; }
main { flex: 1; }
.flip-view {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 0.5rem 0.35rem;
  padding: 0.75rem 0.5rem 1rem;
  min-height: calc(100vh - 7rem);
}
.book-frame {
  width: min(96vw, calc((100vh - 9rem) * 16 / 9));
  height: min(calc(100vh - 9rem), calc(96vw * 9 / 16));
  margin: 0 auto;
  justify-self: center;
  grid-column: 2;
  grid-row: 1;
}
.nav-btn {
  grid-row: 1;
  width: 42px; height: 42px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 50%; font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.nav-btn:hover { background: var(--ink); color: #fff; }
.page-ind {
  grid-column: 1 / -1; grid-row: 2;
  text-align: center; margin: 0; font-size: 0.85rem; color: var(--muted); letter-spacing: 0.08em;
}
.scroll-view { max-width: 1100px; margin: 0 auto; padding: 1rem 0.75rem 3rem; }
.scroll-view figure { margin: 0 0 1.25rem; }
.scroll-view img {
  width: 100%; height: auto; display: block;
  box-shadow: 0 8px 28px rgba(40,30,20,0.12);
  border-radius: 2px; background: #fff;
}
.scroll-view figcaption {
  font-size: 0.75rem; color: var(--muted); letter-spacing: 0.08em;
  text-transform: uppercase; margin-top: 0.35rem;
}
footer { text-align: center; padding: 1rem; font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--line); }

@media (max-width: 800px) {
  .top { flex-direction: column; align-items: flex-start; }
  .flip-view { min-height: 0; padding: 0.5rem; }
}

/* Preview fixes: honor the hidden attribute (display:grid on .flip-view was
   overriding it, so the flipbook stayed on screen in Scroll mode), and size
   the book to leave room for the two arrow buttons so nothing overflows. */
[hidden] { display: none !important; }
.flip-view { grid-template-columns: auto minmax(0, 1fr) auto; }
.book-frame {
  width: min(calc(100vw - 120px), calc((100vh - 9rem) * 16 / 9));
  height: min(calc(100vh - 9rem), calc((100vw - 120px) * 9 / 16));
}
@media (max-width: 800px) {
  .flip-view { gap: 0.5rem 0.25rem; }
  .book-frame {
    width: calc(100vw - 104px);
    height: calc((100vw - 104px) * 9 / 16);
  }
  .nav-btn { width: 38px; height: 38px; }
  .tools { gap: 0.5rem; }
}
/* Keep section jumps clear of the sticky header */
.scroll-view figure { scroll-margin-top: 64px; }
@media (max-width: 800px) { .scroll-view figure { scroll-margin-top: 196px; } }

/* ---------- Page-turn flipbook (StPageFlip) ---------- */
html { overflow-x: clip; }
.flip-view { overflow: clip; overflow-clip-margin: 0; }
.book-frame { position: relative; }
.book-frame #book {
  position: absolute; inset: 0;
  width: 100% !important; height: 100%;
  min-width: 0 !important; max-width: none !important;
  margin: 0;
}
#book .stf__wrapper { padding-bottom: 0 !important; height: 100%; }
#book .page {
  background: #fff;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
#book .page img {
  display: block; width: 100%; height: 100%;
  object-fit: cover; pointer-events: none;
  background: #f1ede7;
}
/* Gentle binding shading on the left edge of every page */
#book .page .sheen {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to right,
    rgb(0 0 0 / 0.10) 0, rgb(0 0 0 / 0.03) 1.2%, transparent 3%,
    transparent 97%, rgb(255 255 255 / 0.06) 100%);
}
/* The folding flap shows the blank back of the sheet, lit by a soft gradient */
#book .page.is-back { background: #fbfaf8; }
#book .page.is-back img { visibility: hidden; }
#book .page.is-back .sheen {
  background: linear-gradient(to left,
    rgb(0 0 0 / 0.10) 0, rgb(0 0 0 / 0.02) 8%, rgb(255 255 255 / 0.5) 40%,
    rgb(0 0 0 / 0.04) 80%, rgb(0 0 0 / 0.12) 100%);
}
/* Drop shadow under the book and a stack of page edges on the right */
.book-frame::before {
  content: ""; position: absolute; inset: 0;
  box-shadow: 0 18px 40px -12px rgb(40 30 20 / 0.35), 0 2px 8px rgb(40 30 20 / 0.12);
  pointer-events: none;
}
.edges {
  --stack: 6;
  position: absolute; top: 2px; bottom: 2px; left: 100%;
  width: calc(var(--stack) * 1px);
  background: repeating-linear-gradient(to right, #fdfcfa 0 1px, #d9d3ca 1px 2px);
  border-radius: 0 2px 2px 0;
  box-shadow: 2px 6px 12px -4px rgb(40 30 20 / 0.3);
  transition: width 0.3s ease;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 30px; padding: 0;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 4px; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .off, .icon-btn.muted .on { display: none; }
.icon-btn.muted .off { display: block; }
.icon-btn:hover { background: var(--ink); color: #fff; }
.nav-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
