/* tradeeverything docs. Layout follows docs.papertrade.xyz: sticky top bar,
   grouped sidebar, article column, "On this page" column, prev/next cards. */
:root {
  --bg: #f4ecd8;
  --bg-2: #ede5d0;
  --panel: #faf6ed;
  --line: #d4cbba;
  --line-soft: rgba(42, 37, 32, .08);
  --ink: #2a2520;
  --ink-2: #5f564b;
  --muted: #7a7060;
  --muted-2: #998c76;
  --accent: #1f6a4f;
  --warn: #b97a1a;
  --sidebar-w: 232px;
  --toc-w: 192px;
  --max: 1200px;
  --sans: Inter, system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  border-top: 3px solid var(--ink);
  font: 14.5px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
:focus-visible { outline: none; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip-link { position: absolute; top: 8px; left: -9999px; z-index: 100; padding: 8px 14px; border-radius: 4px; background: var(--ink); color: var(--panel); font: 600 12px var(--sans); }
.skip-link:focus { left: 8px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 14px; height: 44px; padding: 0 20px; }
.brand { display: flex; align-items: center; flex-shrink: 0; transition: opacity .12s; }
.brand:hover { opacity: .72; }
.wordmark { font: 600 18px/1 var(--sans); letter-spacing: -.035em; color: var(--ink); }
.wordmark .tld { color: var(--accent); }
.draft-badge { padding: 2px 7px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); font: 600 9.5px var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.top-nav { display: flex; margin-left: auto; flex-shrink: 0; }
.top-nav a { padding: 2px 12px 4px; border-bottom: 2px solid transparent; color: var(--muted); font: 600 12px var(--sans); transition: color .12s, border-color .12s; }
.top-nav a.on { color: var(--ink); border-bottom-color: var(--ink); }
.top-nav a:hover:not(.on):not(.soon) { color: var(--ink); }
.top-nav a.soon { cursor: default; }
.soon-tag { margin-left: 4px; padding: 0 5px; border-radius: 3px; background: var(--line-soft); font-size: 10px; font-weight: 500; }
@media (max-width: 420px) {
  .topbar-inner { gap: 8px; padding: 0 16px; }
  .draft-badge { display: none; }
  .top-nav a { padding: 2px 8px 4px; }
}

/* Three-column shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w); gap: 40px; align-items: start; max-width: var(--max); margin: 0 auto; padding: 32px 20px 120px; }
@media (max-width: 1199px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 32px; }
  .toc-col { display: none; }
}

/* Sidebar */
.sidebar-col { position: sticky; top: 64px; max-height: calc(100vh - 84px); overflow-y: auto; padding-right: 6px; }
.sidebar-section { margin: 0 0 22px; }
.sidebar-head { padding: 0 12px 8px; color: var(--muted); font: 600 10px var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.sidebar-list { list-style: none; }
.sidebar-list a { position: relative; display: block; padding: 6px 12px; border-radius: 3px; color: var(--ink-2); font: 500 13px var(--sans); transition: color .12s, background .12s; }
.sidebar-list a:hover { color: var(--ink); background: rgba(42, 37, 32, .04); }
.sidebar-list a.active { color: var(--ink); background: var(--panel); font-weight: 600; }
.sidebar-list a.active::before { content: ""; position: absolute; top: 6px; bottom: 6px; left: 0; width: 2px; border-radius: 1px; background: var(--accent); }
.sidebar-toggle { display: none; }

@media (max-width: 899px) {
  .shell { grid-template-columns: 1fr; gap: 12px; padding: 16px 16px 96px; }
  .sidebar-col { position: static; max-height: none; overflow: visible; padding: 0; border: 1px solid var(--line-soft); border-radius: 6px; background: var(--panel); }
  .sidebar-col.is-collapsed { display: none; }
  .sidebar-section { margin: 0; padding: 10px 6px; }
  .sidebar-section + .sidebar-section { border-top: 1px solid var(--line-soft); }
  .sidebar-head { padding: 0 10px 6px; font-size: 9px; }
  .sidebar-list a { padding: 5px 10px; font-size: 12.5px; }
  .sidebar-toggle { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 9px 12px; border: 1px solid var(--line-soft); border-radius: 6px; background: var(--panel); color: var(--ink); cursor: pointer; font: 600 11px var(--sans); letter-spacing: .08em; text-transform: uppercase; }
  .sidebar-toggle .chev { width: 8px; height: 8px; margin-bottom: 2px; border-right: 1.5px solid var(--ink-2); border-bottom: 1.5px solid var(--ink-2); transform: rotate(45deg); transition: transform .15s; }
  .sidebar-toggle[aria-expanded="true"] .chev { margin-bottom: -2px; transform: rotate(-135deg); }
}

/* Article */
.article-col { min-width: 0; }
.article { max-width: 74ch; color: var(--ink); }
.article .eyebrow { display: inline-block; margin-bottom: 10px; color: var(--muted); font: 600 10px var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.article h1 { margin: 0 0 14px; color: var(--ink); font: 700 32px/1.18 var(--sans); letter-spacing: -.02em; }
.article .lead { max-width: 62ch; margin: 0 0 36px; color: var(--ink-2); font: 400 16px/1.6 var(--sans); }
.article h2 { margin: 46px 0 14px; scroll-margin-top: 64px; font: 700 22px/1.3 var(--sans); letter-spacing: -.01em; }
.article h3 { margin: 30px 0 8px; scroll-margin-top: 64px; font: 600 16px/1.35 var(--sans); }
.article p { margin: 0 0 14px; }
.article ul, .article ol { margin: 0 0 16px; padding-left: 22px; }
.article li { margin-bottom: 5px; }
.article li::marker { color: var(--muted-2); }
.article li > p { margin-bottom: 6px; }
.article a { border-bottom: 1.5px solid var(--line); transition: border-color .15s; }
.article a:hover { border-bottom-color: var(--accent); }
.article strong { font-weight: 600; }
.article em { color: var(--ink-2); }
.article code { padding: 1px 5px; border: 1px solid var(--line); border-radius: 3px; background: var(--panel); font: 500 12.5px/1.4 var(--mono); overflow-wrap: anywhere; }
.article pre { margin: 18px 0 22px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font: 400 12.5px/1.55 var(--mono); overflow-x: auto; }
.article pre code { padding: 0; border: none; background: none; overflow-wrap: normal; }
.article blockquote { margin: 18px 0; padding: 14px 18px; border-left: 3px solid var(--accent); background: rgba(31, 106, 79, .05); color: var(--ink-2); }
.article table { display: block; width: 100%; overflow-x: auto; margin: 18px 0 22px; border-collapse: collapse; font-size: 13.5px; }
.article th, .article td { padding: 9px 14px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
.article th { background: rgba(42, 37, 32, .025); color: var(--muted); font: 600 11px var(--sans); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.article tr:nth-child(2n) td { background: rgba(42, 37, 32, .02); }
.article hr { margin: 36px 0; border: 0; border-top: 1px solid var(--line-soft); }
@media (max-width: 899px) {
  .article h1 { font-size: 26px; }
  .article h2 { margin-top: 32px; font-size: 19px; }
  .article .lead, .article h3 { font-size: 15px; }
}

/* Prev / next */
.prev-next { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; max-width: 74ch; }
.prev-next a { display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); transition: border-color .15s; }
.prev-next a:hover { border-color: var(--ink); }
.prev-next .label { margin-bottom: 6px; color: var(--muted); font: 600 10px var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.prev-next .title { color: var(--ink); font: 600 14px/1.3 var(--sans); }
.prev-next .next { text-align: right; }
.prev-next a.disabled { opacity: .35; pointer-events: none; }
@media (max-width: 560px) {
  .prev-next { grid-template-columns: 1fr; }
  .prev-next .next { text-align: left; }
}

/* On this page */
.toc-col { position: sticky; top: 64px; max-height: calc(100vh - 84px); overflow-y: auto; }
.toc-head { padding: 0 12px 8px; color: var(--muted); font: 600 10px var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.toc-list { list-style: none; }
.toc-list a { position: relative; display: block; padding: 5px 12px; color: var(--ink-2); font: 400 12.5px var(--sans); transition: color .12s; }
.toc-list a:hover { color: var(--ink); }
.toc-list a.active { color: var(--ink); font-weight: 600; }
.toc-list a.active::before { content: ""; position: absolute; top: 6px; bottom: 6px; left: 0; width: 2px; border-radius: 1px; background: var(--accent); }
.toc-list a.h3 { padding-left: 24px; font-size: 12px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* Charts (built by site/build.py). One series each, so no legend: the title names it. */
:root { --chart: #1a7f5a; --chart-wash: rgba(26, 127, 90, .10); --grid: rgba(42, 37, 32, .09); }
.chart-pair { display: grid; gap: 28px; margin: 22px 0 26px; }
.chart { position: relative; margin: 0; }
.chart figcaption { margin-bottom: 12px; }
.chart-title { display: block; color: var(--ink); font: 600 13.5px/1.35 var(--sans); }
.chart-sub { display: block; color: var(--muted); font: 400 12px/1.4 var(--sans); }
.chart-frame { display: grid; grid-template-columns: 40px minmax(0, 1fr); height: 190px; }
.chart-y { position: relative; }
.chart-y span { position: absolute; right: 8px; transform: translateY(50%); color: var(--muted); font: 400 11px/1 var(--sans); font-variant-numeric: tabular-nums; }
.chart-plot { position: relative; border-bottom: 1px solid var(--line); }
.chart-grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--grid); }
.chart-cols, .chart-hits { position: absolute; inset: 0; display: flex; }
.chart-col, .chart-hit { flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; cursor: default; }
.chart-bar { position: relative; width: 62%; max-width: 18px; min-height: 1px; background: var(--chart); border-radius: 4px 4px 0 0; transition: opacity .12s; }
.chart-cols:hover .chart-col .chart-bar { opacity: .45; }
.chart-cols:hover .chart-col:hover .chart-bar { opacity: 1; }
.chart-val { position: absolute; bottom: calc(100% + 4px); color: var(--ink-2); font: 600 11px/1 var(--sans); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-val.first { left: 0; }
.chart-val.last { right: 0; }
.chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart-area { fill: var(--chart-wash); }
.chart-line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--chart); box-shadow: 0 0 0 2px var(--bg); pointer-events: none; }
.chart-val.endlabel { right: 8px; bottom: auto; transform: translateY(-160%); }
.chart-cross { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid var(--muted-2); pointer-events: none; }
.chart-x { position: relative; height: 18px; margin-left: 40px; }
.chart-x span { position: absolute; top: 5px; transform: translateX(-50%); color: var(--muted); font: 400 11px/1 var(--sans); }
.chart-x-title { margin: 4px 0 0 40px; color: var(--muted-2); font: 400 11px/1.2 var(--sans); text-align: center; }
.chart-tip { position: absolute; z-index: 5; min-width: 150px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); box-shadow: 0 4px 14px rgba(42, 37, 32, .12); color: var(--ink); font: 400 12px/1.45 var(--sans); pointer-events: none; font-variant-numeric: tabular-nums; }
.chart-tip b { display: block; margin-bottom: 2px; font-weight: 600; }
.chart-tip span { display: block; color: var(--ink-2); }
@media (max-width: 560px) { .chart-frame { height: 160px; } }

/* Flow diagrams: fixed drawing, scrolls sideways inside its own box on narrow screens. */
.diagram { margin: 22px 0 26px; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.diagram-svg { display: block; width: 100%; min-width: 600px; height: auto; }
