:root {
    color-scheme: light;
    --bg: #F5F7F9;
    --surface: #FFFFFF;
    --ink: #1E2A36;
    --muted: #5B6B7B;
    --line: #DCE1E7;
    --accent: #0F6E6E;
    --accent-ink: #FFFFFF;
    --stripe: #F0F3F6;
    --danger: #A23B2C;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      color-scheme: dark;
      --bg: #141B22;
      --surface: #1B242D;
      --ink: #E4E9EE;
      --muted: #94A3B1;
      --line: #2E3A46;
      --accent: #3FB3AE;
      --accent-ink: #0E1C1C;
      --stripe: #202A34;
      --danger: #E27A69;
    }
  }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  }
  .wrap { max-width: 1200px; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }

  header.top {
    display: flex; flex-wrap: wrap; align-items: flex-end;
    justify-content: space-between; gap: 1.25rem;
    padding-bottom: 1.5rem; border-bottom: 2px solid var(--ink);
  }
  h1 { margin: 0; font-size: clamp(1.75rem, 4vw, 2.5rem); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
  .count { margin: .35rem 0 0; color: var(--muted); }

  .btn {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .75rem 1.25rem; border-radius: 6px;
    background: var(--accent); color: var(--accent-ink);
    font-weight: 700; text-decoration: none; border: 0; cursor: pointer;
  }
  .btn:hover { filter: brightness(1.08); }
  .btn svg { width: 18px; height: 18px; }
  a:focus-visible, button:focus-visible, input:focus-visible {
    outline: 3px solid var(--accent); outline-offset: 2px;
  }

  form.search { display: flex; gap: .5rem; margin: 1.5rem 0 1rem; max-width: 520px; }
  form.search input {
    flex: 1; padding: .65rem .85rem; font: inherit; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  }
  form.search button {
    padding: .65rem 1rem; font: inherit; font-weight: 500; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
  }
  .clear { align-self: center; color: var(--muted); font-size: .9rem; }

  .table-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
  table { width: 100%; border-collapse: collapse; font-size: .95rem; }
  th, td { padding: .7rem .9rem; text-align: left; vertical-align: top; white-space: nowrap; }
  td { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
  thead th {
    position: sticky; top: 0; background: var(--surface);
    font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line);
  }
  tbody tr:nth-child(even) { background: var(--stripe); }
  .null { color: var(--muted); }

  .empty {
    padding: 3rem 1.5rem; text-align: center;
    background: var(--surface); border: 1px dashed var(--line); border-radius: 8px;
  }
  .empty p { margin: 0 0 1.25rem; color: var(--muted); }
  .error {
    padding: 1rem 1.25rem; border-left: 4px solid var(--danger);
    background: var(--surface); color: var(--ink); border-radius: 4px; margin-top: 1.5rem;
  }
  .error strong { color: var(--danger); }

  nav.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; color: var(--muted); }
  nav.pager a { color: var(--accent); font-weight: 500; }

  .flash {
    margin-top: 1.5rem; padding: .85rem 1.1rem; border-radius: 6px;
    background: var(--surface); border-left: 4px solid var(--accent);
  }
  .flash a { color: var(--accent); font-weight: 500; }

  /* Form */
  .back { display: inline-block; margin-bottom: 1rem; color: var(--muted); text-decoration: none; }
  .back:hover { color: var(--ink); text-decoration: underline; }
  form.item { margin-top: 2rem; }
  fieldset {
    margin: 0 0 1.5rem; padding: 1.25rem 1.25rem .5rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  }
  legend { padding: 0 .4rem; font-weight: 700; font-size: 1.05rem; }
  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 1.25rem; }
  .field { margin-bottom: 1rem; }
  .field.wide { grid-column: 1 / -1; }
  .field label { display: block; margin-bottom: .3rem; font-weight: 500; font-size: .95rem; }
  .field .hint { display: block; color: var(--muted); font-size: .85rem; margin-top: .25rem; }
  .field input[type=text], .field input[type=number], .field input[type=date],
  .field input[type=url], .field select, .field textarea {
    width: 100%; padding: .6rem .75rem; font: inherit; color: var(--ink);
    background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  }
  .field textarea { min-height: 6rem; resize: vertical; }
  .check { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; font-weight: 500; }
  .check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
  .req { color: var(--danger); }
  .field.invalid input, .field.invalid select { border-color: var(--danger); }
  .field .err { color: var(--danger); font-size: .85rem; margin-top: .25rem; display: block; }
  .actions { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
  .actions .cancel { color: var(--muted); }
  .error ul { margin: .5rem 0 0; padding-left: 1.25rem; }

/* Search-first landing */
.search-hero { max-width: 640px; margin: 3rem auto 0; }
.search-hero input { padding: .9rem 1rem; font-size: 1.1rem; }
.search-hero button { padding: .9rem 1.25rem; }
/* Search box on its own row, the Search button (and Clear) under it on the left, then the filters. */
form.search { flex-wrap: wrap; align-items: center; }
form.search input[type="search"] { order: 0; flex: 1 1 100%; }
form.search button[type="submit"] { order: 1; flex: 0 0 auto; }
form.search .clear { order: 2; }
form.search::after { content: ""; order: 2; flex-basis: 100%; height: 0; }
form.search .shelf-select { order: 3; flex: 1 1 160px; min-width: 0; }
.search-note { text-align: center; color: var(--muted); margin-top: .75rem; }
.results-count { color: var(--muted); margin: 0 0 .75rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Clickable results */
table.results tbody tr { cursor: pointer; }
table.results tbody tr:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
td.thumb-cell { width: 52px; padding-top: .45rem; padding-bottom: .45rem; }
.title-link { color: var(--ink); font-weight: 700; text-decoration: none; }
.title-link:hover { color: var(--accent); text-decoration: underline; }

/* Covers */
.thumb { display: block; width: 36px; height: 54px; object-fit: cover; border-radius: 2px; background: var(--stripe); }
.cover { display: block; width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px;
         box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 8px 24px rgba(0,0,0,.14); background: var(--stripe); }
.cover-ph { display: flex; align-items: center; justify-content: center; text-align: center;
            background: var(--accent); color: var(--accent-ink); overflow: hidden; }
.cover-ph[hidden] { display: none; }
.thumb.cover-ph span { display: none; }
.cover.cover-ph span { padding: 1.25rem; font-weight: 700; font-size: 1.2rem; line-height: 1.25; }

/* Book page */
.book { display: grid; grid-template-columns: minmax(180px, 280px) 1fr; gap: 2.5rem; align-items: start; margin-top: .5rem; }
/* The cover sits at the top of the page and scrolls away with it. */
@media (max-width: 680px) { .book { grid-template-columns: 1fr; } .book-cover { max-width: 220px; } }
.book-main h1 { margin-bottom: .25rem; }
.subtitle { margin: 0 0 .25rem; font-size: 1.15rem; color: var(--muted); }
.byline { margin: 0; font-size: 1.1rem; }
.book-actions { margin: 1.25rem 0 2rem; }
.synopsis, .details { padding: 1.25rem 0; border-top: 1px solid var(--line); }
.synopsis h2, .details h2 { margin: 0 0 .75rem; font-size: 1rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.synopsis p { margin: 0 0 .9rem; font-size: 1.05rem; line-height: 1.65; max-width: 68ch; }
.synopsis a { color: var(--accent); }
.details dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .9rem 1.5rem; margin: 0; }
.details dt { font-size: .85rem; color: var(--muted); }
.details dd { margin: .1rem 0 0; }

/* Delete */
.delete-form { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.btn-danger { padding: .6rem 1rem; font: inherit; font-weight: 500; color: var(--danger);
              background: transparent; border: 1px solid var(--danger); border-radius: 6px; cursor: pointer; }
.btn-danger:hover { background: var(--danger); color: var(--surface); }

/* Browse full list */
.browse-row { margin: .75rem 0 1rem; color: var(--muted); }
.search-hero + .browse-row { text-align: center; }
.btn-secondary { display: inline-block; padding: .5rem .95rem; border: 1px solid var(--accent); border-radius: 6px;
                 color: var(--accent); font-weight: 500; text-decoration: none; }
.btn-secondary:hover { background: var(--accent); color: var(--accent-ink); }