:root {
  color-scheme: light dark;
  --bg: #f7f5f0;
  --panel: #ffffff;
  --ink: #171717;
  --muted: #67625a;
  --line: #d9d3c8;
  --line-strong: #b9b09f;
  --field: #fffefa;
  --table-head: #ece7dc;
  --row-hover: #faf8f3;
  --table-heading: #34302a;
  --accent: #14614f;
  --link: #8d3527;
  --focus: #d5a21b;
  --shadow: 0 18px 42px rgba(28, 24, 18, 0.09);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11100e;
    --panel: #1b1916;
    --ink: #f2eee7;
    --muted: #b9afa0;
    --line: #39342d;
    --line-strong: #5a5146;
    --field: #12110f;
    --table-head: #25211c;
    --row-hover: #221f1b;
    --table-heading: #e8dfd1;
    --accent: #4cae91;
    --link: #ee9c84;
    --focus: #e2b83d;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

a {
  color: var(--link);
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 34px clamp(18px, 4vw, 56px) 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

h1 {
  max-width: 860px;
  margin: 6px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.1rem, 4vw, 4.3rem);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 0.97;
}

.source-link {
  color: var(--link);
  font-size: inherit;
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.download-link {
  flex: 0 0 auto;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  padding: 11px 15px;
  font-size: 0.92rem;
  font-weight: 800;
  text-decoration: none;
}

main {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 34px) 46px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(520px, 0.9fr);
  gap: 14px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.search-control input,
select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--field);
  color: var(--ink);
  padding: 0 12px;
}

.search-control input {
  font-size: 1.02rem;
}

.search-control input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.filters {
  display: grid;
  grid-template-columns: 120px 120px minmax(260px, 1fr);
  gap: 12px;
}

.summary {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin: 18px 2px 10px;
  color: var(--muted);
  font-size: 0.95rem;
}

.summary p {
  margin: 0;
}

.results-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 288px);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--table-head);
}

th {
  border-bottom: 1px solid var(--line-strong);
  text-align: left;
}

th button {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--table-heading);
  padding: 12px 14px;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
}

th button::after {
  content: "↕";
  float: right;
  color: var(--muted);
  font-weight: 700;
}

th button.active.asc::after {
  content: "↑";
  color: var(--accent);
}

th button.active.desc::after {
  content: "↓";
  color: var(--accent);
}

td {
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

tbody tr:hover {
  background: var(--row-hover);
}

.date-cell {
  width: 118px;
  color: var(--muted);
  font-weight: 800;
}

.entry-cell {
  width: 45%;
}

.entry-toggle {
  display: -webkit-box;
  width: 100%;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  font-weight: 700;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}

.entry-toggle:hover {
  color: var(--link);
}

tr.expanded .entry-toggle {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
  line-clamp: unset;
}

.citation-cell {
  width: 20%;
  color: var(--muted);
}

.source-cell {
  width: 18%;
}

.source-cell a {
  font-weight: 800;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.empty {
  padding: 42px 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .site-header,
  .summary {
    display: block;
  }

  .download-link {
    display: inline-block;
    margin-top: 18px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .filters label:last-child {
    grid-column: 1 / -1;
  }

  .summary p + p {
    margin-top: 8px;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .site-header {
    padding-top: 24px;
  }

  main {
    padding-inline: 10px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    padding: 14px;
    border-bottom: 1px solid var(--line);
  }

  td {
    border: 0;
    padding: 3px 0;
  }

  .date-cell {
    display: inline-block;
    width: auto;
    margin-right: 8px;
  }

  .citation-cell,
  .source-cell {
    margin-top: 8px;
    font-size: 0.9rem;
  }

  .entry-toggle {
    display: block;
    overflow: visible;
    -webkit-line-clamp: unset;
    line-clamp: unset;
  }
}
