:root {
  --bg: #0b0f1a;
  --bg2: #0f1524;
  --card: #141b2e;
  --card2: #1a2338;
  --line: #26304a;
  --txt: #eaf0ff;
  --muted: #8a97b8;
  --dim: #5d6a8a;
  --green: #34d399;
  --green-d: #059669;
  --red: #fb7185;
  --amber: #fbbf24;
  --purple: #a78bfa;
  --blue: #60a5fa;
  --accent: #7c5cff;
  --ring-bg: #202a44;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
  --r: 18px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 80% -10%, #16203a 0%, transparent 60%),
              radial-gradient(1000px 700px at 0% 0%, #17203a 0%, transparent 55%),
              var(--bg);
  color: var(--txt);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; border: none; color: inherit; }
input, select { font: inherit; }
.hidden { display: none !important; }

/* ---- login ---- */
#login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 24px;
  padding: 40px; width: 380px; max-width: 100%; box-shadow: var(--shadow); text-align: center;
}
.login-card .logo { font-size: 44px; }
.login-card h1 { margin: 12px 0 4px; font-size: 24px; letter-spacing: -.02em; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card input {
  width: 100%; padding: 14px 16px; border-radius: 14px; background: var(--bg2);
  border: 1px solid var(--line); color: var(--txt); margin-bottom: 12px; text-align: center;
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn-primary {
  width: 100%; padding: 14px; border-radius: 14px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #5b8cff); color: white;
  transition: transform .08s ease, filter .2s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(.98); }
.login-err { color: var(--red); min-height: 20px; font-size: 13px; margin-top: 6px; }

/* ---- shell ---- */
#app { max-width: 1120px; margin: 0 auto; padding: 20px 20px 80px; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand .dot { width: 12px; height: 12px; border-radius: 4px; background: linear-gradient(135deg, var(--accent), var(--green)); box-shadow: 0 0 16px var(--accent); }
.topbar .spacer { flex: 1; }
.month-select {
  background: var(--card); border: 1px solid var(--line); color: var(--txt);
  padding: 9px 14px; border-radius: 12px; font-weight: 600;
}
.icon-btn { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; color: var(--muted); }
.icon-btn:hover { color: var(--txt); border-color: var(--accent); }

/* ---- player strip ---- */
.player {
  display: flex; align-items: center; gap: 16px; background: linear-gradient(135deg, var(--card), var(--card2));
  border: 1px solid var(--line); border-radius: var(--r); padding: 14px 18px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.level-badge {
  width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 20%, #b39dff, var(--accent)); color: white; font-weight: 800;
  box-shadow: 0 6px 20px rgba(124,92,255,.5); flex-shrink: 0; line-height: 1;
}
.level-badge small { display: block; font-size: 9px; opacity: .8; font-weight: 700; letter-spacing: .08em; }
.level-badge b { font-size: 22px; }
.player .who { min-width: 150px; }
.player .who .title { font-weight: 700; }
.player .who .name { color: var(--muted); font-size: 13px; }
.xpbar { flex: 1; min-width: 160px; }
.xpbar .track { height: 10px; border-radius: 6px; background: var(--ring-bg); overflow: hidden; }
.xpbar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--blue)); border-radius: 6px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.xpbar .lbl { font-size: 12px; color: var(--muted); margin-top: 5px; display: flex; justify-content: space-between; }
.stat-chip { text-align: center; padding: 4px 8px; }
.stat-chip .v { font-weight: 800; font-size: 18px; }
.stat-chip .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.flame { color: var(--amber); }
.banked { color: var(--green); }

/* ---- layout grid ---- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid .col { display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.card h2 .r { float: right; text-transform: none; letter-spacing: 0; }

/* ---- today ring ---- */
.today { display: flex; gap: 22px; align-items: center; }
.ring-wrap { position: relative; width: 180px; height: 180px; flex-shrink: 0; }
.ring-wrap .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-wrap .center .big { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.ring-wrap .center .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.today .side { flex: 1; }
.today .side .row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.today .side .row:last-child { border: none; }
.today .side .row .k { color: var(--muted); }
.today .side .row .v { font-weight: 700; }
.pos { color: var(--green); } .neg { color: var(--red); }

/* quick add */
.quick { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.quick input, .quick select {
  background: var(--bg2); border: 1px solid var(--line); color: var(--txt); border-radius: 12px; padding: 11px 12px;
}
.quick input.amt { width: 110px; font-weight: 700; }
.quick input.note { flex: 1; min-width: 120px; }
.quick .add { background: linear-gradient(135deg, var(--green), var(--green-d)); color: #04120c; font-weight: 800; padding: 11px 18px; border-radius: 12px; }
.quick .add:active { transform: scale(.97); }

/* ---- weeks ---- */
/* bar-col is a FIXED-height plot area; the amount/budget/label lines sit under
   it, so the column never grows past its box and overlaps the card title. */
.weeks { display: flex; gap: 12px; align-items: flex-end; }
.week { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-col { height: 110px; width: 100%; display: flex; align-items: flex-end; gap: 4px; }
.bar { flex: 1; border-radius: 8px 8px 0 0; min-height: 4px; background: var(--ring-bg); position: relative; transition: height .5s; }
.bar.budget { background: var(--ring-bg); }
.bar.spent-under { background: linear-gradient(180deg, var(--green), var(--green-d)); }
.bar.spent-over { background: linear-gradient(180deg, var(--red), #b91c4b); }
.week .lbl { font-size: 11px; color: var(--muted); }
.week .amt { font-size: 13px; font-weight: 800; margin-top: 4px; }
.week .wbudget { font-size: 11px; color: var(--dim); }

/* ---- day heatmap ---- */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-cell {
  aspect-ratio: 1; border-radius: 9px; background: var(--bg2); border: 1px solid var(--line);
  display: grid; place-content: center; font-size: 12px; color: var(--dim); position: relative; cursor: default;
}
.day-cell .d { font-weight: 700; }
.day-cell.under { background: linear-gradient(135deg, rgba(52,211,153,.22), rgba(5,150,105,.12)); border-color: rgba(52,211,153,.4); color: var(--green); }
.day-cell.over { background: linear-gradient(135deg, rgba(251,113,133,.22), rgba(185,28,75,.12)); border-color: rgba(251,113,133,.4); color: var(--red); }
.day-cell.today { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--txt); }
.day-cell.future { opacity: .5; }

/* ---- overview stats ---- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 14px;
}
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-weight: 800; font-size: 20px; margin-top: 3px; letter-spacing: -.02em; }
.stat.pot { grid-column: 1 / -1; background: linear-gradient(135deg, rgba(124,92,255,.18), rgba(96,165,250,.08)); border-color: rgba(124,92,255,.4); }
.stat.pot .v { font-size: 26px; }

/* ---- lists / plan editor ---- */
.line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border: none; }
.line .lbl-in { flex: 1; background: transparent; border: none; color: var(--txt); padding: 4px; border-radius: 6px; }
.line .lbl-in:focus, .line .amt-in:focus { outline: none; background: var(--bg2); }
.line .amt-in { width: 100px; text-align: right; background: transparent; border: none; color: var(--txt); font-weight: 700; padding: 4px; border-radius: 6px; }
.line .kr { color: var(--dim); font-size: 12px; }
.line .del { color: var(--dim); background: none; padding: 4px 6px; border-radius: 6px; }
.line .del:hover { color: var(--red); background: var(--bg2); }
.subtotal { display: flex; justify-content: space-between; margin-top: 10px; font-weight: 800; }
.subtotal .v { color: var(--txt); }
.add-line { margin-top: 10px; color: var(--accent); background: var(--bg2); border: 1px dashed var(--line); border-radius: 10px; padding: 8px; width: 100%; font-weight: 600; }
.add-line:hover { border-color: var(--accent); }

.section-tab { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-bottom: 6px; }
.tab-bill { background: rgba(96,165,250,.15); color: var(--blue); }
.tab-inst { background: rgba(251,191,36,.15); color: var(--amber); }

/* ---- savings goals ---- */
.goal { margin-bottom: 14px; }
.goal .top { display: flex; justify-content: space-between; margin-bottom: 6px; }
.goal .top .name { font-weight: 700; }
.goal .top .num { color: var(--muted); font-size: 13px; }
.goal .track { height: 12px; border-radius: 8px; background: var(--ring-bg); overflow: hidden; }
.goal .fill { height: 100%; border-radius: 8px; background: linear-gradient(90deg, var(--green), var(--blue)); transition: width .6s; }

/* ---- spend log ---- */
.log-item { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.log-item:last-child { border: none; }
.log-item .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-content: center; background: var(--bg2); font-size: 16px; }
.log-item .meta { flex: 1; }
.log-item .meta .t { font-weight: 600; }
.log-item .meta .s { color: var(--muted); font-size: 12px; }
.log-item .amt { font-weight: 800; }
.log-item .x { color: var(--dim); background: none; padding: 4px; }
.log-item .x:hover { color: var(--red); }
.empty { color: var(--dim); text-align: center; padding: 20px; font-size: 14px; }

/* ---- badges ---- */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { text-align: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; opacity: .35; filter: grayscale(1); transition: .3s; }
.badge.got { opacity: 1; filter: none; border-color: rgba(124,92,255,.4); }
.badge .ic { font-size: 26px; }
.badge .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--card2); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 20px;
  box-shadow: var(--shadow); font-weight: 600; transition: transform .35s cubic-bezier(.2,.9,.3,1.2); z-index: 50;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.good { border-color: var(--green); }
.toast.bad { border-color: var(--red); }

.horizon-toggle { display: flex; gap: 4px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.horizon-toggle button { padding: 6px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 13px; }
.horizon-toggle button.on { background: var(--accent); color: white; }

/* split toggle + hint + shared chip */
.split-toggle { background: var(--bg2); border: 1px solid var(--line); color: var(--muted); border-radius: 12px; padding: 11px 14px; font-weight: 600; white-space: nowrap; }
.split-toggle.on { background: rgba(96,165,250,.18); border-color: var(--blue); color: var(--blue); }
.quick-hint { color: var(--blue); font-size: 12px; margin-top: 8px; min-height: 16px; }
.chip-split { font-size: 10px; font-weight: 700; background: rgba(96,165,250,.18); color: var(--blue); padding: 1px 6px; border-radius: 6px; margin-left: 4px; vertical-align: middle; }
.day-cell[data-day] { cursor: pointer; }
.day-cell[data-day]:hover { border-color: var(--accent); }
.day-cell.active { outline: 2px solid var(--accent); outline-offset: 1px; box-shadow: 0 0 0 4px rgba(124,92,255,.18); }
.day-cell.today.active { outline-color: var(--accent); }

/* ---------- phone ---------- */
@media (max-width: 640px) {
  #app { padding: 12px 12px 60px; }
  body { overflow-x: hidden; }
  .topbar { gap: 8px; margin-bottom: 16px; }
  .brand { font-size: 17px; width: 100%; }
  .topbar .spacer { display: none; }
  .month-select { flex: 1 1 auto; min-width: 130px; }
  .horizon-toggle { order: 10; flex-basis: 100%; }
  .horizon-toggle button { flex: 1; }
  .icon-btn { padding: 8px 10px; font-size: 13px; }

  .player { flex-wrap: wrap; gap: 12px; padding: 14px; }
  .xpbar { order: 5; flex-basis: 100%; }
  .player .who { min-width: 0; flex: 1; }
  .stat-chip { padding: 2px 4px; }

  .card { padding: 16px; border-radius: 16px; }
  .today { flex-direction: column; align-items: stretch; gap: 16px; }
  .ring-wrap { margin: 0 auto; }
  .quick { gap: 8px; }
  .quick input.amt { flex: 1; width: auto; }
  .quick select { flex: 1; }
  .quick .note { flex-basis: 100%; order: 4; }
  .split-toggle { flex: 1; text-align: center; }
  .quick .add { flex-basis: 100%; order: 5; padding: 13px; }

  .weeks { gap: 8px; }
  .bar-col { height: 92px; }
  .week .lbl { font-size: 10px; }
  .week .amt { font-size: 12px; }
  .week .wbudget { font-size: 10px; }
  .day-cell { border-radius: 8px; font-size: 11px; }
  .stat.pot .v { font-size: 22px; }
  .level-badge { width: 46px; height: 46px; }
  .level-badge b { font-size: 18px; }

  /* Plan editor rows: label on its own full-width line, amount/goal/delete below,
     so nothing overflows the card on a narrow screen. */
  .line { flex-wrap: wrap; gap: 6px 8px; padding: 10px 0; }
  .line .lbl-in { flex: 1 1 100%; background: var(--bg2); padding: 9px 10px; border-radius: 8px; }
  .line .amt-in { flex: 1 1 auto; width: auto; background: var(--bg2); padding: 9px 10px; border-radius: 8px; }
  .line .goal-in { flex: 1 1 auto; width: auto !important; background: var(--bg2); padding: 9px 10px; border-radius: 8px; }
  .line .kr { align-self: center; }
  .line .del { align-self: center; padding: 8px 10px; }
  .stats { grid-template-columns: 1fr; }
}
