/* Roboto — self-hosted variable font for the knowledge-graph (Material) view.
   latin + latin-ext subsets so te reo Māori macrons (ā ē ī ō ū) render in Roboto
   rather than a fallback. Apache-2.0 — see LICENSE. */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 100 900;                 /* one variable file covers the weight axis */
  font-display: swap;
  src: url('/fonts/roboto-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/roboto-latinext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Cal Sans — self-hosted display face for headings (OFL-1.1; latin + latin-ext
   subsets so macrons render). Single weight, no synthetic bolding. Shared with
   the Bragge story-map. */
@font-face {
  font-family: 'Cal Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/calsans-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Cal Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/calsans-latinext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #ffffff;
  --panel: #f4f5f7;
  --panel-2: #e9ebef;
  --line: #d7dbe1;
  --text: #1a1d23;
  --muted: #5b6472;
  --accent: #0cb0a9;      /* palette teal — bright accent (spinner, tints) */
  --accent-2: #ef476f;    /* palette pink — error / danger */
  --ok: #0a8f67;          /* palette emerald, darkened for status legibility */
  --radius: 12px;
  --shadow: 0 8px 24px rgba(20, 30, 50, 0.12);
  --content-max: 1280px;  /* centred content column on wide screens (Material measure) */
}

/* ===== Material 3 design tokens — used by the knowledge-graph view =====
   Teal-primary tonal palette on a light theme. Bound to the app's existing
   --accent / --ok / --accent-2 so brand + status colours stay in sync. */
:root {
  --md-font: 'Roboto', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --md-font-display: 'Cal Sans', 'Roboto', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;

  /* Color roles (tonal palette from the Te Papa teal primary) */
  --md-primary: #073b4c;                  /* palette navy (coolors.co flat-UI set) */
  --md-primary-hover: #0c5266;
  --md-on-primary: #ffffff;
  --md-primary-container: #cfe7ee;
  --md-on-primary-container: #073b4c;
  --md-primary-fixed-dim: #5fa9c0;        /* bundle hairline */

  /* Neutral surfaces (M3 surface-container family) */
  --md-surface: #fbfcfd;
  --md-surface-container-lowest: #ffffff;
  --md-surface-container-low: #f4f6f7;
  --md-surface-container: #eef0f2;
  --md-surface-container-high: #e8eaec;
  --md-surface-container-highest: #e1e4e6;
  --md-on-surface: #191c1d;
  --md-on-surface-variant: #3f484a;
  --md-outline: #6f797b;
  --md-outline-variant: #bfc8ca;

  /* State-layer opacities (M3 spec) */
  --md-state-hover: 0.08;
  --md-state-focus: 0.10;
  --md-state-press: 0.12;

  /* Status semantics — reuse the app's existing green/red */
  --md-status: var(--ok);                 /* green = status / loading */
  --md-error: var(--accent-2);            /* red = error */
  --md-snackbar-bg: #2f3132;
  --md-snackbar-on: #f1f1f1;
  --md-scrim: rgba(0, 0, 0, 0.40);        /* dialog scrim (40% — a touch more focus than the M3 ~32% default) */

  /* Shape scale (M3) */
  --md-shape-xs: 4px;
  --md-shape-sm: 8px;
  --md-shape-md: 12px;
  --md-shape-lg: 16px;
  --md-shape-xl: 28px;
  --md-shape-full: 999px;

  /* Elevation (M3 dp shadows, light) */
  --md-elev-1: 0 1px 2px rgba(0,0,0,.30), 0 1px 3px 1px rgba(0,0,0,.15);
  --md-elev-2: 0 1px 2px rgba(0,0,0,.30), 0 2px 6px 2px rgba(0,0,0,.15);
  --md-elev-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.30);
  --md-elev-4: 0 6px 10px 4px rgba(0,0,0,.15), 0 2px 3px rgba(0,0,0,.30);

  /* Motion (M3 standard easing) */
  --md-ease: cubic-bezier(0.2, 0, 0, 1);
  --md-dur: 200ms;

  /* Type scale (M3) */
  --md-title-lg: 500 22px/28px var(--md-font);
  --md-title-md: 500 16px/24px var(--md-font);
  --md-label-lg: 500 14px/20px var(--md-font);
  --md-label-md: 500 12px/16px var(--md-font);
  --md-body-md: 400 14px/20px var(--md-font);
  --md-body-sm: 400 12px/16px var(--md-font);
}

/* ===== Dark theme =====
   Redefines only the colour tokens (shape / type / motion are shared). Applied
   when <html data-theme="dark">, which the inline script in index.html sets from
   localStorage, falling back to the OS prefers-color-scheme. Because --md-status
   / --md-error resolve var(--ok) / var(--accent-2) lazily, overriding those here
   recolours the status/error roles too. */
:root { color-scheme: light; }
[data-theme="dark"] {
  color-scheme: dark;

  /* Primary — a lighter teal tone reads as the accent on dark surfaces */
  --md-primary: #6cc3dd;                  /* light tint of the navy hue for dark surfaces */
  --md-primary-hover: #8ad1e7;
  --md-on-primary: #073b4c;               /* palette navy text on the light tint */
  --md-primary-container: #0c4456;
  --md-on-primary-container: #cfe7ee;
  --md-primary-fixed-dim: #3f8ba8;

  /* Neutral surfaces — warm-leaning charcoal (R≥G≥B, no green tint) */
  --md-surface: #141312;
  --md-surface-container-lowest: #0e0e0d;
  --md-surface-container-low: #1c1b19;
  --md-surface-container: #201f1d;
  --md-surface-container-high: #2b2926;
  --md-surface-container-highest: #353330;
  --md-on-surface: #e7e3df;
  --md-on-surface-variant: #cbc6c1;
  --md-outline: #948f89;
  --md-outline-variant: #4b4844;

  /* Snackbar inverts to a light surface; scrim deepens */
  --md-snackbar-bg: #e7e3df;
  --md-snackbar-on: #32302d;
  --md-scrim: rgba(0, 0, 0, 0.6);

  /* Elevation — deeper shadows; on dark, contrast is mostly carried by surfaces */
  --md-elev-1: 0 1px 2px rgba(0,0,0,.5), 0 1px 3px 1px rgba(0,0,0,.35);
  --md-elev-2: 0 1px 2px rgba(0,0,0,.5), 0 2px 6px 2px rgba(0,0,0,.35);
  --md-elev-3: 0 4px 8px 3px rgba(0,0,0,.35), 0 1px 3px rgba(0,0,0,.5);
  --md-elev-4: 0 6px 10px 4px rgba(0,0,0,.35), 0 2px 3px rgba(0,0,0,.5);

  /* Legacy tokens still referenced directly */
  --accent: #2ad0cb;       /* palette teal — bright accent (spinner, tints, filter chip) */
  --accent-2: #ff8aa0;     /* palette pink (lightened) — error */
  --ok: #3fe0a8;           /* palette emerald (lightened) — status / loading */
  --shadow: 0 8px 24px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--md-font);
  background: var(--md-surface);
  color: var(--md-on-surface);
  line-height: 1.45;
}

a { color: var(--md-primary); }

/* Headings use the Cal Sans display face. Rules that set `font:` shorthand
   reset font-family, so each prominent heading re-asserts it below. */
h1, h2, h3, h4, h5, h6 { font-family: var(--md-font-display); }

/* ===== Top app bar ===== */
.topbar {                                    /* full-bleed app bar… */
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--md-surface-container);
  border-bottom: 1px solid var(--md-outline-variant);
  box-shadow: var(--md-elev-2);
}
.topbar-inner {                              /* …with its content in the centred column */
  max-width: var(--content-max);
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
}

/* Constrain the content to a centred column on wide screens (Material measure/margins) */
.toolbar,
#result-tabs,
#collection-filter,
#home,
#results,
.pager,
.footer {
  max-width: var(--content-max);
  margin-inline: auto;
}

/* ===== Brand / home button ===== */
.brand {
  display: inline-flex; align-items: center; gap: 11px;
  margin: 0; padding: 5px 8px;
  border: none; background: none; cursor: pointer;
  border-radius: var(--md-shape-md); color: var(--md-on-surface);
  font: inherit; text-align: left;
  transition: background-color var(--md-dur) var(--md-ease);
}
.brand:hover, .brand:focus-visible { background: var(--md-surface-container-high); outline: none; }
.brand-logo { flex: 0 0 auto; width: 30px; height: 30px; color: var(--md-on-surface); }
.brand-text { font: 600 16px/1.15 var(--md-font); font-family: var(--md-font-display); color: var(--md-on-surface); letter-spacing: 0.1px; }

/* ===== Theme switch (Light | Dark segmented pill — shared with Bragge) ===== */
.theme-switch {
  position: relative; flex: 0 0 auto; order: 3;
  box-sizing: border-box; display: inline-flex; padding: 3px;
  background: var(--md-surface-container-low);
  border-radius: var(--md-shape-full);
  box-shadow: inset 0 0 0 1px var(--md-outline-variant);   /* border via shadow so % widths ignore it */
}
.theme-knob {
  position: absolute; top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px) / 2); border-radius: var(--md-shape-full);
  background: var(--md-primary);
  transition: transform 180ms var(--md-ease);
}
.theme-switch[data-active="dark"] .theme-knob { transform: translateX(100%); }
.theme-opt {
  position: relative; z-index: 1; box-sizing: border-box;
  flex: 1 1 0; min-width: 52px; padding: 5px 14px; text-align: center;
  background: none; border: none; cursor: pointer;
  font: var(--md-label-lg); color: var(--md-on-surface-variant);
  transition: color 160ms;
}
.theme-opt[aria-checked="true"] { color: var(--md-on-primary); }
@media (prefers-reduced-motion: reduce) { .theme-knob { transition: none; } }

