:root {
  --paper: #F3F5F1;
  --paper-2: #E8EDE7;
  --ink: #142B23;
  --ink-2: #4E6359;
  --green: #1F6B52;
  --mint: #CFE3D6;
  --plum: #7A2E5E;
  --plum-soft: #F1E1EB;
  --rule: #D5DDD6;
  --over: #A3361F;
  --radius: 10px;
  --wide: "Archivo", system-ui, sans-serif;
  --bangla: "Hind Siliguri", "Archivo", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F1C17; --paper-2: #16271F; --ink: #E7EEE9; --ink-2: #9DB2A7;
    --green: #6CC4A1; --mint: #24453A; --plum: #E08BBE; --plum-soft: #3A2132;
    --rule: #26392F; --over: #F08A6E; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font-family: var(--wide); font-size: 16px; line-height: 1.45;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--green); }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---- Top bar ---- */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--paper);
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--rule);
}
.mark { display: flex; align-items: baseline; gap: 8px; text-decoration: none; color: var(--ink); }
.mark b { font-family: var(--bangla); font-weight: 700; font-size: 22px; color: var(--green); }
.mark span { font-size: 13px; color: var(--ink-2); }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; padding: 2px; background: var(--paper-2); }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-size: 14px; cursor: pointer; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

main { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.view { display: none; }
.view.on { display: block; }

/* ---- Home hero ---- */
.hero { padding: 28px 0 8px; }
.hero p { margin: 0; color: var(--ink-2); font-size: 17px; max-width: 30ch; }
.big {
  font-family: var(--wide); font-stretch: 112%; font-weight: 800; letter-spacing: -0.02em;
  font-size: clamp(48px, 15vw, 92px); line-height: 0.95; margin: 6px 0 6px; color: var(--ink);
}
.big.neg { color: var(--over); }
.sub { color: var(--ink-2); font-size: 15px; }
.sub strong { color: var(--ink); font-weight: 600; }

/* Runway ribbon: one bar per month, height = closing balance */
.ribbon { margin: 22px 0 6px; }
.bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; align-items: end; height: 132px; position: relative; }
.bar { position: relative; height: 100%; display: flex; align-items: flex-end; cursor: pointer; border: 0; background: none; padding: 0; }
.bar i { display: block; width: 100%; background: var(--mint); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar.past i { background: var(--paper-2); outline: 1px solid var(--rule); }
.bar.current i { background: var(--green); }
.bar.low i { background: var(--plum); }
.bar.neg i { background: var(--over); }
.bar em { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--h) + 4px); width: 7px; height: 7px; border-radius: 50%; background: var(--plum); }
.track-line { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--ink-2); opacity: .55; pointer-events: none; }
.months { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; margin-top: 6px; font-size: 11px; color: var(--ink-2); text-align: center; }
.months .yr { color: var(--ink); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; background: var(--k); }
.callout { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--plum); background: var(--plum-soft); border-radius: 0 var(--radius) var(--radius) 0; font-size: 15px; }

/* ---- Sections ---- */
.sec { padding: 22px 0; border-top: 1px solid var(--rule); }
.sec h2 { font-size: 20px; font-weight: 700; margin: 0 0 12px; letter-spacing: -0.01em; }
.sec h3 { font-size: 15px; font-weight: 600; margin: 18px 0 6px; color: var(--ink-2); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule); }
.row:last-child { border-bottom: 0; }
.row .l { min-width: 0; }
.row .l small { display: block; color: var(--ink-2); font-size: 13px; }
.row .r { text-align: right; white-space: nowrap; font-weight: 600; }
.row .r small { display: block; font-weight: 400; color: var(--ink-2); font-size: 13px; }
.in { color: var(--green); }
.out { color: var(--ink); }
.muted { color: var(--ink-2); }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--paper-2); color: var(--ink-2); margin-left: 6px; vertical-align: 1px; }

