.gallery-heading { max-width: 900px; padding-bottom: 30px; }
.gallery-heading h1 { max-width: 21ch; }
.gallery-heading h1 em { display: inline-block; color: var(--teal); font-weight: 400; }
.gallery-intro-links { display: flex; flex-wrap: wrap; gap: 12px 30px; margin-top: 24px; font-size: 13px; }
.gallery-intro-links>span { color: var(--muted); }
.gallery-intro-links strong { color: var(--ink); font-weight: 600; }
.figure-tools { display: grid; grid-template-columns: minmax(200px, 1.4fr) minmax(200px, 1fr) minmax(155px, .55fr); gap: 16px 20px; background: var(--wash); border: 1px solid var(--line); border-radius: 5px; padding: 20px 22px 15px; }
.figure-tools input, .figure-tools select { height: 46px; font-size: 14px; }
.figure-filter-status { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 16px; align-items: center; min-height: 26px; font-size: 12px; color: var(--muted); }
.figure-filter-status button { background: none; border: 0; padding: 4px 0; color: var(--teal); text-decoration: underline; text-underline-offset: 4px; }
.gallery-help { font-size: 12px; color: var(--muted); margin: 18px 0 25px; }
.figure-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; align-items: start; }
.figure-card { background: #fffefa; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; scroll-margin-top: 22px; }
.figure-card:target { box-shadow: 0 0 0 3px #14636c55; }
.figure-preview { display: flex; align-items: center; justify-content: center; background: white; position: relative; aspect-ratio: 1.55; padding: 12px; border-bottom: 1px solid var(--line); }
.figure-preview img { width: 100%; height: 100%; object-fit: contain; }
.figure-preview:focus-visible { outline-offset: -5px; }
.figure-enlarge { position: absolute; bottom: 8px; right: 8px; padding: 4px 8px; border-radius: 3px; font-size: 10px; background: #fffef5ee; border: 1px solid #d8dfdacc; }
.figure-preview:hover .figure-enlarge { color: white; background: var(--teal); border-color: var(--teal); }
.figure-card-copy { padding: 20px; }
.figure-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 11px; font-size: 11px; color: var(--muted); }
.figure-permalink { text-decoration: none; font-weight: 650; letter-spacing: .025em; }
.figure-permalink:hover { text-decoration: underline; }
.figure-card h2 { font-family: var(--serif); font-size: 23px; line-height: 1.17; letter-spacing: -.015em; }
.figure-caption { font-size: 12px; line-height: 1.7; color: var(--muted); margin: 14px 0 19px; overflow-wrap: anywhere; }
.figure-math { display: inline; }
.figure-caption mjx-container { font-size: 106% !important; }
.figure-links { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; font-size: 11px; line-height: 1.6; }
.figure-links a { text-decoration: none; }
.figure-links a:hover { text-decoration: underline; }
.figure-page { color: var(--muted); padding-left: 3px; }
.figure-links .notebook-link { font-weight: 650; }
.gallery-footnote { margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
#figure-viewer { padding: 0; border: 1px solid var(--line); border-radius: 6px; width: min(1280px, calc(100% - 48px)); max-width: none; max-height: calc(100dvh - 40px); color: var(--ink); background: var(--paper); }
#figure-viewer::backdrop { background: #142a30bf; }
.viewer-heading { padding: 18px 22px; display: flex; gap: 20px; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.viewer-heading h2 { font-family: var(--serif); font-size: 25px; line-height: 1.25; }
.viewer-close { flex-shrink: 0; background: white; border: 1px solid var(--line); border-radius: 4px; padding: 10px 14px; font-size: 13px; }
.viewer-close span { margin-left: 10px; font-size: 20px; line-height: 1; }
.viewer-image { padding: 20px; background: white; min-height: 180px; display: grid; place-items: center; }
.viewer-image img { width: 100%; height: min(65dvh, 720px); object-fit: contain; }
.viewer-footer { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 17px 22px; border-top: 1px solid var(--line); }
.viewer-footer .figure-links { font-size: 12px; }
.viewer-navigation { display: flex; gap: 12px; align-items: center; flex-shrink: 0; font-size: 12px; }
.viewer-navigation button { width: 42px; height: 42px; background: white; border: 1px solid var(--line); border-radius: 4px; font-size: 18px; }
.viewer-navigation button:disabled { opacity: .35; cursor: default; }
body.figure-viewer-open { overflow: hidden; }
@media (max-width: 1050px) {
  .figure-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figure-tools { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .figure-tools .field:first-child { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .gallery-heading h1 { font-size: 42px; }
  .gallery-heading { padding-block: 30px 25px; }
  .gallery-intro-links { gap: 10px; font-size: 12px; }
  .figure-tools { padding: 16px; gap: 14px; grid-template-columns: minmax(0, 1fr); }
  .figure-tools input, .figure-tools select { font-size: 16px; }
  .figure-grid { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .figure-card h2 { font-size: 25px; }
  .figure-caption { font-size: 13px; }
  .figure-links { font-size: 12px; gap: 12px 18px; }
  #figure-viewer { width: calc(100% - 20px); max-height: calc(100dvh - 20px); }
  .viewer-heading { padding: 14px; gap: 10px; }
  .viewer-heading h2 { font-size: 20px; }
  .viewer-close { padding: 9px; }
  .viewer-close span { margin-left: 3px; }
  .viewer-image { padding: 8px; }
  .viewer-image img { height: min(53dvh, 600px); }
  .viewer-footer { padding: 15px; align-items: start; flex-direction: column; }
  .viewer-navigation { align-self: center; }
}
@media print {
  .figure-tools, .gallery-help, .figure-enlarge, #figure-viewer { display: none; }
  .figure-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figure-card { break-inside: avoid; }
}
