:root {
  --bg: #EDF1EE;
  --surface: #FFFFFF;
  --sunken: #E3E9E5;
  --ink: #17262F;
  --muted: #56676F;
  --line: #D2DBD6;
  --accent: #0E6470;
  --accent-ink: #FFFFFF;
  --in: #1E7650;
  --out: #A23E62;
  --move: #56676F;
  --pay: #D9A21B;
  --warn: #9A6A0E;
  --bad: #B03A3A;
  --good: #1E7650;
  --radius-lg: 18px;
  --radius-sm: 10px;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1A1F;
    --surface: #17252B;
    --sunken: #1D2D33;
    --ink: #E5EEEA;
    --muted: #97A9A4;
    --line: #2B3C42;
    --accent: #4DB5C1;
    --accent-ink: #0F1A1F;
    --in: #5CC495;
    --out: #E683A8;
    --move: #97A9A4;
    --pay: #F0C24B;
    --warn: #E9B95A;
    --bad: #F08A80;
    --good: #5CC495;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--body);
  font-variant-numeric: tabular-nums;
  padding-top: env(safe-area-inset-top, 0px);
}
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}
.loading { padding: 40vh 0 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.in { color: var(--in); }
.out { color: var(--out); }
.move { color: var(--move); }
.neg { color: var(--bad); }

/* Header with month switcher */
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 8px 0 16px; }
.hello { color: var(--muted); font-size: 0.95rem; }
.month { display: flex; align-items: center; gap: 4px; margin-left: -10px; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink); font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--sunken); }

section { margin-bottom: 28px; }
.panel { background: var(--surface); border-radius: var(--radius-lg); padding: 18px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.section-head a { font-size: 0.95rem; }

/* The payday rail: the month as a line, with both paydays pinned on it */
.rail { margin: 0 0 12px; }
.rail svg { width: 100%; height: auto; display: block; overflow: visible; }
.rail-base { stroke: var(--line); stroke-width: 2; }
.rail-spend { fill: var(--out); opacity: 0.22; stroke: var(--out); stroke-width: 2; stroke-linejoin: round; }
.rail-income { stroke: var(--in); stroke-width: 2.5; stroke-linejoin: round; }
.rail-pin line { stroke: var(--pay); stroke-width: 2; stroke-dasharray: 2 3; }
.rail-pin circle { fill: var(--pay); stroke: var(--bg); stroke-width: 3; }
.rail-today { stroke: var(--ink); stroke-width: 1.5; }
.rail-label { fill: var(--muted); font: 11px var(--body); }
.rail-label.pay { fill: var(--ink); font-weight: 700; }
.rail-legend { display: flex; gap: 16px; font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.key::before { content: ""; display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.key.in::before { background: var(--in); }
.key.out::before { background: var(--out); height: 8px; opacity: 0.6; }
.key.pay::before { background: var(--pay); width: 8px; height: 8px; border-radius: 50%; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats span { display: block; color: var(--muted); font-size: 0.85rem; }
.stats strong { font-family: var(--display); font-size: 1.25rem; font-weight: 600; }

/* Account rows */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rows li:last-child { border-bottom: 0; }
.rows li.total { font-weight: 700; padding-top: 14px; }
.rows .sub { display: block; color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.meter { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }

/* Charts */
.chart-box { position: relative; height: 220px; }
.chart-box.small { height: 180px; }
.legend { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 10px; align-items: center; font-size: 0.95rem; }
.legend i { width: 12px; height: 12px; border-radius: 3px; }
.legend .pct { color: var(--muted); min-width: 3ch; text-align: right; }

/* Entries */
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.tx-list li:last-child .tx { border-bottom: 0; }
.tx-main, .tx-side { display: flex; flex-direction: column; min-width: 0; }
.tx-side { align-items: flex-end; flex-shrink: 0; }
.tx-cat { font-weight: 700; }
.tx-sub, .tx-who { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-head { font-family: var(--display); font-weight: 600; font-size: 0.95rem; color: var(--muted); margin: 18px 0 2px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .btn { margin-top: 14px; }

/* Forms */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; }
.form label > span { font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  background: var(--bg); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
}
textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
.amount-input { font-family: var(--display); font-size: 2rem; font-weight: 600; min-height: 64px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--bad); min-height: 1.5em; font-size: 0.95rem; }

.btn {
  display: inline-flex; justify-content: center; align-items: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.block { width: 100%; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 18px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; font-size: 0.95rem;
}
.chip:hover { border-color: var(--accent); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--sunken); border-radius: 999px; padding: 4px; gap: 4px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { display: block; text-align: center; padding: 8px 6px; border-radius: 999px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg input:checked + label { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(23, 38, 47, 0.12); }
.seg input:focus-visible + label { outline: 3px solid var(--accent); }

.filters { display: grid; gap: 10px; margin-bottom: 8px; }
.totals { display: flex; gap: 18px; color: var(--muted); font-size: 0.95rem; margin: 8px 0 0; }
.totals strong { color: var(--ink); }

/* Review */
.score { display: grid; grid-template-columns: 112px 1fr; gap: 18px; align-items: center; }
.score svg { width: 112px; height: 112px; }
.score-track { stroke: var(--sunken); }
.score-fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.8s ease; }
.score-num { font: 700 30px var(--display); fill: var(--ink); }
.score-of { font: 12px var(--body); fill: var(--muted); }
.score h2 { margin-bottom: 4px; }
details summary { cursor: pointer; color: var(--accent); margin-top: 6px; }
details .rows { margin-top: 6px; }

.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.figures span { display: block; color: var(--muted); font-size: 0.85rem; }
.figures strong { display: block; font: 600 1.15rem var(--display); }
.figures small { display: block; font-size: 0.8rem; color: var(--muted); }

.advice { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.advice li { padding: 14px 16px 14px 18px; background: var(--surface); border-radius: var(--radius-sm); border-left: 4px solid var(--muted); }
.advice li.bad { border-left-color: var(--bad); }
.advice li.warn { border-left-color: var(--warn); }
.advice li.good { border-left-color: var(--good); }
.advice li.info { border-left-color: var(--accent); }
.advice strong { display: block; margin-bottom: 2px; }
.advice p { color: var(--muted); font-size: 0.95rem; }

.budget-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.budget-row:last-child { border-bottom: 0; }
.budget-row .line { display: flex; justify-content: space-between; gap: 10px; }
.budget-row .line span:last-child { color: var(--muted); font-size: 0.95rem; }

.settings-group { display: grid; gap: 14px; }
.account-edit { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.account-edit:last-child { border-bottom: 0; }
.hint { color: var(--muted); font-size: 0.85rem; }

/* Login */
.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.login-mark svg { width: 56px; height: 56px; display: block; margin-bottom: 10px; }
.login .panel { margin-top: 16px; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  max-width: 560px; margin: 0 auto;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs[hidden] { display: none; }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); text-decoration: none; font-size: 0.75rem; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.tabs .tab-add svg { width: 44px; height: 44px; padding: 10px; margin-top: -16px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); stroke-width: 2.5; }
.tabs .tab-add span { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 20; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--bad); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (min-width: 600px) {
  .app { padding-top: 28px; }
  .tabs { border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}
.panel > .day-head:first-child { margin-top: 0; }
