:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --bg: #F4F6F7;
  --paper: #FFFFFF;
  --line: #EDEDEA;
  --ink: #1A1A18;
  --muted: #8A8A85;
  --accent: #2E3A36;
  --gold: #D4A574;
  --fab-yellow: #FFC900;
  --sage: #7A897E;
  --card-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.04);
  --motion: cubic-bezier(.4,0,.2,1);
  --duration: 200ms;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  transition-duration: var(--duration);
  transition-timing-function: var(--motion);
}

html, body { margin: 0; min-width: 320px; min-height: 100%; overflow-x: hidden; overflow-x: clip; background: var(--bg); }
body { color: var(--ink); font-weight: 400; }
button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
strong, b { font-weight: 500; }
#app { position: relative; width: 100%; max-width: 620px; min-height: 100dvh; margin: 0 auto; padding: 0 20px calc(156px + var(--safe-bottom)); overflow-x: clip; background: var(--bg); }
#screen { animation: appear var(--duration) var(--motion); }

.topbar { display: flex; height: calc(60px + var(--safe-top)); align-items: center; justify-content: space-between; gap: 12px; padding-top: var(--safe-top); }
.brand { display: flex; min-width: 0; align-items: center; gap: 8px; color: var(--ink); font-size: 20px; font-weight: 600; letter-spacing: .04em; text-decoration: none; }
.brand-mark { display: grid; width: 32px; height: 32px; flex: none; place-items: center; border-radius: var(--radius); background: var(--accent); }
.brand-mark svg { width: 20px; height: 20px; fill: none; stroke: #FFFFFF; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.brand-en { margin: 4px 0 0; color: var(--muted); font-size: 8px; font-weight: 500; letter-spacing: .16em; }
.icon-button { display: grid; width: 40px; height: 40px; flex: none; place-items: center; border: 0; border-radius: var(--radius); background: transparent; }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:active { background: #F0F0ED; transform: scale(.96); }

.eyebrow { color: var(--muted); font-size: 12px; font-weight: 400; letter-spacing: .04em; }
.month-line { display: flex; align-items: center; margin: 16px 0 30px; }
.month-picker { display: grid; gap: 2px; min-width: 84px; padding: 8px 12px; border: .5px solid #FFFFFF; border-radius: 22px; background: rgba(255,255,255,.82); box-shadow: var(--card-shadow); }
.month-picker > span:first-child { color: var(--muted); font-size: 10px; font-weight: 400; }
.month-choice { display: flex; align-items: center; gap: 4px; }
.month-select { width: auto; max-width: 74px; padding: 0; border: 0; appearance: none; background: transparent; color: var(--ink); font-size: 16px; font-weight: 500; }
.month-choice svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.home-overview { margin: 0 0 28px; padding: 0 4px; }
.overview-label { color: var(--muted); font-size: 13px; font-weight: 400; }
.overview-total { display: flex; align-items: baseline; gap: 4px; margin: 8px 0 16px; color: var(--ink); font-size: clamp(38px, 11vw, 46px); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.04em; line-height: 1.08; }
.overview-total small { font-size: 20px; font-weight: 400; letter-spacing: 0; }
.summary-pill { display: inline-flex; max-width: 100%; min-height: 36px; flex-wrap: wrap; align-items: center; gap: 12px; padding: 8px 14px; border: .5px solid #FFFFFF; border-radius: 24px; background: rgba(255,255,255,.86); color: var(--muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; box-shadow: 0 1px 2px rgba(0,0,0,.025); }
.summary-pill strong { margin-left: 4px; color: var(--ink); font-size: 13px; font-weight: 500; }
.summary-pill i, .day-totals i { width: 1px; height: 13px; flex: none; background: #D9DDDF; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 12px; }
.section-head h2 { margin: 0; color: var(--ink); font-size: 16px; font-weight: 600; letter-spacing: .005em; }
.section-link { padding: 4px; border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.section-link:active { color: var(--accent); transform: translateX(2px); }
.list, .panel { border: .5px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--card-shadow); }
.list { padding: 0 16px; }
.home-ledger { overflow: hidden; padding: 16px 20px 4px; border: .5px solid #FFFFFF; border-radius: 30px; background: var(--paper); box-shadow: var(--card-shadow); }
.home-day + .home-day { margin-top: 20px; padding-top: 16px; border-top: .5px solid #F0F1F1; }
.day-heading { display: flex; min-height: 36px; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; padding: 7px 12px; border-radius: 24px; background: #F5F7F8; color: var(--muted); font-size: 11px; font-weight: 400; }
.day-heading time { flex: none; }
.day-totals { display: flex; min-width: 0; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.day-totals span { color: var(--ink); }
.day-totals span.income-color { color: var(--sage); }
.day-totals small { color: var(--muted); font-size: 10px; font-weight: 400; }
.home-ledger .transaction { padding: 14px 0; border-bottom: 0; }
.panel { margin-bottom: 12px; padding: 16px; }
.panel h3 { margin: 0 0 16px; color: var(--ink); font-size: 13px; font-weight: 500; }
.transaction { display: flex; width: 100%; min-width: 0; align-items: center; gap: 12px; padding: 16px 0; border: 0; border-bottom: .5px solid var(--line); appearance: none; background: transparent; text-align: left; -webkit-appearance: none; }
.transaction:last-child { border-bottom: 0; }
.transaction:active { background: #F7F7F4; transform: scale(.992); }
.category-icon, .ratio-icon { display: grid; width: 40px; height: 40px; flex: none; place-items: center; border-radius: var(--radius); background: #F5F5F2; color: var(--accent); }
.line-icon { display: block; width: 20px; height: 20px; flex: none; }
.category-glyph { width: 20px; height: 20px; stroke-width: 1.6; }
.transaction-main { display: block; min-width: 0; flex: 1; }
.transaction-title { display: block; overflow: hidden; color: var(--ink); font-size: 13px; font-weight: 500; line-height: 20px; text-overflow: ellipsis; white-space: nowrap; }
.transaction-sub { display: block; overflow: hidden; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 400; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; }
.transaction-amount { flex: none; margin-left: 4px; color: #4B4C47; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; }
.income-color { color: var(--sage); }
.empty { display: flex; min-height: 104px; flex-direction: column; align-items: center; justify-content: center; gap: 8px; margin: 8px 0; padding: 20px 16px; border: 1px dashed #D9D9D3; border-radius: var(--radius); background: var(--paper); }
.empty-title { color: var(--ink); font-size: 13px; font-weight: 500; line-height: 20px; text-align: center; }
.empty-hint { color: var(--muted); font-size: 11px; font-weight: 400; line-height: 16px; text-align: center; }
.trust-note { display: flex; align-items: center; gap: 12px; margin: 18px 4px 0; padding: 12px 16px; border: .5px solid #FFFFFF; border-radius: 28px; background: rgba(255,255,255,.62); box-shadow: var(--card-shadow); }
.trust-icon { display: grid; width: 32px; height: 32px; flex: none; place-items: center; border-radius: 50%; background: #F1F4F2; color: var(--accent); }
.trust-icon .line-icon { width: 18px; height: 18px; }
.trust-note p { margin: 0; color: var(--ink); font-size: 12px; font-weight: 500; }
.trust-note strong { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }

.tabbar { position: fixed; z-index: 10; bottom: 0; left: 50%; display: grid; width: min(100%, 620px); min-height: calc(60px + var(--safe-bottom)); grid-template-columns: repeat(4, 1fr); align-items: center; gap: 4px; padding: 8px 16px calc(8px + var(--safe-bottom)); transform: translateX(-50%); border-top: .5px solid var(--line); background: rgba(244,246,247,.82); box-shadow: 0 -4px 16px rgba(0,0,0,.025); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.tab { position: relative; display: grid; min-width: 0; min-height: 48px; align-content: center; justify-items: center; gap: 4px; padding: 4px 0; border: 0; background: transparent; color: var(--muted); font-size: 10px; font-weight: 400; letter-spacing: .01em; }
.tab:active { transform: scale(.94); }
.tab-icon { display: grid; width: 36px; height: 28px; place-items: center; border-radius: var(--radius); background: transparent; color: var(--muted); }
.tab-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--ink); font-weight: 500; }
.tab.active .tab-icon { background: transparent; color: var(--muted); }
.tab.active .tab-icon svg { stroke: currentColor; stroke-width: 2.2; }
.fab { position: fixed; z-index: 11; bottom: calc(76px + var(--safe-bottom)); left: 50%; display: grid; width: 64px; height: 64px; place-items: center; border: 0; border-radius: 50%; background: var(--fab-yellow); box-shadow: 0 8px 22px rgba(170,133,0,.2); color: #171815; font-size: 34px; font-weight: 400; transform: translateX(-50%); }
.fab:active { transform: translateX(-50%) scale(.92); }
.fab span { margin-top: -4px; }

.page-title { margin: 16px 0 4px; color: var(--ink); font-size: 24px; font-weight: 600; letter-spacing: -.03em; }
.page-subtitle { margin: 0 0 16px; color: var(--muted); font-size: 12px; font-weight: 400; }
.period-switch { display: flex; gap: 4px; margin: 16px 0; padding: 4px; border-radius: var(--radius); background: #F0F0ED; }
.period-switch button { flex: 1; padding: 8px; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted); font-size: 12px; font-weight: 400; }
.period-switch button.selected { background: #FFFFFF; box-shadow: 0 1px 2px rgba(0,0,0,.04); color: var(--ink); font-weight: 500; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric { padding: 12px; border: .5px solid var(--line); border-radius: var(--radius); background: #FFFFFF; }
.metric span { color: var(--muted); font-size: 10px; font-weight: 400; }
.metric strong { display: block; margin-top: 8px; color: var(--ink); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.chart { position: relative; display: flex; height: 144px; align-items: end; gap: 8px; padding: 4px 0 24px; border-bottom: .5px solid var(--line); }
.bar-group { position: relative; display: flex; height: 100%; flex: 1; align-items: end; justify-content: center; gap: 4px; }
.bar { width: min(12px, 38%); min-height: 4px; border-radius: 4px 4px 0 0; background: #C8CEC9; }
.bar.expense { background: var(--accent); }
.bar-label { position: absolute; bottom: -20px; color: var(--muted); font-size: 9px; font-weight: 400; }
.legend { display: flex; gap: 16px; margin-top: 12px; color: var(--muted); font-size: 10px; }
.legend i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; background: var(--accent); }
.legend span + span i { background: #C8CEC9; }
.ratio-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 72px; align-items: center; gap: 8px; margin: 12px 0; }
.ratio-track { overflow: hidden; height: 4px; margin-top: 8px; border-radius: 4px; background: #F0F0ED; }
.ratio-track i { display: block; height: 100%; border-radius: 4px; background: #8A958D; }
.ratio-meta { color: var(--muted); font-size: 11px; font-weight: 400; }
.ratio-meta b { display: block; margin-bottom: 4px; color: var(--ink); font-size: 12px; font-weight: 500; }
.ratio-value { color: var(--ink); font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
.budget-meta, .amount-comparison { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.budget-meta b { color: var(--ink); font-weight: 500; }
.budget-progress { overflow: hidden; height: 8px; margin-top: 12px; border-radius: 8px; background: #EDEDEA; }
.budget-progress i { display: block; height: 100%; border-radius: 8px; background: #8A958D; }
.budget-progress i.over { background: var(--gold); }
.budget-alert { margin-top: 8px; color: var(--gold); font-size: 11px; font-weight: 500; }

.bill-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.bill-summary { padding: 12px 16px; }
.amount-comparison { font-size: 11px; }
.search { width: 100%; margin: 8px 0 12px; padding: 12px; border: .5px solid var(--line); border-radius: var(--radius); outline: none; background: var(--paper); font-size: 13px; }
.search:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: #A8B0AA; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 0 0 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.pill { flex: none; padding: 8px 12px; border: .5px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--muted); font-size: 11px; font-weight: 400; white-space: nowrap; }
.pill.selected { border-color: var(--accent); background: var(--accent); color: #FFFFFF; }
.month-heading { display: flex; justify-content: space-between; padding: 16px 4px 8px; color: var(--muted); font-size: 11px; font-weight: 400; }

.settings-hero { display: flex; align-items: center; gap: 12px; margin: 16px 0; padding: 20px; border-radius: var(--radius); background: var(--accent); color: #FFFFFF; }
.avatar { display: grid; width: 48px; height: 48px; flex: none; place-items: center; border-radius: var(--radius); background: #FFFFFF20; font-size: 19px; font-weight: 500; }
.settings-hero strong { font-size: 15px; font-weight: 500; }
.settings-hero small { display: block; margin-top: 4px; color: #D8DDD9; font-size: 11px; font-weight: 400; }
.setting-row { display: flex; min-height: 48px; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0; border-bottom: .5px solid var(--line); color: var(--ink); font-size: 13px; font-weight: 500; }
.setting-row:last-child { border-bottom: 0; }
.setting-row small { color: var(--muted); font-size: 11px; font-weight: 400; }
.setting-row-spaced { margin-top: 8px; }
.setting-action { padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 13px; font-weight: 500; }
.category-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.category-chip { padding: 8px 12px; border-radius: var(--radius); background: #F5F5F2; color: var(--ink); font-size: 11px; font-weight: 400; }
.budget-caption { margin-top: 12px; color: var(--muted); font-size: 11px; font-weight: 400; }
.export-full { padding: 16px 0; }
.notice { margin: 12px 0 16px; padding: 12px 16px; border-radius: var(--radius); background: #F3F2EE; color: var(--muted); font-size: 11px; font-weight: 400; line-height: 16px; }

.overlay { position: fixed; z-index: 20; inset: 0; display: flex; align-items: end; justify-content: center; overscroll-behavior: contain; background: rgba(21,25,22,.38); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.overlay[hidden] { display: none; }
.sheet { width: min(100%, 620px); max-height: min(90dvh, 820px); overflow: auto; padding: 8px 20px calc(24px + var(--safe-bottom)); border-radius: var(--radius) var(--radius) 0 0; background: var(--bg); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; animation: rise var(--duration) var(--motion); }
.sheet-handle { width: 32px; height: 4px; margin: 0 auto 16px; border-radius: 4px; background: #D9D9D3; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 16px; }
.sheet-head h2 { margin: 0; color: var(--ink); font-size: 17px; font-weight: 600; text-align: center; }
.sheet-head > :last-child { justify-self: end; }
.sheet-spacer { width: 40px; }
.text-button { padding: 8px; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; }
.danger-button { color: var(--muted); }
.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 16px; padding: 4px; border-radius: var(--radius); background: #F0F0ED; }
.type-switch button { padding: 8px; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted); font-size: 12px; font-weight: 400; }
.type-switch button.selected { background: #FFFFFF; box-shadow: 0 1px 2px rgba(0,0,0,.04); color: var(--ink); font-weight: 500; }
.amount-input { position: relative; display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 16px 0 20px; padding-bottom: 8px; }
.amount-input::after { position: absolute; right: 17%; bottom: 0; left: 17%; height: 1px; background: var(--line); content: ""; }
.amount-input:focus-within::after { background: #A8B0AA; transform: scaleX(1.03); }
.amount-input span { color: var(--muted); font-size: 22px; font-weight: 400; }
.amount-input input { width: 70%; min-width: 0; padding: 0; border: 0; outline: none; background: transparent; color: var(--ink); font-size: clamp(40px,12vw,48px); font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -.04em; line-height: 1.15; text-align: center; }
.amount-input input:focus-visible { outline: none; color: var(--accent); }
.amount-input input::-webkit-inner-spin-button, .amount-input input::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.field { margin: 12px 0; }
.field label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 400; }
.field input, .field select, .field textarea { width: 100%; padding: 12px; border: .5px solid var(--line); border-radius: var(--radius); outline: none; background: var(--paper); color: var(--ink); font-size: 13px; }
.field textarea { min-height: 64px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.category-options { display: flex; flex-wrap: wrap; gap: 8px; }
.category-options button { min-height: 36px; padding: 8px 12px; border: .5px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--muted); font-size: 11px; font-weight: 400; }
.category-options button.selected { border-color: var(--accent); background: var(--accent); color: #FFFFFF; }
.submit { width: 100%; margin-top: 8px; padding: 16px; border: 0; border-radius: var(--radius); background: var(--accent); color: #FFFFFF; font-size: 14px; font-weight: 500; }
.category-form { display: flex; gap: 8px; margin-top: 16px; }
.category-form .search { min-width: 0; margin: 0; }
.export-button { padding: 8px 12px; border: .5px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--accent); font-size: 11px; font-weight: 500; white-space: nowrap; }
.toast { position: fixed; z-index: 40; bottom: calc(144px + var(--safe-bottom)); left: 50%; padding: 12px 16px; transform: translateX(-50%); border-radius: var(--radius); background: var(--accent); box-shadow: var(--card-shadow); color: #FFFFFF; font-size: 12px; font-weight: 500; white-space: nowrap; animation: appear var(--duration) var(--motion); }

button, a, input, select, textarea { transition-property: color, background-color, border-color, box-shadow, opacity, transform; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid #A8B0AA; outline-offset: 2px; }
@keyframes appear { from { opacity: .6; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes rise { from { opacity: .7; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 700px) {
  body { padding: 20px 0; }
  #app { min-height: calc(100dvh - 40px); border-radius: var(--radius); background: var(--bg); box-shadow: var(--card-shadow); }
  .tabbar { bottom: 20px; border-radius: var(--radius) var(--radius) 0 0; }
  .fab { bottom: calc(96px + var(--safe-bottom)); }
  .overlay { align-items: center; }
  .sheet { border-radius: var(--radius); }
}
@media (max-width: 380px) {
  #app { padding-right: 16px; padding-left: 16px; }
  .month-line { margin-bottom: 24px; }
  .home-ledger { padding-right: 14px; padding-left: 14px; border-radius: 26px; }
  .day-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .day-totals { flex-wrap: wrap; gap: 6px; font-size: 10px; white-space: normal; }
  .summary-pill { gap: 8px; padding-right: 10px; padding-left: 10px; font-size: 11px; }
  .summary-pill strong { margin-left: 3px; font-size: 12px; }
  .overview-total { font-size: 38px; }
  .transaction { gap: 8px; }
  .transaction-amount { margin-left: 4px; font-size: 12px; }
  .tabbar { padding-right: 12px; padding-left: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