/* ===== Animated brand mark (from the nextepisode hub) =====
   Three resting states, each a distinct colour, shape AND orientation: a whirl
   (eased in/out) carries the mark to blue at 30deg with the left arms long; holds
   ~5.5s; then teal at 150deg with the right arms long; then coral upright with
   balanced arms — looping (28s cycle). currentColor animates per theme. */
.brand-logo-anim { overflow: visible; animation: brand-tint-light 28s linear infinite; }
[data-theme="dark"] .brand-logo-anim { animation-name: brand-tint-dark; }
.brand-logo-anim .link { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.brand-logo-anim .node, .brand-logo-anim .hub { fill: currentColor; }
.brand-logo-anim .rotor, .brand-logo-anim .spoke { transform-box: view-box; transform-origin: 16px 16px; }
.brand-logo-anim .hub, .brand-logo-anim .node { transform-box: fill-box; transform-origin: center; }
.brand-logo-anim .rotor { animation: brand-rotor 28s infinite; }
.brand-logo-anim .spoke.s1 { animation: brand-reach-1 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s2 { animation: brand-reach-2 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s3 { animation: brand-reach-3 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s4 { animation: brand-reach-4 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s5 { animation: brand-reach-5 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s6 { animation: brand-reach-6 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s1 .node { animation: brand-node-1 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s2 .node { animation: brand-node-2 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s3 .node { animation: brand-node-3 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s4 .node { animation: brand-node-4 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s5 .node { animation: brand-node-5 28s ease-in-out infinite; }
.brand-logo-anim .spoke.s6 .node { animation: brand-node-6 28s ease-in-out infinite; }
.brand-logo-anim .hub { animation: brand-hub 28s ease-in-out infinite; }

/* Four states. Each whirl eases in/out and lands at a distinct orientation
   (90 · 180 · 270 · 0deg), then holds for the ~5.5s pause. Whirls 1.5s, holds
   5.5s, 28s loop. Holds: 5.357-25%, 30.357-50%, 55.357-75%, 80.357-100%. */
@keyframes brand-rotor {
  0%      { transform: rotate(0deg);    animation-timing-function: cubic-bezier(.45,0,.45,1); }
  5.357%  { transform: rotate(810deg);  animation-timing-function: linear; }
  25%     { transform: rotate(810deg);  animation-timing-function: cubic-bezier(.45,0,.45,1); }
  30.357% { transform: rotate(1620deg); animation-timing-function: linear; }
  50%     { transform: rotate(1620deg); animation-timing-function: cubic-bezier(.45,0,.45,1); }
  55.357% { transform: rotate(2430deg); animation-timing-function: linear; }
  75%     { transform: rotate(2430deg); animation-timing-function: cubic-bezier(.45,0,.45,1); }
  80.357% { transform: rotate(3240deg); }
  100%    { transform: rotate(3240deg); }
}
/* Colour fades to the next hue during each whirl, then holds: blue · teal · coral · emerald */
@keyframes brand-tint-light {
  0%      { color: #06d6a0; }
  5.357%  { color: #118ab2; } 25%     { color: #118ab2; }
  30.357% { color: #0cb0a9; } 50%     { color: #0cb0a9; }
  55.357% { color: #f78c6b; } 75%     { color: #f78c6b; }
  80.357% { color: #06d6a0; } 100%    { color: #06d6a0; }
}
@keyframes brand-tint-dark {
  0%      { color: #34e2ad; }
  5.357%  { color: #58c4ec; } 25%     { color: #58c4ec; }
  30.357% { color: #2ad0cb; } 50%     { color: #2ad0cb; }
  55.357% { color: #f99e7e; } 75%     { color: #f99e7e; }
  80.357% { color: #34e2ad; } 100%    { color: #34e2ad; }
}
/* Arm LENGTH (spoke scale) and node SIZE (node scale) animate independently —
   each arm has its own length pattern AND its own size pattern across the four
   states, so an arm can reach far with a small node, or short with a big one.
   The node scale is authored as desired-size / arm-length, so the *visible*
   node size is decoupled from how far the arm reaches. 0% == state 4 (loop);
   states land at 5.357% (s1), 30.357% (s2), 55.357% (s3), 80.357% (s4). */
@keyframes brand-reach-1 {
  0% { transform: scale(1.2); }
  5.357%, 25% { transform: scale(1.45); }
  30.357%, 50% { transform: scale(0.7); }
  55.357%, 75% { transform: scale(1); }
  80.357%, 100% { transform: scale(1.2); }
}
@keyframes brand-reach-2 {
  0% { transform: scale(1.15); }
  5.357%, 25% { transform: scale(0.65); }
  30.357%, 50% { transform: scale(1.4); }
  55.357%, 75% { transform: scale(0.9); }
  80.357%, 100% { transform: scale(1.15); }
}
@keyframes brand-reach-3 {
  0% { transform: scale(0.7); }
  5.357%, 25% { transform: scale(1.1); }
  30.357%, 50% { transform: scale(0.6); }
  55.357%, 75% { transform: scale(1.4); }
  80.357%, 100% { transform: scale(0.7); }
}
@keyframes brand-reach-4 {
  0% { transform: scale(1.35); }
  5.357%, 25% { transform: scale(0.8); }
  30.357%, 50% { transform: scale(1.2); }
  55.357%, 75% { transform: scale(0.65); }
  80.357%, 100% { transform: scale(1.35); }
}
@keyframes brand-reach-5 {
  0% { transform: scale(0.6); }
  5.357%, 25% { transform: scale(1.3); }
  30.357%, 50% { transform: scale(0.95); }
  55.357%, 75% { transform: scale(0.7); }
  80.357%, 100% { transform: scale(0.6); }
}
@keyframes brand-reach-6 {
  0% { transform: scale(0.85); }
  5.357%, 25% { transform: scale(0.7); }
  30.357%, 50% { transform: scale(1.05); }
  55.357%, 75% { transform: scale(1.35); }
  80.357%, 100% { transform: scale(0.85); }
}
/* Node SIZE (own scale = desired-size / arm-length) plus a DEPTH SHADE: each
   node's brightness tracks its *visible* size, so the big "near" nodes come up
   light (~1.46) and the small "far" nodes fall into shadow (~0.52). Riding on
   currentColor, this shades whatever palette hue the state is in. The brightness
   value below pairs with the visible size, not the raw scale. */
@keyframes brand-node-1 {
  0% { transform: scale(1.08); filter: brightness(1.32); }
  5.357%, 25% { transform: scale(0.62); filter: brightness(0.79); }
  30.357%, 50% { transform: scale(1.93); filter: brightness(1.39); }
  55.357%, 75% { transform: scale(1.05); filter: brightness(0.99); }
  80.357%, 100% { transform: scale(1.08); filter: brightness(1.32); }
}
@keyframes brand-node-2 {
  0% { transform: scale(0.7); filter: brightness(0.65); }
  5.357%, 25% { transform: scale(2.15); filter: brightness(1.46); }
  30.357%, 50% { transform: scale(0.54); filter: brightness(0.59); }
  55.357%, 75% { transform: scale(1.22); filter: brightness(1.06); }
  80.357%, 100% { transform: scale(0.7); filter: brightness(0.65); }
}
@keyframes brand-node-3 {
  0% { transform: scale(2); filter: brightness(1.46); }
  5.357%, 25% { transform: scale(0.77); filter: brightness(0.72); }
  30.357%, 50% { transform: scale(2.08); filter: brightness(1.26); }
  55.357%, 75% { transform: scale(0.5); filter: brightness(0.52); }
  80.357%, 100% { transform: scale(2); filter: brightness(1.46); }
}
@keyframes brand-node-4 {
  0% { transform: scale(0.56); filter: brightness(0.59); }
  5.357%, 25% { transform: scale(1.5); filter: brightness(1.19); }
  30.357%, 50% { transform: scale(0.58); filter: brightness(0.52); }
  55.357%, 75% { transform: scale(2.08); filter: brightness(1.39); }
  80.357%, 100% { transform: scale(0.56); filter: brightness(0.59); }
}
@keyframes brand-node-5 {
  0% { transform: scale(2); filter: brightness(1.19); }
  5.357%, 25% { transform: scale(0.58); filter: brightness(0.59); }
  30.357%, 50% { transform: scale(1.21); filter: brightness(1.12); }
  55.357%, 75% { transform: scale(1.86); filter: brightness(1.32); }
  80.357%, 100% { transform: scale(2); filter: brightness(1.19); }
}
@keyframes brand-node-6 {
  0% { transform: scale(1.12); filter: brightness(0.86); }
  5.357%, 25% { transform: scale(1.79); filter: brightness(1.26); }
  30.357%, 50% { transform: scale(0.86); filter: brightness(0.79); }
  55.357%, 75% { transform: scale(0.56); filter: brightness(0.59); }
  80.357%, 100% { transform: scale(1.12); filter: brightness(0.86); }
}
/* Hub size shifts per state too (its apparent depth) */
@keyframes brand-hub {
  0% { transform: scale(1.12); }
  5.357%, 25% { transform: scale(1.18); }
  30.357%, 50% { transform: scale(0.85); }
  55.357%, 75% { transform: scale(1); }
  80.357%, 100% { transform: scale(1.12); }
}
@media (prefers-reduced-motion: reduce) {
  .brand-logo-anim, .brand-logo-anim .rotor, .brand-logo-anim .spoke, .brand-logo-anim .node, .brand-logo-anim .hub { animation: none; }
  .brand-logo-anim { color: var(--md-on-surface); }
}

/* ===== Search ===== */
.search {
  display: flex;
  gap: 8px;
  flex: 1 1 420px;
}

/* M3 filled pill search field */
.search input[type="search"] {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 20px;
  border: none;
  border-radius: var(--md-shape-full);
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
  font: var(--md-body-md);
}
.search input[type="search"]::placeholder {
  color: var(--md-on-surface-variant);
}
.search input[type="search"]:focus,
.search select:focus {
  outline: 2px solid var(--md-primary);
  outline-offset: 0;
}

/* Outlined select (kept for any select inside .search) */
.search select {
  height: 48px;
  padding: 0 16px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-sm);
  background: transparent;
  color: var(--md-on-surface);
  font: var(--md-body-md);
  cursor: pointer;
}

/* M3 filled button */
.search button {
  position: relative;
  overflow: hidden;
  height: 48px;
  padding: 0 24px;
  border: none;
  border-radius: var(--md-shape-full);
  background: var(--md-primary);
  color: var(--md-on-primary);
  font: var(--md-label-lg);
  cursor: pointer;
}
.search button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--md-on-primary);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.search button:hover::before { opacity: var(--md-state-hover); }
.search button:focus-visible::before { opacity: var(--md-state-focus); }
.search button:active::before { opacity: var(--md-state-press); }

@media (prefers-reduced-motion: reduce) {
  .search button::before { transition: none; }
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px 4px;
  flex-wrap: wrap;
}
.status {
  font: var(--md-body-md);
  color: var(--md-on-surface-variant);
}
.status strong { color: var(--md-on-surface); }
.controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

.sort-control[hidden] { display: none; }
.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--md-on-surface-variant);
  font: var(--md-label-md);
}
.sort-control select {
  height: 40px;
  padding: 0 14px;
  border-radius: var(--md-shape-sm);
  border: 1px solid var(--md-outline);
  background: transparent;
  color: var(--md-on-surface);
  font: var(--md-body-md);
  cursor: pointer;
  transition: border-color var(--md-dur) var(--md-ease);
}
.sort-control select:hover { border-color: var(--md-on-surface); }
.sort-control select:focus {
  border: 2px solid var(--md-primary);
  outline: none;
  padding: 0 13px;
}

.viewswitch {
  display: inline-flex;
  align-items: stretch;
  height: 40px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-full);
  overflow: hidden;
}
.viewswitch button {
  position: relative;
  overflow: hidden;
  background: transparent;
  color: var(--md-on-surface-variant);
  border: none;
  padding: 0 16px;
  font: var(--md-label-lg);
  cursor: pointer;
  transition: background-color var(--md-dur) var(--md-ease), color var(--md-dur) var(--md-ease);
}
.viewswitch button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--md-on-surface);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.viewswitch button:hover::before { opacity: var(--md-state-hover); }
.viewswitch button:focus-visible::before { opacity: var(--md-state-focus); }
.viewswitch button:active::before { opacity: var(--md-state-press); }
.viewswitch button:focus-visible { outline: none; }
.viewswitch button + button { border-left: 1px solid var(--md-outline); }
.viewswitch button.active {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}
.viewswitch button.active::before { background: var(--md-on-primary-container); }

.img-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--md-on-surface-variant);
  font: var(--md-label-lg);
  cursor: pointer;
  user-select: none;
}
.img-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 52px;
  height: 32px;
  border-radius: var(--md-shape-full);
  border: 2px solid var(--md-outline);
  background: var(--md-surface-container-highest);
  position: relative;
  cursor: pointer;
  flex: none;
  transition: background-color var(--md-dur) var(--md-ease), border-color var(--md-dur) var(--md-ease);
}
.img-toggle input[type="checkbox"]::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-outline);
  transform: translateY(-50%);
  transition: all var(--md-dur) var(--md-ease);
}
.img-toggle input[type="checkbox"]:checked {
  background: var(--md-primary);
  border-color: var(--md-primary);
}
.img-toggle input[type="checkbox"]:checked::before {
  left: auto;
  right: 6px;
  width: 24px;
  height: 24px;
  background: var(--md-on-primary);
}
.img-toggle input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .sort-control select,
  .viewswitch button,
  .viewswitch button::before,
  .img-toggle input[type="checkbox"],
  .img-toggle input[type="checkbox"]::before {
    transition: none;
  }
}

.result-tabs[hidden] { display: none; }

.result-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 4px 20px 0;
  background: var(--md-surface);
  border-bottom: 1px solid var(--md-outline-variant);
}

.result-tabs .tab {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 48px;
  margin-bottom: -1px;
  padding: 0 16px;
  border: none;
  background: transparent;
  border-bottom: 3px solid transparent;
  color: var(--md-on-surface-variant);
  font: var(--md-label-lg);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--md-dur) var(--md-ease),
    border-bottom-color var(--md-dur) var(--md-ease);
}

.result-tabs .tab::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--md-primary);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}

.result-tabs .tab:hover::before { opacity: var(--md-state-hover); }
.result-tabs .tab:focus-visible::before { opacity: var(--md-state-focus); }
.result-tabs .tab:active::before { opacity: var(--md-state-press); }
.result-tabs .tab:focus-visible { outline: none; }
/* Disabled in map view (record types with no coordinates) */
.result-tabs .tab.tab-disabled { opacity: 0.36; cursor: default; }
.result-tabs .tab.tab-disabled::before { display: none; }
.img-toggle.disabled { opacity: 0.45; cursor: default; pointer-events: none; }

.result-tabs .tab:hover { color: var(--md-on-surface); }

.result-tabs .tab.active {
  color: var(--md-primary);
  border-bottom-color: var(--md-primary);
}

.result-tabs .tab-count {
  font: var(--md-label-md);
  color: var(--md-on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.result-tabs .tab.active .tab-count { color: var(--md-primary); }

@media (prefers-reduced-motion: reduce) {
  .result-tabs .tab,
  .result-tabs .tab::before {
    transition: none;
  }
}

.cfilter[hidden] { display:none; }

.cfilter {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:8px;
  padding:10px 20px 2px;
}

.cfilter-label {
  font:var(--md-label-md);
  text-transform:uppercase;
  letter-spacing:.06em;
  color:var(--md-on-surface-variant);
  margin-right:2px;
}

/* M3 FILTER chip */
.cchip {
  position:relative;
  overflow:hidden;
  display:inline-flex;
  align-items:center;
  gap:6px;
  height:32px;
  box-sizing:border-box;
  border:1px solid var(--md-outline-variant);
  border-radius:var(--md-shape-sm);
  background:transparent;
  color:var(--md-on-surface-variant);
  padding:0 12px;
  font:var(--md-label-md);
  cursor:pointer;
}

.cchip::before {
  content:'';
  position:absolute;
  inset:0;
  background:var(--md-on-surface-variant);
  opacity:0;
  transition:opacity var(--md-dur) var(--md-ease);
  pointer-events:none;
}

.cchip:hover::before { opacity:var(--md-state-hover); }
.cchip:focus-visible::before { opacity:var(--md-state-focus); }
.cchip:active::before { opacity:var(--md-state-press); }
.cchip:focus-visible { outline:none; }

.cchip.active {
  background:var(--md-primary-container);
  color:var(--md-on-primary-container);
  border-color:transparent;
}

.cchip.active::before { background:var(--md-on-primary-container); }

.cchip-count {
  position:relative;
  font:var(--md-label-md);
  color:var(--md-on-surface-variant);
  font-variant-numeric:tabular-nums;
}

.cchip.active .cchip-count { color:var(--md-on-primary-container); }

/* M3 TEXT button */
.cchip-clear {
  position:relative;
  overflow:hidden;
  display:inline-flex;
  align-items:center;
  height:32px;
  border:none;
  border-radius:var(--md-shape-full);
  background:transparent;
  color:var(--md-primary);
  font:var(--md-label-lg);
  cursor:pointer;
  padding:0 12px;
}

.cchip-clear::before {
  content:'';
  position:absolute;
  inset:0;
  background:var(--md-primary);
  opacity:0;
  transition:opacity var(--md-dur) var(--md-ease);
  pointer-events:none;
}

.cchip-clear:hover::before { opacity:var(--md-state-hover); }
.cchip-clear:focus-visible::before { opacity:var(--md-state-focus); }
.cchip-clear:active::before { opacity:var(--md-state-press); }
.cchip-clear:focus-visible { outline:none; }

@media (prefers-reduced-motion: reduce) {
  .cchip::before,
  .cchip-clear::before { transition:none; }
}

.grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(210px,1fr)); gap:16px; padding:16px 20px 40px; }
/* Image cards keep each image's aspect ratio (set inline, never cropped); in the
   results grid they're packed gap-free via per-card row-spans (layoutGridMasonry). */
.grid.masonry { row-gap:0; grid-auto-rows:4px; align-items:start; }

.card { background:var(--md-surface-container-low); border:none; border-radius:var(--md-shape-md); overflow:hidden; cursor:pointer; display:flex; flex-direction:column; position:relative; box-shadow:var(--md-elev-1); transition:box-shadow var(--md-dur) var(--md-ease); }
.card::before { content:''; position:absolute; inset:0; background:var(--md-on-surface); opacity:0; transition:opacity var(--md-dur) var(--md-ease); pointer-events:none; z-index:1; }
.card:hover { box-shadow:var(--md-elev-2); }
.card:hover::before { opacity:var(--md-state-hover); }
.card:focus-within::before { opacity:var(--md-state-focus); }
.card:active::before { opacity:var(--md-state-press); }

.result-graph { position:relative; overflow:hidden; display:inline-flex; align-items:center; justify-content:center; width:40px; height:40px; padding:0; border:none; border-radius:var(--md-shape-full); background:var(--md-surface-container-highest); color:var(--md-on-surface-variant); cursor:pointer; font-size:20px; line-height:1; }
.result-graph::before { content:''; position:absolute; inset:0; background:var(--md-on-surface); opacity:0; transition:opacity var(--md-dur) var(--md-ease); pointer-events:none; }
.result-graph:hover::before { opacity:var(--md-state-hover); }
.result-graph:focus-visible::before { opacity:var(--md-state-focus); }
.result-graph:active::before { opacity:var(--md-state-press); }
.card .result-graph { position:absolute; top:8px; right:8px; opacity:0; transition:opacity var(--md-dur) var(--md-ease); z-index:2; }
.card:hover .result-graph,
.card:focus-within .result-graph { opacity:1; }

.list .col-act { width:44px; text-align:center; }
.list .col-act .result-graph { width:32px; height:32px; font-size:18px; }

.thumb { aspect-ratio:1/1; background:var(--md-surface-container-high); display:flex; align-items:center; justify-content:center; overflow:hidden; position:relative; }
.thumb img { width:100%; height:100%; object-fit:contain; display:block; }
.thumb.no-image { color:var(--md-on-surface-variant); font:var(--md-body-sm); text-align:center; padding:12px; }
.thumb.no-image span { opacity:.7; }

.sensitive > img { filter:blur(22px); transform:scale(1.12); }
.sensitive.revealed > img { filter:none; transform:none; }
.sensitive-overlay { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px; padding:12px; text-align:center; background:rgba(18,22,30,.55); color:#fff; }
.sensitive.revealed .sensitive-overlay { display:none; }
.sensitive-msg { font:var(--md-label-lg); font-weight:700; }
.sensitive-overlay small { font:var(--md-body-sm); line-height:1.3; opacity:.92; max-width:95%; }

.reveal-btn { position:relative; overflow:hidden; margin-top:2px; height:32px; display:inline-flex; align-items:center; padding:0 16px; border:none; box-shadow:inset 0 0 0 1px rgba(255,255,255,.7); border-radius:var(--md-shape-full); background:transparent; color:#fff; font:var(--md-label-md); cursor:pointer; }
.reveal-btn::before { content:''; position:absolute; inset:0; background:#fff; opacity:0; transition:opacity var(--md-dur) var(--md-ease); pointer-events:none; }
.reveal-btn:hover::before { opacity:var(--md-state-hover); }
.reveal-btn:focus-visible::before { opacity:var(--md-state-focus); }
.reveal-btn:active::before { opacity:var(--md-state-press); }

.media { position:relative; display:block; }
.media.sensitive > img { border-radius:var(--md-shape-sm); }

.list .col-thumb .lthumb { position:relative; display:block; width:40px; height:40px; overflow:hidden; border-radius:var(--md-shape-xs); background:var(--md-surface-container-highest); }
.list .col-thumb .lthumb.sensitive img { filter:blur(6px); }
.lthumb-warn { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; font-size:14px; color:#fff; text-shadow:0 1px 3px rgba(0,0,0,.8); }

.card-body { padding:11px 12px 13px; display:flex; flex-direction:column; gap:6px; position:relative; z-index:1; }
.card-title { font:var(--md-body-md); font-weight:600; color:var(--md-on-surface); display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.card-sub { font:var(--md-body-sm); color:var(--md-on-surface-variant); display:-webkit-box; -webkit-line-clamp:1; -webkit-box-orient:vertical; overflow:hidden; }
.card-meta { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }

.badge { font:var(--md-label-md); padding:2px 8px; border-radius:var(--md-shape-sm); background:var(--md-surface-container-highest); color:var(--md-on-surface-variant); border:none; }
.badge.type { color:var(--md-primary); background:var(--md-surface-container-highest); border:none; }

/* Inline record-type icon (type-coloured) used in badges, tabs, list Type cells
   and explorer-card subtitles */
.type-icon { display:inline-block; vertical-align:-4px; margin-right:5px; }
.result-tabs .tab .type-icon { vertical-align:-4px; margin-right:6px; }
/* Imageless cards: a large, muted type icon as the placeholder. Sized relative
   to the box (overriding the generic `.thumb img` fill) so it scales with the
   card — grid, home shelf and explorer cards alike. */
.thumb .type-icon-ph { width:40%; height:40%; opacity:.4; }

@media (prefers-reduced-motion: reduce) {
  .card, .card::before, .result-graph, .card .result-graph, .result-graph::before, .reveal-btn::before { transition:none; }
}

/* ---- Map view ---- */
.map-view { padding: 16px 20px 40px; }
.map-wrap { position: relative; }
.map-wrap #map {
  height: min(70vh, 680px);
  border-radius: var(--md-shape-md);
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface-container);
  z-index: 0;
}

/* Leaflet controls. The vendored build ships no images/ dir, so the collapsed
   layers control's icon (images/layers.png) 404s and renders as a blank square.
   Supply our own stacked-layers glyph as an inline SVG (light + dark), and tone
   the controls for the dark basemap. */
/* Scoped under .leaflet-control-layers to out-specify Leaflet's own
   .leaflet-retina / .leaflet-touch toggle rules (which set the 404-ing PNG). */
.leaflet-control-layers .leaflet-control-layers-toggle {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23191c1d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 2 7 12 12 22 7 12 2'/%3E%3Cpolyline points='2 17 12 22 22 17'/%3E%3Cpolyline points='2 12 12 17 22 12'/%3E%3C/svg%3E");
  background-size: 22px 22px;
  background-position: center;
  background-repeat: no-repeat;
}
[data-theme="dark"] .leaflet-control-layers .leaflet-control-layers-toggle {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cbc6c1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 2 7 12 12 22 7 12 2'/%3E%3Cpolyline points='2 17 12 22 22 17'/%3E%3Cpolyline points='2 12 12 17 22 12'/%3E%3C/svg%3E");
}
[data-theme="dark"] .leaflet-bar a,
[data-theme="dark"] .leaflet-control-layers,
[data-theme="dark"] .leaflet-control-attribution {
  background: var(--md-surface-container-high);
  color: var(--md-on-surface-variant);
}
[data-theme="dark"] .leaflet-bar a { border-bottom-color: var(--md-outline-variant); }
[data-theme="dark"] .leaflet-bar a:hover { background: var(--md-surface-container-highest); }
[data-theme="dark"] .leaflet-control-layers a,
[data-theme="dark"] .leaflet-control-attribution a { color: var(--md-primary); }
/* Loading overlay — covers the map while fetching/resolving */
.map-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--md-surface) 72%, transparent);
  backdrop-filter: blur(3px);
  border-radius: var(--md-shape-md);
  z-index: 500;
  transition: opacity 0.4s, visibility 0.4s;
}
.map-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.map-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 40px;
  background: var(--md-surface);
  border: 1px solid var(--md-outline-variant);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
  max-width: 300px;
  text-align: center;
}
.map-overlay-spinner {
  width: 36px; height: 36px;
  border: 3.5px solid var(--md-outline-variant);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: map-spin 0.75s linear infinite;
}
@keyframes map-spin { to { transform: rotate(360deg); } }
.map-overlay-msg {
  margin: 0;
  font: var(--md-body-md);
  font-weight: 500;
  color: var(--md-on-surface);
}
/* Status pill — only appears after loading completes */
.map-view .map-status {
  margin: 14px 0 0;
  padding: 10px 16px;
  display: none;
  align-items: center;
  gap: 10px;
  border-radius: 20px;
  font: var(--md-body-md);
  font-weight: 500;
}
.map-view .map-status[data-state="done"],
.map-view .map-status[data-state="empty"] { display: inline-flex; }
.map-view .map-status[data-state="done"] {
  background: color-mix(in srgb, var(--accent) 12%, var(--md-surface));
  color: var(--md-on-surface);
  font-weight: 600;
}
.map-view .map-status[data-state="done"]::before {
  content: '✓';
  color: var(--accent);
  font-size: 1.1em;
  font-weight: 700;
}
.map-view .map-status[data-state="empty"] {
  background: color-mix(in srgb, #e65100 10%, var(--md-surface));
  color: var(--md-on-surface-variant);
}
.map-view .map-status[data-state="empty"]::before { content: '⚠'; color: #e65100; }
.map-pop { min-width: 150px; }
.map-pop strong { display: block; font: var(--md-body-md); font-weight: 600; color: var(--md-on-surface); }
.map-pop-meta { margin: 4px 0 6px; font: var(--md-body-sm); color: var(--md-on-surface-variant); }
.map-pop-via { margin: 0 0 8px; font: var(--md-body-sm); color: var(--md-on-surface-variant); }
.map-pop-btn {
  border: none; background: var(--md-primary); color: var(--md-on-primary);
  padding: 6px 12px; border-radius: var(--md-shape-full);
  font: var(--md-label-md); cursor: pointer;
}
.leaflet-popup-content { margin: 12px 14px; }
/* Marker popup: Leaflet's wrapper + tip default to white, leaving the
   token-coloured (light) popup text unreadable in dark mode — theme them. */
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip {
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
}
[data-theme="dark"] .leaflet-popup-content-wrapper { box-shadow: var(--md-elev-3); }
[data-theme="dark"] .leaflet-popup-close-button { color: var(--md-on-surface-variant); }
[data-theme="dark"] .leaflet-popup-close-button:hover { color: var(--md-on-surface); background: transparent; }

.list-wrap { padding: 16px 20px 40px; overflow-x: auto; }
.list {
  width: 100%;
  border-collapse: collapse;
  font: var(--md-body-md);
  min-width: 640px;
}
.list thead th {
  text-align: left;
  color: var(--md-on-surface-variant);
  font: var(--md-label-md);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--md-outline-variant);
  background: var(--md-surface);
}
.list tbody tr {
  cursor: pointer;
  border-bottom: 1px solid var(--md-outline-variant);
  transition: background-color var(--md-dur) var(--md-ease);
}
.list tbody tr:hover { background: rgba(25, 28, 29, 0.05); }
.list td { padding: 9px 12px; vertical-align: middle; }
.list .col-thumb { width: 48px; padding-right: 0; }
.list .col-thumb img {
  width: 40px; height: 40px;
  object-fit: contain;
  border-radius: var(--md-shape-xs);
  display: block;
}
.list .col-thumb .ph {
  width: 40px; height: 40px;
  border-radius: var(--md-shape-xs);
  background: var(--md-surface-container-highest);
  display: block;
}
.list .col-reg { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--md-on-surface-variant); white-space: nowrap; }
.list .col-title { font-weight: 600; color: var(--md-on-surface); }
.list .col-date { color: var(--md-on-surface-variant); white-space: nowrap; }
.list .col-maker { color: var(--md-on-surface); }
.list .col-soft { color: var(--md-on-surface-variant); }
.list .col-sci { font-style: italic; color: var(--md-on-surface); }
.list .col-type { color: var(--md-primary); white-space: nowrap; }
.list tbody tr:hover .col-title { color: var(--md-primary); }
.list tbody tr:hover .col-type { color: var(--md-primary-hover); }

/* ---- Pager ---- */
.pager[hidden] { display: none; }
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 20px 48px;
}
.pager button {
  position: relative;
  overflow: hidden;
  height: 40px;
  padding: 0 24px;
  border-radius: var(--md-shape-full);
  border: 1px solid var(--md-outline);
  background: transparent;
  color: var(--md-primary);
  cursor: pointer;
  font: var(--md-label-lg);
}
.pager button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--md-primary);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.pager button:not(:disabled):hover::before { opacity: var(--md-state-hover); }
.pager button:not(:disabled):focus-visible::before { opacity: var(--md-state-focus); }
.pager button:not(:disabled):active::before { opacity: var(--md-state-press); }
.pager button:focus-visible { outline: none; }
.pager button:disabled {
  opacity: 0.38;
  cursor: default;
  color: var(--md-on-surface);
  border-color: var(--md-outline-variant);
}
#page-info {
  color: var(--md-on-surface-variant);
  font: var(--md-body-md);
  min-width: 160px;
  text-align: center;
}

/* ---- States ---- */
.message {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--md-on-surface-variant);
  font: var(--md-body-md);
  padding: 60px 20px;
}
.message.error { color: var(--md-error); }
.spinner {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding: 60px;
}
.spinner div {
  width: 38px;
  height: 38px;
  border: 4px solid var(--md-outline-variant);
  border-top-color: var(--md-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Footer ---- */
.footer {
  padding: 22px 20px 40px;
  border-top: 1px solid var(--md-outline-variant);
  color: var(--md-on-surface-variant);
  font: var(--md-body-sm);
  text-align: center;
}

/* ---- Detail side sheet (M3) ---- */
.overlay[hidden] { display: none; }
.overlay {                                  /* M3 dialog scrim — centred, margin on every edge */
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--md-scrim);
  backdrop-filter: blur(2px);               /* softens the background a touch; remove for crisp */
  animation: scrim-in var(--md-dur) var(--md-ease);
}
@keyframes scrim-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {                                    /* M3 centred dialog (elevation 3) */
  width: min(680px, 100%);
  max-height: 85vh;
  background: var(--md-surface-container-high);
  border-radius: var(--md-shape-md);
  box-shadow: var(--md-elev-3);
  overflow-y: auto;
  position: relative;
  font-family: var(--md-font);
  color: var(--md-on-surface);
  -webkit-font-smoothing: antialiased;
  animation: dialog-in var(--md-dur) var(--md-ease);
}
@keyframes dialog-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }

