
/* Phase 4.3: layout-adjust loop marker class — force a page break before the
   marked element (used to push orphaned headings to the next page). */
.break-before-page {
  break-before: page;
  page-break-before: always;
}

@page {
  size: 6in 9in;
  margin: 0.82in 0.72in 0.9in;

  @top-left {
    content: string(chapter-title, first);
    font-family: var(--font-sans);
    font-size: 8.8pt;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
  }

  @top-right {
    content: string(section-title, first);
    font-family: var(--font-sans);
    font-size: 8.3pt;
    color: var(--muted);
  }

  @bottom-center {
    content: counter(page);
    font-family: var(--font-sans);
    font-size: 9pt;
    color: var(--muted);
  }

  @footnote {
    border-top: 1px solid var(--rule);
    margin-top: 0.16in;
    padding-top: 0.09in;
  }
}

@page :first {
  @top-left { content: ""; }
  @top-right { content: ""; }
  @bottom-center { content: ""; }
}

body {
  background: #fff;
  counter-reset: figure table;
}

main {
  max-width: none;
  margin: 0;
  padding: 0;
}

p,
li {
  orphans: 2;
  widows: 2;
}

.book-cover {
  page-break-after: always;
  min-height: 7.05in;
  height: 7.05in;
  max-height: 7.05in;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  overflow: hidden;
  background: #081d2e;
  break-after: page;
  break-inside: avoid;
  page-break-inside: avoid;
}

.book-cover::before,
.book-cover::after {
  content: none;
}

.cover-image {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 1;
  margin: 0;
  height: 100%;
  max-height: 100%;
  width: 100%;
  overflow: hidden;
}

.cover-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(7, 22, 34, 0.05) 0%,
    rgba(8, 24, 37, 0.16) 48%,
    rgba(8, 31, 48, 0.44) 72%,
    rgba(8, 36, 56, 0.78) 90%,
    rgba(8, 39, 60, 0.9) 100%
  );
}

.cover-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  filter: saturate(1.12) contrast(1.08);
}

.cover-image-fallback::after {
  background: linear-gradient(
    180deg,
    rgba(5, 16, 25, 0.48) 0%,
    rgba(6, 19, 30, 0.62) 48%,
    rgba(6, 22, 34, 0.78) 72%,
    rgba(6, 24, 38, 0.9) 90%,
    rgba(6, 26, 40, 0.96) 100%
  );
}

.cover-image-fallback img {
  filter: blur(0.052in) brightness(0.56) saturate(0.76) contrast(0.92);
  transform: scale(1.055);
}

.cover-content {
  position: relative;
  z-index: 1;
  max-width: calc(100% - 0.8in);
  margin: 0 auto;
  padding: 0.32in 0.38in 0.3in;
  border-radius: 0.1in;
  border: 1px solid rgba(247, 243, 232, 0.2);
  background: linear-gradient(160deg, rgba(6, 24, 39, 0.82), rgba(8, 29, 46, 0.72));
  box-shadow: 0 0.09in 0.22in rgba(2, 8, 16, 0.3);
}

.book-cover .book-title {
  font-size: 2.22rem;
  line-height: 1.04;
  text-shadow: 0 0.02in 0.08in rgba(2, 10, 18, 0.38);
}

.book-cover .book-subtitle {
  margin-top: 0.56rem;
  font-size: 0.92rem;
  letter-spacing: 0.09em;
  color: rgba(247, 243, 232, 0.9);
}

.book-cover .book-meta {
  margin-top: 0.9rem;
  font-size: 0.79rem;
  color: rgba(247, 243, 232, 0.9);
  border-color: rgba(247, 243, 232, 0.3);
}

.book-cover .book-date {
  margin-top: 0.7rem;
  font-size: 0.74rem;
  color: rgba(247, 243, 232, 0.78);
}

.toc {
  page-break-after: always;
  margin-top: 0;
}

.toc-entry {
  border-bottom: none;
}

.toc-title-text::after {
  content: none;
}

