:root {
  color-scheme: light;
  --surface: #fff; --background: #f6f8fa; --surface-2: #f0f2f5; --border: #d0d7de;
  --hairline: rgba(31, 35, 40, .08); --foreground: #24292f; --body: #414a56;
  --muted: #57606a; --faint: #8c959f; --accent: #0969da; --accent-strong: #0550ae;
  --green: #1db26b; --red: #f05143; --amber: #633806;
  --font-display: "Hanken Grotesk", "Geist", system-ui, sans-serif;
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --header-height: 64px; --sidebar-width: 240px; --nav-gap: clamp(48px, 9vw, 140px);
  --ease: 170ms ease-out;
  font-family: var(--font-sans);
  font-synthesis: none; text-rendering: optimizeLegibility;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #111821; --background: #080c12; --surface-2: #151e2a; --border: #273040;
  --hairline: rgba(255, 255, 255, .07); --foreground: #e6edf3; --body: #c3ccd8;
  --muted: #7a8492; --faint: #4d5664; --accent: #58a6ff; --accent-strong: #79b8ff;
  --green: #1db26b; --red: #f05143; --amber: #d7a75f;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100svh; display: flex; flex-direction: column; background: var(--surface); color: var(--body); font-size: 17px; line-height: 1.72; -webkit-font-smoothing: antialiased; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }
a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; transition: color var(--ease), background-color var(--ease), border-color var(--ease); }
a:hover { color: var(--accent-strong); text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }

.site-header { position: sticky; top: 0; z-index: 30; height: var(--header-height); flex-shrink: 0; display: flex; align-items: center; gap: 20px; padding: 0 32px; background: var(--surface); border-bottom: 1px solid var(--hairline); }
.header-identity { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 21px; font-weight: 600; line-height: 1; letter-spacing: -.03em; color: var(--foreground); white-space: nowrap; }
.brand:hover { color: var(--foreground); text-decoration: none; }
.brand-mark { display: block; flex-shrink: 0; width: 22px; height: 22px; }
.header-description { margin: 0; padding-left: 16px; border-left: 1px solid var(--border); color: var(--muted); font-size: 13px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 7px 10px; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--body); font: 400 13px/1 var(--font-sans); transition: color var(--ease), background-color var(--ease); }
.theme-toggle:hover { background: var(--surface-2); color: var(--foreground); }
.theme-toggle svg { flex-shrink: 0; }
.theme-toggle .icon-sun, [data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
.menu-toggle { display: none; align-items: center; height: 32px; padding: 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--foreground); font: 500 13px/1 var(--font-sans); flex-shrink: 0; transition: background-color var(--ease); }
.menu-toggle:hover { background: var(--surface-2); }
.reading-progress { position: absolute; left: 0; bottom: -1px; width: 0; height: 1px; background: var(--accent); transition: width 120ms linear; }

.page-group { flex: 1 0 auto; width: 100%; max-width: 1440px; margin: 0 auto; padding: 0 32px; display: flex; gap: var(--nav-gap); align-items: flex-start; }
.sidebar { position: sticky; top: 120px; margin-top: 120px; width: var(--sidebar-width); flex-shrink: 0; max-height: calc(100vh - 140px); overflow-y: auto; background: var(--surface); z-index: 25; }
.sidebar .overview-link { display: block; padding: 6px 0 6px 14px; border-left: 2px solid transparent; color: var(--body); font-size: 14px; line-height: 1.5; }
.nav-group { margin: 24px 0 10px 16px; color: var(--muted); font-size: 12.5px; line-height: 1.45; font-weight: 500; }
.nav-chapters { display: flex; flex-direction: column; border-left: 1px solid var(--hairline); }
.nav-chapters a { display: grid; grid-template-columns: 26px 1fr; align-items: baseline; margin-left: -1px; padding: 7px 0 7px 15px; border-left: 2px solid transparent; color: var(--body); font-size: 14px; line-height: 1.5; }
.sidebar a:hover { color: var(--foreground); text-decoration: none; }
.sidebar .overview-link, .nav-chapters a { transition: color var(--ease), border-color var(--ease); }
.sidebar .overview-link:focus-visible, .nav-chapters a:focus-visible { border-left-color: var(--muted); }
@media (hover: hover) {
  .sidebar .overview-link:hover, .nav-chapters a:hover { border-left-color: var(--muted); }
}
.sidebar .overview-link[aria-current], .nav-chapters a[aria-current] { color: var(--foreground); font-weight: 600; border-left-color: var(--foreground); }
.chapter-number { font-family: var(--font-mono); font-size: 11.5px; font-weight: 400; color: var(--faint); font-variant-numeric: tabular-nums; }
.article > .chapter-label { display: none; margin: 0 0 12px; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; color: var(--muted); }

