/* Colors: every text/background pair meets WCAG AA (4.5:1) or better in both themes. */
:root {
  color-scheme: light;
  --bg: #fbfbf9;
  --surface: #ffffff;
  --surface-2: #f0f1ee;
  --text: #1b1c1f;
  --muted: #4a4d55;
  --border: #767983;
  --link: #0a55a8;
  --link-visited: #6b2fa0;
  --accent: #0a55a8;
  --accent-text: #ffffff;
  --focus: #b3440b;
  --good: #1d6b35;
  --warn: #8a4b00;
  --error: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131417;
    --surface: #1c1e22;
    --surface-2: #26292e;
    --text: #eceef2;
    --muted: #b9bdc7;
    --border: #8a8f9b;
    --link: #8cc4ff;
    --link-visited: #d3a8ff;
    --accent: #8cc4ff;
    --accent-text: #0b1a2b;
    --focus: #ffb86b;
    --good: #7fd69a;
    --warn: #ffc56b;
    --error: #ff9b91;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131417;
  --surface: #1c1e22;
  --surface-2: #26292e;
  --text: #eceef2;
  --muted: #b9bdc7;
  --border: #8a8f9b;
  --link: #8cc4ff;
  --link-visited: #d3a8ff;
  --accent: #8cc4ff;
  --accent-text: #0b1a2b;
  --focus: #ffb86b;
  --good: #7fd69a;
  --warn: #ffc56b;
  --error: #ff9b91;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.55;
}

.wrap { max-width: 72rem; margin-inline: auto; padding-inline: 1rem; }

a { color: var(--link); text-underline-offset: 0.15em; }
a:visited { color: var(--link-visited); }

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  z-index: 10;
}
.skip-link:focus { top: 0.5rem; }

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

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding-block: 0.75rem; }
.site-name { margin: 0; font-size: 1.25rem; font-weight: 700; }
.header-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.theme-control { display: flex; align-items: center; gap: 0.5rem; }
.narrow { max-width: 40rem; }
button[aria-disabled="true"] { opacity: 0.6; cursor: progress; }
.nav-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0; padding: 0 0 0.5rem; }
.nav-list a {
  display: inline-block;
  min-height: 44px;
  padding: 0.6rem 1rem;
  border-radius: 0.4rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.nav-list a:hover { background: var(--surface-2); text-decoration: underline; }
.nav-list a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-text);
}

main { padding-block: 1.5rem 3rem; }
h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 0.75rem; }
h2 { font-size: 1.35rem; margin: 1.75rem 0 0.5rem; }
h3 { font-size: 1.15rem; margin: 0 0 0.35rem; }

.notice { padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: 0.4rem; background: var(--surface); }
.notice.error, .error { color: var(--error); }

/* Forms */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem;
  padding: 1rem; margin-block: 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem;
}
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 10rem; }
.field.grow { flex: 1 1 16rem; }
.field.actions { min-width: auto; }
label { font-weight: 600; }

input, select, button {
  font: inherit;
  min-height: 44px;
  border-radius: 0.4rem;
}
input, select {
  padding: 0.45rem 0.6rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
}
button {
  padding: 0.5rem 1.1rem;
  border: 2px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--link); }
button:hover { text-decoration: underline; }
button.more { margin-top: 1rem; }

.status { min-height: 1.5em; font-weight: 600; }

/* Books table */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 0.5rem; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
caption { text-align: left; padding: 0.75rem 1rem; font-weight: 700; }
th, td { text-align: left; vertical-align: top; padding: 0.6rem 0.75rem; border-top: 1px solid var(--border); }
thead th { background: var(--surface-2); border-top: 0; }
tbody th { font-weight: 600; }
td ul, .plain { list-style: none; margin: 0; padding: 0; }
td li + li { margin-top: 0.25rem; }
.muted { color: var(--muted); }
.tag { display: inline; }

/* Series and search cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-block: 0.75rem;
}
.card p { margin: 0.25rem 0; }
.card ol, .card ul { margin: 0.4rem 0 0; padding-left: 1.4rem; }
.card li + li { margin-top: 0.2rem; }
.card h4 { font-size: 1rem; margin: 0.75rem 0 0.2rem; }
.good { color: var(--good); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }

.site-footer { padding-block: 1rem 2rem; color: var(--muted); border-top: 1px solid var(--border); }

/* Small screens: full-width fields. The table keeps real table layout (so screen readers
   still announce rows and columns) and scrolls sideways inside its own box. */
@media (max-width: 40rem) {
  .field, .field.grow { min-width: 100%; }
  table { min-width: 44rem; }
}

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

@media (forced-colors: active) {
  .nav-list a[aria-current="page"] { border: 2px solid CanvasText; }
  button { border: 2px solid ButtonText; }
}
