:root {
  color-scheme: light dark;
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #23211c;
  --muted: #6d695f;
  --line: #e2ded4;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e0eee9;
  --danger: #b3382c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191a18;
    --card: #242522;
    --ink: #eeece6;
    --muted: #a5a297;
    --line: #3a3b36;
    --accent: #5fb49c;
    --accent-ink: #10201b;
    --accent-soft: #24403a;
    --danger: #ef8579;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

main#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom));
}

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 14px; font-weight: 600; color: var(--muted); margin: 24px 0 8px; }

/* 入力欄。文字を16px未満にすると iPhone が画面を拡大してしまう */
input, select, button { font: inherit; color: inherit; }

input, select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
}

input[type="date"] { -webkit-appearance: none; appearance: none; }

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }

.amount-wrap { position: relative; }
.amount-wrap input { font-size: 28px; font-weight: 600; text-align: right; padding-right: 44px; min-height: 60px; }
.amount-wrap::after { content: "円"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }

button { cursor: pointer; border: 0; border-radius: 10px; min-height: 48px; padding: 8px 14px; background: var(--card); }
button:disabled { opacity: 0.55; }
.primary { width: 100%; background: var(--accent); color: var(--accent-ink); font-weight: 600; min-height: 52px; }
.secondary { border: 1px solid var(--line); }
.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

.chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.chip {
  padding: 6px 4px;
  min-height: 48px;
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.chip-group { margin-bottom: 12px; }
.chip-group h3 { font-size: 13px; font-weight: 400; color: var(--muted); margin: 0 0 6px; }

.form-error { color: var(--danger); font-size: 14px; min-height: 21px; margin: 0 0 8px; }

/* 月の画面 */
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-head h1 { margin: 0; font-variant-numeric: tabular-nums; }
.month-head button { min-width: 48px; font-size: 20px; background: transparent; }
.total { text-align: center; padding: 12px 0 8px; }
.total .label { color: var(--muted); font-size: 14px; }
.total .value { font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* 円グラフ。色は circle の線と凡例の印の両方に効かせる */
.pie { display: block; width: 100%; max-width: 220px; margin: 0 auto 16px; }
.pie-1 { stroke: #38bdf8; background-color: #38bdf8; }
.pie-2 { stroke: #2dd4bf; background-color: #2dd4bf; }
.pie-3 { stroke: #a78bfa; background-color: #a78bfa; }
.pie-4 { stroke: #f59e0b; background-color: #f59e0b; }
.pie-5 { stroke: #f472b6; background-color: #f472b6; }
.pie-6 { stroke: #64748b; background-color: #64748b; }
.pie-legend { list-style: none; margin: 0; padding: 0; }
.pie-legend li { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 15px; }
.pie-legend .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pie-legend .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pie-mark { flex: none; width: 12px; height: 12px; border-radius: 3px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px; }
.row-button { width: 100%; background: transparent; border-radius: 0; text-align: left; }
.row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .sub { display: block; color: var(--muted); font-size: 13px; }
.row .num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.row.stopped .grow, .row.stopped .num { opacity: 0.55; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
}
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; box-shadow: inset 0 2px 0 var(--accent); }

dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  border: 0;
  border-radius: 16px;
  padding: 16px;
  background: var(--bg);
  color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h1:focus { outline: none; }
.dialog-actions { display: grid; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

.login-page { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; }
.login-box h1 { text-align: center; font-size: 28px; margin-bottom: 24px; }
