:root {
  --bg: #F5EFE6;
  --surface: #FFFCF7;
  --surface-2: #F3EBDF;
  --surface-3: #E9DDCB;
  --field: #FAF5ED;
  --line: #E8DDCD;
  --line-strong: #D5C4AC;
  --ink: #3A2E24;
  --ink-2: #5A4838;
  --muted: #75634F;
  --accent: #8A5A36;
  --accent-hover: #774B2B;
  --accent-ink: #FFFCF7;
  --accent-soft: #EEDFCB;
  --leaf: #5D7A4C;
  --leaf-soft: #E4EBD8;
  --track: #EDE3D4;
  --danger: #B24F38;
  --danger-bg: #F7E3DA;
  --shadow-sm: 0 1px 2px rgba(74, 52, 30, 0.05);
  --shadow: 0 1px 2px rgba(74, 52, 30, 0.04), 0 8px 24px rgba(74, 52, 30, 0.06);
  --r-card: 22px;
  --r-ctl: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Zen Maru Gothic', 'Zen Kaku Gothic New', system-ui, -apple-system, 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(214, 186, 150, 0.22), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(170, 190, 150, 0.16), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; font-weight: 700; line-height: 1.35; letter-spacing: 0.02em; }
h2 { font-size: 20px; font-weight: 700; line-height: 1.45; }
h3 { font-size: 14px; font-weight: 700; color: var(--ink-2); }

.num, input[type="number"], .amount { font-variant-numeric: tabular-nums; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

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

input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 8px 14px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  font-size: 16px;
  transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #A08D78; }
input[type="date"], input[type="month"] { min-width: 0; color-scheme: light; }
input[type="file"] { padding: 8px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

label.field { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
label.field > span { font-weight: 500; letter-spacing: 0.02em; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); background: var(--surface-3); }
.btn:disabled { color: var(--muted); cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 4px 12px rgba(138, 90, 54, 0.22); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:active { background: var(--accent-hover); }
.btn.primary:disabled { background: var(--surface-3); border-color: var(--surface-3); color: var(--muted); box-shadow: none; }
.btn.danger { color: var(--danger); border-color: #E2B5A8; background: var(--surface); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.soft { background: var(--surface-2); border-color: transparent; }
.btn.soft:hover { background: var(--surface-3); }
.btn.small { min-height: 44px; padding: 4px 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.icon { width: 44px; padding: 0; }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }

.link {
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 14px;
  min-height: 44px;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 4px;
}
.link:hover { color: var(--accent-hover); text-decoration-color: var(--accent); }

.loading { padding: 24px 16px; color: var(--muted); font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.text-14 { font-size: 14px; }
.accent { color: var(--accent); font-weight: 700; }
.danger-text { color: var(--danger); }
.income { color: var(--leaf); }
.expense { color: var(--ink); }
.hidden { display: none !important; }

.shell { min-height: 100dvh; }
.nav {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + var(--safe-b));
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 252, 247, 0.88);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  backdrop-filter: saturate(140%) blur(16px);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 8px 28px rgba(74, 52, 30, 0.12);
  padding: 4px;
}
.nav-brand { display: none; }
.nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 54px;
  border-radius: 20px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  transition: transform 120ms ease, color 120ms ease, background-color 120ms ease;
}
.nav a:active { transform: scale(0.95); }
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 700; }

.main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(20px + var(--safe-t)) 16px calc(112px + var(--safe-b));
}
.view { display: grid; gap: 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; flex-wrap: wrap; padding: 4px 0; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .nav {
    position: sticky;
    top: 0;
    left: auto;
    right: auto;
    bottom: auto;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 28px 14px;
    background: rgba(255, 252, 247, 0.6);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }
  .nav-brand { display: flex; align-items: center; gap: 10px; padding: 0 12px 24px; font-weight: 700; font-size: 16px; }
  .nav-brand img { width: 30px; height: 30px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 46px; padding: 0 16px; border-radius: 999px; font-size: 14px; }
  .nav a:hover { color: var(--ink); background: var(--surface-2); }
  .main { width: 100%; padding: 44px 32px 56px; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 14px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }

.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row > .grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid-2 > .btn, .grid-3 > .btn { white-space: normal; text-align: center; line-height: 1.4; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }

.seg {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  min-width: 0;
}
.seg button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(74, 52, 30, 0.12); }

.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list > li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
  min-width: 0;
}
.list > li:first-child { border-top: 0; }
.item-body { flex: 1 1 auto; min-width: 0; display: grid; gap: 2px; }
.item-title { overflow-wrap: anywhere; }
.item-title.done { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); align-items: center; }
.item-note { font-size: 12px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 2px; flex: 0 0 auto; }
.item-actions .btn { color: var(--muted); }
.item-actions .btn:hover { color: var(--ink); }
.item-actions .btn.danger-text:hover { color: var(--danger); background: var(--danger-bg); }
.item-amount { flex: 0 0 auto; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

.check {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: transform 120ms ease;
}
.check:active { transform: scale(0.9); }
.check span {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  display: grid;
  place-items: center;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.check:hover span { border-color: var(--accent); }
.check[aria-checked="true"] span { border-color: var(--leaf); background: var(--leaf); }
.check[aria-checked="true"] span::after {
  content: '';
  width: 10px;
  height: 5px;
  border-left: 2px solid var(--accent-ink);
  border-bottom: 2px solid var(--accent-ink);
  transform: translateY(-1px) rotate(-45deg);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--ink-2);
  line-height: 22px;
}
.tag.danger { color: var(--danger); background: var(--danger-bg); }
.tag.accent { color: var(--accent); background: var(--accent-soft); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { display: grid; gap: 2px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
@media (min-width: 600px) { .stat .value { font-size: 20px; } }

.bar { height: 8px; background: var(--track); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.over > i { background: var(--danger); }
.bar.mutedbar > i { background: #C7B39A; }
.meter { display: grid; gap: 6px; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.meter-top .num { color: var(--muted); font-size: 12px; text-align: right; }
.meter.over .meter-top .num { color: var(--danger); }

.trend { display: grid; gap: 10px; }
.trend-row { display: grid; grid-template-columns: 40px 1fr; gap: 8px; align-items: center; }
.trend-row .bars { display: grid; gap: 4px; min-width: 0; }
.trend-line { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 12px; }
.trend-line .num { min-width: 88px; text-align: right; color: var(--muted); }
.trend-line .bar:not(.mutedbar) > i { background: var(--leaf); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend .lg-income { background: var(--leaf); }
.legend .lg-expense { background: #C7B39A; }

.budget-input { width: 144px; flex: 0 0 auto; }

.month-switch { display: flex; align-items: center; gap: 4px; }
.month-switch .label { min-width: 112px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.month-switch .btn.icon { border-color: var(--line); background: var(--surface); box-shadow: var(--shadow-sm); }
.month-switch .btn.icon:hover { background: var(--surface-2); }

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal .dow.sun { color: var(--danger); }
.cal-cell {
  min-height: 64px;
  min-width: 0;
  padding: 6px 2px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  cursor: pointer;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  transition: transform 120ms ease, background-color 120ms ease;
}
.cal-cell:hover { background: var(--surface-2); }
.cal-cell:active { transform: scale(0.96); }
.cal-cell.out { visibility: hidden; }
.cal-cell .d { font-size: 14px; font-weight: 500; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; }
.cal-cell.today .d { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.cal-cell[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--line-strong); }
.cal-cell .t { color: var(--muted); }
.cal-cell .m { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink-2); }
.cal-cell .m.income { color: var(--leaf); }
@media (min-width: 600px) { .cal-cell { min-height: 80px; } }

.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: 18px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
}
.alert .msg { flex: 1 1 200px; overflow-wrap: anywhere; }
.alert.info { background: var(--leaf-soft); color: #3F5432; }
.notice { font-size: 14px; color: var(--leaf); }
.empty { font-size: 14px; color: var(--muted); padding: 8px 0; }

dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 24px 60px rgba(74, 52, 30, 0.22);
}
dialog::backdrop { background: rgba(58, 46, 36, 0.28); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.dialog-body { display: grid; gap: 16px; padding: 22px; }
.dialog-body p { overflow-wrap: anywhere; white-space: pre-wrap; }

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b));
}
.auth-box { width: 100%; max-width: 400px; display: grid; gap: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); padding: 32px 24px; }
.auth-brand { display: grid; justify-items: center; gap: 12px; text-align: center; }
.auth-brand img { width: 72px; height: 72px; }
.auth form { display: grid; gap: 16px; }
.auth .switch { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; }

details summary { cursor: pointer; color: var(--muted); font-size: 14px; min-height: 44px; display: flex; align-items: center; }
details summary:hover { color: var(--ink); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.home-hero { display: grid; gap: 4px; padding: 8px 0 4px; }
.eyebrow { font-size: 12px; color: var(--muted); letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.home-hero h1 { font-size: 28px; }

.quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.quick .btn { min-height: 50px; padding: 8px; background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-sm); font-weight: 500; }
.quick .btn:hover { background: var(--surface-2); }
.quick .btn.primary { background: var(--accent); border-color: var(--accent); box-shadow: 0 4px 12px rgba(138, 90, 54, 0.22); }
.quick .btn.primary:hover { background: var(--accent-hover); }

.bento { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.bento > .span-2 { grid-column: 1 / -1; }
.tile { align-content: start; }
.tile-label { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: 0.04em; }
.tile-big { font-size: 28px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-big .unit { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.tile-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile-link {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  transition: background-color 120ms ease, transform 120ms ease;
}
.tile-link:hover { background: #FFFFFF; border-color: var(--line-strong); }
.tile-link:active { transform: scale(0.98); }
.tile-link.alerting { background: var(--danger-bg); border-color: #EBC7BB; }
.tile-link.alerting .tile-big { color: var(--danger); }

.money { background: linear-gradient(160deg, #8A5A36 0%, #6E4528 100%); border-color: #6E4528; color: var(--accent-ink); box-shadow: 0 10px 28px rgba(110, 69, 40, 0.28); }
.money:hover { background: linear-gradient(160deg, #94623D 0%, #774B2B 100%); border-color: #6E4528; }
.money .tile-label, .money .tile-sub { color: rgba(255, 248, 238, 0.78); }
.money .money-split > div { background: rgba(255, 248, 238, 0.12); }
.money .bar { background: rgba(255, 248, 238, 0.2); }
.money .bar > i { background: #FFF3E2; }
.money .bar.over > i { background: #FFB4A0; }
.money .meter-top .num { color: rgba(255, 248, 238, 0.85); }
.money .meter.over .meter-top .num { color: #FFC9BA; }

.money-split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.money-split > div { background: var(--surface-2); border-radius: 16px; padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.money-split .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.today-head { display: flex; align-items: center; gap: 16px; }
.ring { width: 64px; height: 64px; flex: 0 0 auto; position: relative; }
.ring svg { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring .ring-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--leaf); }
.ring-track { stroke: var(--track); }
.ring-value { stroke: var(--leaf); transition: stroke-dashoffset 240ms ease; }

@media (min-width: 600px) {
  .tile-big { font-size: 36px; }
  .money-split .v { font-size: 20px; }
}

@media (max-width: 420px) {
  .form-grid { grid-template-columns: 1fr; }
  .item-actions .btn { padding: 4px 8px; }
  .card { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .btn:active, .check:active, .cal-cell:active, .nav a:active, .tile-link:active { transform: none; }
}