.meter { height: 10px; background: var(--paper-2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.meter i { display: block; height: 100%; background: var(--green); border-radius: 999px; }
.meter.over i { background: var(--over); }
.split { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 18px 24px; }
.stat b { display: block; font-size: 24px; font-stretch: 108%; font-weight: 700; letter-spacing: -0.01em; }
.stat span { font-size: 14px; color: var(--ink-2); }

/* ---- Buttons & forms ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer;
  background: var(--green); color: #fff; padding: 12px 18px; border-radius: var(--radius); font-weight: 600; font-size: 16px; }
@media (prefers-color-scheme: dark) { .btn { color: #0F1C17; } }
.btn.ghost { background: transparent; color: var(--green); border: 1px solid var(--rule); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--ink-2); cursor: pointer; padding: 4px; font-size: 14px; text-decoration: underline; }
label.f { display: block; margin: 0 0 14px; font-size: 14px; color: var(--ink-2); }
label.f > span { display: block; margin-bottom: 5px; }
input, select { width: 100%; padding: 11px 12px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); font-size: 16px; }
input.amount { font-size: 34px; font-weight: 700; font-stretch: 110%; padding: 8px 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.err { color: var(--over); font-size: 14px; min-height: 1.2em; margin: 4px 0 8px; }

/* ---- Plan table ---- */
.ptable { width: 100%; border-collapse: collapse; font-size: 15px; }
.ptable th { text-align: right; font-weight: 500; color: var(--ink-2); font-size: 13px; padding: 6px 4px; border-bottom: 1px solid var(--rule); }
.ptable th:first-child { text-align: left; }
.ptable td { white-space: nowrap; padding: 10px 4px; text-align: right; border-bottom: 1px solid var(--rule); }
.ptable td:first-child { text-align: left; font-weight: 600; }
.ptable tr.mrow { cursor: pointer; }
.ptable tr.cur td:first-child::after { content: "now"; margin-left: 6px; font-size: 11px; font-weight: 500; color: var(--paper); background: var(--green); padding: 1px 6px; border-radius: 999px; }
.ptable tr.lowrow td { color: var(--plum); }
.ptable tr.detail td { text-align: left; background: var(--paper-2); padding: 4px 12px 10px; }
.ptable .d { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 14px; border-bottom: 1px dotted var(--rule); }
.ptable .d:last-child { border: 0; }
.ptable .d > span:last-child { white-space: nowrap; }

@media (max-width: 520px) { .ptable .c-start { display: none; } .ptable { font-size: 14px; } }
.ptable tr.detail td { white-space: normal; }

/* ---- Bottom nav ---- */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--paper); border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { background: none; border: 0; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--ink-2); cursor: pointer; }
nav.tabs svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs button[aria-current="page"] { color: var(--green); font-weight: 600; }

/* ---- Gate / onboarding ---- */
.gate { max-width: 440px; margin: 10vh auto 0; padding: 0 16px; }
.gate .wm { font-family: var(--bangla); font-size: 54px; font-weight: 700; color: var(--green); line-height: 1; }
.gate .wm small { display: block; font-family: var(--wide); font-size: 15px; font-weight: 500; color: var(--ink-2); margin-top: 6px; }
.gate p { color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius); font-size: 15px; z-index: 9; }

/* ---- Wider screens ---- */
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  nav.tabs { position: sticky; top: 59px; bottom: auto; display: flex; justify-content: center; gap: 6px; border-top: 0; border-bottom: 1px solid var(--rule); }
  nav.tabs button { flex-direction: row; gap: 8px; padding: 12px 16px; font-size: 15px; }
  .home-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 0 48px; }
  .home-grid > .side { padding-top: 28px; }
  .home-grid > .side .sec:first-child { border-top: 0; padding-top: 0; }
  .bars { height: 180px; }
  .toast { bottom: 24px; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar i { transition: height .5s cubic-bezier(.2,.8,.2,1); }
}
