/* TUI patch layer — sits on top of the archie base theme.

   Direction: a quiet terminal manuscript, after ascii.rest. One monospace
   voice (Paper Mono; LXGW WenKai carries the CJK), ink on a cool pale ground
   or the reverse, 1px dotted rules instead of boxes, links that invert into a
   solid ink block. The only colour on the site is one sage "spot" ink (#A2C2A1),
   kept for the NoLE cube, the cursor and "you are here". It is pale, so it
   is used as a fill; where it must be read as text on the light ground the
   same hue goes deeper as --spot-ink. */

/* --- type ---------------------------------------------------------------- */

/* Latin side (OFL, variable weight 100-800). */
@font-face {
  font-family: "Paper Mono";
  src: url("/fonts/paper-mono.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

/* CJK side. unicode-range keeps WenKai off Latin, so it can sit first in the
   stack and still hand ASCII to Paper Mono. The reading subset loads first;
   characters outside it fall through to the full font shipped with the site. */
@font-face {
  font-family: "LXGW WenKai";
  src: local("LXGW WenKai"), url("/fonts/wenkai-reading.woff2") format("woff2");
  font-display: swap;
  unicode-range: U+2E80-9FFF, U+F900-FAFF, U+FF00-FFEF, U+20000-323AF;
}

@font-face {
  font-family: "WenKai Full";
  src: local("LXGW WenKai"), url("/assets/fonts/LXGWWenKai-Regular.ttf") format("truetype");
  font-display: swap;
  unicode-range: U+2E80-9FFF, U+F900-FAFF, U+FF00-FFEF, U+20000-323AF;
}

/* --- tokens -------------------------------------------------------------- */

:root {
  --paper: #f5f6f7;
  --ink: #1e2125;
  --text: #3b4149;
  --muted: #5f6873;
  --well: #eceef0;
  --rule: #b9bec5;
  --spot: #a2c2a1;      /* fills: current tab, cursor, progress, underline */
  --spot-ink: #4a7449;  /* same hue, dark enough for text on --paper (4.8:1) */

  --mono: "LXGW WenKai", "WenKai Full", "Paper Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --notebook-font: var(--mono);
  --hand-font: "LXGW WenKai", "WenKai Full", "Paper Mono", "Kaiti SC", KaiTi, monospace;
  --gutter: 1.25rem;
  --measure: 800px; /* text width; the column adds a gutter on each side */
  --page: calc(var(--measure) + 2 * var(--gutter));
  --pad: .5ch;

  /* Archie reads these names; point them at the tokens above. The *-dark
     values feed archie's dark.css, which the theme toggle enables. */
  --color-background: var(--paper);
  --color-text: var(--text);
  --color-text-muted: var(--muted);
  --color-text-meta: var(--muted);
  --color-border: var(--rule);
  --color-primary: var(--spot-ink);
  --color-primary-hover: var(--ink);
  --color-background-code: var(--well);
  --color-background-pre: var(--well);
  --color-background-toc: var(--paper);
  --color-background-draft: transparent;
  --color-background-dark: #131518;
  --color-text-dark: #c3c9d1;
  --color-text-muted-dark: #8c95a1;
  --color-border-dark: #3b4048;
  --color-primary-dark: #a2c2a1;
  --color-primary-hover-dark: #e8ebef;
  --color-background-code-dark: #1a1d21;
  --color-background-pre-dark: #1a1d21;
  --color-background-toc-dark: #131518;
  --color-background-draft-dark: transparent;

  --tui-accent: var(--spot);
  --tui-border: var(--rule);
  color-scheme: light;
}

html[data-theme="dark"] {
  --paper: #131518;
  --ink: #e8ebef;
  --text: #c3c9d1;
  --muted: #8c95a1;
  --well: #1a1d21;
  --rule: #3b4048;
  --spot: #a2c2a1;
  --spot-ink: #a2c2a1;
  color-scheme: dark;
}

/* --- base ---------------------------------------------------------------- */

html {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  font-size: 15px;
  font-family: var(--mono);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body,
html[data-theme="dark"] body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 400 1rem/1.8 var(--mono);
  font-variant-ligatures: none;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: none;
}

p {
  font-family: inherit;
  line-height: inherit;
  /* Plain greedy wrap: `pretty` breaks CJK lines early and leaves them ragged. */
  text-wrap: wrap;
}

::selection,
html[data-theme="dark"] ::selection,
.highlight pre ::selection {
  background: var(--ink);
  color: var(--paper);
  text-shadow: none;
}

h1, h2, h3, h4, h5, h6,
html[data-theme="dark"] :is(h1, h2, h3, h4, h5, h6) {
  color: var(--ink);
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0;
}

/* Markdown heading markers stay, stepped back to rule grey. */
h1::before, h2::before, h3::before, h4::before, h5::before, h6::before,
html[data-theme="dark"] :is(h1, h2, h3, h4, h5, h6)::before {
  color: var(--rule);
  font-weight: 400;
}

/* --- links: invert on hover ---------------------------------------------- */

a,
html[data-theme="dark"] a {
  padding: 0 var(--pad);
  margin: 0 calc(var(--pad) * -1);
  border: 0;
  color: var(--ink);
  text-decoration: none;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: none;
}

/* html prefix: outrank the dark-mode `a` reset above. */
html :is(.body, .tldr, .notebook-cover__lede, .list-head__meta) a {
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--muted);
  text-underline-offset: .28em;
}

@media (hover: hover) {
  a:hover,
  html[data-theme="dark"] a:hover {
    background: var(--ink);
    color: var(--paper);
    outline: 0;
    text-decoration-line: none;
  }
}

a:focus,
html[data-theme="dark"] a:focus {
  background: none;
  color: var(--ink);
  outline: 0;
}

a:focus-visible,
html[data-theme="dark"] a:focus-visible {
  background: var(--ink);
  color: var(--paper);
  outline: 1px dotted var(--ink);
  outline-offset: 2px;
  text-decoration-line: none;
}

/* --- frame --------------------------------------------------------------- */

.site-width,
.content {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--page);
  max-inline-size: var(--page);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.content { margin-block-end: 0; }

/* Sticky footer: on short pages .content takes the spare height, so the
   colophon sits at the bottom of the window instead of mid-screen. */
body {
  display: flex;
  flex-direction: column;
  min-block-size: 100vh;
  min-block-size: 100svh;
}
.content { flex: 1 0 auto; }

/* --- masthead: elonnzhang@<space>$ ▌ ------------------------------------- */

.masthead,
.site-width > header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem 3ch;
  margin: 0;
  padding-block: 2.75rem .9rem;
  border-block-end: 1px dotted var(--rule);
  line-height: 1.6;
}

