:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #63635e;
  --border: #e0e0da;
  /* Input edges: at least 3:1 against --surface and --bg (WCAG 1.4.11), unlike --border. */
  --control-border: #86867f;
  --accent: #c23300;
  --accent-text: #ffffff;
  --accent-soft: #fdeee7;
  --good: #1d7a46;
  --good-soft: #e5f4ea;
  --info: #1f5c9e;
  --info-soft: #e6eef8;
  --error: #b42318;
  --error-soft: #fdecea;
  --bar-bg: #ecece8;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1e1e1c;
    --text: #ececea;
    --muted: #a0a09a;
    --border: #33332f;
    --control-border: #74746e;
    --accent: #ff6a33;
    --accent-text: #1a0a03;
    --accent-soft: #3a2117;
    --good: #5fcf8e;
    --good-soft: #17301f;
    --info: #8cb8f0;
    --info-soft: #172537;
    --error: #ff8a80;
    --error-soft: #3a1a18;
    --bar-bg: #2a2a27;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 860px; margin: 0 auto; padding: 32px 16px 48px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 6px; letter-spacing: -0.01em; }
.lede { margin: 0 0 20px; color: var(--muted); }
a { color: var(--accent); }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

input, button, select { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="number"], select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  padding: 9px 11px;
  min-width: 0;
}
::placeholder { color: var(--muted); opacity: 1; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
input:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[aria-invalid="true"] { border-color: var(--error); }
button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:disabled { opacity: .55; cursor: default; }
button.link {
  background: none; border: 0; padding: 0; color: var(--accent);
  text-decoration: underline; font-size: inherit;
}

.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

#options { margin: 12px 0 0; }
#scheduler { margin: 10px 0 0; }
#scheduler > summary { cursor: pointer; color: var(--muted); width: fit-content; max-width: 100%; }
#queue-summary { color: var(--text); }
.scheduler-body { margin-top: 12px; }
textarea {
  display: block; width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--control-border); border-radius: 8px; padding: 9px 11px; resize: vertical;
}
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.queue-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.inline-check { display: flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); }
#queue-add-note:empty { display: none; }
.queue-list { list-style: none; margin: 12px 0 0; padding: 0; }
.queue-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 10px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  margin-bottom: 6px; font-size: .9rem;
}
.queue-item[data-status="running"] { border-color: var(--accent); }
.queue-ref { overflow-wrap: anywhere; }
.queue-note { grid-column: 2 / -1; color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.queue-note:empty { display: none; }
.queue-actions { display: flex; gap: 6px; }
.queue-actions button { padding: 3px 9px; font-size: .82rem; }
.pill.running { background: var(--accent); color: var(--accent-text); font-weight: 600; }
#options > summary { cursor: pointer; color: var(--muted); width: fit-content; max-width: 100%; }
#options-summary { color: var(--text); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 16px;
  margin-top: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.field > label { color: var(--muted); }
.field small { color: var(--muted); font-size: .8rem; }
.field small:empty { display: none; }
.field > label.inline-check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.field.check { justify-content: flex-end; }
.field.check label { display: flex; align-items: center; gap: 8px; min-height: 42px; color: var(--text); }
.hint { font-size: .85rem; color: var(--muted); margin: 14px 0 0; }
.badges { margin-top: 14px; font-size: .9rem; }
.badges legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.badges .legend-note { font-weight: 400; color: var(--muted); }
.badge-rule { display: flex; gap: 8px; align-items: baseline; margin: 6px 0; line-height: 2; }
.badge-rule .pill { flex: none; min-width: 7.4em; text-align: center; }
.badges input[type="number"] { width: 4.2em; padding: 2px 6px; line-height: 1.3; }
.badges small { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.facts { margin: 0 0 6px; font-size: .85rem; color: var(--muted); }

.error { background: var(--error-soft); color: var(--error); padding: 10px 12px; border-radius: 8px; margin-top: 16px; }
.error p { margin: 0; }
.error details { margin-top: 6px; font-size: .85rem; overflow-wrap: anywhere; }
.error summary { cursor: pointer; }

#status { margin-top: 20px; }
.breakdown { margin-top: 8px; font-size: .85rem; color: var(--muted); }
.breakdown > summary { cursor: pointer; width: fit-content; }
.breakdown ul { margin: 6px 0 0; padding-left: 20px; overflow-wrap: anywhere; }
.status-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; color: var(--muted); font-size: .92rem; min-height: 40px; }
.confirm { background: var(--info-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.confirm p { margin: 0 0 8px; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.bar { height: 6px; background: var(--bar-bg); border-radius: 3px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-top: 20px; }
.post-sub { font-size: .85rem; color: var(--muted); }
.post-title { display: block; font-weight: 600; font-size: 1.05rem; color: var(--text); text-decoration: none; margin: 2px 0; overflow-wrap: anywhere; }
.post-title:hover { text-decoration: underline; }
.post-meta { font-size: .85rem; color: var(--muted); }

#results { margin-top: 20px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 200px; }
.actions { display: flex; gap: 8px; }
.toolbar-2 { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.inline input { width: 4.5em; padding: 4px 8px; margin: 0 4px; }
.nowrap { white-space: nowrap; }
#filter-note:empty { display: none; }
.legend { font-size: .85rem; color: var(--muted); margin: 10px 0 12px; }

.user {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  /* Long lists: let the browser skip rendering cards that are off screen. */
  content-visibility: auto;
  contain-intrinsic-size: auto 78px;
}
.user > summary {
  list-style: none;
  cursor: pointer;
  position: relative;
  padding: 12px 14px 12px 34px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
}
.user > summary::-webkit-details-marker { display: none; }
/* A chevron, so it's clear the card opens. */
.user > summary::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 19px;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .15s;
}
.user[open] > summary::before { transform: rotate(45deg); }
.user > summary:focus-visible { outline-offset: -2px; border-radius: var(--radius); }
.user[open] > summary { border-bottom: 1px solid var(--border); }
.name { font-weight: 600; overflow-wrap: anywhere; }
.stats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { font-size: .8rem; padding: 2px 8px; border-radius: 999px; background: var(--bar-bg); color: var(--muted); white-space: nowrap; }
.pill.new { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill.occasional { background: var(--info-soft); color: var(--info); font-weight: 600; }
.pill.regular { background: var(--good-soft); color: var(--good); font-weight: 600; }
.pill.saved { background: transparent; border: 1px dashed var(--border); padding: 1px 7px; }
.pill.err { background: var(--error-soft); color: var(--error); }
.top { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panel { padding: 8px 14px 10px; }
.panel-links { margin: 0 0 6px; font-size: .9rem; }
.panel .empty { margin: 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.subs-wrap { max-height: 420px; overflow: auto; }
.subs { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.subs th, .subs td { padding: 5px 6px; text-align: right; border-bottom: 1px solid var(--border); }
.subs th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 500; }
.subs th:first-child, .subs td:first-child { text-align: left; overflow-wrap: anywhere; }
.subs tr.target td { color: var(--accent); font-weight: 600; }
/* Counts link to Arctic Shift; underline them only on hover so the table reads as numbers. */
.subs td:not(:first-child) a { color: inherit; text-decoration: none; border-bottom: 1px dotted currentColor; }
.subs td:not(:first-child) a:hover { text-decoration: underline; border-bottom: 0; }
.subs tr:last-child td { border-bottom: 0; }

#saved { margin-top: 36px; }
#saved h2 { font-size: 1.15rem; margin: 0; }
#saved .count { color: var(--muted); font-weight: 400; font-size: .95rem; }
.saved-list { list-style: none; margin: 0; padding: 0; }
.scan {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: start;
}
.scan[aria-current="true"] { border-color: var(--accent); }
.scan-title {
  display: block; background: none; border: 0; padding: 0; margin: 2px 0 4px; text-align: left;
  font-weight: 600; font-size: 1rem; color: var(--text); white-space: normal; overflow-wrap: anywhere;
}
.scan-title:hover:not(:disabled) { text-decoration: underline; }
.scan-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.scan-meta { font-size: .85rem; color: var(--muted); margin-top: 6px; overflow-wrap: anywhere; }
.scan-actions { display: flex; gap: 6px; }
.scan-actions button { padding: 5px 10px; font-size: .85rem; }

footer { margin-top: 40px; font-size: .82rem; color: var(--muted); }

@media (max-width: 520px) {
  .row { flex-direction: column; }
  .user > summary { grid-template-columns: 1fr; }
  .stats { justify-content: flex-start; }
  .actions { flex: 1 1 100%; }
  .actions button { flex: 1; }
  .scan { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  #bar-fill, .user > summary::before { transition: none; }
}

.saved-tools { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.about { margin-top: 28px; border-top: 1px solid var(--border); padding-top: 12px; }
.about summary { cursor: pointer; font-weight: 600; }
.about-body { font-size: .9rem; }
.about-body ul { padding-left: 1.2em; }
.about-body li { margin-bottom: 6px; }