/* Full-screen on narrow viewports — M3 full-screen dialog for long content on phones */
@media (max-width: 600px) {
  .overlay { padding: 0; }
  .sheet { width: 100%; height: 100%; max-height: none; border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay, .sheet { animation: none; }
}

/* Close = M3 round icon button (40x40, neutral state layer) */
.close {
  position: sticky;
  top: 10px;
  float: right;
  margin: 10px 12px 0 0;
  width: 40px; height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--md-shape-full);
  background: transparent;
  color: var(--md-on-surface-variant);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
  z-index: 2;
}
.close::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-on-surface);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.close:hover::before { opacity: var(--md-state-hover); }
.close:focus-visible { outline: none; }
.close:focus-visible::before { opacity: var(--md-state-focus); }
.close:active::before { opacity: var(--md-state-press); }

/* ---- Detail typography ---- */
.detail { padding: 8px 28px 48px; }
.detail h2 {                                /* M3 headline-small */
  margin: 4px 0 4px;
  font: 400 24px/32px var(--md-font);
  font-family: var(--md-font-display);
  color: var(--md-on-surface);
}
.detail .sub {
  color: var(--md-on-surface-variant);
  font: var(--md-body-md);
  margin-bottom: 18px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---- Gallery ---- */
/* Detail gallery: a hero image + a capped thumbnail grid (tap → lightbox) */
.gallery { margin-bottom: 22px; }
.g-hero {
  display: block; width: 100%; position: relative;
  padding: 0; border: none; cursor: pointer;
  border-radius: var(--md-shape-md); overflow: hidden;
  background: var(--md-surface-container-high);
}
.g-hero img { width: 100%; display: block; }
.g-zoom {
  position: absolute; top: 10px; right: 10px; z-index: 1;
  font: var(--md-label-md); color: #fff;
  background: rgba(0, 0, 0, 0.55); padding: 4px 10px;
  border-radius: var(--md-shape-full); pointer-events: none;
}
/* Rights-restricted hero (allowsDownload:false): thumbnail at natural size, no zoom */
.g-hero-static { cursor: default; display: flex; align-items: center; justify-content: center; }
.g-hero-static img { width: auto; max-width: 100%; height: auto; }
/* Thumbnail filmstrip — horizontal scroll; centres when few, scrolls when many */
.g-strip-wrap { display: flex; align-items: center; gap: 4px; margin-top: 12px; }
.g-strip {
  display: flex; gap: 8px; flex: 1; min-width: 0;
  overflow-x: auto; scroll-behavior: smooth;
  justify-content: safe center;     /* centre when they fit, no clipping when they overflow */
  scrollbar-width: none; padding: 2px;
}
.g-strip::-webkit-scrollbar { display: none; }
.g-thumb {
  position: relative; flex: 0 0 auto; width: 68px; height: 68px;
  padding: 0; border: none; cursor: pointer;
  border-radius: var(--md-shape-sm); overflow: hidden;
  background: var(--md-surface-container-high);
}
.g-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.g-thumb.sensitive img { filter: blur(6px); }
/* Swap-mode strips mark the image currently shown in the hero slot */
.g-thumb.current { outline: 2px solid var(--md-primary); outline-offset: 2px; }
.g-arrow {
  flex: 0 0 auto; width: 36px; height: 68px;
  border: none; border-radius: var(--md-shape-sm);
  background: var(--md-surface-container-high); color: var(--md-on-surface-variant);
  font-size: 24px; line-height: 1; cursor: pointer;
  transition: background-color var(--md-dur) var(--md-ease);
}
.g-arrow:hover { background: var(--md-surface-container-highest); }
.g-arrow:disabled { opacity: 0.35; cursor: default; }
.g-arrow[hidden] { display: none; }
@media (hover: none) { .g-arrow { display: none; } }   /* touch: swipe to scroll */
.g-count { margin: 12px 0 0; font: var(--md-body-sm); color: var(--md-on-surface-variant); }

/* ---- Lightbox: full-screen IIIF deep-zoom viewer ---- */
.lightbox[hidden] { display: none; }
.lightbox {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, 0.92);
}
/* width/height 100% survives OpenSeadragon forcing position:relative on the element.
   The preview image is set as a background (contain) for an instant placeholder while tiles load. */