.masthead .main {
  flex: none;
  display: flex;
  align-items: baseline;
  font-size: 1rem;
  font-weight: 500;
}

/* One continuous hairline under owner + @space (skip-ink off so descenders
   don't break it); the caret is inline-block and sits outside the line. */
.tui-prompt {
  display: inline;
  color: var(--ink);
  font: inherit;
  white-space: nowrap;
  text-decoration: underline;
  text-decoration-color: var(--spot);
  text-decoration-thickness: 1px;
  text-underline-offset: .35em;
  text-decoration-skip-ink: none;
}

.tui-prompt__owner,
html[data-theme="dark"] .tui-prompt__owner {
  padding: 0;
  margin: 0;
  color: inherit;
  text-decoration: none;
}

.tui-prompt__space {
  display: inline;
  cursor: pointer;
  list-style: none;
  color: inherit;
}

.tui-prompt__space::-webkit-details-marker { display: none; }
.tui-prompt__space::marker { content: ""; }

@media (hover: hover) {
  .tui-prompt__space:hover .tui-prompt__at { background: var(--ink); color: var(--paper); }
}

.tui-prompt__space:focus-visible,
.tui-prompt__owner:focus-visible {
  outline: 1px dotted var(--ink);
  outline-offset: 3px;
}

.tui-prompt__caret {
  display: inline-block;
  margin-inline-start: .6ch;
  color: var(--muted);
  font-size: .8em;
  text-decoration: none;
}

.space-switcher[open] .tui-prompt__caret { transform: rotate(180deg); }

/* The block cursor after the prompt: the one thing that blinks. */
.tui-cursor {
  display: inline-block;
  inline-size: .6em;
  block-size: 1.05em;
  margin-inline-start: 1ch;
  align-self: center;
  background: var(--spot);
  animation: tui-blink 1.06s steps(1, end) infinite;
}

@keyframes tui-blink {
  50% { opacity: 0; }
}

.space-switcher {
  position: relative;
  display: inline;
}

.space-switcher__menu {
  display: none;
  position: absolute;
  z-index: 85;
  top: calc(100% + .6rem);
  left: 0;
  width: max-content;
  min-width: 14ch;
  max-width: calc(100vw - 2rem);
  padding: .4rem 0;
  border: 1px solid var(--ink);
  background: var(--paper);
  font: 400 .9333rem/1.5 var(--mono);
  text-decoration: none;
}

.space-switcher[open] > .space-switcher__menu { display: grid; }

.space-switcher__menu a {
  margin: 0;
  padding: .3rem 2ch;
  color: var(--text);
}

.space-switcher__menu a[aria-current="page"] { color: var(--spot-ink); }
.space-switcher__menu a[aria-current="page"]::before { content: "› "; }

.space-switcher__menu a:is(:hover, :focus-visible) {
  background: var(--ink);
  color: var(--paper);
  outline: 0;
}

.masthead__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: flex-end;
  gap: .25rem 1.75ch;
  min-width: 0;
  font-size: .8667rem;
}

/* Wide screens: prompt and nav always share one row, whatever the length of
   the current space name, so the header never jumps between pages. */
@media (min-width: 721px) {
  .masthead,
  .site-width > header { flex-wrap: nowrap; }
}

.masthead__nav a,
html[data-theme="dark"] .masthead__nav a { color: var(--muted); }

.masthead__nav a[aria-current="page"],
.masthead__nav a[aria-current="page"]:hover,
html[data-theme="dark"] .masthead__nav a[aria-current="page"] {
  background: var(--spot);
  color: #1e2125; /* ink on sage in both themes: 8:1 */
}

/* Theme toggle as text, "light/dark" with the active half in ink. The SVG
   archie's themetoggle.js writes into the button is hidden. */
#dark-mode-toggle,
html[data-theme="dark"] #dark-mode-toggle {
  display: inline;
  margin: 0 calc(var(--pad) * -1);
  padding: 0 var(--pad);
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

#dark-mode-toggle svg { display: none; }
#dark-mode-toggle::before { content: "light"; color: var(--ink); }
#dark-mode-toggle::after { content: "/dark"; }
html[data-theme="dark"] #dark-mode-toggle::before { content: "light/"; color: var(--muted); }
html[data-theme="dark"] #dark-mode-toggle::after { content: "dark"; color: var(--ink); }

@media (hover: hover) {
  #dark-mode-toggle:hover,
  html[data-theme="dark"] #dark-mode-toggle:hover,
  #dark-mode-toggle:hover::before,
  #dark-mode-toggle:hover::after,
  html[data-theme="dark"] #dark-mode-toggle:hover::before,
  html[data-theme="dark"] #dark-mode-toggle:hover::after {
    background: var(--ink);
    color: var(--paper);
    outline: 0;
  }
}

#dark-mode-toggle:focus,
html[data-theme="dark"] #dark-mode-toggle:focus { outline: 0; }
#dark-mode-toggle:focus-visible { outline: 1px dotted var(--ink); outline-offset: 2px; }

/* "cd .." above single and term pages. */
.tui-back,
html[data-theme="dark"] .tui-back {
  display: inline-block;
  margin-block: 2rem 0;
  color: var(--muted);
  font-size: .8667rem;
}

/* --- shared list rows ---------------------------------------------------- */

.list-head { margin-block: 2.75rem 1.25rem; }
/* Under "cd .." (a single tag) the heading sits where an article title does. */
body:has(.tui-back) .list-head { margin-block-start: 1.25rem; }

.page-title {
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--ink);
  font: 500 1.6rem/1.35 var(--mono);
  text-wrap: balance;
}

.list-head__hash { color: var(--rule); margin-inline-end: .2ch; }

.list-head__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem 3ch;
  margin: .6rem 0 0;
  color: var(--muted);
  font-size: .8667rem;
}

.list-head__count::before { content: "["; }
.list-head__count::after { content: "]"; }

.notebook-home :is(h1, h2)::before,
.article-heading h1::before,
.page-title::before,
.archive-year::before {
  content: none;
}

ul.posts {
  margin: 0;
  padding: 0;
  border-block-start: 1px solid var(--ink);
  list-style: none;
  line-height: 1.6;
}

.posts .post {
  display: grid;
  grid-template-columns: 11ch minmax(0, 1fr);
  align-items: baseline;
  gap: 0 2ch;
  padding-block: .6rem;
  border-block-end: 1px dotted var(--rule);
  text-indent: 0;
}

.posts .post::before,
html[data-theme="dark"] .posts .post::before { content: none; }

.posts .post > a { justify-self: start; }

