:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --text: #1d1b19;
  --muted: #6b655e;
  --border: #e2ddd5;
  --accent: #8b1e1e;
  --accent-soft: #f3e3e1;
  --chip: #ece8e1;
  --row-hover: #faf8f5;
  --heard: 0.5;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121113;
    --surface: #1a191c;
    --text: #e8e4de;
    --muted: #9a948c;
    --border: #2d2b30;
    --accent: #e0645c;
    --accent-soft: #3a1d1d;
    --chip: #2a282d;
    --row-hover: #201f23;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

.top { padding: 20px 24px 4px; }
.top h1 { margin: 0; font: 600 26px/1.2 Georgia, "Times New Roman", serif; letter-spacing: 0.01em; }
.top h1 span { color: var(--accent); }
.meta { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.controls {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 12px 24px 10px;
  border-bottom: 1px solid var(--border);
}
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
#q {
  flex: 1; min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
input:focus-visible, select:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.facet label, .selects label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.facet input, .selects select {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.selects { display: flex; gap: 10px; grid-column: 1 / -1; }
.selects label { flex: 0 1 180px; }
.series { margin-top: 3px; }
.series .chip { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.series .chip::before { content: "series · "; opacity: 0.7; }
.selects label { margin: 0; }
.selects select { margin-top: 3px; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px;
  border: 0; border-radius: 999px;
  background: var(--chip);
  font-size: 12.5px; line-height: 1.6;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: var(--accent-soft); }
.chips .chip { background: var(--accent-soft); color: var(--accent); }
.chips .chip::after { content: "×"; font-weight: 600; }

.actions { margin-top: 10px; flex-wrap: wrap; }
.count { color: var(--muted); font-size: 13px; }
.btn {
  padding: 6px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 13.5px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 4px);
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.15);
}

main { padding: 0 24px 40px; }
table { width: 100%; border-collapse: collapse; margin-top: 4px; }
th {
  position: sticky; top: var(--controls-h, 0); z-index: 2;
  background: var(--bg);
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 10px 8px 6px;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--text); }
th[aria-sort="ascending"]::after { content: " ↑"; }
th[aria-sort="descending"]::after { content: " ↓"; }
td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: var(--row-hover); }
tr.heard .c-title, tr.heard .c-meta { opacity: var(--heard); }
tr.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } }
.c-heard { width: 32px; text-align: center; }
.c-heard input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; margin: 2px 0 0; }
.c-title a { font-weight: 550; text-decoration: none; }
.c-title a:hover { text-decoration: underline; color: var(--accent); }
.c-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.badge { display: inline-block; margin-left: 6px; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; vertical-align: 1px; }
.list { display: flex; flex-wrap: wrap; gap: 3px; }
.dim { color: var(--muted); }
details.stories summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 2px; }
details.stories ol { margin: 4px 0 0; padding-left: 20px; font-size: 13.5px; }
details.stories li { margin: 2px 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.only-mobile { display: none; }
.m-label { display: none; }

@media (max-width: 960px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .selects label { flex: 1; }
}

/* Compact card layout on phones */
@media (max-width: 720px) {
  .top { padding: 14px 16px 2px; }
  .top h1 { font-size: 21px; }
  .controls { padding: 10px 16px 8px; }
  main { padding: 0 16px 32px; }
  .only-mobile { display: inline-block; }
  .filters { display: none; grid-template-columns: 1fr; }
  .filters.open { display: grid; }
  .selects { flex-wrap: wrap; }
  .selects label { flex: 1 1 30%; }

  thead { display: none; }
  table, tbody { display: block; }
  tbody tr {
    display: grid;
    grid-template-columns: 30px auto minmax(0, 1fr) auto;
    grid-template-areas:
      "heard title  title title"
      ".     author narr  narr"
      ".     types  types meta";
    column-gap: 6px; row-gap: 3px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  td { display: block; padding: 0; border: 0; }
  td.c-heard { grid-area: heard; text-align: left; width: auto; }
  td.c-title { grid-area: title; }
  td.c-author { grid-area: author; font-size: 13.5px; }
  td.c-narr { grid-area: narr; font-size: 13.5px; }
  td.c-narr .list::before { content: "read by"; color: var(--muted); font-size: 12px; align-self: center; margin-right: 2px; }
  td.c-narr .list:empty::before { content: none; }
  td.c-types { grid-area: types; }
  td.c-meta { grid-area: meta; font-size: 12.5px; align-self: end; }
  td.c-dur { display: none; }
  .m-label { display: inline; }
  .chip { font-size: 12px; }
}

/* Facet type-ahead */
.facet { position: relative; }
.suggest {
  position: absolute; z-index: 20; left: 0; right: 0; top: 58px;
  max-height: 280px; overflow-y: auto;
  margin: 0; padding: 4px 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}
.suggest li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 10px; cursor: pointer; font-size: 14px;
}
.suggest li.active, .suggest li[data-i]:hover { background: var(--accent-soft); }
.suggest li .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.suggest li.none { color: var(--muted); cursor: default; }
