/* tsogtochir.com/writing: shared styles for long-form posts.
   Reading layout: centred masthead, table of contents on the left, sidenotes on the right, stepped figures.
   From the homepage: the black terminal bar, green monospace, the blinking caret, typed commands. */

:root {
  color-scheme: light;
  --bg: #fbfaf7; --panel: #f2f1ec; --inset: #fbfaf7; --rule: #e1dfd8;
  --ink: #1b1b1a; --ink-2: #4f4e4a; --muted: #6f6d67; --faint: #a3a19a;
  --grid: #e1e0d9; --axis: #c3c2b7;
  --blue: #2a78d6; --orange: #eb6834; --context: #b9b8b1; --context-ink: #807e78;
  --good: #15803d; --bad: #d2403f; --warn: #a16207;
  --term: #15803d; --term-soft: rgba(21, 128, 61, .10);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --panel: #1a1a19; --inset: #121211; --rule: #2c2c2a;
  --ink: #ecebe7; --ink-2: #c3c2b7; --muted: #8f8d86; --faint: #5f5d58;
  --grid: #2c2c2a; --axis: #383835;
  --blue: #3987e5; --orange: #d95926; --context: #6c6b66; --context-ink: #8f8d86;
  --good: #4ade80; --bad: #e66767; --warn: #eab308;
  --term: #4ade80; --term-soft: rgba(74, 222, 128, .09);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --panel: #1a1a19; --inset: #121211; --rule: #2c2c2a;
    --ink: #ecebe7; --ink-2: #c3c2b7; --muted: #8f8d86; --faint: #5f5d58;
    --grid: #2c2c2a; --axis: #383835;
    --blue: #3987e5; --orange: #d95926; --context: #6c6b66; --context-ink: #8f8d86;
    --good: #4ade80; --bad: #e66767; --warn: #eab308;
    --term: #4ade80; --term-soft: rgba(74, 222, 128, .09);
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-padding-top: 64px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 19px/1.62 var(--serif); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--term); outline-offset: 2px; border-radius: 3px; }