.posts .post .meta {
  order: -1;
  color: var(--muted);
  font-size: .8667rem;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.archive-year {
  display: flex;
  align-items: baseline;
  gap: 1.5ch;
  margin: 2.5rem 0 .6rem;
  font: 500 1rem/1.4 var(--mono);
}

.archive-year span { color: var(--muted); font-size: .8667rem; font-weight: 400; }

.term-index {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 3ch;
  margin: 0;
  padding: 1rem 0 0;
  border-block-start: 1px solid var(--ink);
  list-style: none;
}

.term-index li { text-indent: 0; }
.term-index li::before,
html[data-theme="dark"] .term-index li::before { content: none; }
.term-index a { display: inline-flex; gap: 1ch; }
.term-index__name::before { content: "#"; color: var(--rule); }
.term-index__count { color: var(--muted); font-size: .8667rem; }
.term-index a:hover .term-index__count,
.term-index a:hover .term-index__name::before { color: inherit; }

.draft-label,
html[data-theme="dark"] .draft-label {
  margin-inline-start: 1ch;
  padding: 0;
  border-radius: 0;
  background: none;
  color: var(--spot-ink);
  font-size: .8em;
  font-weight: 400;
}

.draft-label::before { content: "["; }
.draft-label::after { content: "]"; }

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 100%;
  margin: 2.5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: .9333rem;
  text-transform: lowercase;
}

.pagination .page-item { display: inline-flex; }
.pagination .page-prev { margin-right: auto; }
.pagination .page-next { margin-left: auto; }
.pagination a { color: var(--muted); }

/* --- home ---------------------------------------------------------------- */

/* The cover shares the reading column with everything else: the title sits on
   the masthead's left edge, the cube on its right edge. */
.notebook-cover {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2rem 4ch;
  padding-block: 3.5rem 3rem;
}

.notebook-cover h1 {
  margin: 0;
  color: var(--ink);
  font: 500 2rem/1.35 var(--mono);
  letter-spacing: 0;
  text-wrap: balance;
}

.notebook-cover__lede {
  max-inline-size: 34ch;
  margin: 1.1rem 0 0;
  color: var(--muted);
  font-size: .9333rem;
  line-height: 1.7;
}

.notebook-cover__stat {
  margin: 1.6rem 0 0;
  color: var(--muted);
  font-size: .8667rem;
}

.notebook-cover__stat span { color: var(--ink); }
.notebook-cover__stat::before { content: "$ "; color: var(--rule); }

.nole-ascii {
  justify-self: center;
  margin: 0;
  padding: 0;
}

.nole-ascii pre,
html[data-theme="dark"] .nole-ascii pre {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 400 9.5px/.96 "Paper Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-ligatures: none;
  letter-spacing: 0;
  white-space: pre;
  overflow: visible;
  overflow-wrap: normal;
}

/* Two inks meet at the centre crease of the monospaced drawing. */
@media screen and (forced-colors: none) {
  @supports (background-clip: text) {
    .nole-ascii pre,
    html[data-theme="dark"] .nole-ascii pre {
      background: linear-gradient(to right, var(--ink) calc(50% + .5ch), var(--spot-ink) 0);
      -webkit-background-clip: text;
      background-clip: text;
      color: transparent;
    }
    .nole-ascii pre::selection { color: HighlightText; background: Highlight; }
  }
}

/* Live layer painted by nole-flow.js: <b.g> = glint band / shockwave,
   <b.a> = crest of the flowing fabric on the right face. */
.nole-ascii pre.is-live {
  --nole-glint: #1f7a3e;
  cursor: crosshair;
  touch-action: manipulation;
  user-select: none;
}
html[data-theme="dark"] .nole-ascii pre.is-live { --nole-glint: #dff2d8; }
.nole-ascii pre.is-live b { font-weight: inherit; }
.nole-ascii pre.is-live b.g {
  color: var(--nole-glint);
  -webkit-text-fill-color: var(--nole-glint);
}
html[data-theme="dark"] .nole-ascii pre.is-live b.g {
  text-shadow: 0 0 6px color-mix(in oklab, var(--nole-glint) 70%, transparent);
}
.nole-ascii pre.is-live b.a {
  color: var(--spot-ink);
  -webkit-text-fill-color: var(--spot-ink);
  text-shadow: 0 0 4px color-mix(in oklab, var(--spot) 60%, transparent);
}

.nole-ascii figcaption {
  margin-block-start: 1rem;
  color: var(--muted);
  font-size: .8rem;
  text-align: center;
}

.nole-ascii figcaption::before { content: "fig.0 — "; color: var(--rule); }

.project-notes { border-block: 1px dotted var(--rule); }

.project-notes summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2ch;
  padding-block: .85rem;
  color: var(--muted);
  font-size: .9333rem;
  cursor: pointer;
  list-style: none;
}

.project-notes summary::-webkit-details-marker { display: none; }
.project-notes summary::marker { content: ""; }
.project-notes summary:hover { color: var(--ink); }

.project-notes summary:focus-visible {
  outline: 1px dotted var(--ink);
  outline-offset: 3px;
}

.project-notes__action { flex-shrink: 0; color: var(--ink); }
.project-notes__action::after { content: " [+]"; color: var(--muted); }
.project-notes[open] .project-notes__action::after { content: " [-]"; }

.project-notes__groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem 4ch;
  padding: .25rem 0 1.5rem;
}

.project-notes__groups h2 {
  margin: 0 0 .5rem;
  color: var(--muted);
  font: 400 .8667rem/1.6 var(--mono);
}

.project-notes dl { margin: 0; }

.project-notes dt {
  margin: .3rem 0 0;
  padding-inline-start: 2ch;
  text-indent: -2ch;
  color: var(--text);
  font-size: .9333rem;
  line-height: 1.6;
}

.project-notes dt::before { content: "- "; color: var(--rule); }

.project-notes dd {
  margin: 0 0 0 2ch;
  color: var(--muted);
  font-size: .8667rem;
}

.notebook-index {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 2ch;
  margin-block-start: 3.25rem;
  padding-block-end: .6rem;
  border-block-end: 1px solid var(--ink);
}

.notebook-index :is(h1, h2) {
  margin: 0;
  font: 500 1rem/1.4 var(--mono);
}

.notebook-index__page { color: var(--muted); font-weight: 400; }

.notebook-index > a,
html[data-theme="dark"] .notebook-index > a {
  color: var(--muted);
  font-size: .8667rem;
}

.notebook-entry {
  display: grid;
  grid-template-columns: 11ch minmax(0, 1fr);
  gap: 0 2ch;
  padding-block: 1.1rem;
  border-block-end: 1px dotted var(--rule);
}

