:root {
  --ink: #1c1915;
  --muted: #5e584e;
  --faint: #8a8378;
  --paper: #f7f4ee;
  --desk: #e6dfd3;
  --line: #e3dbcf;
  --white: #fffdf9;
  --accent: #1e4d40;
  --accent-press: #173e34;
  --accent-soft: #e5f0eb;
  --danger: #8e2f2a;
  --danger-soft: #f8ecea;
  --track: #e6e0d4;
  --shadow: 0 16px 40px rgba(48, 38, 22, 0.1);
  --pad: 18px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei",
    "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
}

button, input { font: inherit; color: inherit; letter-spacing: inherit; }
button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}
button:disabled { cursor: default; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection { background: #d5e6df; }

.app {
  width: min(520px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.scroller {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px var(--pad) 20px;
  padding-left: calc(var(--pad) + env(safe-area-inset-left));
  padding-right: calc(var(--pad) + env(safe-area-inset-right));
}

.header {
  flex-shrink: 0;
  padding: calc(8px + env(safe-area-inset-top)) var(--pad) 8px;
  padding-left: calc(var(--pad) + env(safe-area-inset-left));
  padding-right: calc(var(--pad) + env(safe-area-inset-right));
  background: var(--paper);
  border-bottom: 1px solid transparent;
}

.header-top, .header-sub, .switcher, .header-actions, .dialog-actions, .date-row {
  display: flex;
  align-items: center;
}

.header-top, .header-sub { justify-content: space-between; gap: 8px; }
.header-actions { gap: 2px; }

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--accent);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.linkish, .mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  border-radius: 10px;
  color: var(--accent);
  font-weight: 600;
}
.linkish {
  min-width: 44px;
  padding: 0 8px;
  font-size: 16px;
}
.mini {
  min-width: 48px;
  padding: 0 8px;
  font-size: 15px;
}
.mini.is-off { color: var(--faint); }
.header-top.sub {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
}
.page-title {
  margin: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
}
.back { justify-self: start; padding-left: 0; }
.linkish:active { background: var(--accent-soft); }

.switcher { justify-content: center; gap: 8px; min-height: 48px; }
.month-label {
  min-width: 7.5em;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--desk); }
.icon-btn svg, .key svg, .primary svg { display: block; }

.jump {
  display: block;
  margin: -2px auto 4px;
  min-height: 32px;
  padding: 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.total-block { padding: 14px 2px 6px; }
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.total {
  margin: 2px 0 0;
  font-size: clamp(36px, 11vw, 48px);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.yen {
  font-size: 0.52em;
  font-weight: 600;
  margin-right: 2px;
  letter-spacing: 0;
  color: var(--muted);
}
.subline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.subline strong { color: var(--ink); font-weight: 600; }

.nudge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: 12px;
  color: var(--accent-press);
  font-size: 13px;
  line-height: 1.4;
}
.nudge button { color: var(--accent); font-weight: 700; min-height: 32px; padding: 0 4px; }

.section-label {
  margin: 22px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.catline {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(48px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  min-height: 40px;
  padding: 4px 2px;
  text-align: left;
  border-radius: 10px;
}
.catline:active, .catline[aria-pressed="true"] { background: var(--accent-soft); }
.catline .name { font-size: 15px; }
.catline .pct {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 2.6em;
  text-align: right;
}
.catline .amt {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-weight: 600;
  font-size: 15px;
  min-width: 5.6em;
  text-align: right;
}
.bar {
  height: 8px;
  background: var(--track);
  border-radius: 99px;
  overflow: hidden;
}
.bar > span { display: block; height: 100%; border-radius: 99px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  flex-shrink: 0;
}

.filter-row { display: flex; margin-top: 8px; }
.chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 99px;
  background: var(--accent);
  color: #f7f4ee;
  font-size: 13px;
  font-weight: 600;
}

.group { margin-top: 8px; }
.group-h {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 12px 2px 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.group-h span:last-child { font-variant-numeric: tabular-nums; }

.item {
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-top: 1px solid var(--line);
  text-align: left;
  background: transparent;
}
.item-text { display: flex; flex-direction: column; min-width: 0; }
.item-title {
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.item-amt {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

.empty {
  padding: 28px 8px 12px;
  color: var(--muted);
}
.empty h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
}
.empty p { margin: 0; font-size: 15px; }

.banner {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

.dock {
  flex-shrink: 0;
  padding: 8px var(--pad) calc(12px + env(safe-area-inset-bottom));
  padding-left: calc(var(--pad) + env(safe-area-inset-left));
  padding-right: calc(var(--pad) + env(safe-area-inset-right));
  background: linear-gradient(to top, var(--paper) 72%, rgba(247, 244, 238, 0));
}

.primary, .secondary, .danger-btn {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.primary {
  background: var(--accent);
  color: #f6f3ec;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.primary:active { background: var(--accent-press); }
.secondary {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
}
.secondary:active { background: #f3eee6; }
.danger-btn {
  background: transparent;
  color: var(--danger);
  min-height: 48px;
  font-size: 15px;
  font-weight: 600;
}

.stack { display: flex; flex-direction: column; gap: 10px; }
.lede { margin: 4px 0 12px; color: var(--muted); font-size: 14px; }
.block-title {
  margin: 22px 0 6px;
  font-size: 15px;
  font-weight: 700;
}
.hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 14px;
}
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px 10px;
  min-width: 0;
}
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat b {
  display: block;
  margin-top: 4px;
  font-size: clamp(14px, 4.2vw, 20px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -0.03em;
}
.stat em {
  display: block;
  margin-top: 2px;
  font-style: normal;
  color: var(--faint);
  font-size: 11px;
}

.sum-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.sum-row .name { flex: 1; }
.sum-row .pct { color: var(--muted); font-size: 12px; width: 3em; text-align: right; }
.sum-row .amt { font-weight: 600; width: 6.4em; text-align: right; }

.entry-amount {
  flex-shrink: 0;
  padding: 8px var(--pad) 4px;
  text-align: center;
}
.app.is-entry .scroller {
  display: flex;
  flex-direction: column;
}
.entry-fields { margin-top: auto; }
.amount {
  font-size: clamp(40px, 12vw, 56px);
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.amount.is-zero { color: #b7b1a6; }
.amount.is-zero .yen { color: #b7b1a6; }
.amount .yen { font-size: 0.42em; }

.cats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.cat {
  min-height: 56px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 4px;
  font-size: 14px;
  line-height: 1.2;
}
.cat small {
  width: 8px;
  height: 8px;
  border-radius: 99px;
}
.cat[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.date-row { gap: 8px; margin: 14px 0 10px; }
.seg {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--white);
  font-size: 14px;
  color: var(--muted);
}
.seg[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  font-weight: 600;
}

.field {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
}
.field:focus { border-color: var(--accent); }
.date-field { margin-bottom: 10px; }

.entry-error {
  min-height: 20px;
  margin: 8px 2px 0;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

.keypad-wrap, .save-wrap {
  flex-shrink: 0;
  padding: 0 var(--pad);
  padding-left: calc(var(--pad) + env(safe-area-inset-left));
  padding-right: calc(var(--pad) + env(safe-area-inset-right));
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 8px;
}
.key {
  height: 52px;
  border-radius: 12px;
  background: var(--white);
  border: 1px solid var(--line);
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.key:active { background: #efeae2; }
.key-muted { color: var(--muted); font-size: 18px; }
.save-wrap { padding-top: 8px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

.cat-manage { margin-top: 8px; }
.cat-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  gap: 4px;
  align-items: center;
  min-height: 56px;
  border-top: 1px solid var(--line);
}
.cat-row .name {
  min-width: 0;
  font-size: 16px;
  text-align: left;
  min-height: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.add-row { display: flex; gap: 8px; margin-top: 16px; }
.add-row .field { flex: 1; }
.add-row .secondary { width: auto; min-width: 76px; padding: 0 14px; }
.form-error { min-height: 20px; margin: 6px 0 0; color: var(--danger); font-size: 13px; }

.page-pad { padding-top: 12px; padding-bottom: 28px; }
.backup-status { margin: 0 0 10px; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(460px, calc(100% - 28px));
  background: #1c1915;
  color: #f7f4ee;
  border-radius: 14px;
  padding: 12px 12px 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(28, 25, 21, 0.28);
  font-size: 14px;
}
.toast[hidden] { display: none; }
.toast button {
  color: #d7efe4;
  font-weight: 700;
  min-height: 36px;
  padding: 0 8px;
  flex-shrink: 0;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(28, 25, 21, 0.46);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.overlay[hidden] { display: none; }
.dialog {
  width: min(440px, 100%);
  background: var(--paper);
  border-radius: 18px;
  padding: 20px 18px 16px;
  box-shadow: var(--shadow);
}
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.dialog .field { margin-bottom: 8px; }
.dialog-actions { gap: 8px; margin-top: 8px; }
.dialog-actions .secondary, .dialog-actions .primary, .dialog-actions .danger-fill {
  flex: 1;
  min-height: 48px;
  border-radius: 12px;
  font-weight: 700;
}
.danger-fill {
  background: var(--danger);
  color: #fffaf8;
  border: 0;
  font-size: 16px;
}

.noscript {
  max-width: 520px;
  margin: 24px auto;
  padding: 0 18px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 760px) {
  body { background: var(--desk); }
  .app {
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    margin: 24px auto;
    border-radius: 28px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(48, 38, 22, 0.06);
  }
  .overlay { align-items: center; }
  .key { height: 56px; }
}

@media (max-height: 700px) {
  .key { height: 46px; }
  .amount { font-size: 40px; }
  .cat { min-height: 48px; }
  .entry-amount { padding-top: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
