@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("../fonts/fraunces-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Outfit";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/outfit-latin.woff2") format("woff2");
}

:root {
  --paper: #f3eee6;
  --ink: #1a1714;
  --muted: #5e574e;
  --cream: #fbf8f3;
  --field: #fffdf9;
  --line: #e0d6c8;
  --control-line: #d5cbbd;
  --pine: #1e4a38;
  --pine-deep: #16382b;
  --on-pine: #f4efe6;
  --copper: #9a4a2a;
  --copper-deep: #7a3a20;
  --glow-a: rgba(255, 252, 246, 0.95);
  --glow-b: rgba(210, 180, 145, 0.2);
  --spine: rgba(154, 74, 42, 0.5);
  --card-shadow: 0 1px 0 rgba(255, 255, 255, 0.75) inset, 0 10px 24px rgba(70, 50, 30, 0.05);
  --bar-track: rgba(154, 74, 42, 0.14);
  --banner-good: rgba(30, 74, 56, 0.1);
  --banner-bad: rgba(154, 74, 42, 0.12);
  --pill: rgba(30, 74, 56, 0.08);
  --modal-shade: rgba(36, 28, 20, 0.4);
  --row-hover: rgba(30, 74, 56, 0.035);
  --ghost-hover: rgba(255, 255, 255, 0.45);
  --chart-grid: rgba(28, 25, 21, 0.08);
  --chart-fill: rgba(30, 74, 56, 0.14);
  --tooltip-bg: #1a1714;
  --tooltip-ink: #f4efe6;
  --danger-line: rgba(154, 74, 42, 0.45);
  --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  color-scheme: light;
}

html[data-theme="dark"] {
  --paper: #16130f;
  --ink: #f3eee6;
  --muted: #b7aa9b;
  --cream: #241f1a;
  --field: #2e2822;
  --line: #3f362e;
  --control-line: #5a4e43;
  --pine: #8fceb4;
  --pine-deep: #b7e0d0;
  --on-pine: #14241c;
  --copper: #f0b59a;
  --copper-deep: #f6c7b2;
  --glow-a: rgba(70, 52, 36, 0.55);
  --glow-b: rgba(154, 74, 42, 0.18);
  --spine: rgba(240, 181, 154, 0.55);
  --card-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 28px rgba(0, 0, 0, 0.28);
  --bar-track: rgba(240, 181, 154, 0.18);
  --banner-good: rgba(143, 206, 180, 0.14);
  --banner-bad: rgba(240, 181, 154, 0.14);
  --pill: rgba(143, 206, 180, 0.14);
  --modal-shade: rgba(0, 0, 0, 0.62);
  --row-hover: rgba(243, 238, 230, 0.04);
  --ghost-hover: rgba(255, 255, 255, 0.06);
  --chart-grid: rgba(243, 238, 230, 0.1);
  --chart-fill: rgba(143, 206, 180, 0.22);
  --tooltip-bg: #f3eee6;
  --tooltip-ink: #1a1714;
  --danger-line: rgba(240, 181, 154, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    radial-gradient(1100px 480px at 8% -10%, var(--glow-a), transparent 55%),
    radial-gradient(800px 520px at 110% 8%, var(--glow-b), transparent 50%);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.45;
}

.page {
  width: min(1120px, calc(100% - 20px));
  margin: 0 auto;
  padding: 22px 4px 36px 16px;
  border-left: 2px solid var(--spine);
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 620;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

h1 { margin: 0; font-size: clamp(2.6rem, 12vw, 4.4rem); }

.tagline {
  margin: 8px 0 0;
  max-width: 24rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.35;
}
h2 { margin: 0 0 14px; font-size: clamp(1.6rem, 4vw, 2.1rem); }
h3 { margin: 0 0 12px; font-size: 1.45rem; }

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
}

::selection { background: rgba(30, 74, 56, 0.18); }

.kicker {
  margin: 0 0 4px;
  color: var(--copper);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.mast {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 3px double var(--ink);
}

.mast-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.mast-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
  max-width: 100%;
}

.theme-toggle, .tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--control-line);
  border-radius: 999px;
  background: var(--field);
  color: var(--ink);
  font-weight: 600;
}

.theme-toggle:hover, .tool-btn:hover { background: var(--ghost-hover); }

.signed-in {
  margin: 0;
  align-self: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.signed-in strong { color: var(--ink); font-weight: 600; }

.year-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 118px;
  flex: 0 0 auto;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.views {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.views button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
}

.views button[aria-current="page"] {
  background: var(--pine);
  color: var(--on-pine);
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.notice {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: var(--pine-deep);
  font-weight: 600;
}

.notice:empty { display: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.btn-primary { background: var(--pine); color: var(--on-pine); }
.btn-primary:hover { background: var(--pine-deep); }

.btn-ghost {
  background: transparent;
  border-color: var(--control-line);
  color: var(--ink);
}

.btn-ghost:hover { background: var(--ghost-hover); }

.btn-danger {
  background: transparent;
  border-color: var(--danger-line);
  color: var(--copper);
}

.data-actions .btn { flex: 1 1 100%; white-space: normal; }

.icon { width: 18px; height: 18px; flex: 0 0 auto; }

.view { display: flex; flex-direction: column; gap: 14px; }

.lede, .help, .stat-hint, .empty, .muted {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.lede, .help { margin: 0; }
.help { font-size: 0.92rem; }
.empty { margin: 0; }

.stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.stat, .card, .modal {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
}

.stat { padding: 14px 16px 16px; border-top: 3px solid var(--ink); min-width: 0; }
.stat.income { border-top-color: var(--pine); }
.stat.spend { border-top-color: var(--copper); }

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-value {
  margin: 6px 0 4px;
  font-family: var(--serif);
  font-size: clamp(1.7rem, 6vw, 2.35rem);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}

.stat-hint { margin: 0; font-size: 0.88rem; }

.card { padding: 16px; min-width: 0; }

.chart-grid { display: grid; gap: 12px; }
.chart-box { position: relative; height: 280px; width: 100%; }
.chart-box canvas { display: block; }

.month-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.month-chip {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--cream);
  font-weight: 600;
}

.month-chip[aria-pressed="true"] {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--on-pine);
}

.cat-row { margin-bottom: 12px; }
.cat-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-weight: 600;
}
.bar-track {
  height: 10px;
  border-radius: 99px;
  background: var(--bar-track);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--copper);
}