.notebook-entry__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .1rem;
  color: var(--muted);
  font-size: .8667rem;
  line-height: 1.75rem;
  font-variant-numeric: tabular-nums;
}

.notebook-entry__meta a,
html[data-theme="dark"] .notebook-entry__meta a { color: var(--muted); }
.notebook-entry__meta a::before { content: "~/"; color: var(--rule); }
.notebook-entry__meta a:hover::before { color: inherit; }

time {
  color: inherit;
  font: inherit;
}

.notebook-entry h2 {
  margin: 0;
  font: 500 1.0667rem/1.65 var(--mono);
}

.notebook-entry .description {
  margin-block-start: .3rem;
  color: var(--muted);
  font-size: .9333rem;
  line-height: 1.75;
}

.description :where(p) { margin: 0; }

/* Body-fallback preview, clamped. */
.description--clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

/* --- article ------------------------------------------------------------- */

.article-heading {
  margin-block: 1.25rem 2.5rem;
}
/* Top-level pages (about) have no "cd ..": title on the list-page baseline. */
body:not(:has(.tui-back)) .article-heading { margin-block-start: 2.75rem; }
.article-heading {
  padding-block-end: 1.25rem;
  border-block-end: 1px dotted var(--rule);
}

.article-heading h1 {
  margin: 0 0 .9rem;
  color: var(--ink);
  font: 500 1.6rem/1.45 var(--mono);
  text-wrap: balance;
}

.article-heading__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .2rem 3ch;
  color: var(--muted);
  font-size: .8667rem;
}

.article-heading__meta a,
html[data-theme="dark"] .article-heading__meta a { color: var(--muted); }
.article-heading__meta a::before { content: "~/"; color: var(--rule); }
.article-heading__meta a:hover::before { color: inherit; }

.tldr {
  margin-block-end: 2rem;
  padding: .9rem 2ch;
  background: var(--well);
  font-size: .9333rem;
}

.tldr strong { color: var(--ink); font-weight: 500; }

.post-container { display: block; }

.post-content {
  min-width: 0;
  max-width: 100%;
}

.post-content .body {
  overflow: visible;
  color: var(--text);
  line-height: 1.85;
}

.post-content .body :is(p, li, blockquote) { line-height: inherit; }
.post-content .body p { margin-block: 1em; }

.body h1 { font-size: 1.3333rem; margin-block: 2.75rem .9rem; }
.body h2 { font-size: 1.2rem; margin-block: 2.75rem .9rem; }
.body h3 { font-size: 1.0667rem; margin-block: 2.25rem .75rem; }
.body :is(h4, h5, h6) { font-size: 1rem; margin-block: 1.75rem .6rem; }
.body :is(h1, h2, h3, h4, h5, h6) { line-height: 1.5; }
.body strong { color: var(--ink); font-weight: 600; }

/* Lists: a muted dash instead of archie's red asterisk. */
ul > li::before,
html[data-theme="dark"] ul > li::before {
  content: "- ";
  color: var(--rule);
  font-weight: 400;
}

ol > li::marker { color: var(--muted); }

blockquote,
html[data-theme="dark"] blockquote {
  margin: 1.5rem 0;
  padding: .1rem 0 .1rem 2ch;
  border: 0;
  border-inline-start: 1px solid var(--ink);
  color: var(--muted);
  font-style: normal;
}

hr,
html[data-theme="dark"] hr {
  margin-block: 2.5rem;
  border: 0;
  border-block-start: 1px dotted var(--rule);
}

img {
  border: 0;
  border-radius: 0;
}

.body img { outline: 1px solid var(--rule); outline-offset: -1px; }

figure h4::before { content: "↳ "; color: var(--rule); }

/* Code: a flat well, no border, no radius. Token colours live in chroma.css. */
code,
html[data-theme="dark"] code {
  padding: .08em .4ch;
  border-radius: 0;
  background: var(--well);
  color: var(--ink);
  font-family: var(--mono);
  font-size: .9em;
}

pre,
html[data-theme="dark"] pre {
  margin-block: 1.5rem;
  padding: 1.1rem 2ch;
  border: 0;
  border-radius: 0;
  background: var(--well);
  font-size: .8667rem;
  line-height: 1.65;
}

pre code,
html[data-theme="dark"] pre code {
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: 100%;
}

.highlight,
html[data-theme="dark"] .highlight {
  margin-block: 1.5rem;
  border-radius: 0;
  background: var(--well);
}

.highlight pre { margin: 0; }

.highlight pre code[class*="language-"]::before {
  top: .35rem;
  right: 1.25ch;
  inset-inline-end: 1.25ch;
  inset-block-start: .35rem;
  padding: 0;
  border-radius: 0;
  background: none !important;
  color: var(--muted) !important;
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: lowercase;
}

/* Tables: horizontal rules only, a solid ink rule under the head. */
table {
  margin-block: 1.5rem;
  border-radius: 0;
  box-shadow: none;
  font-size: .9333rem;
  line-height: 1.65;
}

table th,
table td,
html[data-theme="dark"] table th,
html[data-theme="dark"] table td {
  padding: .55rem 2ch .55rem 0;
  border: 0;
  border-block-end: 1px dotted var(--rule);
  background: none;
  color: var(--text);
  vertical-align: top;
}

table th,
html[data-theme="dark"] table th {
  border-block-end: 1px solid var(--ink);
  color: var(--ink);
  font-weight: 500;
}

table tr:nth-child(even),
html[data-theme="dark"] table tr:nth-child(even) { background: none; }

/* Wide tables scroll inside their own box (render-table hook wrapper). */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.post-tags { margin-block-start: 3rem; }

/* The theme sets `nav { display: flex }`; as a flex item the tag list shrank
   to its text and drew a second dotted rule under the full-width one. */
.post-tags > nav { display: block; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem 2.5ch;
  margin: 0;
  padding: 1rem 0 0;
  border-block-start: 1px dotted var(--rule);
  list-style: none;
  font-size: .8667rem;
}

.tags li { text-indent: 0; }
.tags li::before,
html[data-theme="dark"] .tags li::before { content: none; }

.tags a,
html[data-theme="dark"] .tags a {
  padding: 0 var(--pad);
  border: 0;
  border-radius: 0;
  color: var(--muted);
}

.tags a::before { content: "#"; }

/* --- series list (shortcode) --------------------------------------------- */

.series-list {
  margin: 1.5rem 0;
  padding: 0;
  border-block-start: 1px solid var(--ink);
  list-style: none;
  counter-reset: series;
}

.series-list__item {
  display: grid;
  grid-template-columns: 4ch minmax(0, 1fr);
  padding-block: .6rem;
  border-block-end: 1px dotted var(--rule);
  counter-increment: series;
}