.lb-osd {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background-size: contain; background-position: center; background-repeat: no-repeat;
}
.lb-osd.sensitive { background-size: cover; background-position: center; filter: blur(28px); }
.lb-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; pointer-events: none;
}
.lb-top > * { pointer-events: auto; }
.lb-counter { font: var(--md-label-lg); color: rgba(255, 255, 255, 0.9); font-variant-numeric: tabular-nums; }
.lb-icon, .lb-nav {
  border: none; background: rgba(255, 255, 255, 0.14); color: #fff;
  cursor: pointer; line-height: 1; border-radius: var(--md-shape-full);
  transition: background-color var(--md-dur) var(--md-ease);
}
.lb-icon:hover, .lb-nav:hover { background: rgba(255, 255, 255, 0.26); }
.lb-icon { width: 44px; height: 44px; font-size: 24px; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 52px; height: 52px; font-size: 30px;
}
.lb-prev { left: 16px; } .lb-next { right: 16px; }
.lb-nav[hidden] { display: none; }
.lb-caption {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 2;
  padding: 16px 20px; text-align: center;
  color: rgba(255, 255, 255, 0.92); font: var(--md-body-sm);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6)); pointer-events: none;
}
.lb-caption a { color: #fff; pointer-events: auto; }
.lb-rights { color: rgba(255, 255, 255, 0.6); }
.lb-reveal {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 3;
  border: 1px solid rgba(255, 255, 255, 0.6); background: rgba(255, 255, 255, 0.14);
  color: #fff; padding: 10px 18px; border-radius: var(--md-shape-full);
  font: var(--md-label-lg); cursor: pointer;
}
.lb-reveal[hidden] { display: none; }
@media (max-width: 600px) {
  .lb-nav { width: 44px; height: 44px; font-size: 26px; }
}

/* ---- Home page ---- */
.home[hidden] { display: none; }
.toolbar[hidden] { display: none; }
#results[hidden] { display: none; }
.home { padding: 0 0 48px; font-family: var(--md-font); }

/* Intro — a graphic, branded lead-in panel */
.home-banner {
  position: relative;
  display: block;
  width: calc(100% - 40px);
  max-width: 1000px;   /* cap height on wide screens; matches the image's native width */
  margin: 18px auto 14px;
  border-radius: var(--md-shape-md);
  overflow: hidden;
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface-container-low);
  text-decoration: none;
}
/* The object spans the image's full width with ~20% white margin top and bottom.
   A ~2.1:1 crop with cover trims that white but never clips the object (its
   bounding box is ~2.24:1, so it stays fully inside the frame). */
