
:root {
  --font-serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", "URW Palladio L", "Georgia", serif;
  --font-display: "Baskerville", "Iowan Old Style", "Palatino Linotype", serif;
  --font-sans: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;

  --ink: #1e2430;
  --muted: #5f6476;
  --accent: #0f4c5c;
  --accent-soft: #d8e8ec;
  --accent-warm: #8b5932;
  --rule: #d9d4c8;
  --paper: #fbf8f0;
  --canvas: #102434;
  --canvas-highlight: #1f5f73;
  --canvas-glow: #f1dfc4;

  --max-width: 40rem;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 11pt;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-serif);
  line-height: 1.62;
  letter-spacing: 0.005em;
  background:
    radial-gradient(120rem 28rem at 50% -4rem, #f1ece2 0%, transparent 62%),
    linear-gradient(180deg, #f8f4eb 0%, #fbf8f0 14rem, #ffffff 100%);
}

main {
  display: block;
  max-width: calc(var(--max-width) + 4.25rem);
  margin: 0 auto;
  padding: 2.2rem 1.4rem 4rem;
}

.book {
  padding: 0;
}

.book-cover {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  margin: 0 auto 2.8rem;
  min-height: 22.5rem;
  border-radius: 0.9rem;
  padding: 2.3rem 2rem 2.6rem;
  background:
    linear-gradient(130deg, var(--canvas) 0%, var(--canvas-highlight) 62%, #256a80 100%);
  color: #f7f3e8;
  box-shadow: 0 1.5rem 3rem -2.1rem rgba(13, 24, 34, 0.55);
}

.book-cover::before {
  content: "";
  position: absolute;
  inset: auto -12% -18% 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 32%, rgba(241, 223, 196, 0.52), rgba(241, 223, 196, 0));
  pointer-events: none;
}

.book-cover::after {
  content: "";
  position: absolute;
  inset: 1.15rem 1.15rem auto auto;
  width: 5.1rem;
  height: 5.1rem;
  border: 1px solid rgba(247, 243, 232, 0.35);
  border-radius: 999rem;
  pointer-events: none;
}

.cover-image {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.3;
}

.cover-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(16, 36, 52, 0.8) 18%, rgba(16, 36, 52, 0.38) 62%, rgba(16, 36, 52, 0.72) 100%);
}

.cover-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 38%;
  display: block;
}

.cover-image-fallback::after {
  background: linear-gradient(120deg, rgba(12, 29, 42, 0.88) 18%, rgba(12, 29, 42, 0.62) 58%, rgba(12, 29, 42, 0.84) 100%);
}

.cover-image-fallback img {
  filter: blur(0.32rem) brightness(0.68) saturate(0.78) contrast(0.92);
  transform: scale(1.055);
}

.cover-content {
  position: relative;
  z-index: 1;
  max-width: 34rem;
}

.book-title {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.03;
  letter-spacing: 0.02em;
  margin: 0;
}

.book-subtitle {
  margin: 0.9rem 0 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(247, 243, 232, 0.82);
}

.book-meta {
  margin-top: 1.4rem;
  display: inline-block;
  padding: 0.35rem 0.65rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(247, 243, 232, 0.88);
  border: 1px solid rgba(247, 243, 232, 0.38);
  border-radius: 0.2rem;
}