.series-list__item::before {
  content: counter(series, decimal-leading-zero);
  grid-row: span 2;
  color: var(--muted);
  font-size: .8667rem;
}

.series-list__item > a { justify-self: start; }

.series-list__description,
.post-content .body .series-list__description {
  grid-column: 2;
  margin: .15rem 0 0;
  color: var(--muted);
  font-size: .8667rem;
  line-height: 1.7;
}

/* --- mermaid ------------------------------------------------------------- */

.mermaid-figure {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  /* Break out of the reading column (up to ~1100px) without ever exceeding
     the viewport, so large diagrams get more room for an overview. */
  width: min(1100px, calc(100vw - 3rem));
  margin-block: 1.75rem;
}

pre.mermaid,
.mermaid,
html[data-theme="dark"] pre.mermaid {
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  overflow-x: auto;
  text-align: center;
  line-height: normal;
}

/* Raw source shown before mermaid.js runs (fallback). */
pre.mermaid:not([data-processed="true"]) {
  font-family: var(--mono);
  text-align: left;
  white-space: pre-wrap;
}

.mermaid svg {
  display: block;
  height: auto;
  /* Fit to the widened container as an overview; overrides archie's svg cap. */
  max-width: 100%;
  max-height: none;
  max-inline-size: 100%;
  max-block-size: none;
  margin: 0 auto;
}

.mermaid-fullscreen {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  opacity: .35;
}

.mermaid-figure:hover .mermaid-fullscreen,
.mermaid-fullscreen:focus-visible { opacity: 1; }

.mermaid-fullscreen:hover,
.mermaid-fullscreen:focus-visible {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.mermaid-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  padding: 56px 24px 24px;
  background: rgba(12, 14, 18, .98);
}

.mermaid-overlay__content {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 24px;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, .2);
  background: #f5f6f7;
}

.mermaid-overlay__content svg {
  display: block;
  /* Fixed box; the viewBox scales the diagram to fit, fully visible. */
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  max-inline-size: 100%;
  max-block-size: 100%;
}

.mermaid-overlay__close {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 1001;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 0;
  background: rgba(0, 0, 0, .4);
  color: #fff;
  font: 400 20px/1 var(--mono);
  cursor: pointer;
}

.mermaid-overlay__close:hover,
.mermaid-overlay__close:focus-visible {
  border-color: #fff;
  background: #fff;
  color: #000;
}

@media (max-width: 720px) {
  .mermaid-overlay { padding: 52px 8px 8px; }
  .mermaid-overlay__content { padding: 8px; }
}

/* Collapsed TOC launcher and back-to-top share one chip height. */
:root { --chip-h: 2.25rem; }

/* --- TOC: a floating launcher; docks in the right margin when there's room - */

.toc,
html[data-theme="dark"] .toc {
  display: block;
  position: fixed;
  z-index: 75;
  top: 5.5rem;
  right: .75rem;
  width: min(280px, calc(100vw - 1.5rem));
  max-width: 280px;
  max-height: calc(100vh - 8rem);
  margin: 0;
  padding: .8rem 1.5ch;
  overflow-y: auto;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  box-shadow: none;
  color: var(--text);
  font-size: .8rem;
  line-height: 1.6;
  scrollbar-width: thin;
}

.toc__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5ch;
  margin-block-end: .5rem;
}

.toc__header > strong { color: var(--muted); font-weight: 400; }

