/* Fantasia Fauna — editorial reading and visual catalogue. */
:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --surface: #fffefa;
  --ink: #202b27;
  --muted: #59645d;
  --forest: #234e3c;
  --wash: #e9eee5;
  --line: #d3d7cc;
  --control-line: #7b897f;
  --header-background: #234e3c;
  --header-text: #f7f5ef;
  --target: #e1ead8;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --measure: 1200px;
  --gutter: clamp(20px, 4vw, 48px);
}

:root[data-theme="clair-doux"] { color-scheme: light; --paper: #f7f5ef; }
:root[data-theme="clair"] {
  color-scheme: light;
  --paper: #ffffff;
  --surface: #ffffff;
  --wash: #eff3ef;
  --target: #e3eee1;
}
:root[data-theme="sombre"] {
  color-scheme: dark;
  --paper: #111816;
  --surface: #19231e;
  --ink: #edf1e9;
  --muted: #b8c5ba;
  --forest: #b5d9b7;
  --wash: #243229;
  --line: #45574a;
  --control-line: #8c9e90;
  --target: #2b3d30;
  --header-background: #0c1410;
  --header-text: #edf1e9;
}
:root[data-theme="sombre-doux"] {
  color-scheme: dark;
  --paper: #26312c;
  --surface: #2c3931;
  --ink: #f0f1e8;
  --muted: #c6cec1;
  --forest: #c0dfb8;
  --wash: #334237;
  --line: #5f7162;
  --control-line: #a0af9c;
  --target: #3a4a3d;
  --header-background: #1c2821;
  --header-text: #f0f1e8;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 24px; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.6 var(--ui); }
/* Original marginalia: a transparent, text-free herbarium/sky plate.
   Only creature routes instantiate the layer; catalogues and errors stay plain.
   Width-fit keeps the botanical margins at the viewport edges, never
   drifting inward over the reading column on wide screens. */
:root {
  --creature-wallpaper: url("../img/wallpapers/herbier-celeste-clair.svg");
  --creature-wallpaper-opacity: .065;
}
:root[data-theme="clair-doux"], :root[data-theme="clair"] {
  --creature-wallpaper: url("../img/wallpapers/herbier-celeste-clair.svg");
}
:root[data-theme="sombre"], :root[data-theme="sombre-doux"] {
  --creature-wallpaper: url("../img/wallpapers/herbier-celeste-sombre.svg");
  --creature-wallpaper-opacity: .055;
}
body:has(.creature)::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--creature-wallpaper);
  background-position: center;
  background-size: 100% auto;
  background-repeat: no-repeat;
  opacity: var(--creature-wallpaper-opacity);
}
/* Do not elevate the whole body: the skip link retains z-index 10;
   native showModal() dialogs and their backdrop remain in the top layer. */
