:root {
  --background: #f4f5f3;
  --card: #ffffff;
  --hover: #eceeea;
  --border: #dfe2dc;
  --border-subtle: #e9ebe6;
  --input: #d3d7cf;
  --field: #ffffff;
  --foreground: #14171a;
  --muted: #62686d;
  --brand: #14171a;
  --brand-ink: #2c3238;
  --on-brand: #ffffff;
  --money: #0f7b55;
  --money-soft: #b5dccb;
  --success-ink: #0b6645;
  --warning: #b87503;
  --warning-ink: #8a5800;
  --destructive: #c8434a;
  --destructive-ink: #a52f37;
  --destructive-soft: #ecbcbf;
  --absent: #b4bab2;
  --wash-success: rgba(15, 123, 85, 0.1);
  --wash-warning: rgba(184, 117, 3, 0.12);
  --wash-destructive: rgba(200, 67, 74, 0.1);
  --wash-neutral: rgba(20, 23, 26, 0.07);
  --float: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.08), 0 12px 32px rgba(0, 0, 0, 0.06);
  --veil: rgba(20, 23, 26, 0.28);
  --pad: 32px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0f1211;
    --card: #171b19;
    --hover: #212624;
    --border: #2a302d;
    --border-subtle: #222725;
    --input: #343b37;
    --field: #121514;
    --foreground: #eceeec;
    --muted: #979e99;
    --brand: #eceeec;
    --brand-ink: #ffffff;
    --on-brand: #0f1211;
    --money: #3cc48d;
    --money-soft: #1f5a44;
    --success-ink: #55d3a0;
    --warning: #e0a23c;
    --warning-ink: #ecb556;
    --destructive: #ee6b70;
    --destructive-ink: #f58a8e;
    --destructive-soft: #6b3336;
    --absent: #4b534e;
    --wash-success: rgba(60, 196, 141, 0.14);
    --wash-warning: rgba(224, 162, 60, 0.16);
    --wash-destructive: rgba(238, 107, 112, 0.16);
    --wash-neutral: rgba(236, 238, 236, 0.09);
    --float: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 8px 24px rgba(0, 0, 0, 0.5);
    --veil: rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html { background: var(--background); }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font: 400 14px/22px system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

h1, h2, h3, p, dl, dd, ul, ol { margin: 0; padding: 0; }

ul, ol { list-style: none; }

.num, .stat-value, .acct-num, .count, .tick { font-variant-numeric: tabular-nums; }
.num { white-space: nowrap; }
.muted { color: var(--muted); }
.bad { color: var(--destructive-ink); }
.warn { color: var(--warning-ink); }
.label { font-size: 12px; line-height: 16px; color: var(--muted); }

.mark { width: 20px; height: 20px; flex: none; }
.mark path { stroke: var(--money); stroke-width: 2.5; fill: none; }
.mark circle { fill: var(--foreground); }

.top { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 var(--pad); border-bottom: 1px solid var(--border); background: var(--background); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.top-space { flex: 1; }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; margin-left: 8px; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--money); }
.toggle-rest { margin-left: 4px; }
.state-off { color: var(--warning-ink); }
.state-off .state-dot { background: var(--warning); }

.canvas { max-width: 1200px; margin: 0 auto; padding: 40px var(--pad) 72px; display: grid; gap: 40px; }

.notice { border: 1px solid var(--border); border-radius: 10px; background: var(--card); padding: 10px 16px; color: var(--warning-ink); }

.hero { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 0; }
.stat { display: grid; gap: 6px; align-content: start; padding: 0 32px; border-left: 1px solid var(--border); min-width: 0; }
.stat:first-child { padding-left: 0; border-left: 0; }
.stat:last-child { padding-right: 0; }
.stat-label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--muted); }
.stat-value { font-size: 44px; line-height: 48px; font-weight: 650; letter-spacing: -0.035em; white-space: nowrap; }
.stat-value.up { color: var(--money); }
.stat-value.down { color: var(--destructive-ink); }
.stat-note { font-size: 13px; line-height: 19px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 16px; }
.split { height: 44px; display: flex; align-items: flex-end; padding-bottom: 0; }
.split .money-track { height: 12px; }
.spark { height: 44px; }
.spark-bars { display: flex; align-items: flex-end; gap: 2px; height: 100%; border-bottom: 1px solid var(--border); }
.spark-slot { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 0; }
.spark-bar { display: block; width: 100%; border-radius: 2px 2px 0 0; background: var(--money); }
.spark-soft { background: var(--money-soft); }
.spark-down { background: var(--destructive); }
.spark-down.spark-soft { background: var(--destructive-soft); }
.spark-axis { display: flex; justify-content: space-between; font-size: 11px; line-height: 14px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -2px; }

