:root {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #131a2e;
  --ink: #eef2fa;
  --muted: #98a3b8;
  --line: #26314a;
  --accent: #2340d8;
  --accent-soft: #8ea0ff;
  --accent-ink: #ffffff;
  --err: #ff7b80;
}

html { background: var(--bg); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

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

main {
  max-width: 30rem;
  margin: 0 auto;
  padding: 24px 20px calc(40px + env(safe-area-inset-bottom));
}

/* Connect screen */
.welcome h1 {
  margin: 48px 0 12px;
  font-size: clamp(2rem, 9vw, 2.75rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.welcome > p { margin: 0 0 28px; max-width: 34ch; color: var(--muted); }
.welcome > .note { margin: 14px 0 0; font-size: 0.9rem; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%;
  padding: 14px 16px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 14px;
}

.btn {
  display: block;
  width: 100%;
  padding: 16px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: default; }

.link {
  padding: 8px 0;
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Quick entry */
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.brand { font-weight: 800; letter-spacing: -0.01em; }

.amount {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 28px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--line);
  transition: border-color 0.15s;
}
.amount:focus-within { border-color: var(--accent-soft); }
.amount .cur { font-size: 1.75rem; font-weight: 600; color: var(--muted); }
.amount input {
  flex: 1;
  min-width: 0;
  padding: 0;
  font: inherit;
  font-size: clamp(3.5rem, 18vw, 5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}
.amount input::placeholder { color: var(--muted); opacity: 0.4; }
.amount input::-webkit-outer-spin-button,
.amount input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

fieldset { min-width: 0; margin: 0 0 24px; padding: 0; border: 0; }
legend { margin-bottom: 10px; padding: 0; font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.chip span {
  display: block;
  padding: 10px 16px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip input:checked + span {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
.chip input:focus-visible + span { outline: 3px solid var(--accent-soft); outline-offset: 2px; }

details { margin-bottom: 20px; }
summary { padding: 6px 0; font-weight: 600; list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "+"; display: inline-block; width: 1.25rem; color: var(--muted); }
details[open] summary::before { content: "\2212"; }
details .field { margin-top: 12px; }

.status { min-height: 1.5em; margin: 0 0 12px; font-weight: 600; }
.status.ok { color: var(--accent-soft); animation: rise 0.25s ease-out; }
.status.err { color: var(--err); }
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Recent expenses */
.recent { margin-top: 44px; }
.recent h2 { margin: 0 0 4px; font-size: 1.1rem; }
.rows { margin: 0; padding: 0; list-style: none; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.row .what { display: block; font-weight: 600; overflow-wrap: anywhere; }
.row .sub { display: block; font-size: 0.9rem; color: var(--muted); }
.row .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.row .when { display: block; font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.empty { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .status.ok { animation: none; }
}

/* Home summary */
.mut { margin: 0; color: var(--muted); }
.summary { margin: 4px 0 32px; }
.total {
  margin: 2px 0 20px;
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
}


/* Home tiles */
.tile {
  display: block;
  padding: 16px;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 16px;
}
.tile .t { display: block; font-weight: 700; }
.tile .d { display: block; font-size: 0.9rem; color: var(--muted); }
.tile.add {
  margin-bottom: 10px;
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  transition: transform 0.12s ease;
}
.tile.add:active { transform: scale(0.98); }
.tile.add .d { color: var(--accent-ink); }
.tile.soon { background: transparent; border-style: dashed; }
.tile.soon .t { color: var(--muted); }
.tiles-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Card colour dot on chips */
.chip .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border: 1.5px solid var(--surface);
  border-radius: 50%;
}

.chip input:checked + span .dot { border-color: var(--accent-ink); }

/* Summary header: month picker on the left, Cards menu on the right */
.sum-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.month-nav { display: flex; align-items: center; gap: 2px; margin-left: -8px; font-weight: 700; }
.step {
  width: 36px;
  height: 36px;
  padding: 0;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.step:disabled { opacity: 0.3; cursor: default; }
.month-pick { position: relative; padding: 4px 2px; }
/* The real month input sits invisibly on top, so a tap opens the phone's own picker */
.month-pick input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.cards-menu { position: relative; }
.cards-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 8px 14px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.cards-btn[aria-expanded="true"] { border-color: var(--accent-soft); }
.cards-btn .count {
  min-width: 20px;
  padding: 0 6px;
  font-size: 0.78rem;
  line-height: 20px;
  text-align: center;
  color: var(--bg);
  background: var(--accent-soft);
  border-radius: 999px;
}
.cards-btn .chev::before { content: "\25BE"; font-size: 0.7rem; color: var(--muted); }
.cards-btn[aria-expanded="true"] .chev::before { content: "\25B4"; }

.pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  width: 262px;
  max-width: calc(100vw - 40px);
  padding: 8px 0 4px;
  background: #18213a;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
}
.pop .opt { display: flex; align-items: center; gap: 12px; padding: 9px 16px; cursor: pointer; }
.pop .opt input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--accent-soft); }
.pop .grp { margin: 0; }
.pop .gh {
  margin: 0;
  padding: 10px 16px 2px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pop hr { margin: 6px 16px; border: 0; border-top: 1px solid var(--line); }
.pop .status { min-height: 0; margin: 0; padding: 4px 16px; font-size: 0.85rem; }
.pop .status:empty { display: none; }

/* Cap rows: name on the left, numbers and bar on the right */
.bars { display: grid; gap: 15px; margin-top: 4px; }
.r { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; }
.nm b { display: block; font-size: 0.92rem; line-height: 1.15; white-space: nowrap; }
.nm span { display: block; font-size: 0.76rem; line-height: 1.25; color: var(--muted); }
.l1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.left { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; }
.left small { font-size: 0.8rem; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.left.capped { color: var(--accent-soft); }
.sp { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.track { position: relative; height: 10px; background: var(--line); border-radius: 6px; }
.fill { height: 100%; background: var(--accent-soft); border-radius: 6px; }
.tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--ink);
  transform: translateX(-1px);
}
.l3 { display: flex; gap: 8px; margin-top: 5px; font-size: 0.76rem; color: var(--muted); white-space: nowrap; }
.l3 .range { margin-left: auto; color: var(--ink); opacity: 0.8; }

/* Editing a date in the Recent list */
.row { flex-wrap: wrap; }
.when.edit {
  display: block;
  margin-left: auto;
  padding: 0;
  font: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}
.editor { flex: 1 0 100%; display: flex; align-items: center; gap: 12px; }

.daypick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 14px;
}
.daypick .month-pick { flex: 1; text-align: center; font-weight: 600; }
.editor .daypick { flex: 1; }
.hint { display: block; margin-top: 6px; font-size: 0.85rem; color: var(--muted); }
.hint:empty { display: none; }