.toc__toggle {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.toc__toggle-label { color: var(--muted); margin-inline-end: .5ch; }

.toc__toggle:hover,
.toc__toggle:focus-visible {
  background: var(--ink);
  color: var(--paper);
  outline: 0;
}

.toc__toggle:hover .toc__toggle-label { color: inherit; }

.toc.is-collapsed,
html[data-theme="dark"] .toc.is-collapsed {
  width: auto;
  max-width: none;
  overflow: visible;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  block-size: var(--chip-h);
  padding: 0 1ch;
}

.toc.is-collapsed .toc__header { margin: 0; }

.toc.is-collapsed .toc__content,
.toc.is-collapsed .toc__header > strong { display: none; }

.toc nav > ul { margin: 0; padding: 0; }
.toc nav ul ul { margin: 0; padding-inline-start: 2ch; }
.toc ul li { text-indent: 0; }
.toc ul > li::before,
html[data-theme="dark"] .toc ul > li::before { content: none; }

.toc a,
html[data-theme="dark"] .toc a { color: var(--muted); }

.toc a[aria-current="location"],
html[data-theme="dark"] .toc a[aria-current="location"] { color: var(--ink); }
.toc a[aria-current="location"]::before { content: "› "; color: var(--spot-ink); }

/* The muted/ink colours above tie with the global a:hover and win by source
   order, leaving grey or ink text on the ink hover block. Re-assert the invert. */
@media (hover: hover) {
  .toc a:hover,
  html[data-theme="dark"] .toc a:hover,
  .toc a[aria-current="location"]:hover,
  html[data-theme="dark"] .toc a[aria-current="location"]:hover,
  .toc a[aria-current="location"]:hover::before { color: var(--paper); }
}

.toc a:focus-visible,
html[data-theme="dark"] .toc a:focus-visible { color: var(--paper); }

@media screen and (min-width: 1360px) {
  .toc,
  html[data-theme="dark"] .toc {
    top: 7.5rem;
    right: 1.75rem;
    width: 240px;
    max-width: 240px;
    max-height: calc(100vh - 10rem);
    padding: 0 0 0 2ch;
    border: 0;
    border-inline-start: 1px dotted var(--rule);
    background: transparent;
    z-index: 40;
  }

  .toc.is-collapsed,
  html[data-theme="dark"] .toc.is-collapsed { padding: 0 0 0 2ch; }
}

/* --- reading progress and back-to-top ------------------------------------ */

.reading-progress {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  pointer-events: none;
}

.reading-progress__value {
  display: block;
  width: 0;
  height: 100%;
  background: var(--spot);
}

.reading-progress__label {
  position: absolute;
  top: 8px;
  right: 10px;
  padding: 0 .5ch;
  background: var(--paper);
  color: var(--muted);
  font: 400 .75rem/1.4 var(--mono);
}

.back-to-top {
  position: fixed;
  z-index: 70;
  right: 1.25rem;
  bottom: 1.25rem;
  display: flex;
  gap: 1ch;
  align-items: center;
  box-sizing: border-box;
  block-size: var(--chip-h);
  padding: 0 1.25ch;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  box-shadow: none;
  color: var(--ink);
  font: 400 .8rem/1.2 var(--mono);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms;
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.back-to-top:hover,
.back-to-top:focus-visible {
  background: var(--ink);
  color: var(--paper);
  outline: 0;
}

/* --- ASCII motion (ascii-fx.js) ------------------------------------------ */

/* Titles wait for the decode; the failsafe shows them after 1.2s regardless. */
html.fx-pending :is(.notebook-cover__title h1, .page-title, .article-heading h1) { animation: fx-failsafe 0s linear 1.2s forwards; visibility: hidden; }
@keyframes fx-failsafe { to { visibility: visible; } }

/* Not-yet-resolved characters of a decoding title. */
.fx-noise { color: var(--spot-ink); }
html[data-theme="dark"] .fx-noise { color: var(--spot); }

/* The footer tide replaces the dotted rule with a row of live dots. */
.ascii-tide {
  flex: 0 0 100%;
  overflow: hidden;
  margin: 0 0 .5rem;
  color: var(--rule);
  font: 400 .8rem/1 var(--mono);
  white-space: pre;
  user-select: none;
  cursor: default;
}
.ascii-tide b { color: var(--spot-ink); font-weight: inherit; }
html[data-theme="dark"] .ascii-tide b { color: var(--spot); }
html.has-tide footer.colophon,
html.has-tide[data-theme="dark"] footer.colophon { border-block-start: 0; padding-block-start: 0; }

/* --- 高山流水 (shanshui.js) ---------------------------------------------- */

/* ASCII landscape in the article gutters: mountains and a waterfall on the
   left, a stream into a lake on the right. Only where the gutters exist; it
   sits behind everything and never takes pointer events. */
.shanshui { display: none; }

@media screen and (min-width: 1360px) {
  html.has-shanshui .shanshui {
    position: fixed;
    z-index: 0;
    top: 0;
    bottom: 0;
    display: block;
    overflow: hidden;
    pointer-events: none;
    user-select: none;
  }
  .shanshui--left { left: 0; }
  .shanshui--right { right: 0; }

  .shanshui pre,
  html[data-theme="dark"] .shanshui pre {
    position: absolute;
    left: 50%;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--rule);
    font: 400 .75rem/1.15 var(--mono);
    white-space: pre;
    transform: translateX(-50%);
  }
  .shanshui--left pre { top: 0; }
  .shanshui--right pre { bottom: 0; }

  .shanshui b { font-weight: 400; }
  .shanshui .f { color: color-mix(in oklab, var(--rule) 60%, var(--paper)); }
  .shanshui .m { color: color-mix(in oklab, var(--rule) 45%, var(--paper)); }
  .shanshui .md { color: var(--rule); }
  .shanshui .n { color: color-mix(in oklab, var(--muted) 85%, var(--paper)); }
  .shanshui .s { color: color-mix(in oklab, var(--rule) 80%, var(--paper)); }
  .shanshui .p { color: color-mix(in oklab, var(--spot-ink) 45%, var(--paper)); }
  .shanshui .w { color: var(--spot); }
  .shanshui .wk { color: color-mix(in oklab, var(--spot-ink) 70%, var(--spot)); }
  .shanshui .b { color: color-mix(in oklab, var(--muted) 75%, var(--paper)); }
  /* Campfire: ink gets denser toward the core; sparks in the spot colour. */
  .shanshui .fh { color: var(--ink); }
  .shanshui .fm { color: var(--text); }
  .shanshui .fl { color: var(--muted); }
  .shanshui .lg { color: var(--text); }
  .shanshui .sp { color: var(--spot-ink); }
  html[data-theme="dark"] .shanshui .sp { color: var(--spot); }

  /* A small seal naming each side, with its line of the poem beneath. */
  .shanshui__mark {
    position: absolute;
    top: 6.5rem;
    left: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
  }
  .shanshui__seal {
    padding: .35em .2em;
    border: 1px solid var(--spot-ink);
    color: var(--spot-ink);
    font: 400 .75rem/1.2 var(--mono);
    writing-mode: vertical-rl;
    letter-spacing: .25em;
  }
  .shanshui__verse {
    color: color-mix(in oklab, var(--muted) 70%, var(--paper));
    font: 400 .7rem/1.2 var(--hand-font);
    writing-mode: vertical-rl;
    letter-spacing: .3em;
  }
  /* 流水 is stamped in the bottom-right corner, verse above it, like a
     painting's inscription; a paper ground keeps it clear of the lake. It
     sits just above the back-to-top chip, which shares that corner. */
  .shanshui--right .shanshui__mark {
    top: auto;
    left: auto;
    right: 1.25rem;
    bottom: calc(1.25rem + var(--chip-h) + .75rem);
    flex-direction: column-reverse;
    padding: .4rem .3rem;
    background: var(--paper);
  }
  html[data-theme="dark"] .shanshui__seal { border-color: var(--spot); color: var(--spot); }

  /* With the TOC docked on the right, leave the bottom of the gutter to the lake. */
  html.has-shanshui-toc .toc,
  html.has-shanshui-toc[data-theme="dark"] .toc { max-height: calc(100vh - 7.5rem - 14rem); }

  /* Breakout diagrams cover the landscape instead of showing it through. */
  html.has-shanshui .mermaid-figure { z-index: 2; background: var(--paper); }
}

/* --- footer -------------------------------------------------------------- */

footer.colophon,
html[data-theme="dark"] footer.colophon {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .4rem 3ch;
  margin: 5rem 0 0;
  padding: 1.1rem 0 3.5rem;
  border: 0;
  border-block-start: 1px dotted var(--rule);
  color: var(--muted);
  font-size: .8rem;
}

.colophon__links { display: flex; flex-wrap: wrap; gap: .2rem 2.25ch; }
.colophon a,
html[data-theme="dark"] .colophon a { color: var(--muted); }
.colophon__built { margin-inline-start: auto; }

/* --- annotations (neat-annotations) -------------------------------------- */

.ann {
  --ann-font: var(--hand-font);
  display: inline;
  line-height: inherit;
  padding: .04em .22em;
  margin: 0;
  box-shadow: none;
  vertical-align: baseline;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* Arrows need a box; highlight-only markers stay inline. */
.ann[data-note] { display: inline-block; }
.ann::after { z-index: 1; font-weight: 400; font-size: 1.05rem; }
.ann::before { z-index: 1; }

/* Arrows and labels sit outside the target; reserve space on the annotation
   itself so a following heading cannot slide under the label. */
.ann-n, .ann-ne, .ann-nw { margin-bottom: 4.75rem; }
.ann-s, .ann-se, .ann-sw { margin-top: 4.75rem; }
.ann-e { margin-inline-start: 7.5rem; }
.ann-w { margin-inline-end: 7.5rem; }

/* --- gallery ------------------------------------------------------------- */

.gallery-filter {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem 2ch;
  margin-block-start: .6rem;
  font-size: .8667rem;
}

.gallery-filter a,
html[data-theme="dark"] .gallery-filter a { color: var(--muted); }

/* Album cards: cover, then a list-row style caption. The card is one link, so
   it doesn't invert as a block; only the title does. */
.gallery-albums {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2.25rem 3ch;
  margin: 0;
  padding: 1.5rem 0 0;
  border-block-start: 1px solid var(--ink);
  list-style: none;
}

.gallery-albums li { text-indent: 0; }
.gallery-albums li::before,
html[data-theme="dark"] .gallery-albums li::before { content: none; }

.gallery-album,
.gallery-album:hover,
.gallery-album:focus,
html[data-theme="dark"] .gallery-album,
html[data-theme="dark"] .gallery-album:hover {
  display: grid;
  gap: .2rem;
  margin: 0;
  padding: 0;
  background: none;
  color: var(--text);
}

.gallery-album__cover {
  display: block;
  aspect-ratio: 3 / 2;
  margin-block-end: .6rem;
  overflow: hidden;
  background: var(--well);
  outline: 1px solid transparent;
  outline-offset: 3px;
}

.gallery-album__cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-album:is(:hover, :focus-visible) .gallery-album__cover { outline-color: var(--ink); }

.gallery-album__meta {
  display: flex;
  gap: 2ch;
  color: var(--muted);
  font-size: .8667rem;
  font-variant-numeric: tabular-nums;
}

.gallery-album__title {
  justify-self: start;
  margin-inline: calc(var(--pad) * -1);
  padding-inline: var(--pad);
  color: var(--ink);
  font-weight: 500;
}

.gallery-album:is(:hover, :focus-visible) .gallery-album__title {
  background: var(--ink);
  color: var(--paper);
}

.gallery-album__desc {
  color: var(--muted);
  font-size: .9333rem;
  line-height: 1.7;
}

.gallery-categories__desc {
  margin-inline-start: 1ch;
  color: var(--muted);
  font-size: .9333rem;
}

/* Album page. */
.gallery-lede {
  margin: -.3rem 0 .9rem;
  color: var(--muted);
  font-size: .9333rem;
}

.article-heading__meta a.gallery-tag::before { content: none; }

/* No-JS / narrow fallback is a square grid; gallery.js adds .is-justified and
   absolutely positions justified rows on wide screens. */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gallery-grid.is-justified {
  display: block;
  position: relative;
}

.gallery-item,
.gallery-item:hover,
.gallery-item:focus,
html[data-theme="dark"] .gallery-item,
html[data-theme="dark"] .gallery-item:hover {
  position: relative;
  display: block;
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--well);
  color: var(--paper);
  cursor: zoom-in;
}

.gallery-grid.is-justified .gallery-item {
  position: absolute;
  aspect-ratio: auto;
}

.gallery-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item:focus-visible { outline: 1px dotted var(--ink); outline-offset: 2px; }

/* Hover caption: an ink strip, the site's inverted-link block. */
.gallery-item__caption {
  position: absolute;
  inset: auto 0 0;
  display: none;
  gap: 2ch;
  padding: .15rem 1ch;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-size: .8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.gallery-item__caption > span:first-child { font-variant-numeric: tabular-nums; }

@media (hover: hover) {
  .gallery-item:is(:hover, :focus-visible) .gallery-item__caption { display: flex; }
}

/* Lightbox: the page itself, emptied — paper ground, text controls. */
html.gallery-is-open { overflow: hidden; }

.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem var(--gutter);
  background: var(--paper);
  color: var(--text);
}

.gallery-lightbox[hidden] { display: none; }

.gallery-lightbox__bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2ch;
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  font-size: .8667rem;
}

