    :root {
      --bg: #080b10;
      --surface: #0e1118;
      --card: #131720;
      --border: #1e2535;
      --accent: #f5c518;
      --accent2: #3d6fff;
      --saffron: #e87a12;
      --danger: #ff4757;
      --warn: #ffa502;
      --text: #eef2ff;
      --muted: #8896b3;
      --subtle: #1e2535;
      --mono: 'DM Mono', monospace;
    }

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

    html,
    body {
      height: 100%;
      overflow: hidden;
    }

    body {
      font-family: 'Inter', sans-serif;
      background: var(--bg);
      color: var(--text);
      -webkit-font-smoothing: antialiased;
      -webkit-tap-highlight-color: transparent;
    }

    /* Setup */
    #setup {
      height: 100vh;
      height: 100dvh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 24px;
      overflow-y: auto;
    }

    .si {
      width: 100%;
      max-width: 420px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
    }

    .logo-text {
      font-family: 'Cormorant Garamond', serif;
      font-size: 44px;
      font-weight: 300;
      letter-spacing: 3px;
      margin-bottom: 4px;
    }

    .logo-text .lo {
      font-weight: 700;
      font-style: italic;
      color: #f5c518;
    }

    .logo-sub {
      font-size: 14px;
      color: var(--muted);
      margin-bottom: 28px;
      text-align: center;
      line-height: 1.6;
    }

    .sc {
      width: 100%;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 18px;
      padding: 24px;
      margin-bottom: 8px;
    }

    .sc h3 {
      font-size: 12px;
      color: var(--accent);
      text-transform: uppercase;
      letter-spacing: 2px;
      margin-bottom: 10px;
    }

    .sc p {
      font-size: 14px;
      color: var(--muted);
      line-height: 1.7;
      margin-bottom: 12px;
    }

    .dots {
      display: flex;
      gap: 8px;
      margin-bottom: 20px;
      justify-content: center;
    }

    .dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: var(--border);
      transition: background .3s;
    }

    .dot.active {
      background: var(--accent);
    }

    .dot.done {
      background: var(--accent2);
    }

    /* Buttons */
    .btn {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      width: 100%;
      border: none;
      border-radius: 12px;
      padding: 13px 20px;
      font-family: 'Inter', sans-serif;
      font-size: 14px;
      font-weight: 700;
      cursor: pointer;
      transition: opacity .2s, transform .1s;
    }

    .btn:active {
      transform: scale(.98);
    }

    .btn:disabled {
      opacity: .4;
      cursor: not-allowed;
    }

    .bp {
      background: var(--accent);
      color: #000;
    }

    .bs {
      background: var(--card);
      color: var(--text);
      border: 1px solid var(--border);
    }

    .bg {
      background: #fff;
      color: #1f1f1f;
      border: 1px solid #dadce0;
      margin-top: 14px;
    }

    .bsm {
      padding: 7px 14px;
      font-size: 12px;
      width: auto;
      border-radius: 8px;
    }

    /* Inputs */
    .fi,
    .fs {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 11px 14px;
      color: var(--text);
      font-family: 'Inter', sans-serif;
      font-size: 14px;
      outline: none;
      transition: border-color .2s;
      width: 100%;
    }

    .fi:focus,
    .fs:focus {
      border-color: var(--accent2);
    }

    .fi::placeholder {
      color: var(--muted);
    }

    input[type=number]::-webkit-inner-spin-button,
    input[type=number]::-webkit-outer-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }

    input[type=number] {
      -moz-appearance: textfield;
      appearance: textfield;
    }

    .fs option {
      background: var(--card);
    }

    textarea.fi {
      resize: vertical;
      min-height: 100px;
      font-size: 13px;
      font-family: var(--mono);
    }

    .sfi {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 12px 14px;
      color: var(--text);
      font-family: var(--mono);
      font-size: 13px;
      outline: none;
      width: 100%;
      transition: border-color .2s;
      margin-top: 12px;
    }

    .sfi:focus {
      border-color: var(--accent2);
    }

    .sfi::placeholder {
      color: var(--muted);
    }

    .fl {
      font-size: 11px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 1px;
      margin-bottom: 5px;
      display: block;
    }

    .fg {
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .fr {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
    }

    .full {
      grid-column: 1/-1;
    }

    /* Type toggle */
    .tt {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    .tb {
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 11px;
      font-family: 'Inter', sans-serif;
      font-size: 14px;
      font-weight: 700;
      cursor: pointer;
      transition: all .2s;
      background: var(--card);
      color: var(--muted);
    }

    .tb.income.active {
      background: #2a2200;
      border-color: var(--accent);
      color: var(--accent);
    }

    .tb.expense.active {
      background: #3d0a10;
      border-color: var(--danger);
      color: var(--danger);
    }

    /* App shell */
    #app {
      height: 100vh;
      height: 100dvh;
      display: none;
      flex-direction: column;
      position: relative;
    }

    .ah {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 12px 16px;
      padding-top: calc(12px + env(safe-area-inset-top));
      border-bottom: 1px solid var(--border);
      background: var(--bg);
      flex-shrink: 0;
      z-index: 10;
    }

    .hl {
      font-family: 'Cormorant Garamond', serif;
      font-size: 22px;
      font-weight: 300;
      letter-spacing: 1px;
    }

    .hl .lo {
      font-weight: 700;
      font-style: italic;
      color: #f5c518;
    }

    .hr2 {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .hp {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 20px;
      padding: 5px 10px;
      font-size: 12px;
      color: var(--muted);
      display: flex;
      align-items: center;
      gap: 5px;
      max-width: 150px;
      overflow: hidden;
    }

    .hp .d {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--accent);
      flex-shrink: 0;
    }

    .hp .e {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .ib {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 8px 14px;
      color: var(--text);
      font-size: 20px;
      cursor: pointer;
      line-height: 1;
    }

    /* Nav */
    .nav {
      display: flex;
      background: var(--surface);
      border-top: 1px solid var(--border);
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 100;
      padding-bottom: env(safe-area-inset-bottom);
    }

    .nb {
      flex: 1;
      min-width: 48px;
      background: none;
      border: none;
      color: var(--muted);
      font-family: 'Inter', sans-serif;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-start;
      gap: 3px;
      padding: 8px 4px 10px;
      transition: color .2s;
      -webkit-appearance: none;
      appearance: none;
    }

    .nb .ni {
      font-size: 20px;
      line-height: 1;
    }

    .nb .nl {
      font-size: 11px;
      font-weight: 600;
      white-space: nowrap;
      line-height: 1;
    }

    .nb.active {
      color: var(--accent);
    }

    /* Pages */
    .pages {
      flex: 1;
      overflow: hidden;
      position: relative;
    }

    .page {
      position: absolute;
      inset: 0;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      padding: 16px;
      display: none;
      padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    .page.active {
      display: block;
    }

    .page::-webkit-scrollbar {
      width: 3px;
    }

    .page::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 3px;
    }

    /* Cards */
    .card {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 16px;
      margin-bottom: 12px;
    }

    /* Stats */
    .sg {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      margin-bottom: 14px;
    }

    .stc {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 14px;
    }

    .stl {
      font-size: 11px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 1px;
      margin-bottom: 6px;
    }

    .stv {
      font-size: 20px;
      font-weight: 800;
      letter-spacing: -1px;
      font-family: var(--mono);
    }

    .ste {
      font-size: 12px;
      color: var(--muted);
      font-family: var(--mono);
      margin-top: 2px;
    }

    .sts {
      font-size: 12px;
      color: var(--muted);
      margin-top: 3px;
    }

    /* Section heads */
    .sh {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin: 16px 0 10px;
    }

    .sht {
      font-size: 11px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 1px;
    }

    /* Tx rows */
    .txl {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }

    .txr {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 12px 14px;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .txn {
      font-size: 14px;
      font-weight: 600;
      margin-bottom: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 180px;
    }

    .txm {
      font-size: 12px;
      color: var(--muted);
    }

    .txa {
      font-size: 14px;
      font-weight: 700;
      font-family: var(--mono);
      text-align: right;
    }

    .txe {
      font-size: 11px;
      color: var(--muted);
      font-family: var(--mono);
      text-align: right;
    }

    .tdel {
      background: none;
      border: none;
      color: var(--muted);
      cursor: pointer;
      padding: 4px 8px;
      border-radius: 6px;
      font-size: 14px;
      flex-shrink: 0;
    }

    .tag {
      display: inline-block;
      padding: 2px 7px;
      border-radius: 10px;
      font-size: 11px;
      font-weight: 700;
      margin-left: 4px;
      vertical-align: middle;
    }

    .ti {
      background: #2a2200;
      color: var(--accent);
    }

    .te {
      background: #3d0a10;
      color: var(--danger);
    }

    .tr {
      background: #1a2a4a;
      color: var(--accent2);
    }

    /* Charts */
    .bc {
      width: 100%;
    }

    .chartleg {
      display: flex;
      flex-wrap: wrap;
      gap: 8px 16px;
      margin-top: 10px;
    }

    .legitem {
      display: flex;
      align-items: center;
      gap: 5px;
      font-size: 11px;
      color: var(--muted);
    }

    .legdot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      flex-shrink: 0;
    }

    .cr {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 8px;
    }

    .cn {
      font-size: 13px;
      width: 110px;
      flex-shrink: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .ct {
      flex: 1;
      background: var(--border);
      border-radius: 4px;
      height: 6px;
    }

    .cf {
      height: 6px;
      border-radius: 4px;
      background: var(--accent2);
      transition: width .5s;
    }

    .cv {
      font-size: 12px;
      color: var(--muted);
      font-family: var(--mono);
      width: 72px;
      text-align: right;
      flex-shrink: 0;
    }

    /* Parse */
    .pb {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 16px;
      margin-top: 12px;
    }

    .pt {
      font-size: 11px;
      color: var(--accent);
      text-transform: uppercase;
      letter-spacing: 1px;
      margin-bottom: 12px;
    }

    .pr {
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 10px 12px;
      margin-bottom: 8px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 8px;
    }

    /* Settings */
    .sgl {
      font-size: 11px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 1px;
      margin-bottom: 8px;
    }

    .srow {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 14px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 6px;
    }

    .srt {
      font-size: 14px;
      font-weight: 600;
    }

    .srs {
      font-size: 12px;
      color: var(--muted);
      margin-top: 2px;
      font-family: var(--mono);
    }

    .sra {
      background: var(--subtle);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 6px 12px;
      color: var(--text);
      font-family: 'Inter', sans-serif;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      flex-shrink: 0;
      white-space: nowrap;
    }

    .badge {
      display: inline-flex;
      align-items: center;
      padding: 3px 8px;
      border-radius: 12px;
      font-size: 12px;
      font-weight: 700;
    }

    .bok {
      background: #2a2200;
      color: var(--accent);
    }

    .bmiss {
      background: #3d0a10;
      color: var(--danger);
    }

    /* Recurring */
    .rrow {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 12px 14px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 6px;
    }

    .due {
      background: #1a2a0a;
      color: #7adb4a;
      border-radius: 8px;
      padding: 2px 8px;
      font-size: 11px;
      font-weight: 700;
    }

    /* Filter */
    .frow {
      display: flex;
      gap: 8px;
      margin-bottom: 14px;
    }

    /* Custom month picker */
    .mpick {
      display: flex;
      align-items: center;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 10px;
      overflow: hidden;
      flex: 1;
    }

    .mp-btn {
      background: none;
      border: none;
      color: var(--muted);
      padding: 0 14px;
      height: 38px;
      cursor: pointer;
      font-size: 18px;
      line-height: 1;
      transition: color .15s;
      flex-shrink: 0;
    }

    .mp-btn:active {
      color: var(--text);
    }

    .mp-label {
      flex: 1;
      text-align: center;
      font-size: 13px;
      font-weight: 600;
      color: var(--text);
      white-space: nowrap;
      letter-spacing: 0.2px;
    }

    /* View toggle pills */
    .vtabs {
      display: flex;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 10px;
      overflow: hidden;
      flex-shrink: 0;
    }

    .vt {
      background: none;
      border: none;
      color: var(--muted);
      font-family: 'Inter', sans-serif;
      font-size: 12px;
      font-weight: 600;
      padding: 0 12px;
      height: 38px;
      cursor: pointer;
      transition: all .15s;
      white-space: nowrap;
    }

    .vt+.vt {
      border-left: 1px solid var(--border);
    }

    .vt.active {
      background: var(--subtle);
      color: var(--text);
    }

    .vt[data-v="income"].active {
      color: var(--accent);
    }

    .vt[data-v="expense"].active {
      color: var(--danger);
    }

    /* Empty */
    .empty {
      text-align: center;
      padding: 40px 16px;
      color: var(--muted);
      font-size: 14px;
      line-height: 1.8;
    }

    /* Toast */
    #toast {
      position: fixed;
      bottom: 84px;
      left: 50%;
      transform: translateX(-50%);
      background: var(--accent);
      color: #000;
      padding: 9px 18px;
      border-radius: 20px;
      font-size: 13px;
      font-weight: 700;
      z-index: 9999;
      opacity: 0;
      transition: opacity .3s;
      pointer-events: none;
      white-space: nowrap;
      max-width: calc(100vw - 32px);
    }

    #toast.show {
      opacity: 1;
    }

    #toast.err {
      background: var(--danger);
      color: #fff;
    }

    #toast.wrn {
      background: var(--warn);
      color: #000;
    }

    /* Loading */
    #loading {
      position: fixed;
      inset: 0;
      background: var(--bg);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 16px;
      z-index: 999;
      transition: opacity .4s;
    }

    #loading.hide {
      opacity: 0;
      pointer-events: none;
    }

    .spin {
      width: 40px;
      height: 40px;
      border: 3px solid var(--border);
      border-top-color: var(--saffron);
      border-radius: 50%;
      animation: sp .8s linear infinite;
    }

    @keyframes sp {
      to {
        transform: rotate(360deg);
      }
    }

    .lt {
      font-size: 14px;
      color: var(--muted);
    }

    hr {
      border: none;
      border-top: 1px solid var(--border);
      margin: 14px 0;
    }

    /* Loans */
    .lcard {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 14px 16px;
      margin-bottom: 10px;
      cursor: pointer;
      transition: border-color .2s;
    }

    .lcard:active {
      border-color: var(--accent2);
    }

    .lcard-top {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      margin-bottom: 10px;
    }

    .lcname {
      font-size: 14px;
      font-weight: 600;
      margin-bottom: 2px;
    }

    .lcmeta {
      font-size: 11px;
      color: var(--muted);
    }

    .lcamt {
      font-size: 16px;
      font-weight: 700;
      font-family: var(--mono);
    }

    .lceur {
      font-size: 11px;
      color: var(--muted);
      font-family: var(--mono);
    }

    .lprog-bg {
      background: var(--border);
      border-radius: 4px;
      height: 5px;
      margin-bottom: 8px;
    }

    .lprog-fill {
      height: 5px;
      border-radius: 4px;
      background: var(--accent2);
      transition: width .5s;
    }

    .lcfoot {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 11px;
      color: var(--muted);
    }

    .ldir {
      display: inline-flex;
      align-items: center;
      padding: 2px 7px;
      border-radius: 10px;
      font-size: 10px;
      font-weight: 700;
      margin-left: 6px;
      vertical-align: middle;
    }

    .ldir-t {
      background: #1a1030;
      color: var(--accent2);
    }

    .ldir-g {
      background: #2a2200;
      color: var(--accent);
    }

    .amtbl {
      width: 100%;
      border-collapse: collapse;
      font-size: 11px;
      font-family: var(--mono);
    }

    .amtbl th {
      color: var(--muted);
      font-weight: 600;
      text-align: right;
      padding: 5px 4px;
      border-bottom: 1px solid var(--border);
      font-size: 9px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .amtbl th:first-child {
      text-align: left;
    }

    .amtbl td {
      padding: 5px 4px;
      text-align: right;
      border-bottom: 1px solid var(--subtle);
    }

    .amtbl td:first-child {
      text-align: left;
      color: var(--muted);
      font-size: 10px;
    }

    .amtbl tr.cur-mo td {
      color: var(--accent);
      font-weight: 600;
    }
    .amtbl tr.past-mo td { color: var(--muted); opacity: 0.55; }
    .amtbl tr.past-mo td { color: var(--muted); opacity: 0.55; }

    @media(min-width:600px) {
      .si {
        max-width: 440px;
      }

      #app {
        max-width: 640px;
        margin: 0 auto;
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
      }

      .nav {
        max-width: 640px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
      }

      .sg {
        grid-template-columns: repeat(4, 1fr);
      }
    }