.home-banner-img {
  display: block;
  width: 100%;
  aspect-ratio: 2.1 / 1;
  object-fit: cover;
  object-position: center;
}
/* Caption sits in its own strip below the image so it never obscures the object. */
.home-banner-caption {
  display: block;
  padding: 10px 20px 12px;
  font-size: 10px;
  line-height: 1.4;
  color: var(--md-on-surface-variant);
  background: var(--md-surface-container-low);
}
@media (max-width: 720px) {
  .home-banner { margin: 18px auto 12px; }
  .home-banner-caption { padding: 9px 16px 11px; }
}

.home-intro {
  position: relative;
  margin: 18px 20px 14px;
  padding: 36px 32px 30px;
  border-radius: var(--md-shape-md);
  border: 1px solid var(--md-outline-variant);
  background:
    radial-gradient(135% 150% at 0% 0%, rgba(7, 59, 76, 0.10), rgba(7, 59, 76, 0) 56%),
    var(--md-surface-container-low);
  overflow: hidden;
}
.home-intro-eyebrow {
  margin: 0 0 14px; font: 600 12px/1 var(--md-font);
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--md-primary);
}
.home-intro h1 {
  margin: 0 0 12px; max-width: 20ch;
  font: 700 clamp(28px, 3.4vw, 40px)/1.12 var(--md-font);
  font-family: var(--md-font-display);
  letter-spacing: -0.01em; color: var(--md-on-surface);
}
.home-hero-sub { margin: 0 0 12px; max-width: 62ch; font-size: 17px; line-height: 1.5; color: var(--md-on-surface); }
.home-hero-desc { margin: 0 0 6px; max-width: 72ch; font-size: 14px; line-height: 1.6; color: var(--md-on-surface-variant); }

