:root {
  --bg: #0f1317;
  --card: #181d23;
  --line: #262d35;
  --text: #e8edf2;
  --dim: #8b97a5;
  --up: #4ec98a;
  --down: #e2705f;
  --accent: #5aa9e6;
  --radius: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --line: #e2e6ea;
    --text: #161c22;
    --dim: #6a7683;
    --up: #1d8a56;
    --down: #c04a37;
    --accent: #2b7ec1;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ---------- summary ---------- */

#summary {
  position: relative;
  padding: 20px 20px 0;
  text-align: center;
}

#summary .label {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.total {
  margin: 4px 0 0;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.delta {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--dim);
  min-height: 20px;
}

.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

.sparkline {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 8px;
}

.sparkline.tall { height: 80px; margin-bottom: 8px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark-area { fill: var(--accent); opacity: 0.12; stroke: none; }

.icon-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 20px;
  padding: 6px 10px;
}

/* ---------- accounts ---------- */

main {
  padding: 8px 16px 120px;
  max-width: 640px;
  margin: 0 auto;
}

main h2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 22px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

.subtotal { font-variant-numeric: tabular-nums; }

.account {
  display: flex;
  align-items: stretch;
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.account button {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.account button:active { background: var(--line); }

.account-main { flex: 1; min-width: 0; }
.account-main .name { font-weight: 500; }
.account-main .meta { font-size: 13px; color: var(--dim); }

.account-value {
  align-items: flex-end;
  text-align: right;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--line);
}

.account-value.negative > span:first-child { color: var(--down); }

.change { font-size: 12px; color: var(--dim); }
.change.up { color: var(--up); }
.change.down { color: var(--down); }

.empty {
  text-align: center;
  color: var(--dim);
  margin-top: 60px;
}

/* ---------- add button ---------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.fab:active { transform: scale(0.95); }

/* ---------- dialogs ---------- */

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  padding: 20px;
  margin-bottom: max(20px, env(safe-area-inset-bottom));
}

dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

dialog h2 { margin: 0 0 16px; font-size: 19px; }

dialog label {
  display: block;
  margin: 12px 0 4px;
  font-size: 13px;
  color: var(--dim);
}

dialog input, dialog select {
  width: 100%;
  padding: 11px 12px;
  font-size: 17px; /* stops iOS zooming on focus */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

dialog input:focus, dialog select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.hint { font-size: 12px; color: var(--dim); margin: 6px 2px 0; }

.row { display: flex; align-items: center; gap: 8px; margin-top: 20px; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.spacer { flex: 1; }

dialog button {
  padding: 10px 16px;
  font-size: 15px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

dialog button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
dialog button.danger { border-color: transparent; color: var(--down); background: none; }
dialog button:active { opacity: 0.7; }

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 45vh;
  overflow-y: auto;
}

.history li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.history li span:first-child { color: var(--dim); }
