:root {
  --bg: #0f172a;
  --card: #1e293b;
  --line: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --soft: #cbd5e1;
  --cyan: #06b6d4;
  --rose: #f43f5e;
  --amber: #eab308;
  --green: #10b981;
  --violet: #8b5cf6;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; margin: 0; overflow-x: hidden; }
a { color: var(--cyan); }
strong { color: var(--text); }
h1, h2, h3 { line-height: 1.15; margin: 0; }

.wrap { margin: 0 auto; max-width: 1200px; padding: 0 1rem; }
@media (min-width: 640px) { .wrap { padding: 0 1.5rem; } }

.masthead { background: var(--card); border-bottom: 1px solid var(--line); margin-bottom: 2.5rem; padding: 1.5rem 0 2rem; }
.crumbs { display: flex; font-size: 0.8rem; gap: 1rem; justify-content: space-between; letter-spacing: 0.08em; margin-bottom: 1.5rem; text-transform: uppercase; }
.crumbs a { text-decoration: none; }
.crumbs span { color: var(--muted); }
h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; letter-spacing: -0.02em; margin-bottom: 1rem; }
.hl, .cyan { color: var(--cyan); }
.rose { color: var(--rose); }
.amber { color: var(--amber); }
.green { color: var(--green); }
.lede { color: var(--soft); font-size: 1.1rem; margin: 0 0 1.75rem; max-width: 52rem; }

.stat-row { border-top: 1px solid var(--line); display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); padding-top: 1.5rem; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 0.6rem; padding: 1rem; text-align: center; }
.stat p { margin: 0; }
.stat-label { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase; }
.stat-value { font-size: 2rem; font-weight: 800; }
.stat-note { color: var(--muted); font-size: 0.85rem; }
.assume { color: var(--muted); font-size: 0.85rem; margin: 1.25rem 0 0; max-width: 60rem; }

main section { margin-bottom: 3.5rem; }
h2 { border-bottom: 2px solid var(--rose); color: var(--rose); display: inline-block; font-size: clamp(1.5rem, 3vw, 1.9rem); margin-bottom: 1rem; padding-bottom: 0.4rem; }
h2 span { color: var(--rose); }
.section-lede { color: var(--soft); font-size: 1.05rem; margin: 0 0 1.5rem; max-width: 52rem; }

