:root {
  color-scheme: light;
  --bg: #e4ebf0;
  --sheet: #f7fafb;
  --ink: #163044;
  --muted: #4e6270;
  --line: #d3dee6;
  --accent: #1c5d7a;
  --accent-fill: #1c5d7a;
  --accent-press: #164e66;
  --on-accent: #f4fbfd;
  --danger: #9a3b3b;
  --danger-fill: #8d3333;
  --danger-press: #6e2c2c;
  --radius: 2px;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --space: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1419;
  --sheet: #172027;
  --ink: #d7e4ea;
  --muted: #8aa0ab;
  --line: #2c3c46;
  --accent: #8fcae0;
  --accent-fill: #0e4d66;
  --accent-press: #0b3e52;
  --on-accent: #f4fbfd;
  --danger: #f0b4b4;
  --danger-fill: #6e2c2c;
  --danger-press: #8a3a3a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1419;
    --sheet: #172027;
    --ink: #d7e4ea;
    --muted: #8aa0ab;
    --line: #2c3c46;
    --accent: #8fcae0;
    --accent-fill: #0e4d66;
    --accent-press: #0b3e52;
    --on-accent: #f4fbfd;
    --danger: #f0b4b4;
    --danger-fill: #6e2c2c;
    --danger-press: #8a3a3a;
  }
}

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, .figure, .brand span {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.02em;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 2.4vw + 1rem, 3.25rem);
  line-height: 1.05;
}

h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

p { margin: 0; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: 16px;
  top: -48px;
  background: var(--accent-fill);
  color: var(--on-accent);
  padding: 8px 12px;
  z-index: 2;
}
.skip:focus { top: 8px; }

.mast {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.25rem;
}
.brand-mark { width: 22px; height: 22px; }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 4px 0;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] {
  color: var(--ink);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.mast-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-left: auto;
}
.who { color: var(--muted); font-variant-numeric: tabular-nums; }

.sheet {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 16px 80px;
  border-left: 3px solid var(--accent-fill);
}

.page-head { display: grid; gap: 8px; margin-bottom: 32px; }
.kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.lede { max-width: 42rem; color: var(--muted); }
.lede.narrow { max-width: 38rem; margin-bottom: 24px; }
.page-head .button { justify-self: start; margin-top: 8px; }

.figures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 0 0 40px;
  padding: 0;
  list-style: none;
}
.figure {
  display: block;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.figure.is-alert { color: var(--danger); }
.figure-label { display: block; margin-top: 8px; color: var(--muted); }

.block { margin-top: 40px; }
.block-head, .filters {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 8px;
}
.filters { justify-content: flex-start; margin-bottom: 16px; }
.filters a { color: var(--muted); text-decoration: none; }
.filters a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }

.ledger { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.ledger li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 24px;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.ledger-name {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}
.ledger-name:hover { color: var(--accent); }
.meta { color: var(--muted); font-size: 0.95rem; }
.due, .money, .figure, .budget strong {
  font-variant-numeric: tabular-nums;
}
.due { margin: 0; color: var(--muted); text-align: right; }
.due.is-overdue { color: var(--danger); }
.due.is-soon, .due.is-later { color: var(--accent); }
.money { margin: 0; text-align: right; }
.budget { margin: 0 0 16px; color: var(--muted); }
.budget strong { color: var(--ink); font-weight: 600; }
.empty { color: var(--muted); max-width: 42rem; }
.notes { max-width: 42rem; margin-top: 16px; }

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 32px;
  margin: 0;
}
.facts dt { color: var(--muted); font-size: 0.95rem; }
.facts dd { margin: 4px 0 0; }
.mono { font-family: var(--mono); font-size: 0.95rem; }

.form { display: grid; gap: 16px; max-width: 36rem; }
.form.attach { margin-top: 16px; }
.field { display: grid; gap: 8px; }
.field label { font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.95rem; }
.field-error { color: var(--danger); margin: 0; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
textarea { min-height: 120px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:disabled, select:disabled, textarea:disabled, button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button, .text-button {
  font: inherit;
  border-radius: var(--radius);
  cursor: pointer;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent-fill);
  background: var(--accent-fill);
  color: var(--on-accent);
  text-decoration: none;
  padding: 10px 16px;
}
.button:hover, .button:active { background: var(--accent-press); border-color: var(--accent-press); color: var(--on-accent); }
.button-danger { background: var(--danger-fill); border-color: var(--danger-fill); }
.button-danger:hover, .button-danger:active { background: var(--danger-press); border-color: var(--danger-press); color: var(--on-accent); }
.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 8px 0;
  text-decoration: none;
}
.text-button:hover { text-decoration: underline; text-underline-offset: 3px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.power { display: flex; gap: 12px; }

.messages { display: grid; gap: 8px; margin-bottom: 24px; }
.message { margin: 0; padding: 8px 12px; border-left: 2px solid var(--accent); }
.message.error { border-left-color: var(--danger); }

@media (prefers-reduced-motion: no-preference) {
  a, button, input, select, textarea {
    transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out;
  }
}

@media (min-width: 768px) {
  .mast, .sheet { padding-left: 32px; padding-right: 32px; }
  .sheet { padding-top: 48px; }
}

@media (max-width: 640px) {
  .ledger li { grid-template-columns: 1fr; }
  .due, .money { text-align: left; }
  .facts { grid-template-columns: 1fr; }
  .mast-tools { margin-left: 0; width: 100%; }
}

@media (min-width: 1440px) {
  .mast, .sheet { max-width: 1120px; }
}
