/* MoneyFlow — “Sketchbook Glass” redesign.
 *
 * Same markup contract as before (every class the JS wires is preserved),
 * restyled around four ideas:
 *   1. A living background — aurora blobs drift slowly behind everything.
 *   2. Glass cards — translucent, blurred, big radii, top-light highlight.
 *   3. Hand-drawn accents — squiggle underlines, dashed rings, doodle
 *      illustrations on empty states. The “sketchbook” part.
 *   4. Springs, not slides — every touchable thing answers with a bounce.
 *
 * Motion is decorative only and fully disabled under prefers-reduced-motion.
 */

:root {
  --bg: #0c1512;
  --bg-solid: #101a15;
  --bg-raised: rgba(255, 255, 255, 0.05);
  --bg-raised-2: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.10);
  --line-soft: rgba(255, 255, 255, 0.06);
  --text: #eef7f2;
  --text-dim: #97aca2;

  /* Primary brand (positive / available) */
  --mint: #7ce8bd;
  --mint-strong: #52d6a2;
  --mint-deep: #123f2e;
  --on-mint: #0a2418;

  /* Semantic roles */
  --expense: #ff8f7e;
  --expense-strong: #f26a56;
  --expense-deep: #40201b;
  --expense-soft: rgba(255, 143, 126, 0.13);
  --expense-line: rgba(255, 143, 126, 0.42);

  --income: #7ce8bd;
  --income-deep: #123f2e;

  --saving: #7fb9ec;
  --saving-strong: #5599d8;
  --saving-deep: #17293c;
  --saving-soft: rgba(127, 185, 236, 0.13);
  --saving-line: rgba(127, 185, 236, 0.42);
  --on-saving: #0a1a28;

  --capital: #ecc36a;
  --capital-strong: #dbac3f;
  --capital-deep: #33290f;
  --capital-soft: rgba(236, 195, 106, 0.13);
  --capital-line: rgba(236, 195, 106, 0.42);
  --on-capital: #251b06;

  --gold: #ecc36a;
  --red: #ff8f7e;
  --blue: #7fb9ec;

  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;

  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --glass: linear-gradient(165deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.028) 40%, rgba(255, 255, 255, 0.016));
  --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.18);

  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", "SF Pro Rounded", ui-rounded, "Avenir Next", "Segoe UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior-y: none;
}
input, textarea, select { user-select: text; }
::selection { background: rgba(124, 232, 189, 0.28); }

/* ---- living background: drifting aurora blobs ------------------------ */
body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
}
body::before {
  width: 480px; height: 480px;
  left: -140px; top: -120px;
  background: radial-gradient(circle at 40% 40%, rgba(124, 232, 189, 0.17), transparent 70%);
  animation: drift1 26s ease-in-out infinite alternate;
}
body::after {
  width: 560px; height: 560px;
  right: -180px; bottom: -160px;
  background: radial-gradient(circle at 60% 60%, rgba(127, 185, 236, 0.14), transparent 70%);
  animation: drift2 32s ease-in-out infinite alternate;
}
@keyframes drift1 { from { transform: translate(0, 0) scale(1); } to { transform: translate(70px, 50px) scale(1.15); } }
@keyframes drift2 { from { transform: translate(0, 0) scale(1.1); } to { transform: translate(-60px, -40px) scale(0.95); } }

#app {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 22px 18px 150px;
}

/* ---- titles with hand-drawn squiggle --------------------------------- */
h1.screen-title {
  display: inline-block;
  font-size: 2.05rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin: 6px 0 4px;
  padding-bottom: 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='7' viewBox='0 0 26 7'%3E%3Cpath d='M1 4.5 Q 4.2 1 7.5 4.5 T 14 4.5 T 20.5 4.5 T 27 4.5' fill='none' stroke='%237ce8bd' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: 0 100%;
  background-size: 26px 7px;
}

.screen-sub {
  font-size: 0.86rem;
  color: var(--text-dim);
  margin: 2px 0 18px;
  line-height: 1.5;
}

.muted { color: var(--text-dim); }
.small { font-size: 0.78rem; }
.spacer { height: 12px; }

/* ---- section groups (Settings) ---------------------------------------- */
.section-group { margin-bottom: 6px; }
.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 14px 6px 10px;
}
.section-label::before {
  content: "";
  width: 14px; height: 3px;
  border-radius: 3px;
  background: var(--mint);
  opacity: 0.75;
  transform: rotate(-2deg);
}

