:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --ink: #1a1c20;
  --muted: #5b616b;
  --line: #e0e1dd;
  --accent: #0f6b5c;
  --accent-bg: #e4f2ee;
  --warn: #8a5a00;
  --warn-bg: #fbf1dc;
  --bad: #b3261e;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121416; --surface: #1b1e21; --ink: #eceef0; --muted: #a0a7b0; --line: #2d3136;
    --accent: #6fd0bd; --accent-bg: #173029; --warn: #f0c060; --warn-bg: #3a2f14; --bad: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #121416; --surface: #1b1e21; --ink: #eceef0; --muted: #a0a7b0; --line: #2d3136;
  --accent: #6fd0bd; --accent-bg: #173029; --warn: #f0c060; --warn-bg: #3a2f14; --bad: #ff8a80;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 17px/1.5 "Barlow", system-ui, sans-serif; }
.wrap { max-width: 860px; margin: 0 auto; padding: 40px 16px 64px; }
h1 { font-size: 2.1rem; line-height: 1.15; font-weight: 700; margin: 0 0 10px; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 600; margin: 32px 0 8px; }
h3 { font-size: 1rem; font-weight: 600; margin: 24px 0 6px; }
a { color: var(--accent); }
.kicker { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.lead { font-size: 1.15rem; margin: 0 0 12px; }
.privacy { margin: 0; color: var(--muted); }
.privacy strong { color: var(--ink); }
.hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }

input[type="text"], select {
  font: inherit; font-size: 1rem; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); min-width: 0;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input.bad { border-color: var(--bad); }
input:disabled { opacity: 0.55; }

.panel {
  margin: 28px 0 8px; padding: 18px 20px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px 28px;
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.field > label, legend, .label { font-weight: 600; display: block; margin-bottom: 6px; padding: 0; }
.field > input { width: 100%; max-width: 220px; }
.field > .opt, .opt { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 4px 0; cursor: pointer; }
.opt .hint, .field > .opt .hint { flex-basis: 100%; margin: 0 0 0 24px; }
.inline { display: inline-flex; align-items: center; gap: 4px; }
.inline input { width: 72px; }
.switch { display: flex; gap: 8px; align-items: center; cursor: pointer; }

.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.line {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin: 10px 0; border-left: 4px solid var(--line);
}
.line[data-cat="equipment"], .line[data-cat="capital"], .line[data-cat="patient"], .line[data-cat="rental"],
.line[data-cat="tuition"], .line[data-cat="scholarships"], .line[data-cat="participant"] { border-left-color: var(--muted); }
.line[data-cat="subaward"] { border-left-color: var(--accent); }
.line-top { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.line-years { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; margin-top: 10px; }
.amt { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; color: var(--muted); }
.amt input { width: 100%; text-align: right; font-variant-numeric: tabular-nums; }
.amt.unit span { color: var(--ink); font-weight: 500; }

button { font: inherit; cursor: pointer; }
.button, .add {
  padding: 9px 16px; border-radius: 8px; font-weight: 600; border: 1px solid var(--accent);
}
.button { background: var(--accent); color: var(--surface); }
.add { background: transparent; color: var(--accent); margin-top: 4px; }
.ghost, .remove { background: transparent; border: 0; color: var(--muted); text-decoration: underline; padding: 4px; font-size: 0.9rem; }
.ghost:hover, .remove:hover { color: var(--ink); }

.result { margin-top: 8px; }
.headline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat.key { background: var(--accent-bg); border-color: var(--accent); }
.stat-label { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.stat-value { display: block; font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.msg { margin: 6px 0; padding: 8px 12px; border-radius: 8px; font-size: 0.95rem; }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.note { background: var(--surface); border: 1px solid var(--line); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th[scope="row"], thead th:first-child { text-align: left; font-weight: 500; }
thead th { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
tr.strong td, tr.strong th { font-weight: 600; }
tr.total td, tr.total th { font-weight: 700; border-bottom: 0; }
td[colspan] { text-align: left; color: var(--muted); }

.compare { margin: 16px 0; padding: 12px 14px; border: 1px dashed var(--line); border-radius: var(--radius); }
.compare p { margin: 0; }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.csv-out { width: 100%; min-height: 140px; margin-top: 10px; font: 0.85rem/1.4 ui-monospace, monospace; }
.howto ul { padding-left: 20px; }
.howto li { margin: 6px 0; }

header.site { max-width: 860px; margin: 0 auto; padding: 16px 16px 0; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
header.site .brand { font-weight: 700; color: var(--ink); text-decoration: none; }
header.site nav a { margin-left: 14px; }
footer.site { max-width: 860px; margin: 0 auto; padding: 0 16px 40px; color: var(--muted); font-size: 0.9rem; border-top: 1px solid var(--line); }
.doc p, .doc li { max-width: 680px; }
.note { padding: 10px 14px; background: var(--warn-bg); color: var(--warn); border-radius: 8px; }

@media (max-width: 640px) {
  h1 { font-size: 1.75rem; }
  .wrap { padding-top: 24px; }
  .panel { grid-template-columns: 1fr; padding: 16px; }
  .line-top { grid-template-columns: 1fr auto; }
  .line-top select { grid-column: 1 / -1; grid-row: 2; }
  .line-years { grid-template-columns: 1fr 1fr; }
  .headline { grid-template-columns: 1fr; }
  .stat { display: flex; justify-content: space-between; align-items: baseline; }
  .stat-value { font-size: 1.25rem; }
}

/* /rules/ page: text tables wrap and read left to right */
table.rules th, table.rules td { white-space: normal; text-align: left; vertical-align: top; }
table.rules { min-width: 560px; }
.doc .table-wrap { margin: 12px 0 16px; }
.doc h2 { margin-top: 32px; }