.money-track { display: flex; gap: 2px; width: 100%; height: 8px; }
.money-cash, .money-open { display: block; height: 100%; border-radius: 2px; min-width: 0; }
.money-cash { background: var(--money); }
.money-open { background: var(--money-soft); }
.key { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.key-cash { background: var(--money); }
.key-open { background: var(--money-soft); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.group { display: grid; gap: 12px; min-width: 0; }
.group-head { display: flex; align-items: center; gap: 10px; min-height: 32px; }
h2 { font-size: 17px; line-height: 24px; font-weight: 650; letter-spacing: -0.015em; }
.count { font-size: 13px; color: var(--muted); }
h3 { font-size: 14px; line-height: 20px; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--border-subtle); border-radius: 10px; min-width: 0; }
.card.pad { padding: 20px 22px; display: grid; gap: 14px; align-content: start; }
.rows { overflow: hidden; }
.rows-empty { padding: 12px 16px; }

.need { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 16px; background: none; border: 0; border-bottom: 1px solid var(--border-subtle); color: var(--foreground); font: inherit; text-align: left; cursor: pointer; }
.need:last-child { border-bottom: 0; }
.need:hover { background: var(--hover); }
.need:focus-visible, .acct:focus-visible { outline: 3px solid var(--foreground); outline-offset: -3px; }
.need-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--absent); }
.need-warning { background: var(--warning); }
.need-destructive { background: var(--destructive); }
.need-brand { background: var(--money); }
.need-text { flex: 1; min-width: 0; }
.need-arrow { color: var(--muted); transition: transform 150ms cubic-bezier(0.22, 1, 0.36, 1); }
.need:hover .need-arrow, .acct:hover .need-arrow { color: var(--foreground); transform: translateX(2px); }

.accts { overflow: hidden; }
.accts-head, .accts-person, .acct { display: grid; grid-template-columns: minmax(170px, 240px) minmax(120px, 1fr) 104px 104px 96px 104px 44px; align-items: center; column-gap: 8px; }
.accts-head { height: 38px; border-bottom: 1px solid var(--border-subtle); }
.accts-person { min-height: 36px; background: var(--background); border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.accts-empty { padding: 12px 16px; border-bottom: 1px solid var(--border-subtle); }
.acct { width: 100%; min-height: 48px; background: none; border: 0; border-bottom: 1px solid var(--border-subtle); color: var(--foreground); font: inherit; text-align: left; cursor: pointer; }
.acct:last-child { border-bottom: 0; }
.acct:hover { background: var(--hover); }
.acct-name { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; padding-left: 16px; min-width: 0; }
.acct-name strong { font-weight: 500; }
.acct .acct-name { position: relative; padding-left: 28px; }
.acct .need-dot { position: absolute; left: 12px; top: 50%; margin-top: -4px; }
.acct-legend { display: flex; align-items: center; gap: 6px; padding-left: 16px; }
.acct-legend .key + span { margin-right: 10px; }
.acct .money-track { padding-left: 16px; }
.accts-person .acct-name { font-weight: 600; }
.acct-num { text-align: right; white-space: nowrap; }
.acct-cash { font-weight: 500; }
.acct-meta { display: none; }
.acct .need-arrow { text-align: right; padding-right: 16px; }

.bench summary { display: flex; gap: 10px; align-items: baseline; padding: 6px 2px; font-size: 13px; cursor: pointer; list-style: none; }
.bench summary::-webkit-details-marker { display: none; }
.bench summary::before { content: "›"; color: var(--muted); transition: transform 150ms cubic-bezier(0.22, 1, 0.36, 1); }
.bench[open] summary::before { transform: rotate(90deg); }
.bench summary .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.bench .card { margin-top: 6px; }

.pill { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap; background: var(--wash-neutral); color: var(--muted); }
.pill-rest { margin-left: 4px; }
.pill-success { background: var(--wash-success); color: var(--success-ink); }
.pill-warning { background: var(--wash-warning); color: var(--warning-ink); }
.pill-destructive { background: var(--wash-destructive); color: var(--destructive-ink); }

.bets { display: grid; }
.bet { padding: 12px 16px; border-bottom: 1px solid var(--border-subtle); display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.2fr) minmax(0, 1.2fr) 80px; gap: 2px 16px; align-items: start; }
.bet:last-child { border-bottom: 0; }
.bet-main { display: grid; min-width: 0; }
.bet-event { font-weight: 550; overflow-wrap: anywhere; }
.bet-meta { font-size: 12px; line-height: 17px; color: var(--muted); }
.bet-leg { display: grid; font-size: 13px; line-height: 19px; min-width: 0; }
.bet-profit { text-align: right; font-weight: 550; font-variant-numeric: tabular-nums; }