.grid { display: grid; gap: 1.25rem; margin-bottom: 1.25rem; }
.two, .one-one { grid-template-columns: 1fr; }
.two-one { grid-template-columns: 1fr; }
.four { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
@media (min-width: 960px) {
  .two, .one-one { grid-template-columns: 1fr 1fr; }
  .two-one { grid-template-columns: 2fr 1fr; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: 0.8rem; box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.6); min-width: 0; padding: 1.25rem; }
.card + .card { margin-top: 0; }
section > .card { margin-bottom: 1.25rem; }
.card h3 { font-size: 1.15rem; margin-bottom: 0.75rem; }
.card h3.chart-title { font-size: 1rem; font-weight: 600; text-align: center; }
.card p { color: var(--soft); }
.accent-left { border-left: 4px solid var(--cyan); }
.chart { position: relative; width: 100%; }
.scroll-x { overflow-x: auto; }

.ledger, .matrix { border-collapse: collapse; font-size: 0.9rem; width: 100%; }
.ledger td, .ledger th, .matrix td, .matrix th { border-bottom: 1px solid rgba(51, 65, 85, 0.6); padding: 0.5rem 0.4rem; text-align: left; }
.ledger td:last-child, .ledger th:last-child { text-align: right; }
.ledger th, .matrix th { color: var(--muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.ledger .total td { border-top: 2px solid var(--line); color: var(--text); font-weight: 700; }
.ledger.compact td:nth-child(2) { text-align: right; }
.matrix td:not(:first-child), .matrix th:not(:first-child) { text-align: right; white-space: nowrap; }
.matrix td.em { color: var(--amber); font-weight: 700; }
.records td:first-child { white-space: normal; }
.neg { color: var(--rose); }

.callout { border-left: 4px solid var(--amber); margin: 1.25rem 0 0; padding-left: 0.9rem; }
.reasons { color: var(--soft); margin: 0 0 1rem; padding-left: 1.2rem; }
.reasons li { margin-bottom: 0.6rem; }
.fine { color: var(--muted) !important; font-size: 0.82rem; margin: 0.75rem 0 0; }

.mini p { margin: 0; }
.mini .kicker { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.1em; margin-bottom: 0.3rem; }
.mini .big { color: var(--cyan); font-size: 1.6rem; font-weight: 800; margin-bottom: 0.4rem; }
.mini p:last-child { font-size: 0.9rem; }
.remember .big { color: var(--amber); }

.fee-strip { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.fee-strip div { background: var(--bg); border: 1px solid var(--line); border-radius: 0.5rem; display: grid; gap: 0.15rem; padding: 0.75rem; }
.fee-strip span { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; }
.fee-strip b { font-size: 1.3rem; }
.fee-strip small { color: var(--muted); }

/* Hover / focus popovers for definitions. */
.tip { border-bottom: 1px dotted var(--cyan); color: var(--text); cursor: help; position: relative; }
.tip::after {
  background: #020617;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  bottom: calc(100% + 8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: var(--soft);
  content: attr(data-tip);
  font-size: 0.82rem;
  font-weight: 400;
  left: 50%;
  letter-spacing: normal;
  line-height: 1.45;
  opacity: 0;
  padding: 0.6rem 0.75rem;
  pointer-events: none;
  position: absolute;
  text-align: left;
  text-transform: none;
  transform: translateX(-50%);
  transition: opacity 120ms ease;
  white-space: normal;
  width: min(280px, 80vw);
  z-index: 20;
}
/* Rendered only while open so hidden popovers never widen the page on phones. */
.tip::after { display: none; }
.tip:hover::after, .tip:focus::after, .tip:focus-visible::after { display: block; opacity: 1; }
@media (max-width: 640px) { .tip::after { left: 0; transform: none; width: min(260px, 70vw); } }
.tip:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.method p { color: var(--soft); font-size: 0.92rem; }
.sources { columns: 1; font-size: 0.85rem; line-height: 1.5; margin: 0; padding-left: 1.1rem; }
.sources li { margin-bottom: 0.3rem; }

.foot { border-top: 1px solid var(--line); background: var(--card); padding: 2rem 1rem; text-align: center; }
.foot a { text-decoration: none; }
/* Inside scrolling tables, open popovers downward and keep them inside the card. */
.scroll-x .tip::after { bottom: auto; top: calc(100% + 8px); }
.matrix th .tip::after { left: auto; right: 0; transform: none; }
.matrix td .tip::after { left: 0; transform: none; }
.zoom { display: flex; gap: 0.4rem; justify-content: center; margin: -0.25rem 0 0.75rem; }
.zoom button { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; color: var(--muted); cursor: pointer; font: inherit; font-size: 0.8rem; padding: 0.3rem 0.8rem; }
.zoom button[aria-pressed="true"] { background: var(--cyan); border-color: var(--cyan); color: #04131a; font-weight: 600; }
.zoom button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---- Additions for the debt + AI guide ---- */
.chapters { border-bottom: 1px solid var(--line); margin: -2.5rem 0 2.5rem; }
.chapters .wrap { display: flex; gap: 0.35rem; overflow-x: auto; padding-bottom: 0.6rem; padding-top: 0.6rem; scrollbar-width: none; }
.chapters a { border: 1px solid var(--line); border-radius: 999px; color: var(--soft); flex: none; font-size: 0.8rem; padding: 0.25rem 0.75rem; text-decoration: none; }
.chapters a:hover, .chapters a:focus-visible { border-color: var(--cyan); color: var(--cyan); }
section[id] { scroll-margin-top: 4rem; }

.three { grid-template-columns: 1fr; }
.one-two { grid-template-columns: 1fr; }
@media (min-width: 960px) {
  .three { grid-template-columns: repeat(3, 1fr); }
  .one-two { grid-template-columns: 1fr 2fr; }
}
.violet { color: var(--violet); }
.muted { color: var(--muted); }
.pos { color: var(--green); }

/* Company ↔ country translation table */
.rosetta td:first-child { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; }
.rosetta td:nth-child(2) { color: var(--text); font-weight: 600; }
.rosetta td:last-child, .rosetta th:last-child { color: var(--soft); text-align: left; }

/* Statement cards: one per economy */
.statements { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); }
.statement { background: var(--card); border: 1px solid var(--line); border-radius: 0.8rem; border-top: 4px solid var(--c, var(--cyan)); padding: 1rem; }
.statement h3 { font-size: 1.05rem; margin-bottom: 0.15rem; }
.statement .sub { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; margin: 0 0 0.6rem; text-transform: uppercase; }
.statement dl { display: grid; gap: 0.2rem 0.5rem; grid-template-columns: 1fr auto; margin: 0; }
.statement dt { color: var(--soft); font-size: 0.86rem; }
.statement dd { font-variant-numeric: tabular-nums; font-weight: 700; margin: 0; text-align: right; }
.statement .group { border-top: 1px solid rgba(51, 65, 85, 0.7); color: var(--muted) !important; font-size: 0.68rem; letter-spacing: 0.1em; margin: 0.5rem 0 0.25rem; padding-top: 0.4rem; text-transform: uppercase; }
.statement .verdict { border-top: 1px solid var(--line); color: var(--soft); font-size: 0.85rem; margin: 0.7rem 0 0; padding-top: 0.6rem; }
.statement [data-pct] { display: none; }
.pct-mode .statement [data-pct] { display: inline; }
.pct-mode .statement [data-usd] { display: none; }

.toggle { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 1rem; }
.toggle button { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; color: var(--muted); cursor: pointer; font: inherit; font-size: 0.82rem; padding: 0.3rem 0.85rem; }
.toggle button[aria-pressed="true"] { background: var(--cyan); border-color: var(--cyan); color: #04131a; font-weight: 600; }
.toggle button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.toggle.center { justify-content: center; }

/* Horizontal proportional bars (pure HTML, no chart library) */
.hbars { display: grid; gap: 0.45rem; }
.hbar { align-items: center; display: grid; gap: 0.6rem; grid-template-columns: 7.2rem 1fr 3.2rem; font-size: 0.86rem; }
.hbar > span:first-child { color: var(--soft); }
.hbar .track { background: rgba(51, 65, 85, 0.45); border-radius: 4px; height: 0.9rem; overflow: hidden; }
.hbar .fill { background: var(--c, var(--cyan)); border-radius: 4px; display: block; height: 100%; width: calc(var(--v) * 1%); }
.hbar b { font-variant-numeric: tabular-nums; text-align: right; }

/* Big balance-sheet blocks */
.bs { align-items: end; display: grid; gap: 0.6rem; grid-template-columns: 1fr 1fr; }
.bs-col { display: flex; flex-direction: column; gap: 3px; }
.bs-col > p { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.1em; margin: 0 0 0.3rem; text-align: center; text-transform: uppercase; }
.bs-block { align-items: center; background: var(--c); border-radius: 4px; color: #04131a; display: flex; flex-direction: column; font-size: 0.8rem; font-weight: 600; justify-content: center; min-height: 1.6rem; padding: 0.2rem 0.4rem; text-align: center; }
.bs-block small { font-weight: 500; opacity: 0.8; }
.bs-block.hollow { background: transparent; border: 2px dashed var(--c); color: var(--soft); }

/* Layer cake (China's debt layers) */
.layers { display: grid; gap: 4px; }
.layer { align-items: center; background: var(--c); border-radius: 4px; color: #04131a; display: grid; gap: 0.5rem; grid-template-columns: 1fr auto; padding: 0.55rem 0.8rem; }
.layer b { font-size: 0.95rem; }
.layer span { font-size: 0.78rem; opacity: 0.85; }
.layer strong { color: #04131a; font-variant-numeric: tabular-nums; }
.layer.hollow { background: transparent; border: 2px dashed var(--c); color: var(--soft); }
.layer.hollow strong { color: var(--text); }

/* Flow chain diagrams */
.chain { align-items: stretch; display: grid; gap: 0.5rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .chain { grid-auto-flow: column; grid-auto-columns: 1fr; } }
.chain > div { background: var(--bg); border: 1px solid var(--line); border-radius: 0.6rem; padding: 0.75rem; position: relative; }
.chain > div p { font-size: 0.85rem; margin: 0.25rem 0 0; }
.chain > div b { color: var(--c, var(--cyan)); display: block; font-size: 0.95rem; }
.chain > div small { color: var(--muted); display: block; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; }
@media (min-width: 900px) {
  .chain > div:not(:last-child)::after { color: var(--muted); content: "→"; font-size: 1.1rem; position: absolute; right: -0.55rem; top: 45%; z-index: 2; }
}

/* Scenario cards */
.scenario { border-top: 4px solid var(--c, var(--green)); }
.scenario ul { color: var(--soft); font-size: 0.9rem; margin: 0.5rem 0 0; padding-left: 1.1rem; }
.scenario li { margin-bottom: 0.35rem; }
.tag { border: 1px solid var(--c, var(--line)); border-radius: 999px; color: var(--c, var(--muted)); display: inline-block; font-size: 0.7rem; letter-spacing: 0.08em; margin-bottom: 0.5rem; padding: 0.1rem 0.6rem; text-transform: uppercase; }

/* Back-of-envelope math rows */
.envelope { display: grid; gap: 0.5rem; }
.envelope .row { align-items: baseline; background: var(--bg); border: 1px solid var(--line); border-radius: 0.5rem; display: grid; gap: 0.75rem; grid-template-columns: 1fr auto; padding: 0.6rem 0.8rem; }
.envelope .row p { font-size: 0.88rem; margin: 0; }
.envelope .row p small { color: var(--muted); display: block; font-size: 0.78rem; }
.envelope .row b { color: var(--amber); font-size: 1.2rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.envelope .row.sum { border-color: var(--amber); }
.envelope .row.sum b { color: var(--green); }

.arrow-up::before { color: var(--soft); content: "▲ "; }
.arrow-down::before { color: var(--soft); content: "▼ "; }
.arrow-flat::before { color: var(--muted); content: "◆ "; }
.matrix td.cell { text-align: left; white-space: normal; }
.matrix.scen td, .matrix.scen th { font-size: 0.84rem; text-align: left !important; vertical-align: top; white-space: normal !important; }
.matrix.scen td:first-child { min-width: 9.5rem; }
.ledger.notes td:last-child, .ledger.notes th:last-child { text-align: left; }
@media (min-width: 900px) {
  .chain.wrap3 { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); }
  .chain.wrap3 > div:nth-child(3n)::after { content: none; }
}
.chain.stack { gap: 0.9rem; grid-auto-flow: row; grid-template-columns: 1fr; margin-bottom: 1rem; }
.chain.stack > div { padding: 0.5rem 0.75rem; }
.chain.stack > div:not(:last-child)::after { bottom: -0.95rem; color: var(--muted); content: "↓"; font-size: 0.9rem; left: 50%; line-height: 1; position: absolute; right: auto; top: auto; transform: translateX(-50%); z-index: 2; }
.ledger.pl td:not(:first-child), .ledger.pl th:not(:first-child) { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.legend-dots { color: var(--muted); display: flex; flex-wrap: wrap; font-size: 0.78rem; gap: 0.4rem 1rem; justify-content: center; margin-top: 0.5rem; }
.legend-dots i { border-radius: 2px; display: inline-block; height: 10px; margin-right: 0.35rem; width: 10px; }
.asof { background: rgba(234, 179, 8, 0.08); border: 1px solid rgba(234, 179, 8, 0.35); border-radius: 0.5rem; color: var(--soft); font-size: 0.85rem; margin: 1rem 0 0; padding: 0.6rem 0.8rem; }
.source-cols { columns: 1; }
@media (min-width: 900px) { .source-cols { column-gap: 2rem; columns: 3; } .method-text { column-gap: 2rem; columns: 2; } }
.method-text { margin-bottom: 1.5rem; }
.method-text p { break-inside: avoid; margin-top: 0; }
.source-cols .sources { margin-bottom: 0.4rem; }
.source-cols .sources li { break-inside: avoid; }
.sub-head { font-size: 1.2rem; margin: 1.75rem 0 0.75rem; }
.source-cols h4 { break-after: avoid; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.1em; margin: 0.8rem 0 0.3rem; text-transform: uppercase; }

/* Phones: three-column note tables become stacked rows; the flow diagram scrolls sideways. */
@media (max-width: 640px) {
  .ledger.notes thead { display: none; }
  .ledger.notes tr { border-bottom: 1px solid rgba(51, 65, 85, 0.6); display: block; padding: 0.55rem 0; }
  .ledger.notes td { border: 0; display: block; padding: 0.1rem 0; text-align: left !important; }
  .ledger.notes td:first-child { color: var(--text); font-weight: 700; }
  .ledger.notes td:nth-child(2) { color: var(--amber); }
}
.chart.wide { min-width: 760px; }