main { flex: 1; min-width: 0; min-height: calc(100svh - var(--header-height)); display: flex; flex-direction: column; padding: 72px 0 0; }
/* Fill the viewport on short pages without pinning the footer over chapter content. */
.page { flex: 1 0 auto; }
main:focus { outline: none; }
.reading-layout { display: flex; gap: 64px; align-items: flex-start; }
.article { flex: 1; min-width: 0; max-width: 720px; }
.article h1 { margin: 0; font-family: var(--font-display); font-size: clamp(34px, 4vw, 44px); line-height: 1.08; letter-spacing: -.035em; font-weight: 600; color: var(--foreground); text-wrap: balance; }
.article h1 + p, .overview .lead { margin: 28px 0 24px; font-size: 20px; line-height: 1.6; color: var(--foreground); }
.article h2 { margin: 64px 0 18px; padding-top: 32px; border-top: 1px solid var(--hairline); font-family: var(--font-display); font-size: 28px; line-height: 1.2; letter-spacing: -.025em; font-weight: 600; color: var(--foreground); }
.article h3 { margin: 40px 0 12px; font-size: 19px; line-height: 1.35; letter-spacing: -.015em; font-weight: 600; color: var(--foreground); }
.article p { margin: 0 0 22px; text-wrap: pretty; }
.article strong { color: var(--foreground); font-weight: 600; }
.article ul, .article ol { padding-left: 22px; margin: 20px 0 26px; }
.article li { padding-left: 6px; margin: 12px 0; }
.article li > p { margin-bottom: 10px; }
.article li ul, .article li ol { margin: 12px 0; }
.article li::marker { color: var(--muted); font-size: .9em; }
.heading-link { color: inherit; }
.heading-link:hover { color: var(--accent); text-decoration: none; }
code { font-family: var(--font-mono); font-size: .9em; color: var(--foreground); font-variant-numeric: tabular-nums; }
h1, h2, h3, section, main { scroll-margin-top: calc(var(--header-height) + 24px); }

.page-toc { position: sticky; top: 120px; width: 200px; flex-shrink: 0; margin-top: 48px; max-height: calc(100vh - 140px); overflow-y: auto; }
.page-toc h2 { margin: 0 0 10px 14px; color: var(--muted); font-size: 12.5px; line-height: 1.45; font-weight: 500; }
.toc-links { display: flex; flex-direction: column; border-left: 1px solid var(--hairline); }
.toc-links a { display: block; margin-left: -1px; padding: 5px 0 5px 13px; border-left: 2px solid transparent; color: var(--muted); font-size: 13px; line-height: 1.45; }
.toc-links a:hover { color: var(--foreground); text-decoration: none; }
.toc-links a { transition: color var(--ease), border-color var(--ease); }
.toc-links a:focus-visible { border-left-color: var(--muted); }
@media (hover: hover) {
  .toc-links a:hover { border-left-color: var(--muted); }
}
.toc-links a[aria-current] { color: var(--foreground); font-weight: 500; border-left-color: var(--accent); }
.toc-links a.nested { padding-left: 25px; font-size: 12.5px; }

.example-card { margin: 28px 0; padding: 18px 20px; border: 1px dashed var(--border); border-radius: 8px; background: color-mix(in srgb, var(--accent) 3%, var(--surface)); font-size: 14px; line-height: 1.6; }
.example-card .example-card-label { margin: 0 0 7px; color: var(--accent); font-size: 12px; font-weight: 500; }
.example-card .example-card-title { margin: 0 0 6px; color: var(--foreground); font-size: 16px; line-height: 1.4; font-weight: 600; }
.example-card-body p { margin: 0; }
.example-card-body p + p { margin-top: 10px; }

