:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --line: #e4e3df;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85847f;
  --track: #ecebe7;
  --neg: #c2362f;
  --s1: #2a78d6; /* 이제 */
  --s2: #eb6834; /* 두현 */
  --s3: #1baf7a; /* 모통 */
  --s4: #eda100; /* 기타 */
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --sx: #b9b8b2;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --line: #2c2c2a;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c85;
    --track: #262624;
    --neg: #e66767;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --sx: #5c5b57;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --line: #2c2c2a;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8d8c85;
  --track: #262624; --neg: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --sx: #5c5b57;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom);
}
button, select, input { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.title-row { display: flex; align-items: center; gap: 8px; min-height: 32px; }
h1 { font-size: 18px; margin: 0; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { border: 0; background: none; font-size: 28px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--track); color: var(--text-secondary); white-space: nowrap; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
select, input[type="date"] {
  border: 1px solid var(--line); background: var(--surface-0);
  border-radius: 8px; padding: 6px 10px; min-height: 36px;
}
select { min-width: 140px; }
.custom { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.custom input { width: 140px; }

main { padding: 12px 16px 32px; max-width: 720px; margin: 0 auto; }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 0 0 4px; }
.hero { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.sub { font-size: 13px; color: var(--text-muted); }

/* 누적 막대 */
.stack { display: flex; gap: 2px; height: 12px; border-radius: 4px; overflow: hidden; background: var(--track); }
.stack.big { height: 20px; margin: 12px 0 10px; }
.seg { height: 100%; min-width: 0; }
.seg.p0 { background: var(--s1); } .seg.p1 { background: var(--s2); }
.seg.p2 { background: var(--s3); } .seg.p3 { background: var(--s4); }

.legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; }
@media (max-width: 400px) { .legend .item { font-size: 12px; } .legend .pct { font-size: 11px; } }
.legend .item { display: flex; align-items: baseline; gap: 6px; font-size: 13px; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; transform: translateY(1px); }
.dot.p0 { background: var(--s1); } .dot.p1 { background: var(--s2); }
.dot.p2 { background: var(--s3); } .dot.p3 { background: var(--s4); }
.legend .name { color: var(--text-secondary); white-space: nowrap; }
.legend .val { margin-left: auto; font-weight: 600; white-space: nowrap; }
.legend .pct { color: var(--text-muted); font-size: 12px; margin-left: 4px; }

/* 카테고리 목록 */
.cats { list-style: none; margin: 0; padding: 0; }
.cat { display: block; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cat:first-child { border-top: 0; }
.cat:active { opacity: .6; }
.cat-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.cat-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-amt { font-weight: 600; white-space: nowrap; }
.cat-pct { color: var(--text-muted); font-size: 13px; width: 44px; text-align: right; }
.chev { color: var(--text-muted); }
.bar-wrap { background: var(--track); border-radius: 4px; height: 12px; }
.bar-wrap .stack { background: transparent; }
.sort-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* 상세 목록 */
.seg-ctl { display: inline-flex; background: var(--track); border-radius: 9px; padding: 3px; margin-bottom: 8px; }
.seg-ctl button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; font-size: 14px; cursor: pointer; color: var(--text-secondary); }
.seg-ctl button.on { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.chip { border: 1px solid var(--line); background: var(--surface-1); border-radius: 99px; padding: 4px 10px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.chip.on { border-color: var(--text-primary); font-weight: 600; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .t { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .a { font-weight: 600; text-align: right; white-space: nowrap; }
.row .a.neg { color: var(--neg); }
.row .meta { grid-column: 1 / -1; font-size: 12px; color: var(--text-muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .flag { color: var(--s2); font-weight: 600; }
.empty { text-align: center; color: var(--text-muted); padding: 40px 0; }
.more { width: 100%; border: 1px solid var(--line); background: var(--surface-1); border-radius: 10px; padding: 10px; margin-top: 8px; cursor: pointer; }

.tip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--text-primary); color: var(--surface-1);
  font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px));
}

/* 카테고리 색 (상위 7개 고정 + 그 외) */
.c0 { background: var(--s1); } .c1 { background: var(--s2); } .c2 { background: var(--s3); }
.c3 { background: var(--s4); } .c4 { background: var(--s5); } .c5 { background: var(--s6); }
.c6 { background: var(--s7); } .cx { background: var(--sx); }
.card h3 { font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 16px 0 0; }
.card h3 + .stack.big { margin-top: 6px; }
.clegend { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.litem { border: 0; background: none; padding: 2px 0; display: inline-flex; align-items: baseline; gap: 5px; font-size: 13px; cursor: pointer; }
.litem .name { color: var(--text-secondary); }
.litem .pct { color: var(--text-muted); font-size: 12px; }