.home-cats { display: flex; flex-direction: column; gap: 2px; }
.home-cats-auto { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; align-content: start; }
.home-cats-grouped { display: block; }   /* the groups manage their own columns */

/* split into labelled type-columns (Humanities / Natural history) */
.home-cat-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; align-items: start; }
.home-cat-group-title {
  margin: 0 0 6px; padding: 0 12px 7px;
  font: 600 13px/1.2 var(--md-font); color: var(--md-on-surface);
  border-bottom: 1px solid var(--md-outline-variant);
}
.home-cat-list { display: flex; flex-direction: column; gap: 2px; }

.home-cat {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  width: 100%; padding: 8px 12px; border: none; border-radius: var(--md-shape-sm);
  background: transparent; cursor: pointer; text-align: left;
  font: 500 14.5px/1.3 var(--md-font); color: var(--md-on-surface);
  transition: background-color var(--md-dur) var(--md-ease);
}
.home-cat:hover, .home-cat:focus-visible { background: var(--md-surface-container-high); outline: none; }
.home-cat-label { min-width: 0; }
.home-cat-count { flex: 0 0 auto; color: var(--md-on-surface-variant); font-size: 12px; font-variant-numeric: tabular-nums; }
.home-cat-arrow { flex: 0 0 auto; color: var(--md-on-surface-variant); opacity: 0; transition: opacity var(--md-dur) var(--md-ease); }
.home-cat:hover .home-cat-arrow, .home-cat:focus-visible .home-cat-arrow { opacity: 1; }

/* below this the rail drops beneath the intro text (full width), so the two
   type-columns keep room for the longest labels instead of wrapping */
/* on phones the two sub-columns collapse to one so counts don't clip */
@media (max-width: 520px) {
  .home-cats-auto { grid-template-columns: 1fr; }
  .home-cat-groups { grid-template-columns: 1fr; gap: 18px; }
}

/* Stat band — live collection numbers */
.home-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin: 0 20px 10px;
}
.home-stat {
  padding: 18px; border-radius: var(--md-shape-md);
  border: 1px solid var(--md-outline-variant); background: var(--md-surface-container);
  text-align: center;
}
.home-stat-num {
  font: 700 clamp(22px, 2.8vw, 30px)/1 var(--md-font);
  color: var(--md-primary); font-variant-numeric: tabular-nums;
  transition: color var(--md-dur) var(--md-ease);
}
.home-stat-num[data-loading] { color: var(--md-outline-variant); }
.home-stat-label {
  margin-top: 7px; font: 600 11.5px/1.3 var(--md-font);
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--md-on-surface-variant);
}

/* ===== Collections disclosure — collapsed by default so the long collection
   list doesn't dominate the home page; expands on click. ===== */
.home-cats-disc {
  margin: 0 20px 14px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-md);
  background: var(--md-surface-container-low);
  overflow: hidden;
}
.home-cats-sum {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; cursor: pointer; list-style: none;
  font: var(--md-title-md); font-family: var(--md-font-display); color: var(--md-on-surface);
  transition: background-color var(--md-dur) var(--md-ease);
}
.home-cats-sum::-webkit-details-marker { display: none; }
.home-cats-sum:hover { background: var(--md-surface-container); }
.home-cats-disc:focus-within .home-cats-sum { outline: 2px solid var(--md-primary); outline-offset: -2px; }
.home-cats-sum-meta { display: inline-flex; align-items: center; gap: 10px; color: var(--md-on-surface-variant); font: var(--md-body-sm); }
.home-cats-chevron { flex: 0 0 auto; transition: transform var(--md-dur) var(--md-ease); }
.home-cats-disc[open] .home-cats-chevron { transform: rotate(180deg); }
.home-cats-disc .home-cats { padding: 2px 18px 18px; }
@media (prefers-reduced-motion: reduce) { .home-cats-chevron { transition: none; } }

.home-shelf { padding: 22px 0 2px; }
.home-shelf-title { margin: 0 0 12px; padding: 0 20px; font: var(--md-title-md); font-family: var(--md-font-display); font-size: 18px; color: var(--md-on-surface); }

