/* Article layout and interactive-figure styles for /writing/*. Load after /kit/site.css.
   Semantic colours are shared by every figure: read = cache read, write = cache write,
   fresh = uncached input, out = output, ping = keep-alive. */
:root {
  --read: #2c9a63; --write: #e0812b; --fresh: #d0413b; --out: #1f6fd1; --ping: #8a5cc7; --idle: rgba(138,129,119,.12);
  --read-soft: rgba(44,154,99,.14); --write-soft: rgba(224,129,43,.16); --fresh-soft: rgba(208,65,59,.13); --out-soft: rgba(31,111,209,.13);
  --wide: 58rem;
  --s1: #c2410c; --s2: #0e7490; --s3: #15803d; --s4: #7c3aed; --s5: #be185d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --read: #55c48a; --write: #f0a052; --fresh: #ef6f68; --out: #6ea4ee; --ping: #b48ef0; --idle: rgba(141,133,122,.14);
    --read-soft: rgba(85,196,138,.16); --write-soft: rgba(240,160,82,.16); --fresh-soft: rgba(239,111,104,.15); --out-soft: rgba(110,164,238,.15);
    --s1: #fb923c; --s2: #22d3ee; --s3: #4ade80; --s4: #a78bfa; --s5: #f472b6;
  }
}
:root[data-theme="dark"] {
  --read: #55c48a; --write: #f0a052; --fresh: #ef6f68; --out: #6ea4ee; --ping: #b48ef0; --idle: rgba(141,133,122,.14);
  --read-soft: rgba(85,196,138,.16); --write-soft: rgba(240,160,82,.16); --fresh-soft: rgba(239,111,104,.15); --out-soft: rgba(110,164,238,.15);
  --s1: #fb923c; --s2: #22d3ee; --s3: #4ade80; --s4: #a78bfa; --s5: #f472b6;
}

html { scroll-behavior: smooth; }
body { overflow-x: hidden; }
.page.article { max-width: 44rem; }
article h2 { font-family: var(--font-body); font-size: 1.65rem; line-height: 1.2; letter-spacing: -.005em; text-transform: none;
  color: var(--ink); margin: 3.6rem 0 1rem; scroll-margin-top: 1.5rem; }
article h2 .num { font-family: var(--font-ui); font-size: .8rem; font-weight: 700; color: var(--muted); letter-spacing: .1em;
  display: block; margin-bottom: .35rem; }
article h3 { font-family: var(--font-ui); font-size: 1.02rem; margin: 2rem 0 .5rem; }
article p { margin: 0 0 1.1rem; }
article ul, article ol { padding-left: 1.3rem; margin: 0 0 1.1rem; }
article li { margin: .3rem 0; }
article strong { font-weight: 700; }
.kicker { font-family: var(--font-ui); font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin-bottom: .7rem; }
.dek { font-size: 1.28rem; line-height: 1.5; color: var(--ink-2); margin: .4rem 0 1.2rem; }
.byline { font-family: var(--font-ui); font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-bottom: 2rem; }

/* Inline token-type words: "a cache <span class="t-read">read</span>" */
.t-read, .t-write, .t-fresh, .t-out, .t-ping { font-family: var(--font-ui); font-size: .85em; font-weight: 700; padding: .05em .4em; border-radius: 4px; white-space: nowrap; }
.t-read { color: var(--read); background: var(--read-soft); } .t-write { color: var(--write); background: var(--write-soft); }
.t-fresh { color: var(--fresh); background: var(--fresh-soft); } .t-out { color: var(--out); background: var(--out-soft); }
.t-ping { color: var(--ping); background: rgba(138,92,199,.14); }

/* Claim markers, as in the book */
.claim { font-family: var(--font-ui); font-size: .64rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: .12em .45em; border-radius: 4px; vertical-align: .15em; white-space: nowrap; border: 1px solid currentColor; }
.claim.public { color: var(--read); } .claim.inferred { color: var(--write); } .claim.unknown { color: var(--muted); }

