:root {
  --bg: #0f1419;
  --card: #1a2332;
  --card-hi: #223047;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #c41e3a;
  --good: #22c55e;
  --bad: #ef4444;
  --border: #2a3342;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum";
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
          env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100vh;
}

header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}
h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#period {
  font-size: 13px;
  margin-top: 4px;
}

main {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.grid-2 .card { margin-bottom: 0; }

.label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.big {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.big.accent { color: var(--accent); }
.big.bad { color: var(--bad); }
.big.good { color: var(--good); }

.med {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.muted { color: var(--muted); }

.headline {
  background: linear-gradient(180deg, var(--card) 0%, #161f2e 100%);
}

.delta {
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}
.delta.good { color: #86efac; background: rgba(34,197,94,0.12); }
.delta.bad  { color: #fca5a5; background: rgba(239,68,68,0.12); }

/* Hierarchical collapsible breakdown */
.breakdown { display: flex; flex-direction: column; gap: 14px; }

details.section {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #121a26;
  overflow: hidden;
}
details.section > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before {
  content: "▸";
  display: inline-block;
  color: var(--muted);
  font-size: 11px;
  margin-right: 8px;
  transition: transform 0.15s ease;
}
details.section[open] > summary::before { transform: rotate(90deg); }
details.section > summary .section-title { flex: 1; }
.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.section-total {
  font-size: 14px;
  font-weight: 700;
  color: var(--fg);
}
.section-body {
  padding: 6px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.bar-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  padding: 2px 0;
}
details.bar-row.has-sub {
  padding: 0;
  margin: 0;
}
details.bar-row.has-sub > summary {
  display: block;
  list-style: none;
  cursor: pointer;
  padding: 4px 0;
}
details.bar-row.has-sub > summary::-webkit-details-marker { display: none; }
details.bar-row.has-sub > summary:hover .bar-label { color: #fff; }
.bar-label {
  font-size: 13px;
  line-height: 1.3;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bar-label .chip {
  font-size: 10px;
  color: var(--muted);
  margin-left: 6px;
  transition: transform 0.15s ease;
}
details.bar-row.has-sub[open] > summary .bar-label .chip {
  transform: rotate(180deg);
}
.bar-track {
  background: #0a0f17;
  border-radius: 6px;
  overflow: hidden;
  height: 8px;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.4s ease-out;
  opacity: 0.85;
}
.bar-fill.negative { opacity: 0.4; }
.bar-value {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1px;
}

.sub-breakdown {
  margin: 8px 0 6px 14px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border-left: 2px solid rgba(255,255,255,0.08);
  border-radius: 0 8px 8px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sub-note {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 4px;
}
.sub-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
}
.sub-row .bar-label { font-size: 12px; }
.sub-row .bar-value { font-size: 11px; }

.callout {
  background: #121a26;
  border: 1px dashed var(--border);
}
.callout h2 { color: var(--muted); }
.callout p { font-size: 13px; }

.source {
  background: transparent;
  border: none;
  padding: 12px 0 40px;
  text-align: center;
}
.source a { color: var(--muted); text-decoration: underline; }
.source a:hover { color: var(--fg); }

@media (max-width: 480px) {
  .big { font-size: 34px; }
  .med { font-size: 22px; }
}
