:root {
  /* Always dark (Alex: white hurts the eyes). Soft white text, not pure white, to cut glare.
     Contrast measured with the WCAG formula: text on page 13.2:1, on cards 11.1:1,
     muted text on cards 6.1:1, header 5.5:1 (minimum for normal text is 4.5:1). */
  color-scheme: dark;
  --bg: #1e1f22; --card: #2b2d31; --text: #e6e6e6; --muted: #a8adb4;
  --brand: #0f766e; --brand-text: #ffffff; --ok: #4ade80; --border: #3a3d43;
}
* { box-sizing: border-box; }
/* "hidden" must always win, even over rules like label { display: block } (that was a bug). */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.top { background: var(--brand); color: var(--brand-text); padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
.top h1 { margin: 0; font-size: 1.25rem; }
main { padding: 16px; max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border-radius: 12px; padding: 16px; border: 1px solid var(--border); }
.card h2 { margin-top: 0; font-size: 1.1rem; }
.status { padding-left: 1.2em; color: var(--muted); }
.status strong { color: var(--text); }
.banner {
  position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.banner[hidden] { display: none; }
.banner button {
  background: var(--brand); color: var(--brand-text); border: 0; border-radius: 8px;
  padding: 10px 14px; font: inherit; font-weight: 600; min-height: 44px;
}

/* ---------- stage 1: forms, tabs, lists ---------- */
main { padding-bottom: 96px; } /* room above the tab bar */
.card + .card, .card + details.card, details.card { margin-top: 16px; }
.hint { color: var(--muted); font-size: .9rem; font-weight: normal; }
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .95rem; }
input, select {
  display: block; width: 100%; margin-top: 6px; min-height: 48px; padding: 10px 12px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  font: inherit; font-weight: normal; font-size: 1.05rem;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
#amount { font-size: 1.4rem; font-weight: 600; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
button.primary {
  width: 100%; min-height: 52px; border: 0; border-radius: 12px; background: var(--brand);
  color: var(--brand-text); font: inherit; font-weight: 700; font-size: 1.1rem;
}
button.primary:disabled { opacity: .6; }
.error-box { background: #3b1d1d; color: #fecaca; border: 1px solid #7f1d1d; border-radius: 10px; padding: 10px 12px 10px 28px; margin: 0 0 14px; }
p.error-box { padding-left: 12px; }
.error-box[hidden] { display: none; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { min-height: 56px; background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; }
.tabs button[aria-current="page"] { color: var(--text); box-shadow: inset 0 3px 0 var(--brand); }
.banner { bottom: calc(72px + env(safe-area-inset-bottom)); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom));
  background: #134e4a; color: #ecfdf5; border-radius: 12px; padding: 12px 16px; box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.toast[hidden] { display: none; }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.bal { font-variant-numeric: tabular-nums; font-weight: 600; }
.negative { color: #fca5a5; }
.total-row { display: flex; justify-content: space-between; margin: 12px 0 0; padding-top: 12px; border-top: 2px solid var(--border); }
details summary { font-weight: 700; cursor: pointer; min-height: 32px; }

.tx-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.tx-row:last-child { border-bottom: 0; }
.tx-top { display: flex; justify-content: space-between; }
.tx-date { color: var(--muted); }
.tx-amount { font-variant-numeric: tabular-nums; }
.tx-note { color: var(--muted); font-size: .9rem; margin-top: 2px; }

.start-row { display: grid; grid-template-columns: 1fr 9rem; align-items: center; gap: 12px; margin-bottom: 8px; font-weight: normal; }
.start-row input { margin-top: 0; }
#starts-list h3 { font-size: 1rem; margin: 16px 0 8px; color: var(--muted); }
