:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --text: #1b2420;
  --muted: #55625b;
  --border: #d6ddd7;
  --primary: #1d6b4f;
  --primary-hover: #155440;
  --primary-text: #ffffff;
  --focus: #e3a41b;
  --ok: #1d6b4f;
  --ok-bg: #e3f1ea;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --bad: #9b2c2c;
  --bad-bg: #fbe9e7;
  --info-bg: #e8eef9;
  --info: #2b4c8c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 40, 30, 0.06), 0 2px 8px rgba(20, 40, 30, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111613;
    --surface: #1a211d;
    --surface-2: #222b26;
    --text: #e6ece8;
    --muted: #a3b0a8;
    --border: #34403a;
    --primary: #5cc29a;
    --primary-hover: #7ad2ae;
    --primary-text: #0d1a14;
    --ok: #7ad2ae;
    --ok-bg: #1d3329;
    --warn: #f0c46c;
    --warn-bg: #3a2f17;
    --bad: #f2a29a;
    --bad-bg: #3b2220;
    --info-bg: #1e2a40;
    --info: #a9c1f0;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111613;
  --surface: #1a211d;
  --surface-2: #222b26;
  --text: #e6ece8;
  --muted: #a3b0a8;
  --border: #34403a;
  --primary: #5cc29a;
  --primary-hover: #7ad2ae;
  --primary-text: #0d1a14;
  --ok: #7ad2ae;
  --ok-bg: #1d3329;
  --warn: #f0c46c;
  --warn-bg: #3a2f17;
  --bad: #f2a29a;
  --bad-bg: #3b2220;
  --info-bg: #1e2a40;
  --info: #a9c1f0;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.error { color: var(--bad); }

/* Header & footer */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand svg { color: var(--primary); }
.tagline { color: var(--muted); font-size: 0.875rem; }
.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 24px 0 40px; font-size: 0.875rem; }

/* Intro */
.intro { padding: 32px 0 8px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.25rem); line-height: 1.2; margin: 0 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; margin: 0 0 12px; line-height: 1.3; }
h3 { font-size: 1.05rem; margin: 0; line-height: 1.35; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 46em; margin: 0 0 16px; }
.notice { background: var(--info-bg); color: var(--text); border-left: 4px solid var(--info); padding: 12px 14px; border-radius: 6px; margin: 0; max-width: 50em; }

/* Cards & form */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin: 24px 0; }
fieldset { border: 0; margin: 0 0 22px; padding: 0; min-width: 0; }
legend { font-weight: 650; margin-bottom: 10px; padding: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: var(--primary-text); font-size: 0.85rem; font-weight: 700; flex: none; }
.optional { font-weight: 400; color: var(--muted); font-size: 0.875rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: -4px 0 10px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices.stacked { flex-direction: column; align-items: flex-start; }
.choice { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); cursor: pointer; min-height: 44px; }
.choices.stacked .choice { border-radius: var(--radius); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--ok-bg); font-weight: 600; }
.choice input { accent-color: var(--primary); width: 18px; height: 18px; margin: 0; flex: none; }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--primary); background: var(--surface); color: var(--primary); cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: var(--ok-bg); color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { border-color: var(--border); color: var(--text); }
.btn.small { padding: 6px 12px; font-size: 0.9rem; min-height: 36px; }

/* Results */
.results-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.results-head h2 { margin-bottom: 4px; }
.results-head h2:focus { outline: none; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.group { margin: 32px 0; }
.opp { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin: 12px 0; box-shadow: var(--shadow); }
.opp.compact { padding: 14px 18px; box-shadow: none; }
.opp-head h3 a { color: var(--text); }
.opp-head h3 a:hover { color: var(--primary); }
.meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 4px; }
.provider { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }
.amount { font-weight: 650; }
.badge { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.open { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.soon { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.upcoming { background: var(--info-bg); color: var(--info); border-color: transparent; }
.summary { margin: 10px 0; }
.reasons, .cautions, .blockers { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 4px; font-size: 0.92rem; }
.reasons li::before { content: "✓"; color: var(--ok); font-weight: 700; margin-right: 8px; }
.cautions li { color: var(--warn); }
.cautions li::before { content: "!"; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--warn-bg); font-weight: 700; font-size: 0.75rem; margin-right: 8px; }
.blockers li { color: var(--bad); }
.blockers li::before { content: "✕"; font-weight: 700; margin-right: 8px; }
.notes { font-size: 0.9rem; color: var(--muted); margin: 8px 0; }
.opp-foot { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; border-top: 1px solid var(--border); margin-top: 14px; padding-top: 12px; font-size: 0.85rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.report { font-size: 0.85rem; }

.not-matched > summary { cursor: pointer; font-weight: 650; font-size: 1.05rem; padding: 12px 0; }

/* SBIR & lenders */
.sbir { margin: 12px 0 4px; }
.sbir-panel { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 12px; }
.topic-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.topic-tools input, .topic-tools select { font: inherit; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); min-height: 44px; }
.topic-tools input { flex: 1 1 240px; }
.topics { padding-left: 20px; margin: 8px 0; display: grid; gap: 10px; }
.topics p { margin: 2px 0 0; font-size: 0.88rem; }
.lenders { list-style: none; padding: 0; margin: 12px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.lenders li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 4px; font-size: 0.92rem; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 0.75rem; background: var(--surface-2); border-radius: 4px; padding: 1px 6px; color: var(--muted); }

.help-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.help-list li { display: grid; gap: 4px; font-size: 0.92rem; }

@media (max-width: 560px) {
  .card { padding: 16px; }
  .opp { padding: 14px 16px; }
  .choice { flex: 1 1 100%; border-radius: var(--radius); }
  .form-actions .btn { flex: 1 1 100%; }
  .tagline { display: none; }
}

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #333; --border: #bbb; --shadow: none; }
  .site-header .tagline, .form, .toolbar, .skip, .sbir, .report, .topic-tools, .lenders + button, .actions { display: none !important; }
  .not-matched { display: none; }
  .opp, .lenders li { break-inside: avoid; }
  .opp-head h3 a::after { content: " (" attr(href) ")"; font-weight: 400; font-size: 0.8rem; word-break: break-all; }
  body { font-size: 12pt; }
  a { color: #000; }
}