.balance-brief { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.balance-brief li {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.balance-brief li:last-child { border-bottom: 0; padding-bottom: 0; }
.balance-brief strong { display: block; }
.brief-meta, .brief-value { margin: 2px 0; }
.brief-value {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.value-total {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.7rem, 6vw, 2.2rem);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.group-label {
  margin: 16px 0 8px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
}

.chip-list .btn { margin-left: auto; min-height: 44px; }

.setup-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setup-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.setup-row input,
.setup-row select {
  flex: 1 1 140px;
  min-width: 0;
  max-width: 100%;
}
.setup-row .btn { margin-left: auto; flex: 0 0 auto; }

.two-col { display: grid; gap: 12px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; gap: 12px; }
.form label, .year-field {
  min-width: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 600;
}

.optional { color: var(--muted); font-weight: 500; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--control-line);
  border-radius: 10px;
  background: var(--field);
  font-size: 16px;
}

select.is-uncategorised { color: var(--copper); }
select.is-suggested { box-shadow: inset 3px 0 0 var(--pine); }

input[type="file"] { padding: 8px; }
input[type="file"]::file-selector-button {
  min-height: 36px;
  margin-right: 10px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--pine);
  color: var(--on-pine);
  font: inherit;
  font-weight: 600;
}

.form-error { min-height: 1.2em; margin: 0; color: var(--copper); font-weight: 600; }
.form-error:empty { display: none; }

.banner { margin: 0; padding: 10px 12px; border-radius: 10px; }
.banner.good { background: var(--banner-good); color: var(--pine-deep); }
.banner.bad { background: var(--banner-bad); color: var(--copper-deep); }

.table-wrap { max-width: 100%; overflow-x: auto; }

table.ledger { width: 100%; border-collapse: collapse; }
table.ledger th, table.ledger td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
}
table.ledger th {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
table.ledger .num, .money { font-variant-numeric: tabular-nums; }
table.ledger .num { text-align: right; white-space: nowrap; }
.pos { color: var(--pine); }
.neg { color: var(--copper); }
td.desc { overflow-wrap: anywhere; }
.note { display: block; font-weight: 400; font-size: 0.85rem; }
.uncat { color: var(--copper); font-weight: 600; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--pill);
  color: var(--pine);
  font-size: 0.82rem;
  font-weight: 600;
}

.btn-open, .btn-delete { min-height: 44px; }

.site-footer {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--modal-shade);
}

.modal { width: min(440px, 100%); padding: 18px; }
.modal h2 { font-size: 1.6rem; }
.modal p { margin: 0 0 16px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-actions .btn { flex: 1 1 140px; }

body.modal-open { overflow: hidden; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 520px) {
  .stats.four, .stats.three { grid-template-columns: 1fr 1fr; }
  .month-picker { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (min-width: 700px) {
  .form-grid.tx, .form-grid.bal { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: span 2; }
  .data-actions .btn { flex: 0 1 auto; }
}

@media (min-width: 800px) {
  .stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-box { height: 320px; }
  .page { padding-left: 22px; }
  .form-grid.bal { grid-template-columns: 170px 210px 1fr; }
}

@media (min-width: 980px) {
  .stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .month-picker { grid-template-columns: repeat(12, minmax(0, 1fr)); }
}

@media (min-width: 1040px) {
  .two-col { grid-template-columns: 1.15fr 0.85fr; align-items: start; }
}

@media (max-width: 859px) {
  table.ledger thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  table.ledger, table.ledger tbody { display: block; width: 100%; }
  table.ledger tr {
    display: block;
    margin: 0 0 10px;
    padding: 8px 12px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--field);
  }
  table.ledger th[scope="row"] {
    display: block;
    padding: 4px 0 6px;
    border: 0;
    font-family: var(--serif);
    font-size: 1.3rem;
    font-weight: 620;
    letter-spacing: -0.03em;
    text-transform: none;
    color: var(--ink);
  }
  table.ledger td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 7px 0;
    border: 0;
    text-align: right;
  }
  table.ledger td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
    text-align: left;
  }
  table.ledger td select { max-width: none; }
  table.ledger .num { white-space: normal; }
}

@media (min-width: 860px) {
  table.ledger tbody tr:hover td { background: var(--row-hover); }
  table.ledger td select { max-width: 210px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}

.auth-wrap { width: min(480px, 100%); margin: 4vh auto 0; }
.auth-card .views { margin: 0; }
.login-card h3 { margin: 0; font-size: 1.35rem; }
.login-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.login-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.login-actions select { width: auto; min-width: 9rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; }
.inline-form input[type="password"] { width: min(220px, 100%); }
.pill.off { background: var(--banner-bad); color: var(--copper); }