/* Figures break out of the text column on wide screens */
.fig { margin: 2rem 0 2.2rem; }
.fig.wide { width: min(var(--wide), calc(100vw - 32px)); position: relative; left: 50%; transform: translateX(-50%); }
.widget { background: var(--block-bg); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); padding: 1.1rem 1.2rem 1.2rem; font-family: var(--font-ui); font-size: .92rem; line-height: 1.45; }
.widget-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .4rem 1rem; margin-bottom: .8rem; }
.widget-title { font-weight: 700; font-size: .95rem; color: var(--ink); }
.widget-title .fignum { color: var(--muted); font-weight: 600; margin-right: .4rem; }
.fig figcaption { font-family: var(--font-ui); font-size: .85rem; color: var(--ink-2); margin-top: .7rem; line-height: 1.5; padding: 0 .2rem; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .78rem; color: var(--ink-2); }
.legend i { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .3rem; vertical-align: -.05rem; }

.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .6rem 1.2rem; margin: .2rem 0 1rem; }
.ctl label { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; font-size: .8rem; color: var(--ink-2); margin-bottom: .15rem; }
.ctl output { font-family: var(--font-mono); font-size: .8rem; font-weight: 700; color: var(--ink); white-space: nowrap; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); margin: .25rem 0 0; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: 9px; overflow: hidden; }
.seg button { font: inherit; font-size: .8rem; background: transparent; color: var(--ink-2); border: 0; border-right: 1px solid var(--rule); padding: .38rem .75rem; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn { font: inherit; font-size: .8rem; background: var(--paper-2); color: var(--ink); border: 1px solid var(--rule); border-radius: 8px; padding: .38rem .75rem; cursor: pointer; }
.btn:hover, .seg button:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart svg text { font-family: var(--font-ui); fill: var(--muted); font-size: 11px; }
.chart .grid line { stroke: var(--rule); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--paper); font-family: var(--font-ui); font-size: .75rem; line-height: 1.4;
  padding: .45rem .6rem; border-radius: 7px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity .12s; z-index: 5; }
