:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --good: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --bar: #99d5cf;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --card: #17212c;
    --ink: #e5e7eb;
    --muted: #94a3b8;
    --line: #263241;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --good: #4ade80;
    --bad: #f87171;
    --warn: #fbbf24;
    --bar: #1f6f66;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.top h1 { font-size: 24px; margin: 0; letter-spacing: -0.02em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 24px; line-height: 1; cursor: pointer;
}
main { padding: 4px 16px 16px; max-width: 720px; margin: 0 auto; outline: none; }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; font-size: 11px; color: var(--muted); text-decoration: none;
}
.tabs a span { font-size: 20px; line-height: 1; }
.tabs a.on { color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 12px 0; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: 14px; }
.progress { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; margin: 10px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 12px; }
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 120px; margin-top: 8px; position: relative; }
.bars .b { background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .b.hit { background: var(--accent); }
.bars .goal { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--muted); pointer-events: none; }
.barlabels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; font-size: 10px; color: var(--muted); text-align: center; margin-top: 4px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .l { min-width: 0; }
.list .l b { display: block; }
.list .l small { color: var(--muted); }
.list .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list li.tap { cursor: pointer; }
.pos { color: var(--good); } .neg { color: var(--bad); } .warn { color: var(--warn); }
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.open { border-color: var(--accent); color: var(--accent); }
.seg { display: flex; gap: 6px; margin: 8px 0; overflow-x: auto; }
.seg button { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.seg button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.btn { display: block; width: 100%; padding: 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 16px; margin: 8px 0; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.row { display: flex; gap: 8px; } .row > * { flex: 1; }
dialog {
  border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 92vh;
  margin: auto auto 0; border-radius: 18px 18px 0 0; background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
@media (min-width: 600px) { dialog { margin: auto; border-radius: 18px; } }
#sheetForm { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
#sheetForm h3 { margin: 0 0 8px; font-size: 20px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
textarea { min-height: 60px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0; }
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }
table.months { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.months th, table.months td { padding: 6px 4px; text-align: right; border-top: 1px solid var(--line); }
table.months th:first-child, table.months td:first-child { text-align: left; }
table.months th { color: var(--muted); font-weight: 500; font-size: 12px; }
.scroll { overflow-x: auto; }