/* ---- chips ------------------------------------------------------------ */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.chip {
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 17px;
  font-size: 0.9rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s var(--spring), background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: rgba(124, 232, 189, 0.5); transform: translateY(-1px); }
.chip:active { transform: scale(0.94); }
.chip.on {
  background: linear-gradient(160deg, var(--mint), var(--mint-strong));
  border-color: transparent;
  color: var(--on-mint);
  box-shadow: 0 4px 16px rgba(82, 214, 162, 0.35);
}

/* Type chips — semantic gradients when selected */
.chip.chip-expense.on {
  background: linear-gradient(160deg, var(--expense), var(--expense-strong));
  border-color: transparent;
  color: #34110a;
  box-shadow: 0 4px 16px rgba(242, 106, 86, 0.35);
}
.chip.chip-income.on {
  background: linear-gradient(160deg, var(--mint), var(--mint-strong));
  border-color: transparent;
  color: var(--on-mint);
  box-shadow: 0 4px 16px rgba(82, 214, 162, 0.35);
}
.chip.chip-saving.on {
  background: linear-gradient(160deg, var(--saving), var(--saving-strong));
  border-color: transparent;
  color: var(--on-saving);
  box-shadow: 0 4px 16px rgba(85, 153, 216, 0.35);
}
.chip.chip-capital.on {
  background: linear-gradient(160deg, var(--capital), var(--capital-strong));
  border-color: transparent;
  color: var(--on-capital);
  box-shadow: 0 4px 16px rgba(219, 172, 63, 0.35);
}

