:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --ink: #1d1c1a;
  --ink-2: #5d5b55;
  --line: #ded9d0;
  --accent: #1f5f7a;
  --accent-ink: #ffffff;
  --warn-bg: #fdf3e0;
  --warn-ink: #7a4d0a;
  --bad-bg: #fbe9e7;
  --bad-ink: #8c2f22;
  --good-bg: #e8f2ec;
  --good-ink: #1f5c3d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 18px rgba(0,0,0,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2124;
    --surface-2: #272a2e;
    --ink: #e9e7e3;
    --ink-2: #a7a49d;
    --line: #35383d;
    --accent: #7fc4e0;
    --accent-ink: #10242c;
    --warn-bg: #3a2f14;
    --warn-ink: #f0cf8a;
    --bad-bg: #3a201c;
    --bad-ink: #f3b3a8;
    --good-bg: #1b2f26;
    --good-ink: #a7dcc0;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.skip {
  position: absolute; left: -9999px;
}
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 22px 0 16px;
  margin-bottom: 20px;
}
.topbar h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--ink-2); }
.freshness { margin: 10px 0 0; font-size: .85rem; color: var(--ink-2); }
.freshness.stale {
  background: var(--warn-bg); color: var(--warn-ink);
  padding: 6px 10px; border-radius: var(--radius); display: inline-block;
}

/* ---------- controls ---------- */

.controls {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
/* auto-fit rather than a fixed count: the row holds four fieldsets now, and
 * a fixed three stranded the fourth alone on a second line. */
.row.facets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  align-items: start;
}
.row:last-child { margin-bottom: 0; }
.grow { flex: 1 1 260px; }

label { display: block; font-size: .82rem; }
label > span { display: block; color: var(--ink-2); margin-bottom: 3px; }

input[type=search], input[type=number], input[type=date], select {
  font: inherit; font-size: .95rem;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 9px; width: 100%;
}
input[type=number] { width: 5.5em; }
input[type=date] { width: auto; }

fieldset {
  flex: 1 1 240px;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px 10px; margin: 0; min-width: 0;
}
legend { font-size: .78rem; color: var(--ink-2); padding: 0 4px; }
.hint { font-weight: 400; opacity: .8; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: .82rem;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .n { opacity: .65; font-variant-numeric: tabular-nums; margin-left: 4px; }

/* The two date inputs size to their own content by default (~150px each),
 * which overflowed the fieldset once the facets row gained a fourth column.
 * They shrink and wrap instead, so the box holds them at any column width. */
.dates { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
/* `display: flex` beats the user agent's rule for the hidden attribute, so
 * the inputs stayed on screen however often the attribute was set. */
.dates[hidden] { display: none; }
.dates label { flex: 1 1 130px; min-width: 0; }
.dates input[type=date] { width: 100%; }

.row.actions { align-items: center; gap: 10px; }
#count { margin: 0; flex: 1 1 auto; font-size: .9rem; color: var(--ink-2); }

button.ghost, .card-foot button, .card-foot a {
  font: inherit; font-size: .85rem;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 11px; cursor: pointer; text-decoration: none;
}
button.ghost:hover, .card-foot button:hover, .card-foot a:hover { border-color: var(--accent); }

/* ---------- results ---------- */

#results { display: grid; gap: 14px; }
.month { margin: 6px 0 0; font-size: 1.05rem; color: var(--ink-2); border-bottom: 1px solid var(--line); padding-bottom: 4px; }

.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 13px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
.card.saved { border-color: var(--accent); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.when { font-size: .85rem; font-weight: 600; color: var(--accent); }
.card h3 { margin: 0; font-size: 1.02rem; line-height: 1.3; }
.card h3 a { color: var(--ink); text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.card .meta, .card .summary, .card .tags { margin: 0; font-size: .85rem; color: var(--ink-2); }
.card .summary {
  color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }

.badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.badge {
  font-size: .72rem; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge.free { background: var(--good-bg); color: var(--good-ink); }
.badge.age-eligible { background: var(--good-bg); color: var(--good-ink); }
.badge.age-unknown { background: var(--warn-bg); color: var(--warn-ink); }
.badge.alert { background: var(--bad-bg); color: var(--bad-ink); }
.badge.verified { background: var(--good-bg); color: var(--good-ink); }
.tag {
  display: inline-block; font-size: .74rem; margin: 2px 4px 0 0;
  padding: 1px 7px; border: 1px solid var(--line); border-radius: 999px;
}
/* Subject and ways-of-working are different axes, so they read differently. */
.tag.style { border-style: dashed; color: var(--accent); }
.tag.source { opacity: .7; }
.sub {
  display: block; font-size: .78rem; color: var(--ink-2); margin-top: 2px;
}
.sub.warn { color: var(--warn-ink); }

table { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--surface); }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
td a { color: var(--ink); }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

.empty { padding: 26px; text-align: center; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- health panel ---------- */

.health { margin: 26px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.health summary { cursor: pointer; font-size: .9rem; color: var(--ink-2); }
.health table { margin-top: 10px; }
.note { font-size: .82rem; color: var(--ink-2); }
.note code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .95em; background: var(--surface-2);
  padding: 1px 5px; border-radius: 4px;
}
.status-ok { color: var(--good-ink); }
.status-bad { color: var(--bad-ink); font-weight: 600; }

footer { margin: 30px 0; font-size: .82rem; color: var(--ink-2); }
footer a { color: var(--accent); }

@media (max-width: 560px) {
  .row.facets { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .row { gap: 10px; }
  fieldset { flex-basis: 100%; }
}