.gallery-lightbox__bar:first-child {
  padding-block-end: .6rem;
  border-block-end: 1px dotted var(--rule);
}

.gallery-lightbox__where { color: var(--muted); }
.gallery-lightbox__where .list-head__count { margin-inline-start: 1ch; font-variant-numeric: tabular-nums; }

.gallery-lightbox__btn {
  flex: none;
  padding: 0 var(--pad);
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.gallery-lightbox__btn:is(:hover, :focus-visible) {
  background: var(--ink);
  color: var(--paper);
  outline: 0;
}

.gallery-lightbox__stage {
  position: relative;
  min-height: 0;
  margin: 0;
  cursor: zoom-out;
}

/* Absolutely centred so the image is bounded by the grid row, not its own
   intrinsic height. */
.gallery-lightbox__stage img {
  position: absolute;
  inset: 0;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
  cursor: default;
}

.gallery-lightbox__caption {
  min-width: 0;
  text-align: center;
}

.gallery-lightbox__caption h2 {
  margin: 0;
  font-size: 1rem;
}

.gallery-lightbox__caption h2::before { content: none; }

.gallery-lightbox__caption p {
  margin: 0;
  color: var(--muted);
}

/* --- narrow screens ------------------------------------------------------ */

@media (max-width: 720px) {
  :root { --gutter: 1rem; }

  .masthead,
  .site-width > header {
    flex-direction: column;
    align-items: flex-start;
    gap: .4rem;
    padding-block: 1.75rem .75rem;
  }

  /* Stacked under the prompt, the nav starts at the same left edge. */
  .masthead__nav { justify-content: flex-start; }

  html:not(.eink) .space-switcher { position: static; }
  .masthead .main { position: relative; }

  .notebook-cover {
    grid-template-columns: 1fr;
    gap: 2rem;
    padding-block: 2rem;
  }

  .notebook-cover h1 { font-size: 1.4667rem; }
  .nole-ascii pre,
  html[data-theme="dark"] .nole-ascii pre { font-size: clamp(6px, 2.05vw, 9px); }
  .project-notes__groups { grid-template-columns: 1fr; gap: 1.25rem; }
  .notebook-index { margin-block-start: 2.25rem; }

  .notebook-entry,
  .posts .post {
    grid-template-columns: 1fr;
    gap: .15rem;
  }

  .notebook-entry__meta {
    flex-direction: row;
    gap: 2ch;
    line-height: 1.5;
  }

  .article-heading h1,
  .page-title { font-size: 1.3333rem; }

  .colophon__built { margin-inline-start: 0; }

  .gallery-albums { grid-template-columns: 1fr; gap: 2rem; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* The TOC launcher moves to the bottom-left so it never covers the nav. */
  .toc,
  html[data-theme="dark"] .toc {
    top: auto;
    bottom: 1.25rem;
    left: var(--gutter);
    right: auto;
    max-height: calc(100vh - 6rem);
  }
  .reading-progress__label,
  .back-to-top__label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tui-cursor { animation: none; }
  .back-to-top { transition: none; }
}

/* --- E-Ink -----------------------------------------------------------------
   eink-init.js adds html.eink and forces archie's palette variables to black
   and white; these rules repoint the tokens and strip motion and chrome. */

html.eink {
  --paper: #fff;
  --ink: #000;
  --text: #000;
  --muted: #000;
  --well: #fff;
  --rule: #000;
  --spot: #000;
  --spot-ink: #000;
}

html.eink,
html.eink body {
  background: #fff !important;
  color: #000 !important;
}

html.eink *,
html.eink *::before,
html.eink *::after {
  animation: none !important;
  transition: none !important;
}

html.eink .ascii-tide,
html.eink .shanshui,
html.eink .reading-progress,
html.eink .back-to-top,
html.eink .tui-cursor,
html.eink #dark-mode-toggle,
html.eink .tui-prompt__caret,
html.eink .space-switcher__menu,
html.eink .mermaid-fullscreen,
html.eink .gallery-item__caption,
html.eink .gallery-lightbox {
  display: none !important;
}

html.eink .space-switcher[open] > .space-switcher__menu { display: none !important; }

html.eink .highlight,
html.eink pre,
html.eink code {
  background: #fff !important;
  color: #000 !important;
  border-color: #000 !important;
  box-shadow: none !important;
}

html.eink pre { border: 1px solid #000 !important; }
html.eink .highlight { overflow: visible; }
html.eink .highlight pre code[class*="language-"]::before { display: none !important; }

html.eink ::selection,
html.eink *::selection {
  background: #000 !important;
  color: #fff !important;
}

html.eink .chroma span {
  color: inherit !important;
  background: transparent !important;
  font-weight: inherit !important;
  font-style: inherit !important;
}

html.eink img,
html.eink .mermaid svg { filter: grayscale(1); }

html.eink .ann::before,
html.eink .ann::after { display: none !important; }

html.eink .ann,
html.eink .ann-n,
html.eink .ann-ne,
html.eink .ann-nw,
html.eink .ann-s,
html.eink .ann-se,
html.eink .ann-sw,
html.eink .ann-e,
html.eink .ann-w {
  margin: 0 !important;
}

html.eink .ann {
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  border-radius: 0;
  border-bottom: 1px dashed #000;
}

/* E-Ink paged reader. eink-reader.js sizes article.post to the space left
   under the masthead, lays it out as one viewport-wide CSS column per page
   and turns pages by setting scrollLeft; the container must clip so the
   following columns never bleed into view. Page turns replace scrolling, so
   the document itself is locked and the fixed chrome (TOC, footer) goes. */
html.eink.eink-reader-enabled,
html.eink.eink-reader-enabled body {
  height: 100%;
  overflow: hidden;
}

/* The masthead keeps its normal geometry: compacting it only in reader mode
   made the header jump when moving between paged and unpaged pages. */
html.eink.eink-reader-enabled main { padding-bottom: 0; margin-bottom: 0; }
html.eink.eink-reader-enabled .colophon { display: none !important; }

/* The TOC is a fixed overlay on screens; on E-Ink it never floats. The reader
   moves it under the title as a contents page, without the hide toggle. */
html.eink .toc,
html.eink .toc.is-collapsed,
html.eink[data-theme] .toc {
  position: static;
  inset: auto;
  width: auto;
  max-width: none;
  max-height: none;
  overflow: visible;
  display: block;
  block-size: auto;
  margin: 1.5rem 0 2rem;
  padding: 0 0 1rem;
  border: 0;
  border-bottom: 1px dotted #000;
  background: #fff;
  box-shadow: none;
}
html.eink .toc__toggle { display: none; }
html.eink .toc.is-collapsed .toc__content,
html.eink .toc.is-collapsed .toc__header > strong { display: block; }
html.eink .toc .toc__header { margin: 0 0 .5rem; }
html.eink .toc a { color: #000; }
html.eink .toc a[aria-current="location"]::before { content: none; }

html.eink .eink-reader__pages {
  width: 100%;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  column-fill: auto;
}

/* Inside the paged view the article is a plain block flow: no grid/flex
   container may stretch past a single column. */
html.eink .eink-reader__pages .post-container,
html.eink .eink-reader__pages .post-content {
  display: block;
  width: auto;
  max-width: none;
  margin: 0;
}

/* Headings, media and table rows stay whole; code, tables and quotes are
   allowed to run on to the next page, as in print. */
html.eink .eink-reader__pages :is(.article-heading, img, video, iframe, tr, li.post) {
  break-inside: avoid;
}

html.eink .eink-reader__pages :is(h1, h2, h3, h4, h5, h6) { break-after: avoid; }

/* Nothing may scroll sideways inside a page: wrap code, let tables shrink. */
html.eink .eink-reader__pages :is(pre, .highlight, table, .table-wrap) {
  max-height: none !important;
  overflow: visible !important;
}
html.eink .eink-reader__pages pre,
html.eink .eink-reader__pages pre code {
  white-space: pre-wrap !important;
  overflow-wrap: anywhere;
}
html.eink .eink-reader__pages .chroma .line { display: block; }
html.eink .eink-reader__pages table { display: table; width: 100%; table-layout: auto; }
html.eink .eink-reader__pages :is(td, th) { overflow-wrap: anywhere; }
html.eink .eink-reader__pages img { object-fit: contain; }
html.eink .eink-reader__pages .mermaid-figure { left: auto; transform: none; margin-inline: 0; width: auto; }

/* Page controls: one ruled line, text buttons, the page count centred. */
html.eink .eink-reader {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  width: 100%;
  min-height: 3rem;
  margin: 0;
  border-top: 1px solid #000;
  font: inherit;
  font-size: 1rem;
  color: #000;
}

html.eink .eink-reader__button {
  min-height: 3rem;
  padding: 0 1ch;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: #000;
  font: inherit;
  cursor: pointer;
}
html.eink .eink-reader__button--previous { text-align: left; }
html.eink .eink-reader__button--next { text-align: right; }
html.eink .eink-reader__button:focus-visible { outline: 2px solid #000; outline-offset: -4px; }
html.eink .eink-reader__button:active:not(:disabled) { background: #000; color: #fff; }
html.eink .eink-reader__button:disabled { cursor: default; color: #000; opacity: 1; text-decoration: line-through; }

html.eink .eink-reader__status {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 2ch;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Footer E-Ink / Web mode entries: show the relevant one for the mode. */
.eink-web-mode-entry { display: none; }
html.eink .eink-mode-entry { display: none; }
html.eink .eink-web-mode-entry { display: inline; }
