:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --sunken: #efede7;
  --text: #1d2125;
  --text-2: #474c53;
  --muted: #5f646b;
  --accent: #1f5f8f;
  --accent-hover: #174a70;
  --on-accent: #ffffff;
  --accent-soft: #e4eef6;
  --border: #dedbd2;
  --control: #7c818a;
  --focus: #1f5f8f;
  --note-bg: #fdf3dd;
  --note-text: #5a3d06;
  --note-border: #a86f0c;
  --danger: #a8322d;
  --overlay: rgb(0 0 0 / 0.85);
  --lightbox-bg: #000;
  --lightbox-text: #fff;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 2px 8px rgb(0 0 0 / .06);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Liberation Sans", Arial, sans-serif;
  --fs-xs: 0.8125rem;
  --fs-sm: 0.9375rem;
  --fs-base: 1.0625rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: clamp(1.75rem, 1.35rem + 1.6vw, 2.375rem);
  --lh-xs: 1.4;
  --lh-sm: 1.5;
  --lh-base: 1.6;
  --lh-lg: 1.45;
  --lh-xl: 1.3;
  --lh-2xl: 1.2;

  --sp-1: .25rem;
  --sp-2: .5rem;
  --sp-3: .75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  --section-gap: var(--sp-6);
  --stack-gap: var(--sp-4);
  --wide: 88rem;
  --measure: 42rem;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-pill: 999px;
  --tap: 44px;
  --dur: 150ms;
  --ease: ease;
}

@media (min-width: 600px) {
  :root { --section-gap: var(--sp-7); }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121416;
    --surface: #1b1e21;
    --sunken: #16191b;
    --text: #ebe9e4;
    --text-2: #c9c6be;
    --muted: #a3a7ad;
    --accent: #8cc0ec;
    --accent-hover: #b2d5f3;
    --on-accent: #0d1a26;
    --accent-soft: #1e3347;
    --border: #30353a;
    --control: #80868e;
    --focus: #8cc0ec;
    --note-bg: #2e2513;
    --note-text: #f3dcae;
    --note-border: #b98520;
    --danger: #f08a84;
    --overlay: rgb(0 0 0 / 0.85);
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121416;
  --surface: #1b1e21;
  --sunken: #16191b;
  --text: #ebe9e4;
  --text-2: #c9c6be;
  --muted: #a3a7ad;
  --accent: #8cc0ec;
  --accent-hover: #b2d5f3;
  --on-accent: #0d1a26;
  --accent-soft: #1e3347;
  --border: #30353a;
  --control: #80868e;
  --focus: #8cc0ec;
  --note-bg: #2e2513;
  --note-text: #f3dcae;
  --note-border: #b98520;
  --danger: #f08a84;
  --overlay: rgb(0 0 0 / 0.85);
  --shadow: none;
}

/* Reset and base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  overflow-wrap: break-word;
}
img, video { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-6) 0; }
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); line-height: var(--lh-2xl); font-weight: 700; }
h2 { font-size: var(--fs-xl); line-height: var(--lh-xl); font-weight: 700; }
h3 { font-size: var(--fs-lg); line-height: var(--lh-lg); font-weight: 600; }
p { margin: 0; }
p + p { margin-top: var(--sp-3); }
ul, ol { margin: 0; padding-inline-start: var(--sp-5); }
label, legend { font-weight: 600; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.lead { font-size: var(--fs-lg); line-height: var(--lh-lg); color: var(--text-2); }
.meta { font-size: var(--fs-sm); line-height: var(--lh-sm); color: var(--muted); }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color var(--dur) var(--ease);
}
a:hover { color: var(--accent-hover); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--sp-4);
  top: var(--sp-2);
  z-index: 10;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-md);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* Layout */
.wrap {
  width: 100%;
  max-width: var(--wide);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.measure { max-width: var(--measure); }
main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--wide);
  margin-inline: auto;
  padding: var(--sp-6) var(--gutter) var(--section-gap);
}

/* Header and navigation */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding-block: var(--sp-3);
}
.wordmark {
  order: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  color: var(--text);
  text-decoration: none;
}
.wordmark:hover { color: var(--text); }
.wordmark-mark {
  width: 28px;
  height: 28px;
  flex: none;
  color: var(--accent);
}
.wordmark-title {
  display: block;
  font-size: var(--fs-lg);
  line-height: var(--lh-lg);
  font-weight: 600;
}
.wordmark-sub {
  display: block;
  font-size: var(--fs-sm);
  line-height: var(--lh-sm);
  color: var(--muted);
}
.site-search { order: 1; margin-inline-start: auto; display: flex; gap: var(--sp-2); align-items: center; }
.site-search input { display: none; }
#theme-toggle { order: 2; }
.menu { order: 3; flex: 1 1 100%; }
.menu > summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding-inline: var(--sp-3);
  border: 1px solid var(--control);
  border-radius: var(--r-md);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.site-nav { margin-top: var(--sp-2); }