.book-date {
  margin-top: 1.1rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.book-title,
.book-subtitle,
.book-meta,
.book-date {
  overflow-wrap: break-word;
  word-break: normal;
  text-wrap: balance;
  hyphens: manual;
}

.toc {
  margin: 0 0 2.9rem;
  padding: 1.3rem 1.45rem 1.5rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(15, 76, 92, 0.14);
}

.toc-title {
  margin: 0 0 0.95rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: baseline;
  column-gap: 0.7rem;
  margin: 0;
  padding: 0.24rem 0;
  border-bottom: 1px dotted rgba(30, 36, 48, 0.16);
}

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

.toc-entry a {
  color: inherit;
  text-decoration: none;
}

.toc-entry a:hover {
  color: var(--accent);
}

.toc-title-text {
  flex: 1 1 auto;
  min-width: 0;
}

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

.toc-page::before {
  content: target-counter(attr(data-target), page);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.toc-level-2 {
  margin-left: 1.2rem;
  font-size: 0.96rem;
}

.figure-index {
  margin: 2.9rem 0;
  padding: 1.3rem 1.45rem 1.5rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(15, 76, 92, 0.14);
}

.figure-index-title {
  margin: 0 0 0.95rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.figure-index-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.figure-index-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: baseline;
  column-gap: 0.7rem;
  margin: 0;
  padding: 0.24rem 0;
  border-bottom: 1px dotted rgba(30, 36, 48, 0.16);
}

.figure-index-entry:last-child {
  border-bottom: none;
}

.figure-index-entry a {
  color: inherit;
  text-decoration: none;
}

.figure-index-caption {
  min-width: 0;
}

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

.figure-index-page::before {
  content: target-counter(attr(data-target), page);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.chapter {
  margin: 3rem 0 3.15rem;
}

.chapter-header {
  margin: 0 0 1.2rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--rule);
}

.chapter-eyebrow {
  margin: 0 0 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

.chapter-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.15rem;
  line-height: 1.08;
  letter-spacing: 0.01em;
}

.section {
  margin: 1.9rem 0;
}

.section-title {
  margin: 0 0 0.7rem;
  font-family: var(--font-sans);
  font-size: 1.16rem;
  letter-spacing: 0.02em;
  color: #23384b;
}

h3,
h4,
h5 {
  margin: 1.4rem 0 0.55rem;
  font-family: var(--font-sans);
  color: #223748;
}

p {
  margin: 0 0 0.88rem;
}

.section > p:first-of-type::first-letter {
  font-family: var(--font-display);
  font-size: 1.25em;
  font-weight: 700;
  color: var(--accent-warm);
}

ul,
ol {
  margin: 0 0 1rem;
  padding-left: 1.45rem;
}

li {
  margin-bottom: 0.34rem;
}

a {
  color: #0f5267;
}

figure {
  margin: 1.25rem 0;
  break-inside: avoid;
  page-break-inside: avoid;
  counter-increment: figure;
}

figure img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 20rem;
  margin: 0 auto;
  border-radius: 0.32rem;
  border: 1px solid rgba(30, 36, 48, 0.13);
  box-shadow: 0 0.5rem 1.6rem -1.3rem rgba(30, 36, 48, 0.55);
  object-fit: contain;
}

/* Phase 4.1: three figure presentations only — full / medium / gallery. */
figure.figure--medium {
  margin-left: auto;
  margin-right: auto;
  break-inside: avoid;
  page-break-inside: avoid;
}

figure.figure--full {
  width: 100%;
  break-inside: avoid;
  page-break-inside: avoid;
}

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

figcaption {
  margin-top: 0.45rem;
  font-size: 0.84rem;
  color: var(--muted);
}

figcaption::before {
  content: "Figure " counter(figure) ". ";
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #28384a;
}

.figure-credit {
  display: block;
  margin-top: 0.22rem;
  font-size: 0.75rem;
}

.callout {
  margin: 1.25rem 0;
  padding: 0.95rem 1.1rem;
  border-left: 4px solid var(--accent);
  border-radius: 0.35rem;
  background: linear-gradient(180deg, #f7fafb 0%, #eef4f6 100%);
  break-inside: avoid;
}

.callout-title {
  margin-bottom: 0.45rem;
  font-family: var(--font-sans);
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.callout-warning {
  border-left-color: #8d3f24;
  background: linear-gradient(180deg, #fdf5f1 0%, #f8ece7 100%);
}

.callout-warning .callout-title {
  color: #8d3f24;
}

.callout-tip {
  border-left-color: #2f6a48;
  background: linear-gradient(180deg, #f2faf6 0%, #ebf5ee 100%);
}

.callout-tip .callout-title {
  color: #2f6a48;
}

.gallery {
  margin: 1.2rem 0;
}

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

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

.gallery-item img {
  width: 100%;
  height: auto;
}

blockquote {
  margin: 1.2rem 0;
  padding: 0.35rem 0 0.4rem 0.9rem;
  border-left: 3px solid rgba(15, 76, 92, 0.34);
  color: #3f4f5f;
}

pre {
  margin: 1rem 0;
  padding: 0.82rem 0.94rem;
  border-radius: 0.32rem;
  background: #f3f6f8;
  border: 1px solid rgba(30, 36, 48, 0.12);
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: #f2f4f6;
  padding: 0 0.2rem;
  border-radius: 0.18rem;
}

table {
  width: 100%;
  margin: 1.1rem 0;
  border-collapse: collapse;
  font-size: 0.93rem;
  counter-increment: table;
}

table th,
table td {
  border: 1px solid rgba(30, 36, 48, 0.15);
  padding: 0.42rem 0.58rem;
  vertical-align: top;
}

table th {
  font-family: var(--font-sans);
  background: #eff4f6;
}

.table-caption {
  margin-top: 0.45rem;
  font-size: 0.83rem;
  color: var(--muted);
}

.table-caption::before {
  content: "Table " counter(table) ". ";
  font-family: var(--font-sans);
  font-weight: 600;
}

hr {
  border: 0;
  border-top: 1px solid rgba(30, 36, 48, 0.2);
  margin: 1.6rem 0;
}

.footnote {
  float: footnote;
  font-size: 0.84em;
}

.clearfix::after {
  content: "";
  display: block;
  clear: both;
}

.qa-marker {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  font-size: 0.01pt;
  color: transparent;
  line-height: 0;
  white-space: nowrap;
}

@media screen and (max-width: 720px) {
  main {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .book-cover {
    padding: 1.8rem 1.4rem 2rem;
    border-radius: 0.7rem;
    min-height: 19.5rem;
  }

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

  .chapter-title {
    font-size: 1.85rem;
  }
}