/* ---- glass cards ------------------------------------------------------- */
.card {
  position: relative;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), transparent 18%);
  opacity: 0.7;
}
.card h3 {
  font-size: 1.02rem;
  font-weight: 800;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

/* Soft semantic tints on cards */
.card.tone-expense {
  background:
    radial-gradient(120% 90% at 85% 0%, rgba(255, 143, 126, 0.14), transparent 55%),
    var(--glass);
  border-color: var(--expense-line);
}
.card.tone-income {
  background:
    radial-gradient(120% 90% at 85% 0%, rgba(124, 232, 189, 0.13), transparent 55%),
    var(--glass);
  border-color: rgba(124, 232, 189, 0.32);
}
.card.tone-saving {
  background:
    radial-gradient(120% 90% at 85% 0%, rgba(127, 185, 236, 0.14), transparent 55%),
    var(--glass);
  border-color: var(--saving-line);
}
.card.tone-capital {
  background:
    radial-gradient(120% 90% at 85% 0%, rgba(236, 195, 106, 0.14), transparent 55%),
    var(--glass);
  border-color: var(--capital-line);
}

/* ---- hero --------------------------------------------------------------- */
.hero {
  overflow: hidden;
  background: linear-gradient(145deg, #8defc6 0%, var(--mint-strong) 58%, #35b988 100%);
  color: var(--on-mint);
  border: none;
  box-shadow: 0 16px 40px rgba(82, 214, 162, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
}
/* hand-drawn dashed ring + soft blob: the sketchbook accents */
.hero::after {
  content: "";
  position: absolute;
  right: -52px; top: -52px;
  width: 190px; height: 190px;
  border-radius: 50%;
  border: 2.5px dashed rgba(255, 255, 255, 0.4);
  transform: rotate(8deg);
  pointer-events: none;
}
.hero::before {
  content: "";
  position: absolute;
  left: -70px; bottom: -110px;
  width: 240px; height: 240px;
  border-radius: 46% 54% 60% 40% / 50% 44% 56% 50%;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}
.hero.hero-saving {
  background: linear-gradient(145deg, #9cc9f0 0%, var(--saving-strong) 58%, #3d7fc0 100%);
  color: var(--on-saving);
  box-shadow: 0 16px 40px rgba(85, 153, 216, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
}
.hero.hero-expense {
  background: linear-gradient(145deg, #f5a89c 0%, var(--expense-strong) 58%, #d4503a 100%);
  color: #34110a;
}
/* Debts hero — warm terracotta, distinct from the saving blue and the
   pure-expense red so "owed by you" reads as its own concept. */
.hero.hero-debt {
  background: linear-gradient(145deg, #f0b28c 0%, #e0885f 58%, #b85c3a 100%);
  color: #36150a;
  box-shadow: 0 16px 40px rgba(200, 110, 70, 0.32), 0 2px 8px rgba(0, 0, 0, 0.2);
}
.hero .label { font-size: 0.84rem; font-weight: 800; opacity: 0.85; letter-spacing: 0.02em; }
.hero .big {
  font-size: 2.55rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.12;
  font-variant-numeric: tabular-nums;
}
.hero .sub { font-size: 0.82rem; font-weight: 700; opacity: 0.85; margin-top: 8px; word-break: break-word; line-height: 1.45; }

/* ---- stat tiles ----------------------------------------------------------- */
.tiles { display: flex; gap: 10px; margin-bottom: 14px; }
.tile {
  flex: 1;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  min-width: 0;
  transition: transform 0.18s var(--spring), box-shadow 0.18s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }
.tile.tone-expense {
  background: var(--expense-soft);
  border-color: var(--expense-line);
  backdrop-filter: none;
}
.tile.tone-income {
  background: rgba(124, 232, 189, 0.09);
  border-color: rgba(124, 232, 189, 0.3);
  backdrop-filter: none;
}
.tile.tone-saving {
  background: var(--saving-soft);
  border-color: var(--saving-line);
  backdrop-filter: none;
}
.tile .label { font-size: 0.74rem; font-weight: 700; color: var(--text-dim); margin-bottom: 5px; }
.tile .value {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--mint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.tile .value.plain { color: var(--text); }
.tile .value.bad { color: var(--expense); }
.tile .value.expense { color: var(--expense); }
.tile .value.saving { color: var(--saving); }
.tile.tone-expense .value { color: var(--expense); }
.tile.tone-saving .value { color: var(--saving); }

/* ---- rows ----------------------------------------------------------------- */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 6px;
  margin: 0 -6px;
  border-radius: var(--radius-sm);
  min-width: 0;
}
.row.click { cursor: pointer; transition: background 0.15s, transform 0.15s var(--spring); }
.row.click:hover { background: var(--bg-raised); }
.row.click:active { transform: scale(0.985); }
.row .emoji { font-size: 1.3rem; width: 32px; text-align: center; flex: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: 0.95rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 0.75rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amount { font-weight: 800; font-size: 0.95rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount.in { color: var(--mint); }
.amount.out { color: var(--expense); }
.amount.save { color: var(--saving); }
.amount.capital { color: var(--capital); }
.amount.neg { color: var(--expense); }
.amount.plain { color: var(--text); }
.chev { color: var(--text-dim); font-size: 1.15rem; flex: none; transition: transform 0.2s var(--spring); }

.badge {
  font-size: 0.64rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  border-radius: 8px;
  padding: 3px 7px;
  flex: none;
}
.badge.auto { background: rgba(236, 195, 106, 0.16); color: var(--gold); }
.badge.saving { background: var(--saving-soft); color: var(--blue); }
.badge.capital { background: rgba(236, 195, 106, 0.16); color: var(--gold); }

/* ---- icon grid (platforms / categories) ------------------------------------ */
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.grid-tile {
  background: var(--bg-raised);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  padding: 13px 6px;
  text-align: center;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: transform 0.16s var(--spring), border-color 0.15s, background 0.15s;
}
.grid-tile:hover { border-color: var(--line); transform: translateY(-2px); }
.grid-tile:active { transform: scale(0.93); }
.grid-tile.on {
  background: var(--mint-deep);
  border-color: var(--mint);
  box-shadow: 0 6px 18px rgba(82, 214, 162, 0.25);
}
.grid-tile.on.tone-expense { background: var(--expense-deep); border-color: var(--expense); box-shadow: 0 6px 18px rgba(242, 106, 86, 0.25); }
.grid-tile.on.tone-income { background: var(--income-deep); border-color: var(--income); box-shadow: 0 6px 18px rgba(82, 214, 162, 0.25); }
.grid-tile.on.tone-saving { background: var(--saving-deep); border-color: var(--saving); box-shadow: 0 6px 18px rgba(85, 153, 216, 0.25); }
.grid-tile.on.tone-capital { background: var(--capital-deep); border-color: var(--capital); box-shadow: 0 6px 18px rgba(219, 172, 63, 0.25); }
.grid-tile .emoji { font-size: 1.55rem; display: block; margin-bottom: 5px; }
.grid-tile .name { font-size: 0.72rem; font-weight: 700; line-height: 1.25; word-break: break-word; }

/* ---- forms ------------------------------------------------------------------- */
label.field { display: block; margin-bottom: 14px; }
label.field .cap { display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-dim); margin-bottom: 7px; letter-spacing: 0.02em; }
input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1.5px solid var(--line-soft);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--mint); background: rgba(124, 232, 189, 0.05); }
input[type=date] { color-scheme: dark; }
input[type=checkbox] { width: 19px; height: 19px; accent-color: var(--mint-strong); }
input[type=radio] { accent-color: var(--mint-strong); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1.5 1.5 7 7 12.5 1.5' fill='none' stroke='%2397aca2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px; }

/* ---- buttons ------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: linear-gradient(160deg, var(--mint), var(--mint-strong));
  color: var(--on-mint);
  border: none;
  border-radius: 999px;
  padding: 15px;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.01em;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 8px 22px rgba(82, 214, 162, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.16s var(--spring), box-shadow 0.16s, filter 0.15s;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 10px 26px rgba(82, 214, 162, 0.42), 0 2px 6px rgba(0, 0, 0, 0.2); }
.btn:active { transform: scale(0.965) translateY(1px); }

.btn.secondary {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.secondary:hover { border-color: rgba(124, 232, 189, 0.5); background: var(--bg-raised); }

/* Semantic primary actions */
.btn.btn-expense {
  background: linear-gradient(160deg, var(--expense), var(--expense-strong));
  color: #34110a;
  box-shadow: 0 8px 22px rgba(242, 106, 86, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
}
.btn.btn-expense:hover { box-shadow: 0 10px 26px rgba(242, 106, 86, 0.42), 0 2px 6px rgba(0, 0, 0, 0.2); }

.btn.btn-income {
  background: linear-gradient(160deg, var(--mint), var(--mint-strong));
  color: var(--on-mint);
  box-shadow: 0 8px 22px rgba(82, 214, 162, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.btn.btn-saving {
  background: linear-gradient(160deg, var(--saving), var(--saving-strong));
  color: var(--on-saving);
  box-shadow: 0 8px 22px rgba(85, 153, 216, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
}
.btn.btn-saving:hover { box-shadow: 0 10px 26px rgba(85, 153, 216, 0.42), 0 2px 6px rgba(0, 0, 0, 0.2); }

.btn.btn-capital {
  background: linear-gradient(160deg, var(--capital), var(--capital-strong));
  color: var(--on-capital);
  box-shadow: 0 8px 22px rgba(219, 172, 63, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.btn.danger {
  background: transparent;
  color: var(--expense);
  border: 1.5px solid var(--expense-line);
  box-shadow: none;
}
.btn.danger:hover { background: var(--expense-soft); }
.btn.slim { width: auto; padding: 9px 18px; font-size: 0.85rem; }

.err { color: var(--expense); font-size: 0.85rem; font-weight: 700; margin: 8px 0; }

/* Modal type accent strip */
.modal.tone-expense { box-shadow: inset 0 4px 0 0 var(--expense), var(--shadow-card); }
.modal.tone-income { box-shadow: inset 0 4px 0 0 var(--income), var(--shadow-card); }
.modal.tone-saving { box-shadow: inset 0 4px 0 0 var(--saving), var(--shadow-card); }
.modal.tone-capital { box-shadow: inset 0 4px 0 0 var(--capital), var(--shadow-card); }

/* ---- modal: bottom sheet with grabber ------------------------------------------- */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(4, 10, 8, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: rgba(24, 37, 30, 0.92);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 30px 30px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 22px 36px;
  position: relative;
  animation: sheetUp 0.42s var(--spring);
}
@keyframes sheetUp { from { transform: translateY(60%); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* grabber handle drawn as a pseudo-element so it survives innerHTML redraws */
.modal::before {
  content: "";
  display: block;
  width: 46px; height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.22);
  margin: 4px auto 12px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h2 { font-size: 1.32rem; font-weight: 900; letter-spacing: -0.01em; }
.close-x {
  background: var(--bg-raised-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 50%;
  width: 38px; height: 38px;
  font-size: 1.05rem;
  cursor: pointer;
  flex: none;
  line-height: 1;
  font-family: inherit;
  transition: transform 0.15s var(--spring), border-color 0.15s, color 0.15s;
}
.close-x:hover { border-color: var(--expense); color: var(--expense); transform: rotate(90deg); }
.close-x:active { transform: scale(0.88); }

/* ---- FAB: labeled pill, gently floating ------------------------------------------ */
.fab {
  position: fixed;
  right: max(16px, calc(50vw - 280px + 16px));
  bottom: 104px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 68px;
  height: 56px;
  border-radius: 999px;
  padding: 0 22px;
  background: linear-gradient(150deg, #9af0cd 0%, #4fc48f 55%, #2fae75 100%);
  color: var(--on-mint);
  border: 2px solid rgba(255, 255, 255, 0.25);
  font-family: inherit;
  cursor: pointer;
  box-shadow:
    0 0 0 4px rgba(82, 214, 162, 0.16),
    0 14px 34px rgba(47, 174, 117, 0.5),
    0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 30;
  animation: fabFloat 4.5s ease-in-out infinite;
  transition: transform 0.18s var(--spring), box-shadow 0.18s, filter 0.15s;
}
@keyframes fabFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.fab:hover {
  filter: brightness(1.06);
  box-shadow:
    0 0 0 5px rgba(82, 214, 162, 0.24),
    0 16px 38px rgba(47, 174, 117, 0.58),
    0 4px 12px rgba(0, 0, 0, 0.4);
}
.fab:active { transform: scale(0.93); animation: none; }
.fab .fab-plus { display: flex; animation: none; }
.fab .fab-plus svg { display: block; }
.fab .fab-label { font-size: 0.98rem; font-weight: 900; letter-spacing: 0.01em; }

/* ---- floating dock nav -------------------------------------------------------------- */
nav.tabs {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  z-index: 40;
  pointer-events: none;
}
nav.tabs .inner {
  display: flex;
  width: 100%;
  max-width: 400px;
  gap: 4px;
  padding: 6px;
  border-radius: 26px;
  background: rgba(20, 32, 26, 0.78);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border: 1px solid var(--line);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}
nav.tabs button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  border-radius: 20px;
  color: var(--text-dim);
  font-family: inherit;
  padding: 9px 0 7px;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  transition: color 0.18s, background 0.25s var(--spring);
}
nav.tabs button .tab-ico { display: flex; transition: transform 0.22s var(--spring); }
nav.tabs button .tab-ico svg { display: block; }
nav.tabs button:hover { color: var(--text); }
nav.tabs button:hover .tab-ico { transform: translateY(-1px) scale(1.06); }
nav.tabs button.on {
  color: var(--mint);
  background: rgba(124, 232, 189, 0.13);
  animation: dockPill 0.32s var(--spring);
}
nav.tabs button.on .tab-ico { transform: scale(1.08); }
@keyframes dockPill { from { transform: scale(0.85); } to { transform: scale(1); } }

/* ---- charts -------------------------------------------------------------------------- */
.ring-wrap { display: flex; align-items: center; gap: 18px; }
.ring-wrap svg { flex: none; animation: popIn 0.5s var(--spring); }
.ring-info { display: flex; flex-direction: column; gap: 7px; font-size: 0.85rem; font-weight: 600; }
.ring-center-num { font-size: 1.5rem; font-weight: 900; fill: var(--text); }
.ring-center-cap { font-size: 0.62rem; fill: var(--text-dim); font-weight: 700; letter-spacing: 0.04em; }

.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut-wrap svg { animation: popIn 0.5s var(--spring); }
.legend { display: flex; flex-direction: column; gap: 8px; font-size: 0.88rem; }
.legend .dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50% 50% 50% 4px;
  margin-right: 9px;
  transform: rotate(45deg);
}

/* Bar chart: amounts in a fixed top zone, bars spring up staggered */
.bars {
  display: flex;
  align-items: stretch;
  gap: 8px;
  height: 150px;
  padding-top: 2px;
}
.bars.with-amt { height: 170px; }

.bars .col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  min-width: 0;
  gap: 0;
}

.bars .bar-amt {
  flex: none;
  height: 20px;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--mint);
  white-space: nowrap;
  letter-spacing: -0.03em;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.bars .bar-amt.tone-expense { color: var(--expense); }
.bars .bar-amt.tone-saving { color: var(--saving); }
.bars .bar-amt.placeholder { color: var(--text-dim); opacity: 0.35; font-weight: 600; }

.bars .bar-track {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.bars .bar {
  width: 72%;
  max-width: 38px;
  background: linear-gradient(180deg, var(--mint), var(--mint-strong));
  border-radius: 10px 10px 4px 4px;
  min-height: 4px;
  box-shadow: 0 4px 12px rgba(82, 214, 162, 0.25);
  transform-origin: bottom;
  animation: barGrow 0.65s var(--spring) backwards;
}
.bars .col:nth-child(1) .bar { animation-delay: 0.03s; }
.bars .col:nth-child(2) .bar { animation-delay: 0.08s; }
.bars .col:nth-child(3) .bar { animation-delay: 0.13s; }
.bars .col:nth-child(4) .bar { animation-delay: 0.18s; }
.bars .col:nth-child(5) .bar { animation-delay: 0.23s; }
.bars .col:nth-child(6) .bar { animation-delay: 0.28s; }
.bars .col:nth-child(7) .bar { animation-delay: 0.33s; }
.bars .bar.neg,
.bars .bar.tone-expense { background: linear-gradient(180deg, var(--expense), var(--expense-strong)); box-shadow: 0 4px 12px rgba(242, 106, 86, 0.25); }
.bars .bar.tone-saving { background: linear-gradient(180deg, var(--saving), var(--saving-strong)); box-shadow: 0 4px 12px rgba(85, 153, 216, 0.25); }

.bars .cap {
  flex: none;
  height: 18px;
  margin-top: 6px;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
  line-height: 18px;
}

@keyframes barGrow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes popIn { from { transform: scale(0.82); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.divider { border: none; border-top: 1.5px dashed var(--line); margin: 14px 0; }

.notice {
  background: var(--capital-soft);
  color: var(--gold);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 10px;
}
.section-note {
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-top: 10px;
  line-height: 1.5;
}
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inline-actions { display: flex; gap: 8px; margin-top: 12px; }
.inline-actions .btn { flex: 1; }

@media (max-width: 400px) {
  .grid4 { grid-template-columns: repeat(3, 1fr); }
}

/* ---- card header with an inline action (Edit / More) --------------------- */
.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.head-row h3 { margin: 0; }

.text-btn {
  background: none;
  border: none;
  color: var(--mint);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 900;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 999px;
  flex: none;
  transition: background 0.15s, transform 0.15s var(--spring);
}
.text-btn:hover { background: rgba(124, 232, 189, 0.12); transform: translateY(-1px); }
.text-btn:active { transform: scale(0.93); }
.text-btn.tone-expense { color: var(--expense); }
.text-btn.tone-expense:hover { background: var(--expense-soft); }
.text-btn.tone-saving { color: var(--saving); }
.text-btn.tone-saving:hover { background: var(--saving-soft); }

/* ---- recent records: collapsible day groups ------------------------------- */
.day-group {
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  overflow: hidden;
  transition: background 0.18s;
  border: 1px solid transparent;
}
.day-group:hover { background: var(--bg-raised); }
.day-group.open { background: var(--bg-raised); border-color: var(--line-soft); }
.day-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 8px;
  cursor: pointer;
}
.day-label { font-weight: 900; font-size: 0.92rem; flex: none; }
.day-meta { font-size: 0.78rem; color: var(--text-dim); flex: 1; min-width: 0; text-align: right; font-weight: 600; }
.day-total { font-weight: 900; color: var(--expense); font-variant-numeric: tabular-nums; }
.day-total.muted { color: var(--text-dim); font-weight: 700; }
.day-chev { font-size: 0.9rem; flex: none; }
.day-group.open .day-chev { transform: rotate(90deg); }
.day-rows { padding: 0 8px 8px; animation: slideDown 0.28s var(--ease); }
.day-rows .row { padding: 7px 0; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---- analytics legend -------------------------------------------------------- */
.legend .legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}
.legend .legend-emoji { font-size: 1rem; width: 18px; text-align: center; }
.legend .legend-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.legend .legend-val { font-weight: 800; font-size: 0.82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---- category chips summary (Settings) ----------------------------------------- */
.cat-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.cat-chip {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

/* ---- smart entry (quick-entry box) ---------------------------------------------- */
.quick-entry .quick-note { font-size: 0.75rem; margin-top: 7px; min-height: 1.1em; line-height: 1.45; }
.quick-note .ok { color: var(--mint); font-weight: 800; }
.quick-note .dim { color: var(--text-dim); }

.kw-del {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.68rem;
  padding: 0 0 0 4px;
  font-family: inherit;
}
.kw-del:hover { color: var(--expense); }

/* ---- per-bucket progress (Budget page) -------------------------------------------- */
.bucket-progress { margin-bottom: 13px; }
.bucket-progress:last-of-type { margin-bottom: 0; }
.bp-name { font-weight: 800; font-size: 0.9rem; }
.bp-val { font-size: 0.8rem; color: var(--text-dim); font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bp-val.bad { color: var(--expense); }
.pbar {
  height: 8px;
  border-radius: 6px;
  background: var(--bg-raised-2);
  margin-top: 7px;
  overflow: hidden;
}
.pbar-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--mint), var(--mint-strong));
  transition: width 0.8s var(--spring);
}
.pbar-fill.tone-expense { background: linear-gradient(90deg, var(--expense), var(--expense-strong)); }
.pbar-fill.tone-saving { background: linear-gradient(90deg, var(--saving), var(--saving-strong)); }

/* ---- bucket editor flags (spendable + savings role) -------------------------------- */
.bk-flags { display: flex; flex-direction: column; gap: 4px; }

/* ---- allocation bucket editor -------------------------------------------------------- */
.bucket-list { display: flex; flex-direction: column; gap: 9px; }
.bucket-row {
  display: grid;
  grid-template-columns: 1fr 92px auto 36px;
  align-items: center;
  gap: 8px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 10px;
}
.bucket-row .bk-name { background: transparent; border: none; padding: 4px 6px; font-weight: 700; }
.bk-pct-wrap { position: relative; }
.bk-pct { padding-right: 24px; text-align: right; }
.bk-pct-sign { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--text-dim); font-size: 0.85rem; pointer-events: none; }
.bk-spend { display: flex; align-items: center; gap: 5px; font-size: 0.72rem; color: var(--text-dim); cursor: pointer; white-space: nowrap; font-weight: 700; }
.bk-spend input { width: 16px; height: 16px; }
.bucket-sum { font-weight: 900; text-align: center; margin: 8px 0 4px; font-size: 0.95rem; }
.bucket-sum.ok { color: var(--mint); }
.bucket-sum.bad { color: var(--expense); }

/* ---- platform editor rows ----------------------------------------------------------- */
.plat-row {
  display: grid;
  grid-template-columns: 54px 1fr 1fr 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.plat-emoji-input { text-align: center; font-size: 1.1rem; padding: 10px 4px; }
.plat-bal { text-align: right; }

/* ---- category editor rows ------------------------------------------------------------ */
.cat-list-edit { display: flex; flex-direction: column; gap: 9px; }
.cat-row-edit {
  display: grid;
  grid-template-columns: 54px 1fr 36px;
  gap: 8px;
  align-items: center;
}
.cat-emoji-input { text-align: center; font-size: 1.1rem; padding: 10px 4px; }
.cat-row-edit.with-bucket { grid-template-columns: 54px 1fr 132px 36px; }
.cat-bucket { font-size: 0.85rem; padding: 9px; }

/* ---- empty-state doodles -------------------------------------------------------------- */
.doodle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 0 8px;
  color: var(--text-dim);
}
.doodle svg { display: block; }
.doodle p { font-size: 0.82rem; text-align: center; line-height: 1.5; max-width: 34ch; }

/* ---- toast -------------------------------------------------------------------------------- */
.toast-wrap {
  position: fixed;
  top: 18px;
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(20, 34, 27, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(124, 232, 189, 0.35);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 0.88rem;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.45s var(--spring);
}
.toast.out { animation: toastOut 0.32s var(--ease) forwards; }
.toast .toast-check { color: var(--mint); display: flex; }
@keyframes toastIn { from { transform: translateY(-24px) scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(-16px) scale(0.94); opacity: 0; } }

/* ---- screen entrance: cards cascade in on tab switch ------------------------------------- */
.screen-enter .card,
.screen-enter .tiles .tile,
.screen-enter .day-group {
  animation: cardIn 0.5s var(--ease) backwards;
}
.screen-enter .card:nth-child(1), .screen-enter .tiles .tile:nth-child(1) { animation-delay: 0.02s; }
.screen-enter .card:nth-child(2), .screen-enter .tiles .tile:nth-child(2) { animation-delay: 0.07s; }
.screen-enter .card:nth-child(3), .screen-enter .tiles .tile:nth-child(3) { animation-delay: 0.12s; }
.screen-enter .card:nth-child(4), .screen-enter .tiles .tile:nth-child(4) { animation-delay: 0.17s; }
.screen-enter .card:nth-child(5) { animation-delay: 0.22s; }
.screen-enter .card:nth-child(6) { animation-delay: 0.27s; }
.screen-enter .day-group:nth-child(1) { animation-delay: 0.1s; }
.screen-enter .day-group:nth-child(2) { animation-delay: 0.14s; }
.screen-enter .day-group:nth-child(3) { animation-delay: 0.18s; }
.screen-enter .day-group:nth-child(4) { animation-delay: 0.22s; }
.screen-enter .day-group:nth-child(5) { animation-delay: 0.26s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }

/* ---- focus & scrollbars ------------------------------------------------------------------------ */
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; border-radius: 6px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- responsive tweaks ---------------------------------------------------------------------------- */
@media (max-width: 420px) {
  .bucket-row { grid-template-columns: 1fr 80px 36px; }
  .bucket-row .bk-flags { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; gap: 12px; padding-top: 2px; }
  .plat-row { grid-template-columns: 48px 1fr 32px; }
  .plat-row .plat-bal { grid-column: 1 / -1; }
  .cat-row-edit { grid-template-columns: 48px 1fr 32px; }
  .cat-row-edit.with-bucket { grid-template-columns: 48px 1fr 32px; }
  .cat-row-edit.with-bucket .cat-bucket { grid-column: 1 / -1; }
}

/* ---- accessibility: kill decorative motion ---------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- help: floating "?" button + guided tour ----------------------------------------------- */

/* Sits right above the Add FAB, on every screen. z-index stays below the modal
   layer so it is naturally covered while a dialog is open. */
.help-fab {
  position: fixed;
  right: max(16px, calc(50vw - 280px + 16px));
  bottom: 172px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mint);
  background: rgba(18, 63, 46, 0.55);
  border: 1.5px solid rgba(124, 232, 189, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 70;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  transition: transform 0.16s var(--spring), border-color 0.2s, box-shadow 0.2s;
}
.help-fab:hover {
  transform: translateY(-2px);
  border-color: var(--mint);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45), 0 0 18px rgba(124, 232, 189, 0.25);
}
.help-fab:active { transform: scale(0.92); }

/* Transparent full-screen click catcher: clicks on the dim area step forward. */
.help-catch { position: fixed; inset: 0; z-index: 300; cursor: pointer; }

/* The spotlight: an exact-size window over the target element. Its huge
   box-shadow dims everything else while the target stays fully lit; the extra
   rings make it "light up". Glides between steps. */
.help-spot {
  position: fixed;
  z-index: 301;
  pointer-events: none;
  border-radius: 18px;
  box-shadow:
    0 0 0 200vmax rgba(4, 12, 9, 0.82),
    0 0 0 2px var(--mint),
    0 0 26px 2px rgba(124, 232, 189, 0.4);
  transition:
    top 0.4s var(--ease), left 0.4s var(--ease),
    width 0.4s var(--ease), height 0.4s var(--ease),
    opacity 0.3s ease;
}
@media (prefers-reduced-motion: reduce) {
  .help-spot { transition: opacity 0.3s ease; }
}

/* Explanation card floating next to the spotlight. */
.help-tip {
  position: fixed;
  z-index: 302;
  width: min(340px, calc(100vw - 24px));
  box-sizing: border-box;
  background: rgba(14, 28, 21, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(124, 232, 189, 0.5);
  border-radius: 18px;
  padding: 13px 15px 12px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5), 0 0 30px rgba(124, 232, 189, 0.12);
  animation: helpTipIn 0.32s var(--spring);
}
@keyframes helpTipIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
.help-tip .help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.help-tip h4 { margin: 0; font-size: 0.98rem; font-weight: 800; letter-spacing: 0.01em; }
.help-tip .help-count {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--mint);
  background: rgba(124, 232, 189, 0.12);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.help-tip p { margin: 0 0 11px; font-size: 0.85rem; line-height: 1.55; color: var(--text-dim); }
.help-tip p strong, .help-tip p b { color: var(--text); }
.help-tip .help-actions { display: flex; align-items: center; gap: 8px; }
.help-tip .help-actions .grow { flex: 1; }
.help-tip .close-x { width: 30px; height: 30px; font-size: 0.85rem; flex: none; }
