:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface-1: #ffffff;
  --text-primary: #191919;
  --text-secondary: #666666;
  --line: #e4e4e0;
  --grid: #ececea;
  --accent: #191919;
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --good: #0b7a2a;
  --bad: #c02f30;
  --warn-bg: #fff6e0;
  --warn-line: #f2a600;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111111;
    --surface-1: #191919;
    --text-primary: #efefef;
    --text-secondary: #9c9c9c;
    --line: #2c2c2c;
    --grid: #262626;
    --accent: #efefef;
    --series-1: #338ced;
    --series-2: #e76624;
    --series-3: #00a888;
    --good: #3cc46a;
    --bad: #eb6263;
    --warn-bg: #2a2310;
    --warn-line: #d28e05;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-feature-settings: "palt";
}
a { color: inherit; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: .02em; }
h1 small { font-size: .85rem; font-weight: 500; color: var(--text-secondary); margin-left: .75em; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }

.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .7rem 1.25rem; background: var(--surface-1); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: .08em; }
.topbar nav { display: flex; gap: 1.1rem; align-items: center; flex-wrap: wrap; font-size: .92rem; }
.topbar nav a { text-decoration: none; color: var(--text-secondary); padding: .15rem 0; border-bottom: 2px solid transparent; }
.topbar nav a[aria-current="page"] { color: var(--text-primary); border-color: var(--accent); }
.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--text-secondary); cursor: pointer; }

main { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
main.narrow { max-width: 460px; }
main.narrow > :is(h1, form, p, ul, section, div) { margin-bottom: 1rem; }
main.narrow form p, .stack > div { display: flex; flex-direction: column; gap: .3rem; margin: 0 0 .9rem; }
main.narrow input:not([type=checkbox]), .stack input, .stack select {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); font: inherit;
}
main.narrow button, button.primary {
  padding: .65rem 1.2rem; border-radius: 8px; border: 0; background: var(--accent); color: var(--surface-1);
  font: inherit; font-weight: 600; cursor: pointer;
}
.helptext, .stack .helptext { color: var(--text-secondary); font-size: .82rem; }

.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.filters input[type=month] { padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-1); color: var(--text-primary); font: inherit; }
.btn { display: inline-flex; align-items: center; padding: .4rem .75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-1); text-decoration: none; font-size: .9rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a { padding: .4rem .9rem; text-decoration: none; background: var(--surface-1); color: var(--text-secondary); font-size: .9rem; }
.seg a + a { border-left: 1px solid var(--line); }
.seg a[aria-current="true"] { background: var(--accent); color: var(--surface-1); font-weight: 600; }

.note { color: var(--text-secondary); font-size: .88rem; margin: 0 0 1rem; }
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li, .alert { padding: .7rem .9rem; border-radius: 8px; background: var(--surface-1); border: 1px solid var(--line); margin-bottom: .5rem; font-size: .92rem; }
.alert { border-color: var(--bad); }
.alert.warn, .msg-warning, .msg-info { background: var(--warn-bg); border-color: var(--warn-line); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile, .card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); }
.tile { padding: .9rem 1rem; }
.tile-label { color: var(--text-secondary); font-size: .85rem; display: flex; align-items: center; gap: .4rem; }
.tile-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.tile-value span { font-size: .85rem; font-weight: 500; margin-left: .15rem; color: var(--text-secondary); }
.tile-sub { color: var(--text-secondary); font-size: .82rem; }
.up { color: var(--good); } .down { color: var(--bad); }

.card { padding: 1rem 1.1rem; margin-bottom: 1rem; }
.narrow-card { max-width: 520px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--series-1); flex: none; }
.key.s2 { background: var(--series-2); } .key.s3 { background: var(--series-3); }

.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .grid.base { stroke: var(--text-secondary); stroke-opacity: .5; }
.chart .axis { fill: var(--text-secondary); font-size: 11px; }
.chart .bar { fill: var(--series-1); transition: opacity .12s; }
.chart .bar.s2 { fill: var(--series-2); } .chart .bar.s3 { fill: var(--series-3); }
.chart .grp.dim .bar { opacity: .35; }
.chart data { display: none; }
.tooltip {
  position: absolute; pointer-events: none; min-width: 160px;
  background: var(--surface-1); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12); padding: .5rem .65rem; font-size: .82rem;
}
.tooltip .tip-title { font-weight: 700; margin-bottom: .2rem; }
.tooltip div { display: flex; align-items: center; gap: .4rem; }
.tooltip b { margin-left: auto; font-variant-numeric: tabular-nums; padding-left: 1rem; }

.tableview summary { cursor: pointer; color: var(--text-secondary); font-size: .88rem; margin-top: .5rem; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { color: var(--text-secondary); font-weight: 500; font-size: .82rem; text-align: right; }
thead th:first-child, tbody th, .left { text-align: left; }
table.num td { text-align: right; font-variant-numeric: tabular-nums; }
table.num tbody th { font-weight: 500; }
.ledger .l { text-align: left; }
.ledger .carry td { color: var(--text-secondary); }
.ledger tfoot th, .ledger tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: .82rem; color: var(--text-secondary); }
.empty { text-align: center !important; color: var(--text-secondary); padding: 1.5rem; }
.neg { color: var(--bad); font-weight: 700; }

@media (max-width: 640px) {
  main { padding: 1rem .8rem 3rem; }
  .tile-value { font-size: 1.35rem; }
  .topbar { gap: .6rem; }
}
