:root {
  color-scheme: light;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Hiragino Sans', system-ui, sans-serif;
  --bg: #f5f6f8;
  --surface: #fff;
  --text: #232833;
  --muted: #5e6470;
  --line: #dce0e6;
  --primary: #293b58;
  --primary-soft: #edf2fa;
  --income-accent: #00a6ed;
  --expense-accent: #ff5a5f;
  --income: #006d9d;
  --expense: #bd343e;
  --nav: calc(64px + env(safe-area-inset-bottom, 0px));
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
button { background: transparent; border: 0; cursor: pointer; min-height: 44px; touch-action: manipulation; }
button:disabled { opacity: .38; cursor: default; }
:focus-visible { outline: 2px solid #226d9c; outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.06rem; line-height: 1.3; margin-bottom: 10px; }
h2 { font-size: 1rem; margin: 16px 0 8px; }
h3 { font-size: .88rem; margin: 12px 0 6px; }
small { color: var(--muted); }
.app {
  width: min(100%, 560px); margin: auto; min-height: 100dvh;
  padding: env(safe-area-inset-top, 0px) 0 var(--nav); background: white;
}
main { padding: 10px 12px 14px; }
.screen-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 5px; }
.screen-header h1, .screen-header .segment { margin: 0; }
.screen-header .segment { width: min(62%, 225px); }
#tabs {
  position: fixed; z-index: 2; inset: auto 0 0; margin: auto; width: min(100%, 560px);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
  min-height: var(--nav); background: var(--surface); border-top: 1px solid var(--line);
}
#tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: .67rem; border-top: 2px solid transparent; border-bottom: 2px solid transparent;
}
#tabs svg { width: 20px; height: 20px; }
#tabs button[aria-current="page"] { color: var(--primary); font-weight: 750; border-top-color: var(--primary); }
.segment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; background: var(--bg); border-radius: 5px; padding: 0; margin-bottom: 10px; }
.segment button { border-radius: 4px; font-size: .83rem; font-weight: 700; color: var(--muted); }
.segment button[aria-pressed="true"] { color: var(--primary); background: #e5ebf4; }
.segment [data-tone="income"][aria-pressed="true"], .income { color: var(--income); }
.segment [data-tone="expense"][aria-pressed="true"], .expense { color: var(--expense); }
.card { border: 1px solid var(--line); background: var(--surface); border-radius: 5px; }
.form-card { padding: 0; border-width: 1px 0; border-radius: 0; }
.field { display: grid; grid-template-columns: 54px minmax(0, 1fr); align-items: center; gap: 4px; min-height: 49px; }
.field + .field { border-top: 1px solid var(--line); }
.field label, .field > span { font-size: .85rem; font-weight: 650; }
.field label small { font-weight: 400; font-size: .65rem; }
.field input { width: 100%; min-width: 0; min-height: 44px; border: 0; background: transparent; padding: 4px; }
.date-control { display: grid; align-items: center; grid-template-columns: 44px minmax(0, 1fr) 44px; }
.date-control input { text-align: center; font-variant-numeric: tabular-nums; }
.arrow { font-size: 1.6rem; min-width: 44px; padding: 0; }
.amount { display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%; font-variant-numeric: tabular-nums; padding: 4px 10px; color: var(--primary); background: var(--bg); border-radius: 4px; }
.amount strong { font-size: clamp(1rem, 5vw, 1.65rem); }
.edit-mark { display: flex; flex-shrink: 0; }
.edit-mark svg { width: 19px; height: 19px; }
.category-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.category-tile {
  border: 1px solid var(--line); border-radius: 5px; background: white; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-height: 53px; padding: 3px; font-size: .72rem; font-weight: 650; overflow-wrap: anywhere;
}
.category-tile[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.glyph { display: inline-grid; place-items: center; flex: 0 0 auto; width: 25px; height: 25px; font-size: 17px; color: var(--ink); line-height: 1; }
.glyph svg { width: 22px; height: 22px; }
.add-tile { border-style: dashed; color: var(--primary); }
.primary { display: block; width: 100%; padding: 8px; min-height: 47px; border-radius: 5px; background: var(--primary); color: white; font-weight: 750; margin-top: 12px; }
.save-bar { position: sticky; bottom: var(--nav); background: white; padding: 6px 0 2px; margin-top: 5px; }
.save-bar .primary { margin-top: 0; }
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 7px 0; margin: 7px 0; text-align: center; }
.summary div { min-width: 0; padding: 0 5px; }
.summary div + div { border-left: 1px solid var(--line); }
.summary span { display: block; font-size: .73rem; color: var(--muted); }
[data-screen="reports"] .summary [data-total="income"] span::before, [data-screen="reports"] .summary [data-total="expense"] span::before {
  content: ''; display: inline-block; width: 7px; height: 7px; margin-inline-end: 5px;
  border-radius: 50%; vertical-align: .04em;
}
[data-screen="reports"] .summary [data-total="income"] span::before { background: var(--income-accent); }
[data-screen="reports"] .summary [data-total="expense"] span::before { background: var(--expense-accent); }
.summary strong { display: block; font-size: .91rem; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.period { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; font-weight: 730; }
.period-picker { flex: 1; position: relative; text-align: center; display: grid; place-items: center; min-height: 44px; }
.period-picker input { opacity: .01; cursor: pointer; position: absolute; inset: 0; min-width: 0; width: 100%; }
.period-picker:focus-within { outline: 2px solid #226d9c; }
.period-picker input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; }
.year-picker { margin-left: auto; width: 5ch; min-height: 44px; border: 0; text-align: right; }
.year-picker + span { margin-right: auto; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-radius: 0; border-width: 1px 0; margin-top: 5px; }
.weekday { text-align: center; font-size: .74rem; padding: 4px 0; background: var(--bg); }
.week-0 { color: var(--expense); }
.week-6 { color: var(--income); }
.date-cell { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; min-height: 46px; border-top: 1px solid var(--line); padding: 2px 0; font-size: .75rem; }
.date-cell small { display: block; width: 100%; padding: 0 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; font-size: .58rem; }
.date-cell.today > span { text-decoration: underline; text-underline-offset: 3px; font-weight: 800; }
.date-cell.muted { opacity: .5; }
.date-cell[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--primary); background: var(--primary-soft); }
.section-line { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.quiet { color: var(--primary); padding: 0 5px; font-size: .83rem; font-weight: 700; }
.rows { margin: 8px 0; }
.day-group h3 { background: var(--bg); padding: 4px 8px; margin: 0; font-size: .75rem; }
.day-group .rows { margin: 0; border-width: 0; }
.transaction, .manage-name { display: flex; align-items: center; text-align: left; gap: 8px; min-width: 0; }
.transaction { width: 100%; min-height: 53px; padding: 8px 10px; }
.transaction + .transaction, .manage-row + .manage-row { border-top: 1px solid var(--line); }
.row-info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row-info strong, .row-info small { display: block; }
.transaction b { max-width: 52%; overflow-wrap: anywhere; text-align: right; }
.manage-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); align-items: center; padding: 0 4px; }
.manage-row.is-editing { grid-template-columns: 44px minmax(0, 1fr) 44px; }
.manage-row.removed-row { grid-template-columns: minmax(0, 1fr) 55px; }
.manage-name { min-height: 48px; padding: 4px; }
.category-remove, .category-handle { display: grid; place-items: center; min-width: 44px; padding: 0; }
.category-remove span { display: grid; place-items: center; width: 21px; height: 21px; border-radius: 50%; background: var(--expense); color: white; line-height: 1; font-weight: 750; }
.category-handle { color: var(--muted); cursor: grab; touch-action: none; user-select: none; }
.dragging { background: var(--primary-soft); }
.dragging .category-handle { cursor: grabbing; }
.manage-row[data-drop]::after { content: ''; position: absolute; inset-inline: 4px; height: 2px; background: var(--primary); pointer-events: none; z-index: 1; }
.manage-row[data-drop="before"]::after { top: 0; }
.manage-row[data-drop="after"]::after { bottom: 0; }
.removed-categories summary { display: list-item; min-height: 44px; padding: 12px 6px; cursor: pointer; color: var(--muted); font-size: .83rem; }
.note, .empty { color: var(--muted); font-size: .8rem; margin: 8px 0; }
.empty { padding: 18px 8px; text-align: center; }
.chart { padding: 12px; display: grid; place-items: center; border: 0; }
[data-screen="reports"] .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
[data-screen="reports"] .summary div:last-child { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; margin-top: 5px; padding: 5px 9px 0; border-left: 0; border-top: 1px solid var(--line); }
.donut { position: relative; width: min(100%, 248px); aspect-ratio: 1; }
.donut svg { display: block; width: 100%; height: 100%; }
.donut g[role="button"] { cursor: pointer; outline: none; }
.donut g[role="button"]:focus-visible path {
  stroke: #283043; stroke-width: 2; paint-order: stroke;
}
.donut text {
  fill: white; font-weight: 700; pointer-events: none;
}
.donut-total {
  position: absolute; inset: 28%; display: grid; place-content: center; text-align: center;
  overflow-wrap: anywhere; pointer-events: none;
}
.donut-total b { font-size: .91rem; }
.chart-tooltip {
  position: absolute; z-index: 1; left: 50%; top: 50%; transform: translate(-50%, calc(-100% - 9px));
  width: max-content; max-width: 96%; padding: 6px 10px; border-radius: 5px; background: #515660;
  color: white; text-align: center; font-size: .78rem; overflow-wrap: anywhere; pointer-events: none;
}
.chart-tooltip::after {
  content: ''; position: absolute; top: 100%; left: clamp(6px, var(--tip-arrow, 50%), calc(100% - 6px));
  transform: translateX(-50%); border: 5px solid transparent; border-top: 6px solid #515660;
}
.chart-tooltip strong { display: block; }
dialog { width: min(calc(100% - 20px), 510px); max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); border: 1px solid var(--line); border-radius: 17px; background: white; color: var(--text); padding: 12px; overscroll-behavior: contain; }
dialog::backdrop { background: #29272376; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.dialog-header h2 { margin: 0; }
.stack-label { display: grid; gap: 4px; margin: 8px 0; font-size: .85rem; font-weight: 650; }
.stack-label input, .stack-label select, .edit-amount { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-width: 0; width: 100%; min-height: 44px; padding: 6px 9px; font-size: 16px; }
.key-value { display: block; padding: 10px; text-align: right; font-size: clamp(1.25rem, 6vw, 2rem); font-weight: 750; overflow-wrap: anywhere; }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.keypad button { background: var(--bg); border-radius: 9px; font-weight: 750; min-height: 52px; }
.danger { display: block; width: 100%; color: var(--expense); }
.delete { background: var(--expense); }
.preview { display: flex; align-items: center; gap: 7px; background: var(--primary-soft); padding: 8px; border-radius: 8px; overflow-wrap: anywhere; }
.swatches { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; }
.swatches + .swatches { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.swatches button { display: grid; place-items: center; border-radius: 8px; }
.swatches button::before { content: ''; background: var(--swatch); width: 25px; height: 25px; border-radius: 50%; border: 1px solid #0002; }
.swatches button[aria-pressed="true"], .icon-grid button[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--primary); background: var(--primary-soft); }
.custom-color { display: flex; align-items: center; gap: 8px; padding-top: 4px; font-size: .85rem; }
.custom-color input { width: 52px; height: 44px; }
.icon-results { max-height: 235px; overflow: auto; border: 1px solid var(--line); border-radius: 5px; padding: 0 6px 6px; }
.icon-results h3 { padding: 6px 2px 4px; margin: 0 0 3px; border-bottom: 1px solid var(--line); color: var(--muted); }
.icon-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; }
.icon-grid button { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 50px; border-radius: 4px; padding: 2px; }
.icon-grid small { font-size: .64rem; overflow-wrap: anywhere; }
.error { color: var(--expense); font-size: .85rem; margin: 6px 0; overflow-wrap: anywhere; }
#storage-error { margin: 8px 14px; }
#notice:not(:empty) { position: fixed; bottom: calc(var(--nav) + 56px); z-index: 3; left: 50%; transform: translateX(-50%); max-width: 90%; padding: 8px 13px; color: white; background: var(--primary); border-radius: 9px; font-size: .83rem; pointer-events: none; }
.month-fallback { min-height: 44px; min-width: 0; width: 9ch; text-align: center; border: 0; }
.date-range .stack-label { min-width: 0; }
.date-range input { padding-inline: 5px; }
.date-range { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
#tabs[hidden] { display: none; }
