/* Narrative images are placed once, beside the section they illustrate. */
body.image-maximized { overflow: hidden; }
@media print { body.image-maximized { overflow: visible !important; } }
.reader-layout,
.section-reading-layout,
.section-passages {
  min-width: 0;
}

.illustration-panel,
#illustration-scrim {
  display: none !important;
}

.section-illustrations[hidden],
.image-lightbox[hidden] {
  display: none !important;
}

.picture-toggle {
  min-height: 34px;
  gap: 7px;
}

.picture-toggle[aria-pressed="true"] {
  color: var(--olive-dark);
  background: var(--olive-soft);
  border-color: var(--line);
}

.picture-toggle > span {
  font-size: 10px;
  line-height: 1.8;
}

/* The full section, rather than an individual paragraph, owns the image rail. */
#reading-view .reading-section:has(.section-illustrations:not([hidden])) {
  max-width: none;
}

.section-reading-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 30px;
}

.section-illustrations {
  min-width: 0;
  max-width: 780px;
  width: 100%;
  margin: 0 auto 3px;
  order: -1;
}

.section-image-card {
  min-width: 0;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--line);
}

.section-image-figure {
  margin: 0;
}

.section-image-expand {
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  overflow: hidden;
  cursor: zoom-in;
}

.section-image-expand > img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  background: var(--saffron-soft);
  transition: filter .18s;
}

.image-expand-label {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  border: 1px solid #ede9d7b3;
  border-radius: 4px;
  background: #fbf9f2ed;
  color: #3d4d35;
  font-family: var(--font-ui);
  font-size: 10px;
  line-height: 1.8;
  box-shadow: 0 2px 12px #27301c12;
  pointer-events: none;
}

.image-expand-label > svg {
  width: 15px;
  height: 15px;
}

.section-image-expand:hover > img {
  filter: brightness(1.025);
}

.section-image-expand:hover .image-expand-label {
  background: #fffef8;
}

.section-image-caption {
  padding: 17px 1px 0;
  overflow-wrap: anywhere;
}

.section-image-caption h3 {
  margin: 0 0 7px;
  color: var(--olive-dark);
  font-family: var(--font-reading);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.8;
}

.section-image-caption p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 2;
}

.section-image-caption > span,
.section-image-caption .illustration-kind {
  display: inline-block;
  color: var(--saffron);
  font-size: 9px;
  line-height: 1.8;
  margin-top: 10px;
}

.section-image-caption .illustration-number {
  color: var(--saffron);
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: .08em;
}

.illustration-note,
.print-illustration-notice {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.95;
  margin: 14px 0 0;
}

/* Keep the text readable; only a generous desktop gets a separate right rail. */
@media (min-width: 1250px) {
  .section-reading-layout:has(> .section-illustrations:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) clamp(340px, 38%, 480px);
    column-gap: 36px;
  }

  .section-reading-layout > .section-illustrations {
    position: sticky;
    top: calc(var(--header-height) + 24px);
    align-self: start;
    max-width: none;
    order: 0;
    margin: 0;
  }

  .section-image-card {
    border-bottom: 0;
    padding: 0;
  }

  /* Several language columns belong in the text area, not squeezed beside art. */
  .section-reading-layout:has(> .section-illustrations:not([hidden])) .passage-row.parallel {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }

  .section-reading-layout:has(> .section-illustrations:not([hidden])) .passage-row.parallel > .source-column {
    padding: 0 0 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .section-reading-layout:has(> .section-illustrations:not([hidden])) .language-columns {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }

  .section-reading-layout:has(> .section-illustrations:not([hidden])) .translation-column + .translation-column {
    padding: 18px 0 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .book-sheet:has(.section-illustrations:not([hidden])) {
    max-width: none;
    padding-right: 36px;
    padding-left: 36px;
  }
}

@media (min-width: 1800px) {
  .section-reading-layout:has(> .section-illustrations:not([hidden])) {
    column-gap: 44px;
  }
  .section-reading-layout:has(> .section-illustrations:not([hidden])) .passage-row.parallel {
    grid-template-columns: minmax(230px, .85fr) minmax(0, 1.15fr);
    gap: 24px;
  }
  .section-reading-layout:has(> .section-illustrations:not([hidden])) .passage-row.parallel > .source-column {
    padding: 0 22px 0 0;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }
}

@media (max-width: 760px) {
  .section-reading-layout {
    gap: 26px;
  }

  .section-image-caption {
    padding-top: 13px;
  }

  .section-image-caption h3 {
    font-size: 15px;
  }

  .section-image-caption p {
    font-size: 12px;
  }

  .image-expand-label {
    right: 9px;
    bottom: 9px;
    padding: 8px 10px;
    font-size: 10px;
  }
}

/* Native dialog provides a large, uncropped view while preserving reader position. */
.image-lightbox {
  width: min(1440px, 96vw);
  max-width: 96vw;
  max-height: 96dvh;
  padding: 0;
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 100px #11180e40;
  overflow: hidden;
}

.image-lightbox:not([open]):not(.is-open) {
  display: none;
}

.image-lightbox[open],
.image-lightbox.is-open {
  display: flex;
  flex-direction: column;
}

.image-lightbox::backdrop {
  background: #1b231acc;
  backdrop-filter: blur(4px);
}

.image-lightbox-shell {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 96dvh;
}

.image-lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-shrink: 0;
  padding: 17px 24px;
  border-bottom: 1px solid var(--line);
}

