:root{
  --bg:#0d1117; --fg:#bcc3cd; --muted:#9aa2ad; --head:#e2e6ec;
  --accent:#6cb6ff; --line:#252a31; --panel:#14171c;
  --text-w:68ch; --fig-w:1100px;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%;scroll-behavior:smooth}
body{
  margin:0; background:var(--bg); color:var(--fg); overflow-x:clip;
  font:clamp(1rem,.9rem + .35vw,1.4rem)/1.7 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",sans-serif;
  -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility;
}
main{max-width:var(--text-w); margin:0 auto; padding:2.5rem 1.1rem 2rem}
::selection{background:#2b4a6b}
:focus-visible{outline:2px solid var(--accent); outline-offset:3px; border-radius:3px}

/* ---- header ---- */
header{margin-bottom:1.5rem; padding-bottom:1.5rem; border-bottom:1px solid var(--line)}
h1{
  font-size:clamp(1.9rem,1.3rem + 2.5vw,2.8rem); line-height:1.12; letter-spacing:-.025em;
  color:var(--head); margin:0 0 .8rem; text-wrap:balance;
}
.meta{color:var(--muted); margin:0; font-size:.9em}

/* ---- text ---- */
h2,h3{color:var(--head); line-height:1.25; text-wrap:balance; scroll-margin-top:1.5rem; position:relative}
h2{font-size:1.65em; margin:3rem 0 .9rem; letter-spacing:-.015em}
h3{font-size:1.22em; margin:2.2rem 0 .6rem}
p{margin:0 0 1.25rem; text-wrap:pretty}
strong{color:var(--head); font-weight:650}
a{color:var(--accent); text-decoration-thickness:1px; text-underline-offset:.18em; overflow-wrap:anywhere}
a:hover{text-decoration-thickness:2px}
hr{border:0; border-top:1px solid var(--line); margin:2rem 0}
code{font:.88em ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; background:var(--panel); padding:.1em .35em; border-radius:4px}

/* heading permalinks (appear on hover) */
.headerlink{margin-left:.4em; text-decoration:none; color:var(--muted); opacity:0; transition:opacity .15s}
h2:hover .headerlink,h3:hover .headerlink,.headerlink:focus{opacity:1}
@media (hover:none){.headerlink{display:none}}

/* ---- figures: charts break out of the text column on wide screens ---- */
figure{
  margin:2.2rem 0; position:relative; left:50%; transform:translateX(-50%);
  width:min(var(--fig-w), calc(100vw - 2.2rem));
}
figure a{display:block; width:fit-content; max-width:100%; margin:0 auto; cursor:zoom-in}
/* never larger than the PNG's natural size (avoids blurry upscaling); shrinks to fit */
figure img{
  display:block; width:auto; max-width:100%; height:auto; background:#000;
  border:1px solid var(--line); border-radius:8px; transition:border-color .2s;
}
figure a:hover img{border-color:#3a4350}
figcaption{margin-top:.55rem; text-align:center; font-size:.85em; color:var(--muted); padding:0 .5rem}

@media (hover:none){figure figcaption::after{content:' · tap to enlarge'}}

/* ---- table of contents ---- */
.toc-inline{margin:0 0 2rem; background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:.15rem 1rem}
.toc-inline summary{cursor:pointer; padding:.6rem 0; color:var(--head); font-weight:600}
.toc-inline ul{margin:0 0 .8rem}
nav ul{list-style:none; margin:0; padding:0}
nav ul ul{padding-left:1rem}
nav li{margin:.3rem 0; line-height:1.4}
nav a{text-decoration:none; color:var(--muted); font-size:.92em}
nav a:hover{color:var(--head)}
.toc-side{display:none}
@media (min-width:1700px){
  .toc-inline{display:none}
  .toc-side{
    display:block; position:fixed; top:6rem; width:14.5rem; max-height:calc(100vh - 8rem); overflow:auto;
    left:calc(50vw - var(--fig-w)/2 - 14.5rem - 2rem);
    font-size:.95rem;
  }
  .toc-side p{margin:0 0 .6rem; font-size:.75rem; letter-spacing:.1em; text-transform:uppercase; color:var(--muted)}
  .toc-side li > a{display:block; padding-left:.7rem; border-left:2px solid var(--line); margin-left:-.7rem}
  .toc-side ul ul li > a{margin-left:-1.7rem; padding-left:1.7rem}
}

/* ---- footer ---- */
footer{max-width:var(--text-w); margin:0 auto; padding:1.5rem 1.1rem 3.5rem; border-top:1px solid var(--line); font-size:.88em}
footer a{color:var(--muted); text-decoration:none}
footer a:hover{color:var(--head)}

/* ---- lightbox ---- */
dialog{padding:0; border:0; max-width:none; max-height:none; width:100vw; height:100dvh; background:rgba(0,0,0,.94); overflow:auto}
dialog[open]{display:grid}
dialog::backdrop{background:#000}
dialog img{margin:auto; display:block; cursor:zoom-out; max-width:none; border-radius:6px}
dialog button{
  position:fixed; top:.7rem; right:.7rem; z-index:2; width:2.6rem; height:2.6rem; border-radius:50%;
  border:1px solid var(--line); background:var(--panel); color:var(--head); font-size:1.1rem; cursor:pointer;
}
@media (min-width:900px){dialog img{max-width:96vw; max-height:94dvh; width:auto; height:auto; object-fit:contain}}

/* ---- small screens ---- */
@media (max-width:600px){
  main{padding-top:1.5rem}
  figure{width:calc(100vw - 1rem)}
  figure img{border-radius:6px}
}
@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto} *{transition:none!important}}
@media print{.toc-inline,.toc-side,footer{display:none} body{background:#fff;color:#000}}