body:has(.creature) > #app,
body:has(.creature) > .site-header,
body:has(.creature) > .site-footer { position: relative; z-index: 1; }
img { display: block; max-width: 100%; }
a { color: var(--forest); text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--forest); outline-offset: 4px; }
::selection { background: #cbdcc9; color: #172b20; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.2; text-wrap: pretty; }
p { text-wrap: pretty; }
.wrap, .site-footer { width: min(var(--measure), calc(100% - var(--gutter) * 2)); margin-inline: auto; }
#app { min-height: 60vh; }
.skip { position: fixed; top: 12px; left: 20px; z-index: 10; padding: 12px 20px; background: var(--surface); color: var(--forest); transform: translateY(-160%); }
.skip:focus { transform: none; }

/* A calm masthead, shared by every route. */
.site-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 24px; padding: 20px max(var(--gutter), calc((100% - var(--measure)) / 2)); background: var(--header-background); color: var(--header-text); }
.brand { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; color: inherit; text-decoration: none; }
.brand .mark { width: 32px; height: 32px; flex-shrink: 0; }
.brand-name { font: 500 clamp(22px, 2.4vw, 29px)/1.2 var(--serif); letter-spacing: -.025em; }
.nav-links { display: flex; align-items: center; gap: 20px; margin-left: auto; }
.theme-control { display: flex; align-items: center; gap: 10px; font-size: 14px; min-width: 0; }
.theme-control label { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; cursor: pointer; }
.theme-control input { width: 104px; min-width: 44px; min-height: 44px; margin: 0; accent-color: #d6e1c7; cursor: pointer; }
.theme-control output { width: 6em; white-space: nowrap; }
.theme-icon { width: 20px; height: 20px; flex: none; transform: rotate(0deg); transition: transform .35s ease; }
.theme-icon, .brand .mark { pointer-events: none; }
.theme-icon .sun-rays { opacity: 1; transition: opacity .35s ease; }
:root[data-theme="sombre"] .theme-icon { transform: rotate(-90deg); }
:root[data-theme="sombre-doux"] .theme-icon { transform: rotate(-45deg); }
:root[data-theme="clair"] .theme-icon { transform: rotate(45deg); }
:root[data-theme="sombre"] .sun-rays, :root[data-theme="sombre-doux"] .sun-rays { opacity: 0; }
.brand .wing { transform-origin: 20px 20px; animation: wing-welcome 1.6s ease-in-out 2; }
.brand:hover .wing, .brand:focus-visible .wing { animation-name: wing-greeting; }
@keyframes wing-welcome { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(.48); } }
@keyframes wing-greeting { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(.48); } }
.nav-links a { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 4px; color: inherit; text-decoration: none; border-bottom: 2px solid transparent; }
.nav-links a:hover, .nav-links a[aria-current="page"] { border-color: #d6e1c7; }
.site-header :focus-visible { outline-color: #e3efcf; }
.site-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 32px; margin-top: 32px; padding-block: 24px 36px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.footer-star { padding-inline: 8px; }
.footer-note { font-family: var(--serif); font-style: italic; }

/* Explore: no decorative hero; search precedes the gallery. */
.catalog-intro { padding: 34px 0 26px; }
.intro-copy { display: grid; grid-template-columns: 1.2fr 1fr; gap: 8px 48px; align-items: center; }
.kicker { margin: 0; color: var(--forest); font: 600 12px/1.5 var(--ui); letter-spacing: .12em; text-transform: uppercase; }
.intro-copy .kicker { grid-column: 1 / -1; }
.kicker > span { display: none; }
.catalog-brand { margin: 0; font-size: clamp(30px, 3.3vw, 44px); letter-spacing: -.025em; }
.catalog-brand em { color: var(--forest); font-weight: 400; }
.catalog-lead { margin: 0; max-width: 49ch; font: 19px/1.8 var(--serif); color: var(--muted); }
.atlas-figure, .explore-link, .specimen-frame, .plate-frame { display: none; }
.collection-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 20px 0 14px; border-top: 1px solid var(--line); }
.collection-heading .kicker { display: none; }
.collection-heading h2 { margin: 0; font-size: 26px; }
.census { margin: 0; color: var(--muted); font-size: 16px; }
.census b { color: var(--forest); font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 16px 20px; padding: 18px 20px; margin-bottom: 24px; background: var(--wash); border: 1px solid var(--line); border-radius: 4px; }
.search { flex: 1 1 300px; min-width: 0; }
.sorter { flex: 0 1 220px; }
.search label, .sorter label { display: block; margin-bottom: 6px; font-weight: 600; }
.search-field { position: relative; }
.search-field svg { position: absolute; width: 20px; height: 20px; left: 14px; top: 50%; transform: translateY(-50%); stroke: var(--muted); fill: none; stroke-width: 1.7; pointer-events: none; }
.search input, .sorter select { width: 100%; min-height: 48px; border: 1px solid var(--control-line); border-radius: 3px; background: var(--surface); padding: 10px 12px; }
.search input { padding-left: 44px; }
.search input::placeholder { color: var(--muted); opacity: 1; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.result-count { color: var(--muted); margin: 0; white-space: nowrap; }
.quiet { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 44px; padding: 9px 13px; color: var(--forest); background: var(--surface); border: 1px solid var(--control-line); border-radius: 3px; text-decoration: none; }
.quiet:hover, .quiet[aria-pressed="true"] { background: var(--forest); border-color: var(--forest); color: var(--paper); }
.quiet svg { width: 18px; height: 18px; flex-shrink: 0; }
.dice-dot { fill: currentColor; }
.catalog-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 28px 24px; padding-bottom: 32px; }
.plate { display: block; min-width: 0; color: var(--ink); text-decoration: none; }
.plate-case { display: flex; flex-direction: column; height: 100%; }
.plate-bezel { display: block; border: 1px solid #657267; padding: 4px; background: var(--paper); }
.plate-scene { display: grid; place-items: center; aspect-ratio: 1; background: #000; overflow: hidden; }
.creature-foil { display: grid; place-items: center; width: 90%; height: 90%; min-width: 0; min-height: 0; }
.creature-foil > img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.plate-label { position: relative; display: grid; grid-template-columns: auto 1fr 20px; align-items: baseline; gap: 10px; padding: 12px 0 0; }
.plate-index { font: 13px/1.5 var(--ui); color: var(--muted); font-variant-numeric: tabular-nums; }
.plate-name { font-size: 21px; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.plate-arrow { width: 18px; height: 18px; fill: none; stroke: var(--forest); stroke-width: 1.5; align-self: center; }
.plate:hover .plate-name { color: var(--forest); text-decoration: underline; text-underline-offset: .2em; }
.plate:hover .plate-bezel { border-color: var(--forest); }
.missing-art { display: grid; place-items: center; min-height: 100px; padding: 20px; color: #e0e7db; font: 16px/1.5 var(--ui); }

/* Notice: twelve columns; image and metadata, then index and prose. */
.crumb { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 14px 0 22px; color: var(--muted); }
.crumb a { display: inline-flex; align-items: center; min-height: 44px; }
.creature { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 40px 24px; align-items: start; padding-bottom: 40px; }
.exhibit { grid-column: 1 / 4; grid-row: 1; margin: 0; width: 100%; }
.exhibit-well { position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 1; background: #000; border: 1px solid #657267; padding: 5px; }
.exhibit-foil { width: 94%; height: 94%; }
.exhibit-sprite { object-fit: contain; image-rendering: pixelated; cursor: zoom-in; }
.exhibit-zoom { display: inline-flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; margin-top: 8px; padding: 9px 12px; border: 1px solid var(--control-line); border-radius: 3px; color: var(--forest); background: var(--surface); }
.exhibit-zoom:hover { background: var(--wash); }
/* Also supports a zoom button wrapping the artwork. */
.exhibit-well > .exhibit-zoom { margin: 0; padding: 0; height: 100%; background: #000; border: 0; }
.exhibit-tools { margin-top: 8px; }
.sheet-copy { grid-column: 4 / -1; grid-row: 1; min-width: 0; max-width: 820px; }
.sheet-copy h1 { margin: -6px 0 16px; font-size: clamp(36px, 4.2vw, 56px); letter-spacing: -.025em; overflow-wrap: anywhere; }
.lede { margin: 0 0 24px; max-width: 68ch; font: 19px/1.8 var(--serif); }
.dossier { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; margin: 0; border-top: 1px solid var(--line); }
.dossier > div { padding: 12px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.dossier dt { margin: 0 0 3px; font: 600 14px/1.5 var(--ui); color: var(--muted); }
.dossier dd { margin: 0; font: 18px/1.6 var(--serif); overflow-wrap: anywhere; }
.danger-dots { color: var(--forest); letter-spacing: .16em; font: 17px/1.6 var(--ui); }
.meta-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; list-style: none; padding: 0; margin: 0 0 24px; }
.meta-list span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); }
.undocumented { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font: 18px/1.8 var(--serif); }
.reading { display: contents; }
.toc { grid-column: 1 / 4; grid-row: 2; position: sticky; top: 24px; align-self: start; display: flex; flex-direction: column; max-width: 240px; padding-top: 20px; border-top: 1px solid var(--line); font: 16px/1.45 var(--ui); }
.toc-title { margin: 0 0 8px; color: var(--muted); font: 600 12px/1.5 var(--ui); text-transform: uppercase; letter-spacing: .1em; }
.toc a { display: flex; align-items: center; min-height: 44px; padding: 8px 10px; margin-left: -10px; color: var(--forest); text-decoration: none; border-radius: 3px; }
.toc a:hover, .toc a[aria-current] { background: var(--wash); text-decoration: underline; }
.toc .toc-sub { padding-left: 24px; color: var(--muted); font-size: 15px; }
.notice { grid-column: 4 / -1; grid-row: 2; min-width: 0; width: 100%; max-width: 740px; padding-top: 20px; border-top: 1px solid var(--line); font: 19px/1.8 var(--serif); }
.notice section { scroll-margin-top: 24px; }
.notice section + section { margin-top: 40px; }
.notice h2 { margin: 0 0 18px; font-size: 32px; letter-spacing: -.015em; }
.notice h3 { margin: 30px 0 12px; font-size: 24px; color: var(--forest); scroll-margin-top: 24px; }
.notice p { margin: 0 0 1em; }
.notice p:last-child { margin-bottom: 0; }
.source-call { margin-left: .1em; font: 600 12px/0 var(--ui); }
.source-call a { padding: 4px 2px; }
.notice-sources { margin-top: 40px; padding-top: 6px; border-top: 1px solid var(--line); font: 16px/1.7 var(--ui); }
.notice-sources h3 { font-size: 25px; }
.notice-sources ol { margin: 12px 0 0; padding-left: 28px; }
.notice-sources li { padding: 8px 6px; overflow-wrap: anywhere; scroll-margin-top: 30px; }
.notice-sources a { display: inline-block; min-height: 44px; padding-block: 8px; }
.notice-sources li:target { background: var(--target); outline: 2px solid var(--forest); outline-offset: 3px; }
.notice section:target > h2, .notice h3:target { text-decoration: underline; text-decoration-color: #7b997d; text-underline-offset: .2em; }
.pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; border-top: 1px solid var(--line); padding: 20px 0; }
.pager a { display: block; min-height: 76px; padding: 10px 12px; color: var(--ink); text-decoration: none; border-radius: 3px; }
.pager a:hover { background: var(--wash); }
.pager small { display: block; margin-bottom: 4px; color: var(--muted); font: 14px/1.5 var(--ui); }
.pager strong { font: 500 24px/1.3 var(--serif); overflow-wrap: anywhere; }
.pager .next { text-align: right; }

/* Empty/error routes and the native, keyboard-trapped image dialog. */
.empty, .notfound { padding: 64px 0 80px; max-width: 720px; }
.empty svg, .notfound svg { display: none; }
.empty h2, .notfound h1 { margin: 0 0 16px; font-size: clamp(28px, 4vw, 40px); }
.empty p, .notfound p { font: 19px/1.8 var(--serif); }
.empty a, .notfound a { display: inline-flex; align-items: center; min-height: 44px; }
.viewer { width: min(800px, calc(100% - 32px)); max-height: 92dvh; padding: 0; border: 1px solid var(--control-line); border-radius: 4px; background: #000; color: var(--paper); }
.viewer::backdrop { background: rgb(16 29 23 / 82%); }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 12px 16px; background: var(--paper); color: var(--ink); border-bottom: 1px solid var(--line); }
.viewer-bar strong { font: 500 22px/1.3 var(--serif); }
.viewer img { width: min(100%, 68dvh); height: auto; aspect-ratio: 1; object-fit: contain; image-rendering: pixelated; margin: 12px auto; }
.viewer > :focus-visible { outline-color: #d6e1c7; }

@media (max-width: 1050px) {
  .toolbar .tools { flex-basis: 100%; }
  .tools #random-btn { margin-left: auto; }
  .creature { column-gap: 24px; }
  .exhibit, .toc { grid-column: 1 / 5; }
  .exhibit { max-width: 300px; }
  .sheet-copy, .notice { grid-column: 5 / -1; }
  .dossier { column-gap: 20px; }
}

@media (max-width: 760px) {
  :root { --gutter: 20px; }
  .site-header { padding-block: 14px; gap: 12px; }
  .theme-control { flex-basis: 100%; justify-content: flex-end; }
  .theme-control input { flex: 1; max-width: 160px; }
  .brand { gap: 8px; }
  .brand .mark { width: 26px; height: 26px; }
  .brand-name { font-size: 23px; }
  .catalog-intro { padding: 28px 0 24px; }
  .intro-copy { grid-template-columns: 1fr; gap: 12px; }
  .catalog-brand { font-size: 34px; }
  .catalog-brand br { display: none; }
  .catalog-lead { font-size: 18px; }
  .collection-heading { align-items: center; }
  .collection-heading h2 { font-size: 24px; }
  .census { max-width: 145px; text-align: right; }
  .toolbar { padding: 16px; gap: 14px; }
  .search { flex-basis: 100%; }
  .sorter { flex: 1 1 100%; }
  .tools { width: 100%; }
  .tools #random-btn { margin-left: 0; }
  .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 16px; }
  .plate-label { grid-template-columns: 1fr 18px; gap: 4px; }
  .plate-index { grid-column: 1 / -1; }
  .plate-name { font-size: 20px; }
  .crumb { padding-bottom: 16px; }
  .creature { display: flex; flex-direction: column; gap: 28px; }
  .exhibit { order: 0; max-width: 300px; }
  .sheet-copy { order: 1; width: 100%; }
  .sheet-copy h1 { margin-top: 0; font-size: 40px; }
  .dossier { gap: 0 20px; }
  .toc { order: 2; position: static; flex-direction: row; flex-wrap: wrap; gap: 4px 8px; width: 100%; max-width: none; padding-block: 18px; border-bottom: 1px solid var(--line); }
  .toc-title { width: 100%; margin-bottom: 6px; }
  .toc a { margin: 0; padding: 9px 12px; border: 1px solid var(--line); background: var(--surface); }
  .toc .toc-sub { padding-left: 12px; }
  .notice { order: 3; max-width: none; border-top: 0; padding-top: 0; font-size: 18px; }
  .notice h2 { font-size: 29px; }
  .notice h3 { font-size: 23px; }
  .pager { gap: 12px; }
  .pager a { padding-inline: 0; }
  .pager strong { font-size: 22px; }
}

@media (max-width: 380px) {
  :root { --gutter: 16px; }
  .brand .mark { display: none; }
  .brand-name { font-size: 21px; }
  .catalog-grid { grid-template-columns: minmax(0, 1fr); }
  .dossier, .meta-list { grid-template-columns: 1fr; }
  .catalog-brand { font-size: 31px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  :root, :root[data-theme] { color-scheme: light; --ink: #000; --paper: #fff; --surface: #fff; --wash: #fff; --target: #fff; --muted: #333; --forest: #000; --line: #999; --control-line: #666; }
  body:has(.creature)::before { content: none; display: none !important; background-image: none; }
  body { background: #fff; color: #000; }
  .site-header, .site-footer, .skip, .toolbar, .toc, .pager, .viewer, .exhibit-zoom, .crumb { display: none !important; }
  .wrap { width: 100%; }
  .creature { display: block; }
  .exhibit { float: left; width: 180px; margin: 0 24px 20px 0; break-inside: avoid; }
  .sheet-copy, .notice { width: 100%; max-width: none; }
  .sheet-copy h1 { font-size: 30pt; }
  .notice { clear: both; padding-top: 24px; font-size: 12pt; line-height: 1.8; }
  .lede, .dossier dd { font-size: 12pt; }
  .notice h2 { font-size: 20pt; }
  .notice h3 { font-size: 16pt; }
  h1, h2, h3 { break-after: avoid; }
  p { orphans: 3; widows: 3; }
  .notice-sources { font-size: 12pt; }
  .notice-sources a::after { content: " (" attr(href) ")"; overflow-wrap: anywhere; }
  .catalog-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .plate { break-inside: avoid; }
}