/* Curated feature banner (e.g. the James Bragge story-map) */
.home-feature {
  display: flex; align-items: center; gap: 0; margin: 22px 20px 2px;
  border: 1px solid var(--md-outline-variant); border-radius: var(--md-shape-md);
  overflow: hidden; text-decoration: none; color: inherit;
  background: var(--md-surface-container-low);
  transition: box-shadow 180ms var(--md-ease), transform 180ms var(--md-ease);
}
.home-feature:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
/* Never crop the photo: fixed height, width follows its real aspect ratio. */
.home-feature-img { flex: 0 0 auto; height: 190px; width: auto; display: block; object-fit: contain; background: #efe7da; filter: sepia(0.12); }
.home-feature-text { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 22px 24px; }
.home-feature-eyebrow { font: var(--md-label-md); letter-spacing: 0.06em; text-transform: uppercase; color: var(--md-primary); }
.home-feature-title { font: 600 22px/1.2 var(--md-font); font-family: var(--md-font-display); letter-spacing: -0.01em; color: var(--md-on-surface); }
.home-feature-blurb { font: var(--md-body-md); color: var(--md-on-surface-variant); max-width: 60ch; }
.home-feature-cta { margin-top: 4px; font: var(--md-label-lg); color: var(--md-primary); }
@media (max-width: 640px) {
  .home-feature { flex-direction: column; align-items: stretch; margin: 18px 16px 2px; }
  .home-feature-img { width: 100%; height: auto; max-height: 220px; }
}

/* Card row + the same chevron side-scroll arrows as the detail-view filmstrip */
.home-row-wrap { display: flex; align-items: center; gap: 6px; padding: 0 20px; }
.home-row {
  display: flex; gap: 14px; flex: 1; min-width: 0; overflow-x: auto;
  padding: 4px 4px 10px; scroll-behavior: smooth;
  justify-content: safe center;   /* centre when the cards fit, no clipping on overflow */
  scrollbar-width: none;
}
.home-row::-webkit-scrollbar { display: none; }
.home-arrow {
  flex: 0 0 auto; width: 44px; height: 88px;
  border: none; border-radius: var(--md-shape-full);
  background: var(--md-surface-container-high); color: var(--md-on-surface-variant);
  font-size: 26px; line-height: 1; cursor: pointer;
  box-shadow: var(--md-elev-1);
  transition: background-color var(--md-dur) var(--md-ease);
}
.home-arrow:hover { background: var(--md-surface-container-highest); }
.home-arrow:disabled { opacity: 0.35; cursor: default; }
.home-arrow[hidden] { display: none; }
.home-arrow:focus-visible, .g-arrow:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
@media (hover: none) { .home-arrow { display: none; } }   /* touch: swipe to scroll */
@media (prefers-reduced-motion: reduce) {
  .home-row, .g-strip { scroll-behavior: auto; }
  .home-arrow, .g-arrow { transition: none; }
}

.hcard {
  flex: 0 0 auto; width: auto; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--md-surface-container-low); border: none;
  border-radius: var(--md-shape-md); box-shadow: var(--md-elev-1);
  transition: box-shadow var(--md-dur) var(--md-ease);
  position: relative;
}
.hcard:hover, .hcard:focus-visible { box-shadow: var(--md-elev-2); outline: none; }
.hcard .thumb { height: 176px; width: 100%; }   /* 176px tall, fills the card; card width (set inline = 176 x clamped aspect) drives it. Keep the 176 in sync with homeCardHtml */
.hcard-body { padding: 10px 12px 12px; }
.hcard-title {
  font: var(--md-label-lg); color: var(--md-on-surface);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.hcard-sub { margin-top: 4px; font: var(--md-body-sm); color: var(--md-on-surface-variant); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Related-records explorer (detail view): chips + one swappable carousel ---- */
#rel-explorer { margin: 0 0 18px; }
.rel-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.rel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}
.rel-actions[hidden] { display: none; }
.rel-actions-label { font: var(--md-body-sm); color: var(--md-on-surface-variant); }
.rel-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border: 1px solid var(--md-outline-variant);
  border-radius: 16px;
  background: var(--md-surface);
  color: var(--md-on-surface-variant);
  font: var(--md-body-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.rel-view-btn:hover { background: var(--md-surface-container); color: var(--md-on-surface); }
/* Active relation filter chip shown in the result status bar */
.rel-filter-chip {
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 14%, var(--md-surface));
  color: var(--md-primary);
  font: var(--md-body-sm);
  font-weight: 500;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  cursor: pointer;
  vertical-align: middle;
}
.rel-filter-chip:hover { background: color-mix(in srgb, var(--accent) 22%, var(--md-surface)); }

/* Image-rights filter chips in the results toolbar */
.rights-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rel-row-wrap { display: flex; align-items: center; gap: 6px; }
.rel-row {
  display: flex; gap: 12px; flex: 1; min-width: 0;
  overflow-x: auto; padding: 4px 2px 8px;
  scroll-behavior: smooth; scrollbar-width: none;
}
.rel-row::-webkit-scrollbar { display: none; }
.rel-row .spinner { padding: 24px; }
.rcard .thumb { height: 120px; }            /* smaller cards than the home shelves */
.rcard .hcard-body { padding: 8px 10px 10px; }
.rel-row-wrap .home-arrow { height: 64px; width: 36px; font-size: 22px; }
.rcard-more {
  flex: 0 0 auto; align-self: flex-start;
  height: 120px; width: 104px; margin-top: 4px;
  border: 1px solid var(--md-outline-variant); border-radius: var(--md-shape-md);
  background: var(--md-surface-container-low); color: var(--md-primary);
  font: var(--md-label-lg); cursor: pointer;
  transition: background-color var(--md-dur) var(--md-ease);
}
.rcard-more span { display: block; margin-top: 6px; font: var(--md-label-md); color: var(--md-on-surface-variant); }
.rcard-more:hover { background: var(--md-surface-container); }
.rcard-more:disabled { opacity: 0.5; cursor: default; }
@media (prefers-reduced-motion: reduce) { .rel-row { scroll-behavior: auto; } }

.home-links { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px; }
.home-link {
  height: 36px; padding: 0 16px; border-radius: var(--md-shape-full);
  border: 1px solid var(--md-outline-variant); background: transparent;
  color: var(--md-primary); font: var(--md-label-lg); cursor: pointer;
  transition: background-color var(--md-dur) var(--md-ease);
}
.home-link:hover { background: var(--md-surface-container); }

.home-skeleton {
  height: 196px; margin: 0 20px; border-radius: var(--md-shape-md);
  background: var(--md-surface-container);
  animation: home-pulse 1.4s ease-in-out infinite;
}
@keyframes home-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) { .home-skeleton { animation: none; } }

/* ---- Tombstone / detail list (M3 list pairs) ---- */
.detail dl { margin: 0; display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; }
.detail dt { color: var(--md-on-surface-variant); font: var(--md-body-sm); }
.detail dd { margin: 0; color: var(--md-on-surface); font: var(--md-body-md); }
.detail dd p { margin: 0 0 8px; }

/* Short tombstone caption under the gallery */
.detail .caption {
  margin: 0 0 16px;
  font: var(--md-body-sm);
  color: var(--md-on-surface-variant);
  line-height: 1.5;
}
.detail .caption a { color: var(--md-primary); }

/* "About" web-summary body (HTML from the API) */
.detail .about { font: var(--md-body-md); line-height: 1.6; color: var(--md-on-surface); }
.detail .about p { margin: 0 0 10px; }
.detail .about a { color: var(--md-primary); }

/* ---- Chips (M3) ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .badge { background: var(--md-surface-container-highest); }

/* Interactive connection chip = M3 assist chip with state layer */
.chip-link {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  font: var(--md-label-md);
  line-height: 1.4;
  color: var(--md-on-surface-variant);
  background: var(--md-surface-container-highest);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-sm);
}
.chip-link::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-on-surface-variant);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.chip-link:hover::before { opacity: var(--md-state-hover); }
.chip-link:focus-visible { outline: none; }
.chip-link:focus-visible::before { opacity: var(--md-state-focus); }
.chip-link:active::before { opacity: var(--md-state-press); }

/* ---- Section titles (small-caps label) ---- */
.section-title {
  margin: 26px 0 10px;
  font: var(--md-label-md);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--md-on-surface-variant);
  border-bottom: 1px solid var(--md-outline-variant);
  padding-bottom: 6px;
}

/* ---- Wikipedia preview ---- */
.wiki-section[hidden] { display: none; }
.wiki { display: flex; gap: 14px; align-items: flex-start; }
.wiki-thumb {
  width: 96px; height: 96px; flex: none;
  object-fit: cover;
  border-radius: var(--md-shape-sm);
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface-container-high);
}
.wiki-body { min-width: 0; }
.wiki-desc { font: var(--md-body-sm); color: var(--md-on-surface-variant); margin-bottom: 4px; }
.wiki-extract { margin: 0 0 10px; font: var(--md-body-md); line-height: 1.5; color: var(--md-on-surface); }

/* Wiki link = M3 outlined button */
.wiki-link {
  position: relative;
  display: inline-block;
  overflow: hidden;
  text-decoration: none;
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--md-outline);
  border: none;
  color: var(--md-primary);
  padding: 9px 16px;
  border-radius: var(--md-shape-full);
  font: var(--md-label-lg);
  white-space: nowrap;
}
.wiki-link::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-primary);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.wiki-link:hover::before { opacity: var(--md-state-hover); }
.wiki-link:focus-visible { outline: none; }
.wiki-link:focus-visible::before { opacity: var(--md-state-focus); }
.wiki-link:active::before { opacity: var(--md-state-press); }

.wiki-credit { margin: 10px 0 0; font: var(--md-body-sm); color: var(--md-on-surface-variant); }
.wiki-credit a { color: var(--md-on-surface-variant); text-decoration: underline; }
.wiki-credit a:hover { color: var(--md-primary); }

