/* Flip-book reader (default view), its sheets, and the "back to print page" pill. Phone first. */

body[data-route='home'] #footer,
body[data-route='sach'] #footer {
  display: none;
}

.bk {
  height: calc(100vh - var(--bar) - 2px);
  height: calc(100dvh - var(--bar) - 2px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #24211c;
  color: #eee4cf;
  overscroll-behavior: none;
}

.bk-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 4px 12px;
  background: #1a1814;
  font-size: 13px;
}
.bk-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--gold-bright);
}
.bk-hl {
  background: var(--gold-bright);
  border-color: var(--gold-bright);
  color: #2b2117;
  padding: 3px 10px;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bk-hl:hover {
  color: #2b2117 !important;
}

.bk-main {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.bk-stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  container-type: size;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
.bk-stage.is-zoomed {
  cursor: grab;
}
.bk-sheet {
  display: flex;
  justify-content: center;
  height: min(100cqh - 20px, (100cqw - 12px) / 1.5455);
  transform-origin: 0 0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  will-change: transform;
}
.bk-sheet.single {
  height: min(100cqh - 8px, (100cqw - 4px) / 0.7727);
}
.bk-page {
  position: relative;
  height: 100%;
  aspect-ratio: 612 / 792;
  background: #f8f2e4;
}
.bk-page.blank {
  visibility: hidden;
}
.bk-page img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.bk-page.left::after {
  content: '';
  position: absolute;
  inset: 0 0 0 auto;
  width: 5%;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.16));
  pointer-events: none;
}
.bk-sheet:not(.single) .bk-page.right::after {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 5%;
  background: linear-gradient(270deg, transparent, rgba(0, 0, 0, 0.16));
  pointer-events: none;
}
.bk-layer {
  position: absolute;
  inset: 0;
}
.bk-hot {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  color: #fff;
  border-radius: 2px;
}
.bk-hot svg {
  position: absolute;
  right: 4%;
  bottom: 5%;
  width: clamp(12px, 9cqw, 20px);
  height: clamp(12px, 9cqw, 20px);
  padding: 2px;
  border-radius: 50%;
  background: rgba(20, 25, 15, 0.55);
  opacity: 0.85;
}
.bk-hot:hover,
.bk-hot:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: -2px;
  background: rgba(242, 194, 48, 0.12);
}
.bk-mark {
  position: absolute;
  background: rgba(255, 213, 0, 0.42);
  mix-blend-mode: multiply;
  border-radius: 2px;
  pointer-events: none;
}

.bk-nav {
  display: none;
}
.bk-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(15, 15, 12, 0.82);
  color: #f1e9d6;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.6s;
}
.bk-hint.gone {
  opacity: 0;
}

.bk-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: stretch;
  background: #1a1814;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bk-tool,
.bk-label {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-height: 54px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: #e6dcc6;
  font-size: 11px;
  line-height: 1.15;
}
.bk-tool svg {
  width: 22px;
  height: 22px;
}
.bk-tool:disabled {
  opacity: 0.35;
}
.bk-tool[aria-pressed='true'] {
  color: var(--gold-bright);
}
.bk-tool:not(:disabled):hover,
.bk-label:hover {
  background: rgba(255, 255, 255, 0.08);
}
.bk-label {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--gold-bright);
}
.bk-zoom {
  display: none;
}

@media (min-width: 900px) {
  .bk-main {
    grid-template-columns: 60px minmax(0, 1fr) 60px;
    align-items: center;
  }
  .bk-nav {
    display: grid;
    place-items: center;
    justify-self: center;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
  }
  .bk-nav:hover {
    background: rgba(255, 255, 255, 0.18);
  }
  .bk-nav svg {
    width: 22px;
    height: 22px;
  }
  .bk-bar {
    grid-template-columns: repeat(6, minmax(0, 150px));
    justify-content: center;
  }
  .bk-tool,
  .bk-label {
    grid-auto-flow: column;
    gap: 8px;
    font-size: 13.5px;
    min-height: 46px;
  }
  .bk-zoom {
    display: grid;
  }
}

