:root {
        --bg: #f5f5f3;
        --panel: #e9e9e5;
        --ink: #121212;
        --muted: #70706d;
        --accent: #e64a19;
        --danger: #b3261e;
        --line: #d8d8d4;
        --page-pad: 22px;
        --page-width: 88%;
      }
      * {
        box-sizing: border-box;
      }
      [hidden] {
        display: none !important;
      }
      html,
      body {
        margin: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        overscroll-behavior: none;
        background: #dededc;
        color: var(--ink);
        font-family: "Segoe UI", Arial, sans-serif;
      }
      button,
      input,
      select,
      textarea {
        font: inherit;
        color: inherit;
      }
      button {
        cursor: pointer;
        touch-action: manipulation;
      }
      body {
        position: fixed;
        inset: 0;
        display: grid;
        place-items: center;
        padding: 12px;
      }
      .shell {
        width: min(100%, 430px);
        height: min(calc(100svh - 24px), 900px);
        min-height: 620px;
        overflow: hidden;
        background: var(--bg);
        box-shadow: 0 18px 55px rgba(0, 0, 0, 0.18);
      }
      .app {
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
      }
      .masthead {
        padding: max(25px, env(safe-area-inset-top)) var(--page-pad) 0;
        flex: none;
      }
      .brand-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
      }
      .app-title {
        font-size: 46px;
        line-height: 0.95;
        font-weight: 200;
        margin: 3px 0 7px;
        letter-spacing: -0.06em;
      }
      .quick-add {
        border: 0;
        background: var(--ink);
        color: #fff;
        min-height: 42px;
        padding: 10px 15px;
        font-size: 14px;
        font-weight: 600;
        white-space: nowrap;
      }
      .pivot-mask {
        overflow: hidden;
        margin-left: var(--page-pad);
        flex: none;
      }
      .pivot-strip {
        display: flex;
        gap: 27px;
        align-items: flex-end;
        width: max-content;
        transform: translateX(0);
        transition: transform 0.32s cubic-bezier(0.22, 0.8, 0.26, 1);
        padding: 11px 86px 11px 0;
        will-change: transform;
      }
      .pivot {
        border: 0;
        background: none;
        padding: 0;
        font-size: 27px;
        font-weight: 300;
        color: #aaa;
        white-space: nowrap;
        line-height: 1;
      }
      .pivot.active {
        color: var(--ink);
      }
      .viewport {
        position: relative;
        flex: 1;
        overflow: hidden;
        touch-action: pan-y;
      }
      .track {
        height: 100%;
        display: flex;
        transition: transform 0.34s cubic-bezier(0.22, 0.8, 0.26, 1);
        will-change: transform;
      }
      .page {
        height: 100%;
        flex: 0 0 var(--page-width);
        padding: 10px 12px max(30px, env(safe-area-inset-bottom))
          var(--page-pad);
        overflow-y: auto;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        scrollbar-width: none;
      }
      .page::-webkit-scrollbar {
        display: none;
      }
      .page + .page {
        padding-left: 18px;
      }
      .hero {
        padding: 10px 0 20px;
      }
      .big-number {
        font-size: clamp(49px, 15vw, 64px);
        line-height: 0.92;
        font-weight: 200;
        letter-spacing: -0.065em;
        overflow-wrap: anywhere;
      }
      .hero-label {
        font-size: 14px;
        color: var(--muted);
        margin-top: 10px;
      }
      .accent-line {
        height: 5px;
        background: var(--accent);
        width: 52px;
        margin: 22px 0 0;
      }
      .section-head {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        margin: 0 0 12px;
      }
      .section-title {
        font-size: 13px;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        font-weight: 700;
        margin: 0;
        color: #555;
      }
      .text-button {
        border: 0;
        background: none;
        padding: 2px 0;
        color: var(--accent);
        font-size: 13px;
        font-weight: 600;
      }
      .tile-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 9px;
        margin-bottom: 26px;
      }
      .tile {
        min-height: 122px;
        background: var(--panel);
        padding: 15px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
      }
      .tile.accent {
        background: var(--accent);
        color: #fff;
      }
      .tile.dark {
        background: #222;
        color: #fff;
      }
      .tile.wide {
        grid-column: 1 / -1;
        min-height: 100px;
      }
      .tile-name {
        font-size: 14px;
        font-weight: 600;
        line-height: 1.1;
      }
      .tile-value {
        font-size: 30px;
        font-weight: 300;
        letter-spacing: -0.045em;
        overflow-wrap: anywhere;
      }
      .tile-note {
        font-size: 11px;
        opacity: 0.7;
        margin-top: 3px;
      }
      .list {
        border-top: 1px solid var(--line);
        margin-bottom: 25px;
      }
      .row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px;
        padding: 14px 0;
        border-bottom: 1px solid var(--line);
        align-items: center;
      }
      .row-main {
        min-width: 0;
      }
      .row strong {
        display: block;
        font-size: 16px;
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .row small {
        display: block;
        color: var(--muted);
        margin-top: 3px;
        line-height: 1.25;
      }
      .row-side {
        text-align: right;
      }
      .amount {
        font-size: 16px;
        font-weight: 600;
        white-space: nowrap;
      }
      .amount.income {
        color: #337047;
      }
      .row-actions {
        display: flex;
        justify-content: flex-end;
        gap: 9px;
        margin-top: 5px;
      }
      .row-actions button {
        border: 0;
        background: none;
        padding: 0;
        font-size: 11px;
        color: var(--muted);
      }
      .row-actions .delete {
        color: var(--danger);
      }
      .empty {
        color: var(--muted);
        font-size: 14px;
        line-height: 1.5;
        padding: 24px 0;
        border-top: 1px solid var(--line);
      }
      .page-heading {
        font-size: 36px;
        font-weight: 300;
        line-height: 1.02;
        letter-spacing: -0.045em;
        margin: 4px 0 18px;
      }
      .primary-action {
        width: 100%;
        border: 0;
        background: var(--accent);
        color: #fff;
        min-height: 52px;
        padding: 13px 16px;
        margin: 0 0 12px;
        text-align: left;
        font-size: 17px;
        font-weight: 600;
      }
      .expense-tools { margin-bottom: 17px; }
      .filter-panel { border-bottom: 1px solid var(--line); }
      .filter-panel summary {
        list-style: none;
        padding: 11px 1px;
        color: var(--muted);
        font-size: 13px;
        cursor: pointer;
      }
      .filter-panel summary::-webkit-details-marker { display: none; }
      .filter-panel summary::after {
        content: "+";
        float: right;
        color: var(--ink);
        font-size: 18px;
        line-height: 0.8;
      }
      .filter-panel[open] summary::after { content: "−"; }
      .filter-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 2px 0 12px;
      }
      .filter-grid .wide { grid-column: 1 / -1; }
      .overview-stats {
        border-top: 1px solid var(--line);
        margin-bottom: 25px;
      }
      .stat-row {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 15px;
        padding: 13px 0;
        border-bottom: 1px solid var(--line);
      }
      .stat-row span { color: var(--muted); font-size: 14px; }
      .stat-row strong {
        font-size: 21px;
        font-weight: 400;
        letter-spacing: -0.025em;
        text-align: right;
      }
      .category-highlight {
        background: var(--panel);
        padding: 16px;
        margin-bottom: 26px;
      }
      .category-highlight span {
        display: block;
        color: var(--muted);
        font-size: 12px;
        margin-bottom: 8px;
      }
      .category-highlight strong { font-size: 25px; font-weight: 400; }
      .field-control {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        display: block;
        border: 1px solid var(--line);
        background: #fff;
        border-radius: 0;
        min-height: 42px;
        padding: 9px 10px;
        font-size: 16px;
        outline: none;
        touch-action: manipulation;
      }
      input.field-control,
      textarea.field-control {
        -webkit-user-select: text;
        user-select: text;
        -webkit-touch-callout: default;
      }
      input[type="date"].field-control,
      input[type="month"].field-control {
        min-height: 46px;
        -webkit-appearance: none;
        appearance: none;
      }
      .field-control:focus {
        border-color: var(--accent);
        box-shadow: inset 3px 0 0 var(--accent);
      }
      .summary-line {
        display: flex;
        justify-content: space-between;
        gap: 10px;
        color: var(--muted);
        font-size: 13px;
        margin: 2px 0 10px;
      }
      .metro-bar {
        height: 8px;
        background: #deded9;
        margin-top: 9px;
        overflow: hidden;
      }
      .metro-bar > i {
        display: block;
        height: 100%;
        background: var(--accent);
        width: 0;
        transition: width 0.35s ease;
      }
      .category-row {
        padding: 15px 0;
        border-bottom: 1px solid var(--line);
      }
      .category-top {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px;
      }
      .category-top strong {
        font-weight: 500;
      }
      .category-meta {
        color: var(--muted);
        font-size: 12px;
        margin-top: 3px;
      }
      .budget-input {
        width: 112px;
        text-align: right;
      }
      .over {
        color: var(--danger);
      }
      .category-manager {
        display: flex;
        gap: 8px;
        margin: 18px 0 24px;
      }
      .category-manager input {
        min-width: 0;
      }
      .button {
        border: 0;
        background: var(--ink);
        color: #fff;
        min-height: 42px;
        padding: 10px 15px;
        font-weight: 600;
      }
      .button.accent {
        background: var(--accent);
      }
      .sheet-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.38);
        z-index: 10;
        display: grid;
        align-items: end;
        justify-items: center;
        opacity: 0;
        visibility: hidden;
        transition:
          opacity 0.2s ease,
          visibility 0.2s;
      }
      .sheet-backdrop.open {
        opacity: 1;
        visibility: visible;
      }
      .sheet {
        width: min(100%, 430px);
        max-height: min(92svh, 820px);
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        background: var(--bg);
        padding: 22px 22px max(24px, env(safe-area-inset-bottom));
        transform: translateY(35px);
        transition: transform 0.28s cubic-bezier(0.22, 0.8, 0.26, 1);
      }
      .sheet-backdrop.open .sheet {
        transform: translateY(0);
      }
      .sheet-header {
        display: flex;
        justify-content: space-between;
        align-items: start;
        gap: 16px;
        margin-bottom: 20px;
      }
      .sheet-title {
        font-size: 31px;
        font-weight: 300;
        letter-spacing: -0.04em;
        margin: 0;
      }
      .close-button {
        border: 0;
        background: none;
        font-size: 27px;
        line-height: 1;
        padding: 0;
        color: var(--muted);
      }
      .tabs {
        display: flex;
        border-bottom: 1px solid var(--line);
        margin-bottom: 18px;
      }
      .tab {
        flex: 1;
        border: 0;
        background: none;
        padding: 10px 4px;
        color: var(--muted);
      }
      .tab.active {
        color: var(--ink);
        box-shadow: inset 0 -4px 0 var(--accent);
      }
      .form-grid {
        display: grid;
        gap: 14px;
        min-width: 0;
        width: 100%;
      }
      .field { min-width: 0; width: 100%; }
      .field label {
        display: block;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.09em;
        font-weight: 700;
        color: #555;
        margin-bottom: 6px;
      }
      textarea.field-control {
        min-height: 82px;
        resize: vertical;
      }
      .form-actions {
        display: flex;
        justify-content: flex-end;
        gap: 10px;
        margin-top: 20px;
      }
      .form-error {
        color: var(--danger);
        font-size: 13px;
        min-height: 18px;
        margin-top: 8px;
      }
      .toast {
        position: fixed;
        z-index: 20;
        left: 50%;
        bottom: max(20px, env(safe-area-inset-bottom));
        transform: translate(-50%, 20px);
        background: #222;
        color: #fff;
        padding: 11px 16px;
        font-size: 13px;
        opacity: 0;
        pointer-events: none;
        transition: 0.2s ease;
        white-space: nowrap;
      }
      .toast.show {
        opacity: 1;
        transform: translate(-50%, 0);
      }
      .auth-gate {
        position: fixed;
        inset: 0;
        z-index: 30;
        display: grid;
        place-items: center;
        padding: max(22px, env(safe-area-inset-top)) 22px max(22px, env(safe-area-inset-bottom));
        background: var(--bg);
      }
      .auth-card { width: min(100%, 386px); }
      .auth-mark {
        width: 56px;
        height: 56px;
        display: grid;
        place-items: center;
        margin-bottom: 30px;
        background: var(--accent);
        color: #fff;
        font-size: 29px;
        font-weight: 500;
      }
      .auth-card h1 {
        margin: 0 0 10px;
        font-size: 43px;
        line-height: 0.95;
        font-weight: 200;
        letter-spacing: -0.055em;
      }
      .auth-card > p {
        margin: 0 0 28px;
        color: var(--muted);
        font-size: 14px;
        line-height: 1.5;
      }
      .auth-card .button { width: 100%; min-height: 50px; }
      .auth-reset { justify-self: center; margin-top: 2px; }
      .settings-group {
        margin: 0 0 25px;
        border-top: 1px solid var(--line);
      }
      .settings-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 16px;
        align-items: center;
        padding: 15px 0;
        border-bottom: 1px solid var(--line);
      }
      .settings-row span {
        display: block;
        color: var(--muted);
        font-size: 12px;
        margin-bottom: 4px;
      }
      .settings-row strong {
        display: block;
        font-size: 15px;
        font-weight: 500;
        overflow-wrap: anywhere;
      }
      .sync-dot {
        width: 9px;
        height: 9px;
        border-radius: 50%;
        background: #337047;
      }
      .sync-dot.offline { background: #8a8a86; }
      .sync-dot.saving { background: var(--accent); }
      .settings-copy {
        color: var(--muted);
        font-size: 13px;
        line-height: 1.5;
        margin: 9px 0 18px;
      }
      .settings-action {
        width: 100%;
        text-align: left;
        background: var(--panel);
        color: var(--ink);
      }
      @media (max-width: 480px) {
        body {
          padding: 0;
        }
        .shell {
          width: 100%;
          height: 100dvh;
          min-height: 0;
          box-shadow: none;
        }
      }
      @media (max-height: 700px) {
        .masthead {
          padding-top: 14px;
        }
        .app-title {
          font-size: 38px;
        }
        .pivot {
          font-size: 24px;
        }
        .pivot-strip {
          padding-top: 8px;
          padding-bottom: 8px;
        }
      }
      @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
          scroll-behavior: auto !important;
          transition-duration: 0.01ms !important;
        }
      }
