:root {
  color-scheme: light;
  --page: #f7f6f2;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #76746e;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --up: #006300;
  --down: #b42323;
  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #1baf7a;
  --c4: #eda100;
  --c5: #e87ba4;
  --c6: #008300;
  --c7: #4a3aa7;
  --c8: #e34948;
  --other: #a8a69f;
  --font: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #121211;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9d9b94;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --up: #0ca30c;
    --down: #e66767;
    --c1: #3987e5;
    --c2: #d95926;
    --c3: #199e70;
    --c4: #c98500;
    --c5: #d55181;
    --c6: #008300;
    --c7: #9085e9;
    --c8: #e66767;
    --other: #6b6a65;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.5;
}

h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; }
h2 { font-size: 22px; }
button, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.big { font-size: 20px; }
.error { color: var(--down); font-size: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.center-screen { min-height: 100svh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { text-align: center; display: grid; gap: 16px; justify-items: center; }
.login-card h1 { font-size: 32px; }
.login-card .big { margin: 0; line-height: 1.7; }
.face-icon { width: 96px; height: 96px; fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.primary {
  min-height: 56px; min-width: 240px; padding: 0 28px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: 20px; font-weight: 700; cursor: pointer;
}
.primary:disabled { opacity: 0.6; }

#app { max-width: 640px; margin: 0 auto; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }

/* ---------- 頂部 ---------- */
.top { padding: calc(12px + env(safe-area-inset-top)) 16px 0; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pill {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 6px 16px; font-weight: 600; min-height: 44px;
}
.period select {
  margin-top: 8px; width: 100%;
  font-size: 20px; font-weight: 600;
  padding: 8px 12px; min-height: 48px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.who {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 10px 16px; background: var(--page); border-bottom: 1px solid var(--border);
}
.who button {
  min-height: 52px; font-size: 20px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink-2);
}
.who button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

main { padding: 12px 16px 0; display: grid; gap: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 18px 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 16px; }

/* ---------- 總覽數字 ---------- */
.hero .label { color: var(--ink-2); font-size: 18px; }
.hero .value { font-size: 40px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.15; margin: 2px 0 6px; }
.hero .delta { font-size: 18px; font-weight: 600; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.hero .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--grid); }
.hero .row .value { font-size: 24px; margin: 0; }
.hero .explain { margin: 10px 0 0; color: var(--muted); font-size: 16px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; font-size: 18px; color: var(--ink-2); }
.switch { width: 60px; height: 34px; border-radius: 999px; border: 0; background: var(--axis); position: relative; padding: 0; cursor: pointer; }
.switch span { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(26px); }

/* ---------- 圓餅圖 ---------- */
.donut-block { display: grid; gap: 12px; margin-top: 8px; }
.donut { width: min(260px, 78vw); margin: 0 auto; display: block; }
.donut circle.seg { cursor: pointer; transition: stroke-width 0.15s; }
.donut .c-label { font-size: 15px; fill: var(--ink-2); }
.donut .c-pct { font-size: 30px; font-weight: 700; fill: var(--ink); }
.donut .c-val { font-size: 15px; fill: var(--muted); }

.legend { list-style: none; margin: 0; padding: 0; }
.legend li {
  display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 10px;
  padding: 10px 6px; border-top: 1px solid var(--grid); cursor: pointer; border-radius: 8px;
}
.legend li:first-child { border-top: 0; }
.legend li.on { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.legend .sw { width: 16px; height: 16px; border-radius: 4px; }
.legend .name { font-size: 18px; overflow-wrap: anywhere; }
.legend .name small { display: block; color: var(--muted); font-size: 15px; }
.legend .num { text-align: right; font-variant-numeric: tabular-nums; }
.legend .pct { font-size: 20px; font-weight: 700; }
.legend .amt { display: block; color: var(--muted); font-size: 15px; }

/* ---------- 長條圖 ---------- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 14px; min-height: 44px; font-size: 17px; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
#bars { margin-top: 14px; }
#bars svg { width: 100%; display: block; overflow: visible; }
#bars .tick { font-size: 13px; fill: var(--muted); }
#bars .xl { font-size: 15px; fill: var(--ink-2); }
#bars .top-label { font-size: 15px; font-weight: 700; fill: var(--ink); }
#bars .bar-hit { cursor: pointer; fill: transparent; }
#bars .sel { fill: color-mix(in srgb, var(--accent) 8%, transparent); }
.bar-legend { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 8px; font-size: 16px; color: var(--ink-2); }
.bar-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bar-legend i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.bar-detail { margin-top: 10px; padding: 12px; border-radius: 12px; background: var(--page); font-size: 17px; }
.bar-detail .row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.bar-detail .row b { font-variant-numeric: tabular-nums; }

/* ---------- 明細 ---------- */
details summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "展開 ▾"; color: var(--accent); font-size: 17px; }
details[open] summary::after { content: "收合 ▴"; }
.group-title { margin: 18px 0 4px; font-size: 19px; color: var(--ink-2); }
.item { padding: 10px 0; border-top: 1px solid var(--grid); display: flex; justify-content: space-between; gap: 12px; }
.item .meta { color: var(--muted); font-size: 15px; }
.item .v { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item .debt { display: block; color: var(--down); font-size: 15px; font-weight: 400; }

/* ---------- 公布欄 ---------- */
#board-list { display: grid; gap: 14px; }
.post .tags { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.tag { font-size: 15px; padding: 2px 10px; border-radius: 999px; background: var(--page); color: var(--ink-2); border: 1px solid var(--border); }
.tag.pin { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.post h2 { font-size: 22px; }
.post .date { color: var(--muted); font-size: 16px; margin: 4px 0 0; }
.post .body { white-space: pre-wrap; font-size: 19px; line-height: 1.7; margin: 12px 0 0; overflow-wrap: anywhere; }
.post a.btn {
  display: inline-flex; align-items: center; min-height: 48px; margin-top: 12px; padding: 0 18px;
  border-radius: 12px; background: var(--accent); color: var(--accent-ink); text-decoration: none; font-weight: 600;
}
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 19px; }

/* ---------- 底部 ---------- */
.foot { text-align: center; padding: 24px 16px 8px; display: grid; gap: 4px; }
.foot p { margin: 0; }
.link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 8px 4px; cursor: pointer; }

nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom button {
  border: 0; background: none; min-height: 68px; font-size: 17px; color: var(--muted);
  display: grid; justify-items: center; align-content: center; gap: 2px; position: relative;
}
nav.bottom svg { width: 26px; height: 26px; fill: currentColor; }
nav.bottom button[aria-current="page"] { color: var(--accent); font-weight: 700; }
nav.bottom .dot { position: absolute; top: 12px; left: calc(50% + 14px); width: 10px; height: 10px; border-radius: 50%; background: var(--down); }
