:root {
  --ink: #16130f;
  --paper: #f4efe4;
  --card: #fffdf8;
  --line: #d8d0c0;
  --muted: #6f675b;
  --accent: #b45309;
  --teal: #0f6e6b;
  --flag: #9f1239;
  --ok: #3f6212;
  --shadow: 0 12px 40px rgba(40, 28, 12, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, #f8e7c8 0%, transparent 50%),
    var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 32px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  font-family: "Fraunces", Georgia, serif;
  font-size: 22px;
  letter-spacing: -0.03em;
}
.brand span { color: var(--accent); font-style: italic; }
nav { display: flex; gap: 16px; flex-wrap: wrap; }
nav a { color: var(--muted); font-size: 14px; }
nav a.active { color: var(--ink); font-weight: 600; }

main { padding: 28px 32px 64px; max-width: 1280px; }
main:has(.wide) { max-width: 1480px; }
main.explorer { max-width: 1680px; }
.toolbar input[type="search"], .toolbar input[type="text"] {
  flex: 1;
  min-width: 220px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
}
.pager { display: flex; gap: 10px; align-items: center; margin-top: 12px; color: var(--muted); font-size: 13px; }
.lede { max-width: 720px; color: var(--muted); line-height: 1.55; margin-bottom: 24px; }
h1, h2, h3 { font-family: "Fraunces", Georgia, serif; letter-spacing: -0.03em; }
h1 { font-size: 34px; margin: 0 0 8px; }
h2 { font-size: 22px; margin: 28px 0 12px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi .value { font-size: 22px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .detail { color: var(--muted); font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card { padding: 16px 18px; margin-top: 16px; overflow: visible; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.flag { color: var(--flag); font-weight: 600; }
.ok { color: var(--ok); }
.mono { font-family: "IBM Plex Mono", Consolas, monospace; font-size: 12px; }
.route { display: flex; flex-direction: column; gap: 2px; line-height: 1.35; }
.route span { display: block; }
.tx-stack { display: flex; flex-direction: column; gap: 2px; line-height: 1.35; }
.tx-stack span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.chain-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chain-list a, .chain-pill {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--ink);
}
.ok-check { color: var(--ok); font-weight: 600; }
.warn-check { color: var(--flag); font-weight: 600; }

.sankey { height: 560px; }
.bars { width: 100%; }
.stack-wrap { position: relative; width: 100%; }
.stack-chart { width: 100%; height: 360px; display: block; cursor: crosshair; }
.stack-grid { stroke: #ece6d8; stroke-width: 1; }
.stack-axis { fill: var(--muted); font-size: 11px; text-anchor: end; }
.stack-x { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.stack-band { fill: rgba(180, 83, 9, 0.10); pointer-events: none; }
.stack-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.stack-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.stack-tip {
  position: fixed;
  z-index: 10000;
  min-width: 220px;
  max-width: 300px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 12px;
}
.stack-tip-kicker {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.stack-tip-title { font-weight: 600; margin: 2px 0 4px; }
.stack-tip-sub { color: var(--muted); font-size: 11px; line-height: 1.4; margin-bottom: 8px; }
.stack-tip-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 2px 0; }
.stack-tip-row i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.stack-tip-row b { font-variant-numeric: tabular-nums; }
.stack-tip-row em { color: var(--muted); font-style: normal; font-variant-numeric: tabular-nums; }
.stack-tip-foot { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); font-weight: 600; }
.toolbar { display: flex; gap: 10px; align-items: center; margin: 8px 0 16px; }
button, select {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  cursor: pointer;
}
.note { color: var(--muted); font-size: 13px; line-height: 1.5; }
.method {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px 20px;
  margin: 0;
}
.method div { margin: 0; }
.method dt {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 4px;
}
.method dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
}
.err { color: var(--flag); padding: 20px; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.split .card { margin-top: 0; }
.kpi.hero .value { font-size: 28px; color: var(--accent); }
.usd { font-weight: 600; }
.flow-wrap { width: 100%; scroll-margin-top: 88px; }
.flow-sankey { width: 100%; height: 420px; display: block; }
.flow-readout {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8f1e4;
  font-size: 13px;
  line-height: 1.4;
}
.flow-readout[hidden] { display: none; }
.flow-readout .kicker {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.flow-readout strong { display: block; margin: 2px 0 4px; }
.flow-readout b { font-variant-numeric: tabular-nums; }
.flow-label { fill: var(--ink); font-size: 11px; pointer-events: none; }
.flow-link, .flow-hit { cursor: pointer; pointer-events: stroke; }
.flow-hit { stroke: transparent; }
.flow-node { cursor: pointer; }
.flow-link.active { stroke: #b45309 !important; stroke-opacity: 1; }
.table-scroll { overflow-x: auto; }
.mobile-only { display: none; }
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (max-width: 720px) {
  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 16px 8px;
    padding-top: max(12px, env(safe-area-inset-top));
  }
  .brand { font-size: 18px; }
  nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px;
    margin: 0 -16px;
    padding: 0 16px 6px;
    overscroll-behavior-x: contain;
  }
  nav::-webkit-scrollbar { display: none; }
  nav a {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 999px;
    white-space: nowrap;
  }
  nav a.active {
    background: #f3e6cf;
  }
  main {
    padding: 18px 16px 80px;
    padding-bottom: max(80px, calc(24px + env(safe-area-inset-bottom)));
    max-width: 100%;
    overflow-x: clip;
  }
  main:has(.wide),
  main.explorer { max-width: 100%; }
  h1 {
    font-size: 26px;
    line-height: 1.15;
    overflow-wrap: break-word;
  }
  h2 {
    font-size: 18px;
    margin: 20px 0 10px;
    overflow-wrap: break-word;
  }
  .lede {
    max-width: none;
    font-size: 14px;
    margin-bottom: 16px;
  }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; min-width: 0; }
  .kpi .label {
    font-size: 10px;
    letter-spacing: 0.03em;
    overflow-wrap: break-word;
    line-height: 1.25;
  }
  .kpi .value {
    font-size: 18px;
    overflow-wrap: break-word;
    word-break: normal;
  }
  .kpi.hero .value { font-size: 22px; }
  .card {
    padding: 12px 12px 10px;
    overflow: visible;
  }
  .card h2 { margin-top: 4px; }
  table { min-width: 36rem; font-size: 12px; }
  main.explorer table,
  #transfers table { min-width: 52rem; }
  th, td {
    padding: 10px 8px;
    overflow-wrap: break-word;
  }
  th { white-space: nowrap; }
  .toolbar {
    flex-wrap: wrap;
    align-items: stretch;
  }
  .toolbar input[type="search"],
  .toolbar input[type="text"],
  .toolbar select,
  .toolbar button {
    min-width: 0;
    width: 100%;
    min-height: 44px;
  }
  button, select {
    min-height: 44px;
    padding: 10px 12px;
  }
  .pager {
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .pager button { width: auto; flex: 1 1 120px; }
  .method { grid-template-columns: 1fr; }
  .sankey { height: 280px; }
  .flow-wrap { scroll-margin-top: 132px; }
  .flow-sankey { height: 360px; }
  .flow-label { font-size: 10px; }
  .stack-chart { height: 320px; touch-action: none; }
  .stack-axis, .stack-x { font-size: 13px; }
  nav a, button, select, .toolbar input { touch-action: manipulation; }
  .stack-legend { font-size: 11px; gap: 6px 10px; }
  .stack-legend span {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    overflow-wrap: break-word;
  }
  .stack-tip {
    min-width: 0;
    max-width: calc(100vw - 20px);
    max-height: min(70vh, 420px);
    overflow: auto;
    pointer-events: auto;
  }
  .stack-tip-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
  }
  .stack-tip-row span { min-width: 0; overflow-wrap: break-word; }
  .note { overflow-wrap: break-word; }
  .tx-stack { min-width: 5.5rem; }
  .mobile-only { display: block; }
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    margin: 0 -4px;
  }
  .chain-list a, .chain-pill {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 430px) {
  h1 { font-size: 23px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 16px; }
  table { min-width: 32rem; }
}