.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.chart { min-height: 168px; }
.plot { display: block; max-width: 100%; }
.grid { stroke: var(--border-subtle); stroke-width: 1; }
.base { stroke: var(--border); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11px; }
.bar { fill: var(--money); }
.bar-down { fill: var(--destructive); }
.bar-open { fill: var(--money-soft); }
.bar-down.bar-open { fill: var(--destructive-soft); }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.line-0 { stroke: var(--money); }
.line-1 { stroke: var(--foreground); }
.line-2 { stroke: var(--absent); }
.line-3 { stroke: var(--warning); }
.legend { display: inline-flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-0 { background: var(--money); }
.dot-1 { background: var(--foreground); }
.dot-2 { background: var(--absent); }
.dot-3 { background: var(--warning); }

.funnel { display: grid; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 132px minmax(0, 1fr) 34px; gap: 12px; align-items: center; font-size: 13px; }
.funnel-label { color: var(--muted); }
.funnel-track { height: 8px; display: block; }
.funnel-bar { display: block; height: 100%; border-radius: 2px; background: var(--absent); }
.funnel-last .funnel-bar { background: var(--money); }
.funnel-last .funnel-label { color: var(--foreground); font-weight: 550; }
.funnel-row .num { text-align: right; }
.funnel-note { color: var(--muted); font-size: 13px; line-height: 20px; }

.facts { display: grid; grid-template-columns: 1fr auto; }
.facts dt, .facts dd { padding: 8px 0; border-bottom: 1px solid var(--border-subtle); }
.facts dt { color: var(--muted); }
.facts dd { text-align: right; }

.foot { font-size: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; max-width: min(520px, calc(100vw - 32px)); background: var(--brand); color: var(--on-brand); padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; box-shadow: var(--float); }
.toast-bad { background: var(--destructive); color: #fff; }

@media (max-width: 1040px) {
  .three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .accts-head, .accts-person, .acct { grid-template-columns: minmax(150px, 200px) minmax(80px, 1fr) 96px 96px 84px 96px 40px; }
  .stat { padding: 0 20px; }
  .stat-value { font-size: 36px; line-height: 42px; }
}

@media (max-width: 900px) {
  .accts-head { display: none; }
  .accts-person { grid-template-columns: minmax(0, 1fr) auto; padding-right: 16px; }
  .accts-person > :nth-child(2), .acct-wide { display: none; }
  .acct { grid-template-columns: minmax(0, 1fr) auto; row-gap: 6px; padding: 12px 16px; }
  .acct .acct-name { padding-left: 0; grid-column: 1; grid-row: 1; }
  .acct .need-dot { position: static; margin: 0; }
  .acct-cash { grid-column: 2; grid-row: 1; }
  .acct .money-track { grid-column: 1 / -1; grid-row: 2; padding-left: 0; height: 6px; }
  .acct-meta { display: block; grid-column: 1 / -1; grid-row: 3; font-size: 12px; line-height: 16px; }
  .acct .need-arrow { display: none; }
}

@media (max-width: 760px) {
  :root { --pad: 16px; }
  .toggle-rest { display: none; }
  .top { gap: 8px; }
  .canvas { padding-top: 24px; gap: 32px; }
  .hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px 20px; }
  .stat, .stat:last-child { padding: 0; border-left: 0; }
  .stat:first-child { grid-column: 1 / -1; }
  .stat-value { font-size: 28px; line-height: 34px; }
  .stat:first-child .stat-value { font-size: 40px; line-height: 44px; }
  .split { height: 20px; }
  .three { grid-template-columns: minmax(0, 1fr); }
  .bench summary { flex-wrap: wrap; }
  .bet { grid-template-columns: minmax(0, 1fr) auto; }
  .bet-leg { grid-column: 1 / -1; }
  .bet-profit { grid-column: 2; grid-row: 1; }
}
