:root {
  --ink: #183431;
  --muted: #6d807c;
  --green: #207567;
  --green-dark: #16594f;
  --green-light: #e5f4ee;
  --coral: #d75d51;
  --coral-light: #fff0ed;
  --sun: #f6c458;
  --page: #f7faf8;
  --card: #ffffff;
  --line: #dfebe6;
  --shadow: 0 10px 26px rgba(23, 61, 55, .08);
}

* { box-sizing: border-box; }
html { background: var(--page); }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--page); font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(100%, 800px); min-height: 100vh; margin: 0 auto; background: var(--page); padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: max(22px, env(safe-area-inset-top)) 20px 12px; background: linear-gradient(125deg, #f0faf6, #f7faf8); }
.topbar h1, h2, h3, p { margin-top: 0; }
.topbar h1 { margin-bottom: 0; font-size: 22px; letter-spacing: .03em; }
.eyebrow { margin-bottom: 4px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .11em; }
.icon-button { display: grid; width: 40px; height: 40px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: #fff; color: var(--ink); font-size: 19px; box-shadow: 0 3px 10px rgba(22, 66, 58, .05); }
main { padding: 0 16px; }
.screen { display: none; animation: soft-in .24s ease; }
.screen.active { display: block; }
@keyframes soft-in { from { opacity: .25; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.month-bar { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 7px 0 16px; }
.month-button { width: 38px; height: 38px; border: 0; border-radius: 12px; color: var(--green); background: var(--green-light); font-size: 26px; line-height: 1; }
.month-picker { min-width: 158px; height: 38px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); font-weight: 800; }
.hero-card { padding: 23px 21px 19px; border-radius: 22px; color: #fff; background: linear-gradient(130deg, var(--green), #329783); box-shadow: 0 13px 25px rgba(32, 117, 103, .22); }
.hero-card p { margin-bottom: 7px; font-size: 13px; opacity: .9; }
.hero-card strong { display: block; font-size: clamp(34px, 10vw, 50px); letter-spacing: -.04em; line-height: 1; }
.hero-card span:not(.hero-progress span) { display: block; margin-top: 10px; font-size: 12px; opacity: .86; }
.hero-progress { display: block; height: 7px; margin-top: 16px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.25); }
.hero-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: #fff2bb; transition: width .25s ease; }
.pwa-install-card { display: flex; align-items: center; gap: 10px; margin: 11px 0 13px; padding: 11px 12px; border: 1px solid #cce7da; border-radius: 16px; background: #f4fbf7; }
.install-icon { display: grid; width: 35px; height: 35px; flex: 0 0 35px; place-items: center; border-radius: 11px; background: var(--green); color: #fff; font-size: 20px; font-weight: 800; }
.pwa-install-card > div { min-width: 0; flex: 1; }
.pwa-install-card strong { display: block; font-size: 12px; }
.pwa-install-card p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.install-button { min-height: 36px; padding: 0 12px; border: 0; border-radius: 10px; background: var(--green); color: #fff; font-size: 12px; font-weight: 800; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 13px 0 25px; }
.metric-card { min-height: 84px; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: 0 4px 12px rgba(19, 54, 48, .035); }
.metric-card span, .year-total-card span, .budget-total-card span { display: block; color: var(--muted); font-size: 12px; }
.metric-card strong { display: block; margin-top: 7px; font-size: 17px; letter-spacing: -.02em; }
.income-card { border-color: #caebdf; background: #f6fcf9; }
.income-card strong { color: var(--green); }
.expense-card { border-color: #f6d7d2; background: #fffafa; }
.expense-card strong { color: var(--coral); }
.section-block { margin: 28px 0; }
.section-heading, .inline-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-heading h2, .screen-heading h2, .sheet-heading h2, .dialog-card h2 { margin-bottom: 0; font-size: 20px; letter-spacing: .015em; }
.text-button { border: 0; padding: 7px 0; background: transparent; color: var(--green); font-size: 13px; font-weight: 800; }
.budget-status { display: grid; gap: 9px; }
.status-row { padding: 13px 14px; border: 1px solid var(--line); border-radius: 15px; background: var(--card); }
.status-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.status-top strong { font-size: 13px; }
.status-amount { color: var(--muted); font-size: 12px; }
.track { height: 7px; margin-top: 10px; overflow: hidden; border-radius: 999px; background: #e9f0ed; }
.track span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.track span.caution { background: var(--sun); }
.track span.over { background: var(--coral); }

.transaction-list { display: grid; gap: 8px; }
.transaction-item { display: flex; align-items: center; min-height: 68px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 15px; background: var(--card); }
.transaction-icon { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; margin-right: 10px; border-radius: 13px; background: #f2f8f5; font-size: 20px; }
.transaction-body { min-width: 0; flex: 1; }
.transaction-title { overflow: hidden; margin-bottom: 3px; font-size: 14px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.transaction-meta { color: var(--muted); font-size: 11px; }
.transaction-amount { margin-left: 8px; font-size: 14px; font-weight: 800; white-space: nowrap; }
.transaction-amount.income { color: var(--green); }
.transaction-amount.expense { color: var(--coral); }
.item-actions { display: flex; gap: 3px; margin-left: 7px; }
.mini-action { width: 31px; height: 31px; border: 0; border-radius: 9px; background: #f2f7f5; color: var(--green); font-size: 14px; }
.empty-state { padding: 25px 18px; border: 1px dashed #b6ccc4; border-radius: 15px; color: var(--muted); background: #fbfdfc; text-align: center; font-size: 13px; line-height: 1.7; }

.screen-heading { margin: 13px 2px 20px; }
.screen-heading > p:not(.eyebrow) { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.entry-form { display: grid; gap: 9px; padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); box-shadow: var(--shadow); }
.field-label { margin-top: 7px; font-size: 13px; font-weight: 800; }
.field-input, .filter-panel select, .money-input { width: 100%; min-height: 50px; border: 1px solid #c8d9d3; border-radius: 12px; outline: none; background: #fff; color: var(--ink); font-size: 16px; }
.field-input { padding: 0 13px; }
.field-input:focus, .money-input:focus, .filter-panel select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(32,117,103,.13); }
.category-trigger { display: flex; align-items: center; min-height: 53px; padding: 0 13px; border: 1px solid #c8d9d3; border-radius: 12px; background: #fff; color: var(--ink); font-size: 16px; text-align: left; }
.category-trigger span:first-child { font-size: 22px; margin-right: 9px; }
.select-arrow { margin-left: auto; color: var(--green); font-size: 13px; font-weight: 800; }
.type-hint { margin: -2px 3px 2px; color: var(--muted); font-size: 12px; }
.type-hint strong { color: var(--green); }
.money-input-wrap { display: flex; align-items: center; overflow: hidden; border: 1px solid #c8d9d3; border-radius: 12px; background: #fff; }
.money-input-wrap:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(32,117,103,.13); }
.money-input-wrap span { padding-left: 15px; color: var(--green); font-size: 22px; font-weight: 800; }
.money-input { min-height: 52px; border: 0; padding: 0 14px 0 10px; box-shadow: none !important; font-size: 22px; font-weight: 800; }
.form-error { min-height: 0; margin: 0; color: #b83f35; font-size: 13px; font-weight: 700; }
.primary-button, .secondary-button, .danger-button { min-height: 52px; border-radius: 13px; font-size: 15px; font-weight: 800; }
.primary-button { border: 0; background: var(--green); color: #fff; box-shadow: 0 8px 17px rgba(32, 117, 103, .21); }
.primary-button span { margin-right: 6px; font-size: 18px; }
.secondary-button { border: 1px solid #b9d4ca; background: #f8fcfa; color: var(--green-dark); }
.danger-button { border: 1px solid #f0c8c2; background: #fff7f5; color: #b5473d; }
.friendly-note { margin: 16px 2px; padding: 13px; border-radius: 13px; background: #fff9e9; color: #7f6724; font-size: 12px; line-height: 1.6; }
.hidden { display: none !important; }

.filter-panel { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px 10px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.filter-panel label { color: var(--muted); font-size: 12px; font-weight: 800; }
.filter-panel select { min-height: 43px; padding: 0 10px; font-size: 14px; }
.filter-panel input { min-height: 43px; font-size: 14px; }
.list-summary { margin: 15px 3px 10px; color: var(--muted); font-size: 12px; }
.full-list { padding-bottom: 6px; }

.budget-total-card, .year-total-card { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; padding: 16px; border-radius: 18px; background: #e8f5ef; }
.budget-total-card > div + div { border-left: 1px solid #b7d9cb; padding-left: 14px; }
.budget-total-card strong, .year-total-card strong { display: block; margin-top: 5px; color: var(--green-dark); font-size: 19px; }
.budget-editor { display: grid; gap: 9px; }
.budget-edit-row { padding: 13px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.budget-edit-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.budget-category { font-size: 14px; font-weight: 800; }
.budget-used { color: var(--muted); font-size: 12px; }
.budget-remove { margin-left: 7px; border: 0; padding: 3px 5px; border-radius: 6px; background: #fff1ef; color: #b34a3f; font-size: 11px; font-weight: 800; }
.budget-input-line { display: flex; align-items: center; margin-top: 10px; gap: 7px; }
.budget-input-line label { flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.budget-input-line input { width: 100%; min-height: 38px; padding: 0 10px; border: 1px solid #c8d9d3; border-radius: 10px; text-align: right; }
.budget-remaining { min-width: 75px; color: var(--green); font-size: 12px; font-weight: 800; text-align: right; }
.budget-edit-row.over .budget-remaining { color: var(--coral); }
.custom-budget-form { margin-top: 14px; padding: 14px; border: 1px dashed #9fc9b9; border-radius: 15px; background: #f8fcfa; }
.custom-budget-form label { display: block; color: var(--green-dark); font-size: 13px; font-weight: 800; }
.custom-budget-form > div { display: flex; gap: 8px; margin-top: 9px; }
.custom-budget-form input { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid #c8d9d3; border-radius: 10px; background: #fff; font-size: 14px; }
.custom-budget-form button { flex: 0 0 auto; min-height: 40px; padding: 0 15px; border: 0; border-radius: 10px; background: var(--green); color: #fff; font-weight: 800; }
.custom-budget-form p { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.auto-save-note { color: var(--muted); font-size: 12px; text-align: center; }

.inline-heading select { min-height: 37px; padding: 0 7px; border: 1px solid #c8d9d3; border-radius: 10px; background: #fff; color: var(--ink); }
.year-total-card { grid-template-columns: 1fr 1fr 1fr; padding: 14px; }
.year-total-card > div:not(:last-child) { border-right: 1px solid #b7d9cb; }
.year-total-card strong { font-size: 14px; }
.annual-chart { display: flex; align-items: end; gap: 5px; min-height: 154px; margin: 17px 0; padding: 20px 9px 7px; border: 1px solid var(--line); border-radius: 17px; background: #fff; }
.chart-column { display: flex; min-width: 0; flex: 1; height: 123px; align-items: end; justify-content: end; flex-direction: column; gap: 4px; }
.chart-value { overflow: hidden; max-width: 100%; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.chart-bar-wrap { display: flex; width: 100%; flex: 1; align-items: end; justify-content: center; }
.chart-bar { width: min(24px, 70%); min-height: 3px; border-radius: 7px 7px 3px 3px; background: var(--green); }
.chart-label { color: var(--muted); font-size: 10px; }
.annual-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.annual-table { width: 100%; min-width: 460px; border-collapse: collapse; font-size: 12px; }
.annual-table th { padding: 11px; background: #f1f8f4; color: var(--muted); font-size: 11px; text-align: right; }
.annual-table th:first-child, .annual-table td:first-child { text-align: left; }
.annual-table td { padding: 11px; border-top: 1px solid #edf2ef; text-align: right; }

.settings-card { margin: 14px 0; padding: 17px; border: 1px solid var(--line); border-radius: 18px; background: #fff; }
.settings-card h3 { margin-bottom: 8px; font-size: 15px; }
.settings-card p { color: var(--muted); font-size: 12px; line-height: 1.7; }
.settings-card label:not(.toggle-row) { display: block; margin: 13px 0 7px; font-size: 12px; font-weight: 800; }
.settings-card .secondary-button { width: 100%; margin-top: 13px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; color: var(--ink); font-size: 13px; font-weight: 750; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { position: relative; width: 46px; height: 26px; border-radius: 999px; background: #cad6d2; transition: .2s; }
.toggle-row i::after { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; content: ""; transition: .2s; }
.toggle-row input:checked + i { background: var(--green); }
.toggle-row input:checked + i::after { transform: translateX(20px); }
.danger-card { border-color: #f2d4cf; }
.danger-card .danger-button { width: 100%; margin-top: 4px; }

.bottom-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; display: flex; width: min(100%, 800px); min-height: calc(69px + env(safe-area-inset-bottom)); margin: 0 auto; padding: 7px 7px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.96); box-shadow: 0 -4px 20px rgba(30, 62, 55, .06); backdrop-filter: blur(10px); }
.nav-item { display: grid; flex: 1; place-items: center; gap: 1px; border: 0; border-radius: 12px; background: transparent; color: #71837d; font-size: 10px; font-weight: 700; }
.nav-item span { font-size: 21px; line-height: 1; }
.nav-item.active { color: var(--green); background: #ecf7f1; }
.nav-item.prominent span { display: grid; width: 29px; height: 29px; place-items: center; border-radius: 50%; background: var(--green); color: #fff; font-size: 21px; box-shadow: 0 4px 9px rgba(32,117,103,.25); }
.nav-item.prominent.active { background: #ecf7f1; }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: flex; align-items: end; background: rgba(20, 48, 43, .42); }
.bottom-sheet, .dialog-card { width: min(100%, 800px); margin: 0 auto; border-radius: 24px 24px 0 0; background: #fff; box-shadow: 0 -8px 32px rgba(7, 36, 30, .18); }
.bottom-sheet { max-height: 86vh; overflow-y: auto; padding: 9px 18px calc(24px + env(safe-area-inset-bottom)); }
.sheet-handle { width: 38px; height: 4px; margin: 1px auto 13px; border-radius: 99px; background: #d1dfd9; }
.sheet-heading { display: flex; align-items: start; justify-content: space-between; }
.category-section-label { margin: 20px 0 9px; color: var(--muted); font-size: 12px; font-weight: 800; }
.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.category-option { display: flex; align-items: center; min-height: 51px; padding: 0 11px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); text-align: left; font-weight: 750; }
.category-option span { margin-right: 8px; font-size: 20px; }
.category-option:active { background: var(--green-light); }
.dialog-card { position: relative; max-width: 360px; margin: auto; padding: 25px 20px; border-radius: 20px; }
.dialog-card .icon-button { position: absolute; top: 12px; right: 12px; }
.dialog-card h2 { margin-bottom: 20px; }
.dialog-card .primary-button { width: 100%; margin-top: 11px; }
.install-dialog #installHelpText { color: var(--muted); font-size: 13px; line-height: 1.8; }
.install-dialog #installHelpText strong { color: var(--ink); }
.install-dialog #installHelpText ol { margin: 10px 0 0; padding-left: 22px; }
.toast { position: fixed; z-index: 100; right: 20px; bottom: calc(84px + env(safe-area-inset-bottom)); left: 20px; max-width: 400px; margin: auto; padding: 13px 16px; border-radius: 13px; background: #173d36; color: #fff; box-shadow: 0 7px 20px rgba(0,0,0,.2); font-size: 13px; font-weight: 750; text-align: center; }

@media (min-width: 640px) {
  .app-shell { border-right: 1px solid #e5eee9; border-left: 1px solid #e5eee9; }
  main { padding: 0 28px; }
  .topbar { padding-right: 32px; padding-left: 32px; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .entry-form { grid-template-columns: 1fr 1fr; column-gap: 16px; }
  .entry-form > .field-label:nth-of-type(1), .entry-form > #entryDate, .entry-form > .field-label:nth-of-type(2), .entry-form > #entryDescription, .entry-form > .field-label:nth-of-type(3), .entry-form > .category-trigger, .entry-form > #entryCategory, .entry-form > .type-hint, .entry-form > .field-label:nth-of-type(4), .entry-form > .money-input-wrap, .entry-form > .form-error, .entry-form > .primary-button, .entry-form > .secondary-button { grid-column: span 1; }
  .entry-form > .form-error, .entry-form > .primary-button, .entry-form > .secondary-button { grid-column: 1 / -1; }
  .category-grid { grid-template-columns: repeat(3, 1fr); }
}