.toc-page {
  display: block;
  min-width: 2ch;
  text-align: right;
  white-space: nowrap;
}

.figure-index {
  break-before: page;
  page-break-before: always;
  margin-top: 0;
}

.figure-index-page {
  display: block;
  min-width: 2ch;
  text-align: right;
  white-space: nowrap;
}

.chapter {
  break-before: page;
  page-break-before: always;
  margin-top: 0;
  clear: both;
}

.chapter.back-matter {
  break-before: page;
  page-break-before: always;
}

.chapter-header {
  break-inside: avoid;
  page-break-inside: avoid;
  break-after: avoid-page;
  page-break-after: avoid;
}

.chapter-eyebrow {
  break-after: avoid-page;
  page-break-after: avoid;
}

.chapter-title,
h1 {
  string-set: chapter-title content(), section-title content();
}

.section-title,
h2 {
  string-set: section-title content();
}

h1,
h2,
h3,
.chapter-title,
.section-title,
figcaption {
  break-after: avoid;
}

h2 + p,
h3 + p {
  break-before: avoid;
}

figure,
.callout,
blockquote,
pre,
table {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* Keep captions bound to their figures. */
figcaption {
  break-before: avoid;
}

figure img {
  max-height: 6in;
  object-fit: contain;
  box-shadow: none;
}

figure.figure-tall img {
  max-height: 5.4in;
}

figure.figure-tall-photo img {
  max-height: 4.8in;
}

figure.figure-wide-diagram {
  margin-left: -0.12in;
  margin-right: -0.12in;
}

figure.figure-wide-diagram img {
  width: calc(100% + 0.24in);
  max-width: calc(100% + 0.24in);
}

figure.gallery-diagram .gallery-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.18rem;
}

figure.gallery-diagram {
  margin-left: -0.12in;
  margin-right: -0.12in;
}

table {
  font-size: 0.9rem;
}

::footnote-call {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 1;
}

::footnote-marker {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 1;
}


/* widows/orphans safeguards */

p,
li {
  orphans: 2;
  widows: 2;
}

h1,
h2,
.chapter-title,
.section-title {
  break-after: avoid-page;
  page-break-after: avoid;
}

h1 + p,
h1 + ul,
h1 + ol,
h1 + figure,
h2 + p,
h2 + ul,
h2 + ol,
h2 + figure {
  break-before: avoid-page;
  page-break-before: avoid;
}

/* Keep chapter/section headings tight, but let subheading content flow naturally. */
h4 + p,
h4 + ul,
h4 + ol,
h5 + p,
h5 + ul,
h5 + ol {
  break-before: auto;
  page-break-before: auto;
}

.chapter-header {
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
}

.chapter-eyebrow {
  margin-bottom: 0.35rem;
}

.section {
  margin-top: 1.2rem;
}

.section-title {
  margin-bottom: 0.5rem;
}

h3 {
  margin: 0.85rem 0 0.35rem;
}

h4,
h5 {
  margin: 0.7rem 0 0.3rem;
}

h3 {
  break-after: avoid-page;
  page-break-after: avoid;
}

h3 + p,
h3 + ul,
h3 + ol {
  break-before: avoid-page;
  page-break-before: avoid;
}

h4,
h5 {
  break-after: auto;
  page-break-after: auto;
}

p {
  margin: 0 0 0.72rem;
}

figure {
  break-inside: avoid;
  page-break-inside: avoid;
}

figure {
  margin: 0.6rem 0;
}

figure.gallery {
  margin: 0.45rem 0;
}

figure.gallery .gallery-grid {
  gap: 0.22rem;
}

figure.gallery.gallery--4up .gallery-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

figcaption {
  /* Do not force caption to stay with the following heading/paragraph. */
  break-after: auto;
  page-break-after: auto;
  margin-top: 0.3rem;
}

figcaption + * {
  break-before: auto;
  page-break-before: auto;
}

.figure-tail-keep {
  break-inside: avoid;
  page-break-inside: avoid;
}

