:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f0f3f9;
  --surface-tint: #eff6ff;
  --border: #e4eaf3;
  --border-strong: #d1d9e8;
  --text: #1a2033;
  --text-soft: #4a5568;
  --muted: #8896aa;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #059669;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --purple: #7c3aed;
  --shadow: 0 10px 30px rgba(30, 50, 100, .08), 0 1px 3px rgba(30, 50, 100, .06);
  --radius: 12px;
  --nav-height: 76px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html {
  min-height: 100%;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
body { min-height: 100%; }
body {
  margin: 0;
  background: radial-gradient(circle at top left, rgba(37, 99, 235, .08), transparent 30%), var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  border: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.mobile-shell {
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: #f7f9fc;
}

.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 10px;
  background: rgba(247, 249, 252, .92);
  border-bottom: 1px solid rgba(228, 234, 243, .92);
  backdrop-filter: blur(18px);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mobile-brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #0d9488);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .22);
}
.mobile-brand-title { display: grid; gap: 2px; }
.mobile-brand-title strong { font-size: 15px; line-height: 1; }
.mobile-brand-title small { color: var(--muted); font-size: 11px; }

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 800;
}
.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--green);
}

.mobile-view {
  min-height: calc(100dvh - var(--nav-height));
  overflow: auto;
  padding: 14px 14px calc(var(--nav-height) + 20px);
  scrollbar-width: none;
}
.mobile-view::-webkit-scrollbar { display: none; }

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.page-head h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}
.page-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.month-chip,
.small-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 13px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 900;
  font-size: 13px;
}
.card-title span:first-child {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--primary);
  font-size: 13px;
}
.card-body { padding: 13px; }

.segmented,
.seg {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-soft);
}
.segmented button,
.seg button {
  min-height: 36px;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-weight: 900;
  font-size: 13px;
}
.segmented button.active,
.seg button.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 5px 15px rgba(30, 50, 100, .08);
}
.seg.compact button { min-height: 34px; font-size: 12px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.quick-meta-row {
  grid-template-columns: minmax(122px, .88fr) minmax(0, 1.12fr);
  align-items: end;
}
.quick-meta-row .input[type="date"],
.quick-meta-row input[type="date"] {
  padding-inline: 8px;
  font-size: 14px;
}
.quick-meta-row .seg.compact {
  min-width: 0;
}
.quick-meta-row .seg.compact button {
  min-width: 0;
  padding-inline: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.field label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .05em;
}
.input,
.select,
input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 10px;
  outline: none;
}
textarea { min-height: 76px; resize: vertical; }
.input:focus,
.select:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .10);
}

.amount-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #dbe7fb;
  background: linear-gradient(180deg, #ffffff, #f7fbff);
}
.amount-box input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 30px;
  line-height: 1.1;
  font-weight: 900;
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
  padding: 0;
  caret-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.amount-box input::placeholder { color: #c0cadb; }

.chip-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 7px;
  margin-top: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.chip-grid::-webkit-scrollbar {
  display: none;
}
.settlement-note {
  flex: 0 0 100%;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--surface-tint);
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.6;
  padding: 10px 12px;
  margin-top: 10px;
}
.chip {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  scroll-snap-align: start;
}
.chip.active {
  border-color: #bcd1ff;
  background: var(--surface-tint);
  color: var(--primary-dark);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 12px;
  touch-action: manipulation;
}
.keypad button {
  height: 42px;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 17px;
  font-weight: 900;
  touch-action: manipulation;
}
.keypad button.action { color: var(--primary-dark); background: var(--surface-tint); }
.keypad button.danger { color: var(--red); background: var(--red-soft); }

@media (max-width: 360px) {
  .quick-meta-row {
    grid-template-columns: 1fr;
  }
  .quick-meta-row .seg.compact button {
    min-height: 36px;
  }
}

.primary-button,
.submit {
  width: 100%;
  min-height: 46px;
  margin-top: 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(37, 99, 235, .20);
}
.ghost-button,
.ghost-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text-soft);
  font-weight: 900;
}
.danger-button,
.danger-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 8px;
  border-radius: 12px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 900;
}

.list { display: grid; gap: 8px; }
.tx,
.row-item {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
}
.tx-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--primary);
  font-weight: 900;
}
.tx-main { min-width: 0; }
.tx-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.tx-main span {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11px;
}
.tx-amount,
.row-amount {
  text-align: right;
  font-size: 13px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tx-amount small,
.row-amount small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}
.income, .good { color: var(--green); }
.expense, .bad { color: var(--red); }
.warn { color: var(--amber); }

.alert-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid #fde4b3;
  border-radius: 12px;
  background: linear-gradient(180deg, #fffaf0, #ffffff);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.alert-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 900;
}
.alert-card strong { display: block; margin-bottom: 4px; font-size: 13px; }
.alert-card p { margin: 0; color: var(--text-soft); font-size: 12px; line-height: 1.55; }