/* ---------- terminal bar (the homepage's, slimmed) ---------- */
.term-bar { position: sticky; top: 0; z-index: 30; background: #000; border-bottom: 1px solid #12301c; font: 13px/1 var(--mono); }
.term-bar .in { max-width: 1320px; margin: 0 auto; padding: 11px 16px; display: flex; align-items: center; gap: 14px; }
.term-bar .dots { display: flex; gap: 6px; flex: none; }
.term-bar .dots i { width: 9px; height: 9px; border-radius: 50%; display: block; }
.term-bar .dots i:nth-child(1) { background: #ef4444; } .term-bar .dots i:nth-child(2) { background: #eab308; }
.term-bar .dots i:nth-child(3) { background: #22c55e; }
.term-bar .prompt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; color: #6b7280; }
.term-bar .prompt a { color: #4ade80; text-decoration: none; }
.term-bar .prompt .host { color: #22c55e; } .term-bar .prompt .path { color: #60a5fa; }
.term-bar .typed { color: #86efac; margin-left: 8px; }
.term-bar nav { margin-left: auto; display: flex; gap: 18px; flex: none; }
.term-bar nav a, .term-bar nav button { color: #16a34a; text-decoration: none; transition: color .2s; }
.term-bar nav a:hover, .term-bar nav button:hover { color: #86efac; }
.term-bar nav .y { color: #eab308; }
.caret { color: #4ade80; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- masthead ---------- */
.masthead { text-align: center; padding: 76px 16px 34px; }
.masthead .cmd { font: 13px var(--mono); color: var(--muted); margin: 0 0 22px; }
.masthead .cmd .d { color: var(--warn); } .masthead .cmd .c { color: var(--term); }
.masthead h1 { font: 400 clamp(32px, 5.2vw, 48px)/1.12 var(--serif); letter-spacing: -.012em; margin: 0 auto 20px; max-width: 17em; }
.byline { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); font-size: 17px; }
.byline .tag { font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--warn); border: 1px solid currentColor; border-radius: 3px; padding: 2px 6px; }

/* ---------- reading grid: contents | text | sidenotes ---------- */
.hero { max-width: 1000px; margin: 6px auto 72px; padding: 0 16px; }
.reading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 680px) minmax(0, 1fr); column-gap: 56px; max-width: 1360px; margin: 0 auto; padding: 0 16px; }
.toc { grid-column: 1; justify-self: end; width: 200px; position: sticky; top: 76px; align-self: start; font: 15px/1.45 var(--serif); }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 9px; }
.toc a { color: var(--muted); text-decoration: none; display: block; position: relative; transition: color .2s; }
.toc a:hover { color: var(--ink); }
.toc a.on { color: var(--ink); font-weight: 600; }
.toc a.on::before { content: ">"; position: absolute; left: -16px; font: 13px/1.7 var(--mono); color: var(--term); }
.content { grid-column: 2; min-width: 0; }
.sidenotes { grid-column: 3; position: relative; width: 250px; }
.sidenote { position: absolute; left: 0; right: 0; font: 14px/1.5 var(--serif); color: var(--ink-2); }
.sidenote .n { display: block; font: 11px var(--mono); color: var(--term); margin-bottom: 2px; }
.sidenote a { color: inherit; }
@media (max-width: 1180px) {
  .reading { grid-template-columns: minmax(0, 1fr); max-width: 712px; }
  .toc, .sidenotes { display: none; }
  .content { grid-column: 1; }
}

/* ---------- text ---------- */
.content p, .content ul, .content ol { margin: 0 0 1.05em; }
.content ul, .content ol { padding-left: 1.3em; }
.content li { margin-bottom: .4em; }
.content h2 { font: 400 30px/1.25 var(--serif); letter-spacing: -.005em; margin: 2.1em 0 .55em; position: relative; }
.content h2 .hash { position: absolute; right: 100%; margin-right: 14px; top: .45em; font: 14px var(--mono); color: var(--term); opacity: .6; }
.content a { color: inherit; text-decoration: underline dotted var(--faint); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.content a:hover { text-decoration-color: var(--term); }
.content strong { font-weight: 600; }
.content code { font: .82em var(--mono); background: var(--panel); padding: .1em .35em; border-radius: 4px; }
.content pre { font: 13.5px/1.55 var(--mono); background: var(--panel); padding: 14px 16px; border-radius: 8px; overflow-x: auto; }
sup.fn { line-height: 0; }
sup.fn a { font: 11.5px var(--mono); color: var(--term); text-decoration: none; padding: 0 1px; }
.footnotes { font-size: 15px; color: var(--ink-2); border-top: 1px solid var(--rule); margin-top: 3em; padding-top: 1em; }
.footnotes.as-sidenotes { display: none; }
.lede { font-size: 20.5px; }

/* the 33 words */
.vocab { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 1.2em 0 1.5em; padding: 14px 16px; background: var(--panel); border-radius: 10px; font: 13px/1.5 var(--mono); }
.vocab dt { color: var(--muted); padding-top: 3px; }
.vocab dd { margin: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.vocab span { background: var(--inset); border: 1px solid var(--rule); border-radius: 4px; padding: 1px 7px; color: var(--ink); }

/* ---------- stepped figures ---------- */
.fig { margin: 2.1em 0 2.4em; }
.fig .stage { background: var(--panel); border-radius: 12px; padding: 14px 16px 12px; position: relative; }
.fig .tag { display: flex; justify-content: space-between; align-items: center; gap: 12px; font: 11.5px var(--mono); color: var(--muted); margin-bottom: 6px; }
.fig .tag b { color: var(--term); font-weight: 400; }
.fig .tag button { color: var(--muted); } .fig .tag button:hover { color: var(--term); }
.fig .stage > svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--sans); transition: opacity .3s; }
.fig .stage > svg text { font-family: var(--sans); }
.fig .tag .tools { display: flex; align-items: center; gap: 10px; }
.fig .bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.step { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 5px; border: 1px solid var(--rule); border-radius: 999px; font: 13px/1.2 var(--sans); color: var(--muted); transition: color .2s, border-color .2s; }
.step .n { width: 19px; height: 19px; border-radius: 50%; display: inline-grid; place-items: center; font: 11px var(--mono); background: var(--inset); color: var(--muted); transition: background .2s, color .2s; }
.step:hover { color: var(--ink); }
.step.on { color: var(--ink); border-color: var(--faint); }
.step.on .n { background: var(--term); color: var(--bg); }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; padding: 2px; }
.seg button { font: 12px/1.2 var(--sans); color: var(--muted); padding: 3px 10px; border-radius: 999px; }
.seg button.on { background: var(--inset); color: var(--ink); }
.play { margin-left: auto; width: 30px; height: 30px; flex: none; border: 1px solid var(--rule); border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); }
.play:hover { color: var(--term); border-color: var(--faint); }
.cap { margin: 12px 2px 0; font-size: 16.5px; line-height: 1.55; color: var(--ink-2); min-height: 3.1em; }
.cap p { margin: 0; } .cap p[hidden] { display: none; }
.cap strong { color: var(--ink); font-weight: 600; }
.fig figcaption { margin: 10px 2px 0; font-size: 15px; line-height: 1.5; color: var(--muted); }
.fig figcaption b { color: var(--ink-2); font-weight: 600; }
.csv { display: none; margin-top: 10px; overflow-x: auto; }
.csv.open { display: block; }
.csv table { border-collapse: collapse; font: 12.5px/1.5 var(--mono); color: var(--ink-2); }
.csv th, .csv td { text-align: left; padding: 3px 14px 3px 0; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.csv th { color: var(--muted); font-weight: 400; }

/* svg roles: colour follows the job (blue: the claim; orange: crosses between models; gray: context) */
.f-blue { fill: var(--blue); } .s-blue { stroke: var(--blue); }
.f-orange { fill: var(--orange); } .s-orange { stroke: var(--orange); }
.f-context { fill: var(--context); } .s-context { stroke: var(--context); }
.f-bad { fill: var(--bad); } .s-bad { stroke: var(--bad); }
.f-panel { fill: var(--panel); } .f-inset { fill: var(--inset); } .s-panel { stroke: var(--panel); }
.f-ink { fill: var(--ink); } .f-ink2 { fill: var(--ink-2); } .f-muted { fill: var(--muted); } .f-term { fill: var(--term); }
.s-grid { stroke: var(--grid); } .s-axis { stroke: var(--axis); } .s-rule { stroke: var(--rule); } .s-ink2 { stroke: var(--ink-2); } .s-term { stroke: var(--term); }
.t-mono { font-family: var(--mono) !important; }

/* tooltip: the homepage's terminal, small */
.tip { position: fixed; z-index: 60; pointer-events: none; max-width: 300px; padding: 7px 10px; border-radius: 6px; background: #000; color: #e5e7eb; border: 1px solid #14532d; font: 12.5px/1.45 var(--mono); opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s; }
.tip.on { opacity: 1; transform: none; }
.tip .k { color: #4ade80; } .tip .x { color: #f87171; }

/* ---------- end matter ---------- */
.cite pre { white-space: pre-wrap; }
.site-foot { max-width: 1360px; margin: 90px auto 0; padding: 22px 16px 40px; border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; font: 12.5px var(--mono); color: var(--muted); }
.site-foot a { color: var(--term); text-decoration: none; }

@media (max-width: 640px) {
  body { font-size: 17.5px; }
  .masthead { padding-top: 52px; }
  .content h2 { font-size: 26px; }
  .content h2 .hash { display: none; }
  .cap { font-size: 15.5px; }
  .term-bar nav .opt { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .caret { animation: none; }
  .fig .stage > svg, .step, .step .n, .tip { transition: none; }
}

/* ---------- v2: figure surface, micro labels, halos, step progress ---------- */
:root { --dot: rgba(0, 0, 0, .06); --blue-hi: #79b0f0; --orange-hi: #f5a582; --context-hi: #d8d7d1; --sphere-hi: #ffffff; --sphere-lo: #e8e7e1; }
:root[data-theme="dark"] { --dot: rgba(255, 255, 255, .055); --blue-hi: #7cb5f4; --orange-hi: #f0905f; --context-hi: #93928b; --sphere-hi: #31312e; --sphere-lo: #141413; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --dot: rgba(255, 255, 255, .055); --blue-hi: #7cb5f4; --orange-hi: #f0905f; --context-hi: #93928b; --sphere-hi: #31312e; --sphere-lo: #141413; }
}
.fig .stage {
  border: 1px solid var(--rule); border-radius: 14px; padding: 14px 16px 12px;
  background-color: var(--panel);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.4px);
  background-size: 18px 18px; background-position: 9px 9px;
}
.halo { paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.fig .prog { height: 2px; margin: 10px 2px 0; border-radius: 2px; background: var(--term); opacity: .6; transform: scaleX(0); transform-origin: left center; }
.cap p:not([hidden]) { animation: cap-in .45s ease both; }
@keyframes cap-in { from { opacity: 0; transform: translateY(5px); } }
.fig .stage > svg .hl { stroke: var(--ink) !important; stroke-width: 1.8px !important; }
.fig .stage > svg [data-i] { cursor: crosshair; }
.vers { display: flex; gap: 10px; }
.vers a { color: #4b5563 !important; } .vers a[aria-current] { color: #86efac !important; }
@media (prefers-reduced-motion: reduce) { .cap p:not([hidden]) { animation: none; } .fig .prog { display: none; } }

/* ---------- v3: terminal corner brackets on every figure, as on the homepage's frame ---------- */
:root { --bracket: rgba(21, 128, 61, .45); }
:root[data-theme="dark"] { --bracket: rgba(74, 222, 128, .42); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bracket: rgba(74, 222, 128, .42); } }
.fig .stage::before, .pdt::after {
  content: ""; position: absolute; inset: 7px; pointer-events: none; border: 1px solid var(--bracket); border-radius: 9px;
  -webkit-mask: linear-gradient(#000 0 0) top left / 16px 16px no-repeat, linear-gradient(#000 0 0) top right / 16px 16px no-repeat,
    linear-gradient(#000 0 0) bottom left / 16px 16px no-repeat, linear-gradient(#000 0 0) bottom right / 16px 16px no-repeat;
  mask: linear-gradient(#000 0 0) top left / 16px 16px no-repeat, linear-gradient(#000 0 0) top right / 16px 16px no-repeat,
    linear-gradient(#000 0 0) bottom left / 16px 16px no-repeat, linear-gradient(#000 0 0) bottom right / 16px 16px no-repeat;
}
.f-good { fill: var(--good); }

/* ---------- v4: steady digits, live marks, depth, a canvas layer under the figure ---------- */
.fig .stage > svg text { font-variant-numeric: tabular-nums; }
.fig .stage > svg circle[data-tip] { transform-box: fill-box; transform-origin: center; transition: transform .15s ease; }
.fig .stage > svg circle[data-tip]:hover { transform: scale(1.35); }
.fig .stage { box-shadow: inset 0 0 50px rgba(0, 0, 0, .035); }
:root[data-theme="dark"] .fig .stage { box-shadow: inset 0 0 80px rgba(0, 0, 0, .38); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .fig .stage { box-shadow: inset 0 0 80px rgba(0, 0, 0, .38); } }
.fig .stage canvas.glyphs { position: absolute; pointer-events: none; }
.fig .stage > svg { position: relative; }

/* ---------- v5: one timeline per figure (drag to scrub), and figures that switch on as they scroll in ---------- */
.fig .track { position: relative; height: 20px; margin: 6px 6px 0; cursor: pointer; touch-action: none; outline: none; }
.fig .track .rail { position: absolute; left: 8px; right: 8px; top: 9px; height: 2px; border-radius: 2px; background: var(--rule); }
.fig .track .fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 2px; background: var(--term); }
.fig .track .pend { position: absolute; top: 0; height: 100%; width: 0; border-radius: 2px; background: var(--term); opacity: .3; }
.fig .track .tick { position: absolute; top: -3px; width: 2px; height: 8px; margin-left: -1px; border-radius: 1px; background: var(--faint); }
.fig .track .knob { position: absolute; top: -5px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--term); box-shadow: 0 0 0 3px var(--panel), 0 0 10px var(--term); transition: transform .15s; }
.fig .track:hover .knob, .fig .track.drag .knob { transform: scale(1.3); }
.fig .track:focus-visible .rail { outline: 2px solid var(--term); outline-offset: 6px; border-radius: 4px; }
.fig .stage > svg, .fig .stage > canvas.glyphs { transition: opacity .7s ease; }
.fig .stage:not(.live) > svg, .fig .stage:not(.live) > canvas.glyphs { opacity: 0; }
.fig .stage::before { transition: inset .8s cubic-bezier(.2, .7, .2, 1), opacity .8s ease; }
.fig .stage:not(.live)::before { inset: 28px; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .fig .stage > svg, .fig .stage > canvas.glyphs, .fig .stage::before { transition: none; } }

/* revision 9: captions share one cell so the figure keeps the height of its longest caption */
.fig .cap { display: grid; }
.fig .cap > p { grid-area: 1 / 1; visibility: hidden; opacity: 0; transition: opacity .5s; }
.fig .cap > p.on { visibility: visible; opacity: 1; }
