/* 20-Folio Digital Monograph Reader
 * Preserves exact 210mm x 297mm (794px x 1123px) A4 spreads across desktop and mobile
 * by proportionally scaling each folio via CSS zoom rather than reflowing columns.
 */

body.book-reader {
  margin: 0;
  min-height: 100vh;
  background: #1a2620;
  color: #f7f4ea;
  font-family: "Instrument Sans", "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  overflow-x: clip;
  padding-bottom: 4.75rem;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  padding: 0.6rem 1rem;
  background: #f7f4ea;
  color: #143d2d;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 6px 0;
}

.skip-link:focus {
  left: 0;
}

.book-masthead {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.7rem 1.25rem;
  background: rgba(20, 61, 45, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(164, 129, 73, 0.55);
}

.book-brand {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.65rem;
  min-width: 0;
}

.book-title {
  color: #f7f4ea;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.book-title:hover,
.book-title:focus-visible {
  color: #e6d4b1;
}

.book-imprint {
  color: #dfe8da;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
}

.book-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.book-actions button,
.book-actions a,
.book-controls button,
#contents header button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0.42rem 0.85rem;
  border-radius: 6px;
  border: 1px solid rgba(164, 129, 73, 0.65);
  background: rgba(247, 244, 234, 0.1);
  color: #f7f4ea;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.book-actions button:hover,
.book-actions a:hover,
.book-controls button:hover:not(:disabled),
#contents header button:hover {
  background: #a48149;
  border-color: #a48149;
  color: #162822;
}

.book-actions button:focus-visible,
.book-actions a:focus-visible,
.book-controls button:focus-visible,
#contents a:focus-visible,
#contents header button:focus-visible {
  outline: 2px solid #f7f4ea;
  outline-offset: 2px;
}

.book-controls button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.book-stage {
  --page-scale: min(0.92, (100vw - 32px) / 794px);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  padding: 1.25rem 16px 1.5rem;
}

.book-leaf {
  display: flex;
  justify-content: center;
  max-width: 100%;
}

.book-leaf[hidden] {
  display: none;
}

.book-leaf .folio {
  box-sizing: border-box;
  margin: 0;
  zoom: var(--page-scale);
  box-shadow: 0 22px 54px rgba(6, 15, 11, 0.48), 0 0 0 1px rgba(164, 129, 73, 0.25);
  border-radius: 2px;
  cursor: pointer;
}

.book-leaf .folio a,
.book-leaf .folio button {
  cursor: pointer;
}

.book-controls {
  position: fixed;
  left: 50%;
  bottom: 0.9rem;
  transform: translateX(-50%);
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.42rem 0.6rem;
  border-radius: 999px;
  background: rgba(20, 61, 45, 0.95);
  border: 1px solid rgba(164, 129, 73, 0.7);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(8px);
}

.book-controls #position {
  min-width: 4.4rem;
  text-align: center;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #f7f4ea;
}

dialog#contents {
  width: min(92vw, 34rem);
  max-height: 80vh;
  padding: 0;
  border: 1px solid #a48149;
  border-radius: 10px;
  background: #f7f4ea;
  color: #162822;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

dialog#contents::backdrop {
  background: rgba(12, 24, 19, 0.72);
  backdrop-filter: blur(3px);
}

dialog#contents header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.15rem;
  background: #143d2d;
  color: #f7f4ea;
  border-bottom: 1px solid #a48149;
}

dialog#contents header h2 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
}

dialog#contents ol {
  margin: 0;
  padding: 0.85rem 1.15rem 1.15rem 2.25rem;
  display: grid;
  gap: 0.32rem;
}

dialog#contents li a {
  display: block;
  padding: 0.28rem 0.45rem;
  border-radius: 4px;
  color: #143d2d;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
}

dialog#contents li a:hover {
  background: #dfe8da;
}

dialog#contents li a[aria-current="page"] {
  background: #143d2d;
  color: #f7f4ea;
  font-weight: 600;
}

@media (max-width: 760px) {
  .book-masthead {
    padding: 0.55rem 0.75rem;
    flex-wrap: wrap;
    gap: 0.45rem 0.6rem;
  }

  .book-title {
    font-size: 0.94rem;
  }

  .book-imprint {
    font-size: 0.74rem;
  }

  .book-actions button,
  .book-actions a {
    padding: 0.34rem 0.65rem;
    font-size: 0.76rem;
    min-height: 34px;
  }

  .book-stage {
    --page-scale: min(0.92, (100vw - 16px) / 794px);
    padding: 0.75rem 8px 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .book-actions button,
  .book-actions a,
  .book-controls button,
  #contents header button {
    transition: none;
  }
}

@media print {
  body.book-reader {
    background: #ffffff;
    color: #162822;
    padding-bottom: 0;
  }

  .skip-link,
  .book-masthead,
  .book-controls,
  dialog#contents {
    display: none !important;
  }

  .book-stage {
    display: block;
    padding: 0;
  }

  .book-leaf,
  .book-leaf[hidden] {
    display: block !important;
    break-after: page;
    page-break-after: always;
  }

  .book-leaf:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .book-leaf .folio {
    zoom: 1 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
}