.kpi-grid,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.kpi,
.metric {
  min-width: 0;
  padding: 11px 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.kpi label,
.metric span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .06em;
}
.kpi strong,
.metric strong {
  display: block;
  font-size: 16px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.kpi small,
.metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.budget-summary { display: grid; gap: 10px; }
.budget-item {
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.budget-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  margin-bottom: 7px;
}
.budget-name {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 13px;
  font-weight: 900;
}
.budget-name span:first-child {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--primary);
  font-size: 12px;
  flex-shrink: 0;
}
.budget-amount {
  text-align: right;
  font-size: 12px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.budget-amount small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}
.budget-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.budget-bottom strong { color: var(--green); font-variant-numeric: tabular-nums; }
.budget-bottom strong.over { color: var(--red); }
.track,
.bar-track {
  height: 8px;
  border-radius: 99px;
  background: var(--surface-soft);
  overflow: hidden;
}
.fill,
.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}
.fill.green, .bar-fill.green { background: var(--green); }
.fill.amber, .bar-fill.warn { background: var(--amber); }
.fill.red, .bar-fill.over { background: var(--red); }
.fill.purple { background: var(--purple); }

.pie-wrap {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: center;
}
.donut {
  position: relative;
  width: 132px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--purple) 0 33%, var(--green) 33% 57%, var(--amber) 57% 72%, var(--primary) 72% 88%, var(--red) 88% 100%);
}
.donut::after {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}
.donut-center {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
}
.donut-center strong { display: block; font-size: 14px; font-weight: 900; font-variant-numeric: tabular-nums; }
.donut-center span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; font-weight: 800; }
.legend { display: grid; gap: 7px; }
.legend-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 7px;
  align-items: center;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 800;
}
.legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.legend-row strong { color: var(--text); font-variant-numeric: tabular-nums; }

.spark {
  height: 120px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: end;
  gap: 8px;
  padding: 6px 2px 0;
  border-bottom: 1px solid var(--border);
}
.spark-col {
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, rgba(37, 99, 235, .86), rgba(37, 99, 235, .25));
  min-height: 16px;
}
.spark-col.red { background: linear-gradient(180deg, rgba(220, 38, 38, .86), rgba(220, 38, 38, .22)); }
.spark-labels {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding-top: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}
.type-tabs {
  display: flex;
  gap: 6px;
  overflow: auto;
  padding-bottom: 2px;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.type-tabs::-webkit-scrollbar { display: none; }
.type-tab {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.type-tab.active {
  background: var(--surface-tint);
  border-color: #bcd1ff;
  color: var(--primary-dark);
}

.settings-list { display: grid; gap: 9px; }
.setting-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.setting-row strong { display: block; font-size: 13px; }
.setting-row span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.arrow { color: var(--muted); font-weight: 900; }

.mobile-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 430px);
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  height: var(--nav-height);
  background: rgba(247, 249, 252, .94);
  border-top: 1px solid rgba(228, 234, 243, .92);
  backdrop-filter: blur(18px);
}
.mobile-nav button {
  display: grid;
  place-items: center;
  gap: 2px;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.mobile-nav b { display: block; font-size: 18px; line-height: 1; }
.mobile-nav button.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 8px 22px rgba(30, 50, 100, .10);
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  justify-items: center;
  background: rgba(15, 23, 42, .38);
  backdrop-filter: blur(2px);
}
.modal-root[hidden] { display: none; }
.modal-card {
  width: min(100%, 430px);
  max-height: 84dvh;
  overflow: auto;
  padding: 10px 14px 16px;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: 0 -18px 36px rgba(15, 23, 42, .16);
}
.grab {
  width: 42px;
  height: 5px;
  margin: 0 auto 12px;
  border-radius: 99px;
  background: var(--border-strong);
}
.sheet-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.sheet-title h2 { margin: 0; font-size: 18px; }
.inline-actions { display: grid; gap: 8px; }

.empty-state,
.muted-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 16px);
  z-index: 80;
  transform: translate(-50%, 12px);
  width: min(calc(100% - 28px), 390px);
  padding: 11px 13px;
  border-radius: 12px;
  background: #1e2d47;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 560px) {
  body { padding: 22px 12px; }
  .mobile-shell {
    min-height: calc(100dvh - 44px);
    max-height: 920px;
    border: 1px solid rgba(209, 217, 232, .9);
    border-radius: 28px;
    box-shadow: 0 28px 70px rgba(20, 35, 70, .18);
  }
  .mobile-view { max-height: calc(920px - var(--nav-height)); }
  .mobile-nav { position: absolute; }
}