.tip.on { opacity: 1; }
.tip b { font-family: var(--font-mono); font-weight: 600; }
.readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .5rem; margin: .8rem 0 0; }
.stat { background: var(--paper-2); border-radius: 10px; padding: .55rem .7rem; }
.stat .v { font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700; color: var(--ink); }
.stat .k { font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.stat.read .v { color: var(--read); } .stat.write .v { color: var(--write); } .stat.out .v { color: var(--out); } .stat.fresh .v { color: var(--fresh); } .stat.ping .v { color: var(--ping); }
.small { font-size: .8rem; color: var(--muted); }
.mono { font-family: var(--font-mono); }

/* Stacked horizontal bars (token share vs dollar share) */
.hbars { display: grid; gap: .55rem; }
.hbar-row { display: grid; grid-template-columns: 5.2rem 1fr; gap: .6rem; align-items: center; }
.hbar-row .lab { font-size: .78rem; color: var(--ink-2); text-align: right; }
.hbar { display: flex; height: 1.5rem; border-radius: 6px; overflow: hidden; background: var(--paper-2); }
.hbar span { display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; transition: flex-basis .25s ease; min-width: 0; }

/* Prefix blocks (invalidation widget, hero) */
.blocks { display: flex; flex-wrap: wrap; gap: 4px; }
.blk { font-family: var(--font-ui); font-size: .74rem; font-weight: 600; padding: .45rem .55rem; border-radius: 6px; border: 1px solid transparent; cursor: pointer; user-select: none; transition: background .2s, color .2s; }
.blk.hit { background: var(--read-soft); color: var(--read); border-color: var(--read); }
.blk.miss { background: var(--write-soft); color: var(--write); border-color: var(--write); }
.blk.edited { background: var(--fresh); color: #fff; border-color: var(--fresh); }
.blk.new { background: var(--write-soft); color: var(--write); border-style: dashed; border-color: var(--write); }

/* Callouts */
.key { border-left: 4px solid var(--accent); background: var(--paper-2); padding: .9rem 1.1rem; border-radius: 0 10px 10px 0; margin: 1.6rem 0; }
.key p:last-child { margin-bottom: 0; }
.key .key-label { font-family: var(--font-ui); font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); display: block; margin-bottom: .3rem; }
.note { border: 1px dashed var(--rule); padding: .8rem 1rem; border-radius: 10px; font-size: .98rem; color: var(--ink-2); margin: 1.4rem 0; }
.eq { font-family: var(--font-mono); font-size: .9rem; background: var(--code-bg); border-radius: 8px; padding: .8rem 1rem; margin: 1rem 0 1.3rem; overflow-x: auto; line-height: 1.7; white-space: pre; }
table.data { width: 100%; border-collapse: collapse; font-family: var(--font-ui); font-size: .85rem; margin: 1rem 0 1.4rem; }
table.data th { text-align: left; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--rule); padding: .45rem .5rem; }
table.data td { border-bottom: 1px solid var(--rule); padding: .45rem .5rem; vertical-align: top; }
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono); white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* Table of contents: inline block on small screens, sticky rail on wide ones */
.toc { font-family: var(--font-ui); font-size: .85rem; border: 1px solid var(--rule); border-radius: 12px; padding: .8rem 1rem; margin: 0 0 2.4rem; background: var(--block-bg); }
.toc summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.toc ol { margin: .6rem 0 0; padding-left: 1.2rem; }
.toc li { margin: .2rem 0; }
.toc a { color: var(--ink-2); text-decoration: none; }
.toc a:hover, .toc a.active { color: var(--accent); }
@media (min-width: 1400px) {
  .toc { position: fixed; top: 2rem; left: max(1.5rem, calc(50% - 22rem - 17rem)); width: 14rem; max-height: calc(100vh - 4rem); overflow: auto; margin: 0; border: 0; background: transparent; padding: 0; }
  .toc summary { pointer-events: none; list-style: none; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
  .toc summary::-webkit-details-marker { display: none; }
  .toc ol { padding-left: 0; list-style: none; }
  .toc li a { display: block; padding: .2rem 0 .2rem .7rem; border-left: 2px solid var(--rule); }
  .toc li a.active { border-left-color: var(--accent); }
}

/* Simulator-specific */
.blocklist { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin: .3rem 0 .6rem; }
.chipblk { display: inline-flex; align-items: center; gap: .3rem; border-radius: 8px; padding: .25rem .35rem .25rem .55rem; font-size: .78rem; border: 1px solid var(--rule); }
.chipblk.work { background: var(--out-soft); border-color: var(--out); }
.chipblk.idle { background: var(--idle); }
.chipblk input { width: 3.4rem; font: inherit; font-family: var(--font-mono); font-size: .76rem; border: 1px solid var(--rule); border-radius: 5px; padding: .1rem .25rem; background: var(--paper); color: var(--ink); }
.chipblk button { font: inherit; border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 .2rem; font-size: .9rem; }
.stratgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr)); gap: .5rem; margin: .4rem 0 .8rem; }
.strat { display: flex; gap: .5rem; align-items: flex-start; border: 1px solid var(--rule); border-radius: 10px; padding: .5rem .6rem; font-size: .8rem; cursor: pointer; }
.strat input { margin-top: .15rem; }
.strat .sw { width: .8rem; height: .8rem; border-radius: 50%; flex: none; margin-top: .2rem; }
.strat b { display: block; font-size: .82rem; color: var(--ink); }
.strat small { color: var(--muted); }
.results { width: 100%; border-collapse: collapse; font-size: .8rem; }
.results th { text-align: right; font-weight: 700; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; padding: .35rem .45rem; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.results td { text-align: right; font-family: var(--font-mono); padding: .35rem .45rem; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.results td:first-child, .results th:first-child { text-align: left; font-family: var(--font-ui); }
.results tr.best td { font-weight: 700; }
.results .dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .35rem; }
details.more { margin-top: .8rem; }
details.more summary { cursor: pointer; font-size: .82rem; font-weight: 700; color: var(--ink-2); }
.sources li { font-size: .92rem; }

@media (max-width: 640px) {
  article h2 { font-size: 1.4rem; margin-top: 2.8rem; }
  .dek { font-size: 1.12rem; }
  .widget { padding: .9rem .8rem 1rem; border-radius: 12px; }
  .fig.wide { width: calc(100vw - 20px); }
  .hbar-row { grid-template-columns: 4.2rem 1fr; }
  .eq { font-size: .72rem; padding: .7rem .8rem; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .hbar span { transition: none; } }