/* ---------- sheets ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 92;
  background: rgba(12, 14, 10, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-height: 86vh;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 8px 10px 18px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  flex: 1;
  font-size: 20px;
  color: var(--green);
}
.sheet-close:hover {
  background: var(--paper-3);
}
.sheet-body {
  overflow-y: auto;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom, 0));
  overscroll-behavior: contain;
}
.sheet-sec + .sheet-sec {
  margin-top: 18px;
}
.sheet-sec h3 {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 8px;
}
.sheet-body input[type='search'] {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
}
@media (min-width: 900px) {
  .sheet-backdrop {
    align-items: stretch;
    justify-content: flex-end;
  }
  .sheet {
    width: 420px;
    max-height: none;
    border-radius: 0;
    animation-name: sheet-in;
  }
  .sheet.sheet-wide {
    width: min(760px, 90vw);
  }
  @keyframes sheet-in {
    from {
      transform: translateX(40px);
      opacity: 0;
    }
  }
}

.toc-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}
.toc-list button {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 7px 6px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
}
.toc-list button:hover,
.toc-list button.active {
  background: var(--paper-3);
}
.toc-list img {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 5px;
}
.mark-list img {
  width: 48px;
  height: 62px;
  justify-self: center;
}
.toc-blank {
  width: 64px;
  height: 48px;
  border-radius: 5px;
  background: var(--green-soft);
}
.toc-text {
  display: grid;
  min-width: 0;
}
.toc-text b {
  font-size: 15px;
  font-weight: 600;
}
.toc-text small {
  font-size: 12.5px;
  color: var(--ink-faint);
  font-style: italic;
}
.toc-pg {
  font-size: 13px;
  color: var(--lacquer);
  font-variant-numeric: tabular-nums;
}
.toc-pg svg {
  width: 18px;
  height: 18px;
}

.thumb-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  font-size: 14px;
}
.thumb-jump input {
  width: 84px;
  height: 38px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
}
.thumb-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}
.thumb {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: none;
  font-size: 11.5px;
  color: var(--ink-soft);
}
.thumb img {
  width: 100%;
  height: auto;
  border-radius: 3px;
  background: var(--paper-3);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.thumb.active {
  border-color: var(--gold);
}
.thumb-mark {
  position: absolute;
  top: 0;
  right: 6px;
  color: var(--red);
}
.thumb-mark svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.about-img {
  width: 100%;
  height: auto;
  border-radius: 10px;
}
.about-formal {
  margin-top: 10px;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 18px;
  color: var(--lacquer);
}
.about-sum {
  margin-top: 8px;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
}
.about-facts {
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}
.about-facts dt {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.about-facts dd {
  margin: 1px 0 0;
  font-size: 14.5px;
}
.about-links {
  margin: 16px 0 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.about-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  line-height: 1.25;
}
.about-link:hover {
  border-color: var(--green);
}
.about-link span {
  display: grid;
  color: var(--green);
}
.about-link svg {
  width: 22px;
  height: 22px;
}
.about .milestones li::before {
  box-shadow: 0 0 0 3px var(--paper);
}

/* ---------- reading mode: back to the printed page ---------- */
.print-pill {
  position: fixed;
  right: 14px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--green-deep);
  color: var(--gold-bright);
  border: 1px solid var(--gold-bright);
  box-shadow: var(--shadow);
  font-size: 14px;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.print-pill span {
  display: grid;
}
.print-pill svg {
  width: 18px;
  height: 18px;
}

/* the stage is a size container, so it must be stretched explicitly inside the centred desktop grid */
.bk-stage {
  align-self: stretch;
  justify-self: stretch;
  height: 100%;
}

/* ---------- 3D page turn ---------- */
.bk-sheet {
  position: relative;
  perspective: 2400px;
  perspective-origin: 50% 50%;
}
.bk-page.holding .bk-layer {
  display: none;
}
/* the leaf itself does not move: it is a chain of strips, each hinged on the one before it */
.bk-flip {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  z-index: 4;
  transform-style: preserve-3d;
  pointer-events: none;
}
.bk-flip.right {
  left: 50%;
}
.bk-flip.left {
  left: 0;
}
.bk-flip.full {
  left: 0;
  width: 100%;
}
.bk-strip {
  position: absolute;
  top: 0;
  height: 100%;
  width: 100%;
  transform-style: preserve-3d;
  will-change: transform;
}
.hinge-left .bk-strip {
  left: 100%;
  transform-origin: 0 50%;
}
.hinge-left .bk-strip.root {
  left: 0;
}
.hinge-right .bk-strip {
  right: 100%;
  transform-origin: 100% 50%;
}
.hinge-right .bk-strip.root {
  right: 0;
}
.bk-face {
  position: absolute;
  inset: 0; /* exactly one strip wide: the image slice offsets depend on it */
  background-color: #f8f2e4;
  background-repeat: no-repeat;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.bk-face.face-back {
  transform: rotateY(180deg);
}
.bk-shade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}
.bk-cast {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
}
.bk-cast.right {
  left: 50%;
}
.bk-cast.left {
  left: 0;
}
.bk-cast.full {
  left: 0;
  width: 100%;
}
.bk-cast.hinge-left {
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.65), transparent 70%);
}
.bk-cast.hinge-right {
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.65), transparent 70%);
}
