:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1b1e2e;
  --muted: #6b7088;
  --line: #e2e4ee;
  --accent: #4f5bd5;
  --accent-soft: #e6e8fb;
  --bar: #8a93e6;
  --bar-short: #c3c7f2;
  --avg: #e08a2c;
  --goal: #2f9e6e;
  --low: #2f9e6e;
  --low-soft: #e1f4ea;
  --mid: #c98a12;
  --mid-soft: #fbf0d9;
  --high: #d0473f;
  --high-soft: #fbe3e1;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 4px 16px rgba(20, 24, 50, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1222;
    --card: #191d33;
    --text: #e8eaf6;
    --muted: #9298b8;
    --line: #2a2f4d;
    --accent: #8f99ff;
    --accent-soft: #262c52;
    --bar: #7680e0;
    --bar-short: #3d4479;
    --avg: #f0a24a;
    --goal: #4cc38a;
    --low: #4cc38a;
    --low-soft: #173528;
    --mid: #e6b23c;
    --mid-soft: #3a2f14;
    --high: #f07067;
    --high-soft: #3d1c1c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
  max-width: 640px; margin: 0 auto;
}
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: .02em; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.banner {
  max-width: 608px; margin: 8px auto; padding: 10px 14px; border-radius: 12px;
  background: var(--accent-soft); font-size: 14px;
}
.banner.warn { background: var(--mid-soft); }
.banner.error { background: var(--high-soft); }
.banner ul { margin: 4px 0 0; padding-left: 20px; }

.card {
  background: var(--card); border-radius: 16px; padding: 16px; margin: 12px 0;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.big { font-size: 40px; font-weight: 700; line-height: 1.15; letter-spacing: -.01em; }
.big .unit { font-size: 18px; font-weight: 600; margin-left: 2px; }
.sub { margin-top: 4px; color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.chip {
  display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: 14px; font-weight: 700;
}
.lv-low { color: var(--low); background: var(--low-soft); }
.lv-mid { color: var(--mid); background: var(--mid-soft); }
.lv-high { color: var(--high); background: var(--high-soft); }
.card.debt { border-left: 6px solid var(--line); }
.card.debt.lv-low { border-left-color: var(--low); background: var(--card); }
.card.debt.lv-mid { border-left-color: var(--mid); background: var(--card); }
.card.debt.lv-high { border-left-color: var(--high); background: var(--card); }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair .big { font-size: 30px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; padding: 12px 16px; min-height: 44px;
  background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--high-soft); color: var(--high); }
.btn.block { width: 100%; }

.note { font-size: 12px; color: var(--muted); margin: 16px 4px; }

.seg { display: flex; background: var(--line); border-radius: 10px; padding: 3px; margin: 12px 0 4px; }
.seg button {
  flex: 1; border: none; background: transparent; padding: 7px 0; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.seg button.active { background: var(--card); font-weight: 700; box-shadow: var(--shadow); }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; border-radius: 2px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 18px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: grid; grid-template-columns: 88px 1fr auto; align-items: center; gap: 8px;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: none; }
.list .date { font-size: 14px; white-space: nowrap; }
.list .dur { font-weight: 700; }
.list .times { font-size: 12px; color: var(--muted); }
.list .diff { font-size: 14px; font-weight: 600; text-align: right; min-width: 72px; }
.diff.plus { color: var(--low); }
.diff.minus { color: var(--high); }
.list li.none .dur { color: var(--muted); font-weight: 400; }

.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: none; }
.field label { font-size: 15px; }
.field .hint { display: block; font-size: 12px; color: var(--muted); }
.field input { width: 110px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); text-align: right; }
.field input.wide { width: 150px; text-align: left; }
.inline { display: inline-flex; align-items: center; gap: 4px; }
.inline input { width: 64px; }

details.diag summary { cursor: pointer; font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 28px 16px; }
.empty .big { font-size: 22px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; max-width: 160px; border: none; background: none; padding: 8px 0 10px; font-size: 11px; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar .ico { font-size: 18px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 700; }
