/* Open CKey source browser: syntax token colours, numbered code lines and rendered
   Markdown. See DESIGN.md. Every colour comes from the site palette in site.css (no blue);
   the few derived token colours are defined below and meet 4.5:1 on --raised, --stone,
   --stone-2 and --evergreen-tint (the highlighted line). test/code-render.test.js checks it.
   Page layout lives in code.css; this file owns .code-lines, .tok-* and .md-body only. */

.code-lines, .md-body {
  --tok-constant: oklch(0.48 0.12 45);   /* copper, between Oxblood and Amber */
  --tok-type: oklch(0.45 0.10 125);      /* moss, between Amber and Evergreen */
  --tok-function: oklch(0.44 0.12 330);  /* plum: the one hue not otherwise in use (still no blue) */
  --tok-string: oklch(0.47 0.12 150);    /* a brighter Evergreen, so strings stand apart from Ink text */
}

/* ---- Token classes (emitted by src/code/render.js) ---- */
.tok-comment { color: var(--ink-3); font-style: italic; }
.tok-keyword { color: var(--oxblood); font-weight: 600; }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--amber); }
.tok-constant { color: var(--tok-constant); }
.tok-function { color: var(--tok-function); }
.tok-type { color: var(--tok-type); font-weight: 600; }
.tok-variable { color: var(--ink); }
.tok-operator { color: var(--ink-2); }
.tok-punctuation { color: var(--ink-2); }
.tok-tag { color: var(--oxblood); }
.tok-attr { color: var(--amber); }
.tok-meta { color: var(--oxblood); }
.tok-inserted { color: var(--evergreen); background: var(--evergreen-tint); }
.tok-deleted { color: var(--oxblood); background: var(--oxblood-tint); }
.tok-heading { color: var(--ink); font-weight: 600; }
.tok-link { color: var(--evergreen); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.22em; }

/* ---- Numbered code lines ---- */
.code-lines {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  background: var(--raised);
  color: var(--ink);
  font: 0.875rem/1.6 var(--mono);
  font-variant-numeric: normal;
  tab-size: 4;
  -moz-tab-size: 4;
}
.code-lines td { padding: 0; vertical-align: top; border: 0; }
.code-lines .ln {
  width: 1%;
  min-width: 4ch;
  padding-inline: var(--s4) var(--s3);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  user-select: none;
  -webkit-user-select: none;
  scroll-margin-top: 112px;
}
.code-lines .ln a {
  display: block;
  color: var(--ink-3);
  text-decoration: none;
  border-radius: 3px;
}
.code-lines .ln a:focus-visible { outline-offset: 0; color: var(--ink); }
.code-lines .lc {
  padding-inline: var(--s3) var(--s4);
  white-space: pre;
  overflow-wrap: normal;
}
.code-lines .lc:empty::after { content: "\200b"; }
.code-lines tr:has(> .ln:target) > td { background: var(--evergreen-tint); }
.code-lines tr:has(> .ln:target) .ln a { color: var(--evergreen-deep); font-weight: 600; }
.code-lines tr > .ln:target { background: var(--evergreen-tint); }
.code-lines.is-wrapped .lc { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (hover: hover) and (pointer: fine) {
  .code-lines .ln a:hover { color: var(--ink); text-decoration: underline; }
}

/* ---- Rendered Markdown (src/code/render.js renderMarkdown, wrapped by the page) ---- */
.md-body { max-width: 72ch; color: var(--ink); font: 400 1rem/1.62 var(--sans); overflow-wrap: break-word; }
.md-body > * + * { margin-top: 1.05em; }
.md-body > :first-child { margin-top: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { position: relative; scroll-margin-top: 96px; }
.md-body h1, .md-body h2 { font-family: var(--serif); font-weight: 400; letter-spacing: -0.02em; }
.md-body h1 { font-size: clamp(1.9rem, 1.5rem + 1.6vw, 2.6rem); line-height: 1.12; margin-top: 1.6em; }
.md-body h2 { font-size: clamp(1.45rem, 1.25rem + 0.8vw, 1.85rem); line-height: 1.18; margin-top: 2em; padding-bottom: 0.25em; border-bottom: 1px solid var(--line); }
.md-body h3 { font: 600 1.125rem/1.35 var(--sans); margin-top: 1.8em; }
.md-body h4, .md-body h5, .md-body h6 { font: 600 1rem/1.4 var(--sans); margin-top: 1.6em; }
.md-body h6 { color: var(--ink-2); }
.md-body :is(h1, h2, h3, h4, h5, h6) + * { margin-top: 0.6em; }
.md-body .md-anchor { display: inline-flex; vertical-align: middle; margin-left: 0.35em; color: var(--ink-3); opacity: 0; transition: opacity var(--t-quick) ease; }
.md-body .md-anchor .icon { width: 0.8em; height: 0.8em; }
.md-body :is(h1, h2, h3, h4, h5, h6):hover .md-anchor, .md-body .md-anchor:focus-visible { opacity: 1; }
@media (hover: none) { .md-body .md-anchor { opacity: 1; } }
.md-body p, .md-body li { text-wrap: pretty; }
.md-body ul, .md-body ol { padding-left: 1.4em; }
.md-body li + li { margin-top: 0.35em; }
.md-body li > ul, .md-body li > ol { margin-top: 0.35em; }
.md-body li::marker { color: var(--ink-3); }
.md-body li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.4em; }
.md-body li > input[type="checkbox"] { margin: 0 0.5em 0 0; vertical-align: -0.1em; }
.md-body blockquote { margin-inline: 0; padding-left: var(--s4); border-left: 2px solid var(--line-strong); color: var(--ink-2); }
.md-body hr { margin: var(--s6) 0; }
.md-body img { display: inline-block; max-width: 100%; height: auto; vertical-align: middle; }
.md-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.md-body th { text-align: left; font: 600 0.8125rem/1.4 var(--sans); color: var(--ink-2); border-bottom: 1px solid var(--line-strong); padding: 8px 14px 8px 0; }
.md-body td { border-bottom: 1px solid var(--line); padding: 8px 14px 8px 0; vertical-align: top; }
.md-body th[align="center"], .md-body td[align="center"] { text-align: center; }
.md-body th[align="right"], .md-body td[align="right"] { text-align: right; }
.md-body code { font-family: var(--mono); font-size: 0.875em; background: var(--stone); border: 1px solid var(--line); border-radius: 4px; padding: 0.08em 0.36em; }
/* Fenced code: a light surface so the token colours keep their contrast (overrides .prose pre). */
.md-body pre.md-code { position: static; margin-inline: 0; background: var(--stone); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow-x: auto; font: 0.875rem/1.6 var(--mono); tab-size: 4; -moz-tab-size: 4; }
.md-body pre.md-code code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; white-space: pre; overflow-wrap: normal; }
.md-body .md-external-image { font-size: 0.875rem; }
.md-body .md-dropped-link { color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .md-body .md-anchor { transition: none; } }