/* ---- External links = M3 outlined buttons ---- */
.links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.links a {
  position: relative;
  display: inline-block;
  overflow: hidden;
  text-decoration: none;
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--md-outline);
  border: none;
  color: var(--md-primary);
  padding: 9px 16px;
  border-radius: var(--md-shape-full);
  font: var(--md-label-lg);
}
.links a::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-primary);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.links a:hover::before { opacity: var(--md-state-hover); }
.links a:focus-visible { outline: none; }
.links a:focus-visible::before { opacity: var(--md-state-focus); }
.links a:active::before { opacity: var(--md-state-press); }

/* ---- Explore-graph = M3 filled-tonal button (full width) ---- */
.graph-btn {
  position: relative;
  overflow: hidden;
  margin-top: 24px;
  width: 100%;
  height: 40px;
  padding: 0 24px;
  border: none;
  border-radius: var(--md-shape-full);
  background: #073b4c;   /* darkest palette colour (navy) in light mode */
  color: #ffffff;
  font: var(--md-label-lg);
  cursor: pointer;
}
[data-theme="dark"] .graph-btn { background: #ffffff; color: #073b4c; }   /* white in dark mode */
.graph-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;   /* hover/press tint = the (contrasting) text colour */
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.graph-btn:hover::before { opacity: var(--md-state-hover); }
.graph-btn:focus-visible { outline: none; }
.graph-btn:focus-visible::before { opacity: var(--md-state-focus); }
.graph-btn:active::before { opacity: var(--md-state-press); }

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .close, .close::before,
  .chip-link::before,
  .wiki-link, .wiki-link::before,
  .links a, .links a::before,
  .graph-btn, .graph-btn::before { transition: none; }
}

/* --md-primary is now the AA-safe teal, so all teal text/labels/buttons pass WCAG AA
   without per-selector overrides. Two small carry-overs remain: */
.list tbody tr:hover { background: var(--md-surface-container); } /* state tint via token, not a hardcoded rgba */

/* ---- Knowledge graph overlay — Material 3 ---- */
.graph-overlay[hidden] { display: none; }
.graph-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: var(--md-surface);
  display: flex;
  flex-direction: column;
  font-family: var(--md-font);
  color: var(--md-on-surface);
  -webkit-font-smoothing: antialiased;
}

/* Top app bar (M3 small top app bar) */
.graph-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 64px;
  padding: 0 12px 0 20px;
  background: var(--md-surface-container);
  border-bottom: 1px solid var(--md-outline-variant);
  box-shadow: var(--md-elev-1);
  z-index: 2;
}
.graph-head-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.graph-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; overflow: hidden; }
.graph-title strong { font: var(--md-title-lg); font-family: var(--md-font-display); color: var(--md-on-surface); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.graph-focus {
  font: var(--md-body-md);
  color: var(--md-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.graph-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.graph-count {
  font: var(--md-label-md);
  color: var(--md-on-surface-variant);
  margin-right: 4px;
  white-space: nowrap;
}

/* Text buttons (pill) with an M3 state-layer overlay */
.graph-actions button {
  position: relative;
  appearance: none;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: var(--md-shape-full);
  background: transparent;
  color: var(--md-primary);
  font: var(--md-label-lg);
  letter-spacing: .01em;
  white-space: nowrap;
  cursor: pointer;
  overflow: hidden;
  transition: background-color var(--md-dur) var(--md-ease);
}
.graph-actions button::before {            /* state layer */
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-primary);
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.graph-actions button:hover::before { opacity: var(--md-state-hover); }
.graph-actions button:focus-visible { outline: none; }
.graph-actions button:focus-visible::before { opacity: var(--md-state-focus); }
.graph-actions button:active::before { opacity: var(--md-state-press); }

/* Close = M3 round icon button (neutral state layer) */
.graph-actions .close {
  width: 40px; height: 40px;
  margin: 0; top: 0; float: none;   /* reset the detail-dialog .close corner styles (sticky top:10px, float, margin) — here it's a flex-row item */
  padding: 0;
  border-radius: var(--md-shape-full);
  color: var(--md-on-surface-variant);
  font-size: 22px;
  line-height: 1;
}
.graph-actions .close::before { background: var(--md-on-surface); }

/* Graph header on small screens: drop the record count, then the title, and
   compact the action buttons so they stay on one row instead of wrapping/overlapping. */
@media (max-width: 768px) {
  .graph-count { display: none; }
}
@media (max-width: 600px) {
  .graph-title { display: none; }
  .graph-head { padding: 0 8px 0 12px; gap: 8px; }
  .graph-actions { gap: 4px; }
  .graph-actions button { padding: 0 10px; font: var(--md-label-md); }
}

/* Cytoscape canvas */
.cy { flex: 1; min-height: 0; background: var(--md-surface-container-lowest); }

/* Legend: elevated surface with assist-chip rows */
.graph-legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 60%;
  padding: 12px;
  background: var(--md-surface-container-low);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-md);
  box-shadow: var(--md-elev-2);
  font: var(--md-label-md);
}
.graph-legend .lg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px 0 8px;
  border-radius: var(--md-shape-sm);
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface-variant);
}
.graph-legend .dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.graph-legend .lg-ic { width: 18px; height: 18px; display: inline-block; }

/* Hint: M3 assist-chip pill */
.graph-hint {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;                /* otherwise left:50% caps the auto width at ~half the screen */
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  font: var(--md-label-md);
  line-height: 1.45;
  text-align: center;
  color: var(--md-on-surface-variant);
  background: var(--md-surface-container-low);
  padding: 10px 18px;
  /* xl (28px), not full: a clean pill on one line (desktop) but a tidy rounded
     card when the text wraps on narrow screens, rather than an awkward stadium. */
  border-radius: var(--md-shape-xl);
  border: 1px solid var(--md-outline-variant);
  box-shadow: var(--md-elev-1);
  pointer-events: none;
}
/* Touch devices have no right-click: swap in the long-press wording (and drop the
   verbose parenthetical to save space) on no-hover pointers. */
.graph-hint .hint-touch { display: none; }
@media (hover: none) {
  .graph-hint .hint-mouse { display: none; }
  .graph-hint .hint-touch { display: inline; }
}

/* Node info card: M3 elevated card (dp3) */
.graph-info[hidden] { display: none; }
.graph-info {
  position: absolute;
  top: 80px;
  right: 16px;
  width: 280px;
  max-height: calc(100% - 120px);
  overflow-y: auto;
  background: var(--md-surface-container-low);
  border: none;
  border-radius: var(--md-shape-lg);
  box-shadow: var(--md-elev-3);
  padding: 16px;
  animation: gi-rise var(--md-dur) var(--md-ease);
}
@keyframes gi-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.graph-info img {
  width: 100%;
  border-radius: var(--md-shape-md);
  margin-bottom: 12px;
  background: var(--md-surface-container-high);
}
.graph-info h3 { margin: 0 0 10px; font: var(--md-title-md); font-family: var(--md-font-display); color: var(--md-on-surface); }
.graph-info .gi-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

/* Card actions: first = filled primary, rest = tonal, external = outlined */
.graph-info button, .graph-info a.gi-link {
  position: relative;
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  height: 40px;
  line-height: 40px;
  padding: 0 16px;
  margin-top: 8px;
  border: none;
  border-radius: var(--md-shape-full);
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  font: var(--md-label-lg);
  cursor: pointer;
  overflow: hidden;
  box-sizing: border-box;
  transition: box-shadow var(--md-dur) var(--md-ease);
}
.graph-info button:first-of-type {         /* primary action = filled teal */
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-elev-1);
}
.graph-info a.gi-link {                     /* external link = outlined */
  background: transparent;
  color: var(--md-primary);
  box-shadow: inset 0 0 0 1px var(--md-outline-variant);
}
.graph-info button::before, .graph-info a.gi-link::before {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-dur) var(--md-ease);
  pointer-events: none;
}
.graph-info button:hover::before,
.graph-info a.gi-link:hover::before { opacity: var(--md-state-hover); }
.graph-info button:active::before,
.graph-info a.gi-link:active::before { opacity: var(--md-state-press); }
.graph-info button:first-of-type:hover { box-shadow: var(--md-elev-2); }
.graph-info .gi-note { font: var(--md-body-sm); color: var(--md-on-surface-variant); margin: 10px 0 0; }

/* Snackbar: classic M3 dark surface; green status / red error left-accent */
.graph-toast[hidden] { display: none; }
.graph-toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  min-height: 48px;
  display: flex;
  align-items: center;
  background: var(--md-snackbar-bg);
  color: var(--md-snackbar-on);
  padding: 0 16px;
  border-radius: var(--md-shape-xs);
  font: var(--md-body-md);
  box-shadow: var(--md-elev-3);
  border-left: 4px solid var(--md-status);   /* green = status */
  animation: snack-in var(--md-dur) var(--md-ease);
}
@keyframes snack-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.graph-toast.error { border-left-color: var(--md-error); }  /* red = error */

@media (prefers-reduced-motion: reduce) {
  .graph-info, .graph-toast { animation: none; }
  .graph-actions button, .graph-actions button::before,
  .graph-info button, .graph-info a.gi-link,
  .graph-info button::before, .graph-info a.gi-link::before { transition: none; }
}