.site-nav ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.site-nav a,
.site-nav summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding-inline: var(--sp-3);
  color: var(--text);
  text-decoration: none;
  border-radius: var(--r-md);
  cursor: pointer;
}
.site-nav a:hover,
.site-nav summary:hover { background: var(--accent-soft); color: var(--text); }
.site-nav [aria-current="page"] { color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.site-nav .sections ul { padding-inline-start: var(--sp-4); }
.site-nav .count { margin-inline-start: var(--sp-2); color: var(--muted); font-weight: 400; }
.site-nav .sections > summary::-webkit-details-marker { display: none; }
#nav-sections a { font-weight: 400; }

@media (min-width: 600px) {
  .site-nav .sections ul { padding-inline-start: var(--sp-4); }
}

@media (min-width: 900px) {
  .wordmark { order: 0; }
  .menu { order: 1; flex: 1 1 auto; margin-inline-start: var(--sp-2); }
  .menu > summary { display: none; }
  .site-nav { margin-top: 0; }
  .site-nav ul { flex-direction: row; align-items: center; gap: var(--sp-1); }
  .site-nav .sections { position: relative; }
  .site-nav .sections[open] > ul {
    position: absolute;
    z-index: 5;
    min-width: 14rem;
    flex-direction: column;
    padding: var(--sp-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow);
  }
  .site-search { order: 2; margin-inline-start: 0; }
  #theme-toggle { order: 3; }
}

@media (max-width: 420px) {
  .wordmark { gap: var(--sp-2); }
  .wordmark-title { font-size: var(--fs-base); }
  .wordmark-sub { display: none; }
}

/* The inline search field needs the room of a wide screen; below that the icon opens the search page. */
@media (min-width: 1200px) {
  .site-search input { display: block; width: 9rem; min-height: var(--tap); }
}

/* Footer */
.site-footer {
  flex: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-block: var(--sp-6);
  font-size: var(--fs-sm);
  line-height: var(--lh-sm);
  color: var(--text-2);
}
.footer-label { margin-top: var(--sp-5); font-weight: 600; color: var(--text); }
.footer-links {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-5);
}
.footer-links a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}
.footer-note, .footer-copy { margin-top: var(--sp-3); }
.footer-copy { color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--control);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-icon { width: var(--tap); min-width: var(--tap); padding: 0; }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.6; cursor: not-allowed; }
#theme-toggle[aria-pressed="true"] .icon-moon,
#theme-toggle[aria-pressed="false"] .icon-sun { display: none; }
#theme-toggle svg { width: 20px; height: 20px; }

/* Forms */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  min-height: var(--tap);
  max-width: 100%;
  padding: var(--sp-2) var(--sp-3);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--control);
  border-radius: var(--r-md);
}
::placeholder { color: var(--muted); opacity: 1; }

/* Surfaces */
.card {
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card-primary { background: var(--accent-soft); }
.card h3 a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}
.chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--sunken);
  color: var(--text-2);
  font-size: var(--fs-sm);
  text-decoration: none;
}
a.chip:hover { background: var(--accent-soft); color: var(--text); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--sunken);
  color: var(--text-2);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  font-weight: 600;
}
.callout {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--sunken);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-md);
}
.callout > svg { flex: none; margin-top: 0.15em; }
.callout-note {
  background: var(--note-bg);
  color: var(--note-text);
  border-left-color: var(--note-border);
}

/* Navigation aids */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--accent);
  text-decoration: none;
}
.page-link[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.page-link.is-disabled { color: var(--muted); }
.page-gap { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); color: var(--muted); }
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 0;
  list-style: none;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.breadcrumbs li + li::before { content: "›"; margin-inline: var(--sp-2); }
.breadcrumbs a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  color: var(--text-2);
}

/* Data */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.table th,
.table td {
  padding: var(--sp-2) var(--sp-3);
  text-align: start;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.table th { font-weight: 600; color: var(--text-2); }
.table tbody tr:nth-child(even) { background: var(--sunken); }
.table caption { padding-block: var(--sp-2); text-align: start; color: var(--muted); }

/* States */
.empty {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.empty p { margin-top: var(--sp-2); color: var(--text-2); }
.empty .cluster { justify-content: center; margin-top: var(--sp-4); }
.error {
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: var(--r-md);
  color: var(--danger);
}
.error p + .btn { margin-top: var(--sp-3); }
.loading { color: var(--muted); }

/* Utilities */
.stack > * + * { margin-top: var(--stack-gap); }
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
}
.grid-cards {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(min(16rem, 100%), 1fr));
}
/* Image grids: at least 3 columns at any width, more as the page widens (the -1px keeps rounding from dropping to 2). */
.thumb-grid,
.tile-grid,
.grid-posts {
  --cell: 9rem;
  --gap: var(--sp-2);
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(min(var(--cell), calc((100% - 2 * var(--gap)) / 3 - 1px)), 1fr));
}

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

/* Print */
@media print {
  body { background: Canvas !important; color: CanvasText !important; }
  *, *::before, *::after {
    background: transparent !important;
    color: CanvasText !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  a { text-decoration: underline; }
  .site-nav,
  .menu,
  .site-search,
  #theme-toggle,
  .skip-link,
  .footer-links,
  .btn,
  .no-print { display: none !important; }
  details > *:not(summary) { display: block; }
  h1, h2, h3 { break-after: avoid; }
  .card, .callout, figure { break-inside: avoid; }
}