.example-placeholder { margin: 24px 0; padding: 14px 18px; border: 1px dashed var(--border); border-radius: 6px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.example-placeholder p { margin: 0; }
.example-placeholder strong { display: block; margin-bottom: 3px; color: var(--foreground); font-size: 13px; font-weight: 600; }
.callout { margin: 32px 0; padding: 22px 26px; background: var(--background); border: 1px solid var(--hairline); border-radius: 8px; font-size: 15.5px; line-height: 1.7; --dot: var(--accent); }
.callout p { margin: 0 0 12px; }
.callout p:last-child { margin-bottom: 0; }
.callout > p:first-child > strong:first-child, li.callout > strong:first-child { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; color: var(--foreground); font-weight: 600; }
.callout > p:first-child > strong:first-child::before, li.callout > strong:first-child::before { content: ""; width: 8px; height: 8px; margin-top: 9px; margin-top: calc(.5lh - 4px); border-radius: 50%; flex-shrink: 0; background: var(--dot); }
.callout.green { --dot: var(--green); }
.callout.red { --dot: var(--red); }
.callout.amber { --dot: var(--amber); }
.article li.callout { list-style: none; margin-left: -22px; padding: 18px 22px; }
.callout.summary { margin: 40px 0 32px; padding: 28px 0 4px; background: none; border: 0; border-top: 2px solid var(--foreground); border-radius: 0; font-size: 16px; line-height: 1.7; }
.callout.summary > p:first-child > strong:first-child { display: block; margin-bottom: 10px; color: var(--muted); font-size: 13px; font-weight: 500; line-height: 1.5; }
.callout.summary > p:first-child > strong:first-child::before { content: none; }
.callout.summary > p:first-child > strong:nth-of-type(2) { display: block; margin-bottom: 14px; font-family: var(--font-display); font-size: 26px; line-height: 1.25; letter-spacing: -.02em; text-wrap: balance; }

.table-scroll { overflow-x: auto; margin: 28px 0 32px; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; line-height: 1.6; text-align: left; }
th, td { vertical-align: top; min-width: 130px; }
th { padding: 0 20px 12px 0; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12.5px; font-weight: 500; vertical-align: bottom; }
td { padding: 16px 20px 16px 0; border-bottom: 1px solid var(--hairline); }
th:last-child, td:last-child { padding-right: 0; }
td:first-child { min-width: 155px; color: var(--foreground); font-weight: 600; }

.chapter-pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-top: 72px; }
.chapter-pager a { display: block; padding-top: 20px; border-top: 1px solid var(--border); font-family: var(--font-display); font-size: 18px; line-height: 1.3; letter-spacing: -.015em; font-weight: 600; color: var(--foreground); }
.chapter-pager a:hover { color: var(--foreground); border-top-color: var(--foreground); text-decoration: none; }
.chapter-pager span { display: block; margin-bottom: 6px; font-family: var(--font-sans); font-size: 12.5px; line-height: 1.5; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.chapter-pager a:first-child span::before { content: "← " / ""; }
.chapter-pager .next:not([href="#overview"]) span::after { content: " →" / ""; }
.chapter-pager .next { grid-column: 2; text-align: right; }

/* The rule runs edge to edge like the header's (border-image outset is paint-only, so it adds no scroll width); the text stays aligned with the reading column. */
.site-footer { flex-shrink: 0; margin: 136px 0 0; padding: 16px 0; border-top: 1px solid var(--hairline); border-image: linear-gradient(var(--hairline), var(--hairline)) 1 / 1px 0 0 / 0 100vw; display: flex; flex-wrap: wrap; gap: 4px 8px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.site-footer p { margin: 0; }
.site-footer p + p::before { content: "·" / ""; margin-right: 8px; }
.site-footer a { color: var(--accent); }

.js .page:not([data-active]) { display: none; }
.chapter-index { margin-top: 48px; border-top: 1px solid var(--border); }
.chapter-index a { display: grid; grid-template-columns: 36px 1fr 16px; gap: 16px; align-items: baseline; padding: 18px 0; border-bottom: 1px solid var(--hairline); color: var(--faint); }
.chapter-index a:hover { text-decoration: none; }
.chapter-index .chapter-number { font-size: 12px; }
.chapter-index a > span:nth-child(2) { font-family: var(--font-display); font-size: 19px; line-height: 1.3; letter-spacing: -.015em; font-weight: 600; color: var(--foreground); transition: color var(--ease); }
.chapter-index a:hover > span:nth-child(2), .chapter-index a:hover > span:last-child { color: var(--accent); }

.trend-figure, .zone-figure, .chart-example { margin: 36px 0; }
.chart-example { max-width: 420px; margin-inline: auto; }
.chart-example img { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; }
.chart-example a { display: block; }
.trend-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.article .trend-grid h3 { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.45; letter-spacing: 0; font-weight: 500; }
.trend-grid svg { display: block; width: 100%; }
.zone-figure > svg { display: block; width: 100%; height: auto; }
figcaption { margin-top: 14px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.chart-title { font-family: var(--font-sans); font-size: 15px; font-weight: 600; fill: var(--foreground); }
.chart-label { font-size: 12px; fill: var(--muted); }
.price-label { font-family: var(--font-mono); font-size: 10.5px; fill: var(--muted); }
.chart-grid { stroke: var(--hairline); stroke-width: 1; }
.candle-up { fill: var(--green); }.wick-up { stroke: var(--green); }
.candle-down { fill: var(--red); }.wick-down { stroke: var(--red); }
.zone-demand { fill: var(--green); fill-opacity: .15; }.zone-supply { fill: var(--red); fill-opacity: .15; }
.label-green { fill: var(--green); }.label-red { fill: var(--red); }
.skip-link { position: fixed; z-index: 50; top: -80px; left: 12px; padding: 10px 15px; background: var(--surface); border: 1px solid var(--accent); border-radius: 6px; font: 13px/1.4 var(--font-sans); }
.skip-link:focus { top: 10px; }

@media (max-width: 1239px) {
  .page-toc { display: none; }
}
@media (max-width: 1099px) { .header-description { display: none; } }
@media (max-width: 899px) {
  .article > .chapter-label { display: block; }
  .menu-toggle { display: inline-flex; }
  .page-group { display: block; }
  .sidebar { position: fixed; inset: var(--header-height) auto 0 0; margin: 0; max-height: none; width: min(300px, 85vw); padding: 24px; border-right: 1px solid var(--border); transform: translateX(-100%); visibility: hidden; }
  .sidebar[data-open] { transform: translateX(0); visibility: visible; }
  .sidebar .overview-link, .nav-chapters a { display: grid; align-content: center; min-height: 44px; font-size: 15px; }
  .nav-chapters .chapter-number { font-size: 12px; }
  .sidebar-backdrop { position: fixed; inset: var(--header-height) 0 0; background: rgba(0, 0, 0, .4); z-index: 20; }
  body.menu-open { overflow: hidden; }
  main { margin: 0 auto; max-width: 720px; }
}
@media (max-width: 799px) {
  :root { --header-height: 56px; }
  .site-header { padding: 0 18px; gap: 12px; }
  .theme-toggle { min-width: 44px; min-height: 44px; padding: 0; }
  .theme-toggle span { display: none; }
  .page-group { padding: 0; }
  main { padding: 32px 20px 16px; }
  .article h2 { font-size: 24px; }
  .callout { padding: 18px 20px; }
  .trend-grid { gap: 16px; }
  .chapter-pager { gap: 20px; }
  .site-footer { display: block; margin-top: 84px; padding: 16px 0 0; }
  .site-footer p + p { margin-top: 6px; }
  .site-footer p + p::before { content: none; }
  .zone-figure { overflow-x: auto; }.zone-figure > svg { min-width: 540px; }
  .table-scroll::before { content: 'Scroll horizontally to read all columns'; display: block; color: var(--muted); font-size: 12.5px; padding: 7px 0; }
}
/* Below 375px the header has no room for the mark beside the Chapters button and wordmark. */
@media (max-width: 374px) { .brand .brand-mark { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
@media print {
  .site-header, .sidebar, .page-toc, .chapter-pager, .sidebar-backdrop { display: none !important; }
  body { display: block; }
  .page-group { display: block; max-width: none; padding: 0; }
  main { display: block; min-height: 0; padding: 0; }.reading-layout { display: block; }.page { break-before: page; }
  .js .page:not([data-active]) { display: block; }.table-scroll { overflow: visible; }
  :root { --surface: white; --foreground: black; --body: #222; --background: #f5f5f5; --surface-2: #f5f5f5; }
}