.image-lightbox-header h2,
.image-lightbox-header h3 {
  margin: 0;
  color: var(--olive-dark);
  font-size: 18px;
  line-height: 1.8;
  font-weight: 500;
}

.image-lightbox-header .tool-button,
.image-lightbox-header button {
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
}

.image-lightbox-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 15px 22px;
  overflow: auto;
  background: var(--canvas);
}

.image-lightbox-content > img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(76dvh, 1100px);
  object-fit: contain;
}

.image-lightbox-caption {
  flex-shrink: 0;
  margin: 0;
  padding: 12px 24px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.95;
  max-height: 18dvh;
  overflow-y: auto;
}

@media (max-width: 760px) {
  .image-lightbox {
    width: 96vw;
    max-height: 96dvh;
  }

  .image-lightbox-header {
    padding: 12px 15px;
    gap: 10px;
  }

  .image-lightbox-header h2,
  .image-lightbox-header h3 {
    font-size: 16px;
  }

  .image-lightbox-content {
    padding: 8px;
  }

  .image-lightbox-content > img {
    max-height: 72dvh;
  }

  .image-lightbox-caption {
    padding: 12px 15px 16px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .section-image-expand > img {
    transition: none;
  }
}

/* Print uses complete inline scenes, never a gallery or an enlarged overlay. */
@media print {
  .picture-toggle,
  .image-lightbox,
  .image-expand-label {
    display: none !important;
  }

  .reader-layout,
  .section-reading-layout,
  .section-reading-layout:has(> .section-illustrations:not([hidden])) {
    display: block !important;
    width: auto;
  }

  .section-passages {
    display: block;
  }

  .section-illustrations,
  .section-reading-layout > .section-illustrations {
    position: static !important;
    max-width: none;
    width: 100%;
    margin: 4mm 0 6mm;
    padding: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .section-image-card,
  .section-image-figure,
  .print-illustration {
    display: block;
    margin: 4mm 0 6mm;
    padding: 0;
    border: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .section-image-expand {
    border: 0;
    border-radius: 0;
    overflow: visible;
    background: transparent;
    cursor: default;
  }

  .section-image-expand > img,
  .print-illustration > img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 85mm;
    margin: 0 auto;
    object-fit: contain;
    border: 0;
    border-radius: 0;
  }

  .section-image-caption,
  .print-illustration figcaption {
    padding-top: 3mm;
    color: #39432e;
    font-size: 8pt;
    line-height: 1.7;
  }

  .section-image-caption h3,
  .print-illustration h3 {
    color: #23311c;
    font-size: 10pt;
    line-height: 1.7;
    margin: 0 0 1mm;
  }

  .section-image-caption p,
  .print-illustration p {
    color: #505844;
    font-size: 8pt;
    line-height: 1.7;
    margin: 0;
  }

  .section-image-caption > span,
  .print-illustration .illustration-kind,
  .print-illustration-notice {
    color: #655c45;
    font-size: 7pt;
    line-height: 1.7;
    margin-top: 2mm;
  }
}
