/*
  chalk.css — blackboard theme for the Knowledge Hub.

  Load after style.css. Opt-in: every rule is scoped to <body class="theme-chalk">,
  so removing that class restores the old look.

  Palette and fonts are tokens on body.theme-chalk. style.css already reads its
  colours from tokens (--hue-1, --ink-*, --bg-*), so most of the page follows the
  token block; the rules below only add what tokens cannot: hatching, rough chalk
  outlines, the wood tray, and the reader components (crumbs, contents, page info,
  topic navbox, reading bar).

  Article body copy stays in --f-wiki (system sans) on purpose: long reading in a
  handwriting face is tiring. Point --f-wiki at Schoolbell to try it.
*/
@import url("https://fonts.googleapis.com/css2?family=Schoolbell&family=Walter+Turncoat&display=swap");

html:has(> body.theme-chalk) {
  background: oklch(.22 .02 175);
  scrollbar-color: oklch(.94 .012 95 / .3) transparent;
}

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

body.theme-chalk {
  --chalk: oklch(.94 .012 95);
  --chalk-dim: oklch(.88 .012 95);
  --blue: oklch(.84 .11 235);
  --yellow: oklch(.84 .11 95);
  --green: oklch(.84 .11 160);
  --pink: oklch(.84 .11 350);
  --orange: oklch(.82 .12 60);
  --coral: oklch(.8 .12 30);
  --slate: oklch(.27 .022 175);
  --slate-deep: oklch(.21 .02 175);
  --wood-hi: oklch(.52 .07 62);
  --wood: oklch(.42 .06 58);
  --wood-lo: oklch(.36 .05 56);
  --line-c: oklch(.94 .012 95 / .28);

  --accent: var(--blue);

  --bg-0: var(--slate-deep);
  --bg-1: var(--slate);
  --bg-2: oklch(.31 .024 175);
  --ink: var(--chalk);
  --ink-dim: var(--chalk-dim);
  --ink-mute: oklch(.74 .014 95);
  --ink-faint: oklch(.66 .014 95);
  --hue-1: var(--accent);
  --hue-1-soft: color-mix(in oklch, var(--accent) 45%, transparent);
  --hue-1-faint: color-mix(in oklch, var(--accent) 14%, transparent);
  --hue-2: oklch(.88 .045 240);
  --hue-2-soft: oklch(.88 .045 240 / .4);
  --hue-2-faint: oklch(.88 .045 240 / .1);
  --acid: var(--green);
  --acid-soft: oklch(.84 .11 160 / .45);
  --acid-faint: oklch(.84 .11 160 / .12);
  --warn: var(--coral);
  --warn-soft: oklch(.8 .12 30 / .45);
  --warn-faint: oklch(.8 .12 30 / .12);
  --border: oklch(.94 .012 95 / .22);
  --border-strong: oklch(.94 .012 95 / .5);
  --glass-1: transparent;
  --glass-2: oklch(.21 .02 175 / .5);
  --glass-blur: none;
  --code-num: var(--yellow);
  --code-fn: var(--pink);

  --f-pixel: "Schoolbell", "Segoe Print", "Comic Sans MS", cursive;
  --f-tiny: "Schoolbell", "Segoe Print", "Comic Sans MS", cursive;
  --f-display: "Walter Turncoat", "Schoolbell", "Segoe Print", cursive;

  /* devices */
  --hatch: repeating-linear-gradient(-45deg, color-mix(in oklch, var(--accent) 26%, transparent) 0 2px, transparent 2px 6px);
  --squig: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='4'%3E%3Cpath d='M0 2Q2.5 .3 5 2T10 2' fill='none' stroke='%23e2cd78' stroke-width='1.4'/%3E%3C/svg%3E");
  --rough: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='r' x='-10%25' y='-10%25' width='120%25' height='120%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.045' numOctaves='2' seed='4' result='n'/%3E%3CfeDisplacementMap in='SourceGraphic' in2='n' scale='3.5' xChannelSelector='R' yChannelSelector='G'/%3E%3C/filter%3E%3C/svg%3E#r");

  background:
    radial-gradient(ellipse 55% 38% at 14% 6%, oklch(.94 .012 95 / .07), transparent 62%),
    radial-gradient(ellipse 45% 30% at 88% 92%, oklch(.94 .012 95 / .05), transparent 65%),
    linear-gradient(104deg, transparent 22%, oklch(.94 .012 95 / .03) 30%, transparent 42%),
    linear-gradient(97deg, transparent 58%, oklch(.94 .012 95 / .025) 66%, transparent 78%),
    var(--bg-1);
  text-shadow: 0 0 8px oklch(.94 .012 95 / .06);
}

/* the archive keeps its own colour: yellow chalk instead of blue */
body.theme-chalk.archive-page { --accent: var(--yellow); }

.theme-chalk ::selection { background: oklch(.84 .11 95 / .35); color: var(--chalk); }
.theme-chalk :focus-visible { outline: 2px dashed var(--yellow); outline-offset: 3px; }
.theme-chalk .bg-grid,
.theme-chalk .bg-glow { display: none; }
.theme-chalk .vignette { opacity: .06; }

/* ---------------------------------------------------------------- header -- */

.theme-chalk .brand-word {
  display: inline-block;
  position: relative;
  padding-bottom: 7px;
  font-family: var(--f-display);
  font-size: 26px;
  font-weight: 400;
  letter-spacing: 4px;
  white-space: nowrap;
  color: var(--chalk);
}
.theme-chalk .brand-word::after {
  content: "";
  position: absolute;
  left: 0;
  right: 10%;
  bottom: 0;
  height: 4px;
  background: var(--squig) repeat-x 0 0 / 10px 4px;
}
.theme-chalk .brand-sub { color: var(--ink-mute); }
.theme-chalk .brand-name { animation: none; }
.theme-chalk .topbar-left .auth-link {
  font-family: var(--f-pixel);
  font-size: 14px;
  letter-spacing: .4px;
  text-transform: lowercase;
  white-space: nowrap;
  color: var(--ink-dim);
  background: transparent;
}
.theme-chalk .topbar-left .auth-link:hover { color: var(--chalk); background: var(--hatch); --bc: var(--accent); }
.theme-chalk .date-block { color: var(--chalk); }
.theme-chalk .date-year { color: var(--chalk-dim); }
.theme-chalk .clock-frame { background: var(--slate-deep); border-color: var(--line-c); backdrop-filter: none; -webkit-backdrop-filter: none; }
.theme-chalk .clock { color: var(--chalk); }

/* ------------------------------------------------- rough chalk outlines -- */
/* The real border goes transparent; a filtered pseudo-element draws the line.
   Browsers without url() filters just show a clean outline. */

.theme-chalk :is(.frame, .wiki-nav, .wiki-info, .wiki-toc, .wiki-navbox, .dl-btn, .back-btn, .auth-link) {
  border-color: transparent;
}
.theme-chalk :is(.frame, .wiki-info, .wiki-toc, .wiki-navbox, .dl-btn, .back-btn, .auth-link) { position: relative; }
.theme-chalk :is(.dl-btn, .back-btn) { display: inline-block; }
.theme-chalk :is(.frame, .wiki-nav, .wiki-info, .wiki-toc, .wiki-navbox, .dl-btn, .back-btn, .auth-link)::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--bc, var(--border-strong));
  pointer-events: none;
  filter: var(--rough);
}

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

.theme-chalk .frame {
  background: transparent;
  box-shadow: none;
  padding: 22px 26px;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.theme-chalk .frame::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid var(--line-c);
  pointer-events: none;
}
.theme-chalk .frame-tag {
  flex-wrap: wrap;
  row-gap: 8px;
  font-family: var(--f-display);
  font-size: 16px;
  font-weight: 400;
  letter-spacing: .5px;
  text-transform: none;
}
.theme-chalk .frame-aux { font-family: var(--f-pixel); color: var(--ink-mute); }

/* --------------------------------------------------------------- buttons -- */

.theme-chalk .back-btn {
  padding: 4px 12px;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--f-pixel);
  font-size: 14px;
}
.theme-chalk .back-btn:hover { background: var(--hatch); color: var(--chalk); transform: none; --bc: var(--accent); }
.theme-chalk .dl-btn {
  --bc: var(--accent);
  padding: 4px 12px;
  background: transparent;
  color: var(--accent);
  font-family: var(--f-pixel);
  font-size: 14px;
  letter-spacing: .3px;
}
.theme-chalk .dl-btn:hover { background: var(--hatch); color: var(--chalk); transform: none; box-shadow: none; }
.theme-chalk .wiki-af-acts .dl-btn {
  --bc: var(--yellow);
  color: oklch(.24 .02 175);
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 3px, oklch(.8 .11 95) 3px 5px);
  text-shadow: none;
}
.theme-chalk .wiki-af-acts .dl-btn:hover { color: oklch(.24 .02 175); filter: brightness(1.08); }

/* ------------------------------------------------------------------ nav -- */

.theme-chalk .wiki-nav {
  padding: 12px 14px;
  background: oklch(.2 .02 175 / .35);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.theme-chalk .wiki-nav .wiki-home-link {
  font-family: var(--f-display);
  font-size: 19px;
  font-weight: 400;
  color: var(--chalk);
  border-bottom: 3px double var(--line-c);
}
.theme-chalk .wiki-nav .wiki-home-link.active,
.theme-chalk .wiki-nav .wiki-home-link:hover { color: var(--yellow); }
.theme-chalk .wiki-nav details { border-bottom: 1px dashed var(--line-c); }
.theme-chalk .wiki-nav summary { font-family: var(--f-display); font-size: 16px; letter-spacing: 1px; color: var(--chalk-dim); }
.theme-chalk .wiki-nav summary::before { color: var(--accent); }
.theme-chalk .wiki-nav .wiki-grp > summary { font-family: var(--f-pixel); color: var(--ink-mute); }
.theme-chalk .wiki-nav a { font-size: 15px; letter-spacing: .2px; color: var(--ink-dim); }
.theme-chalk .wiki-nav a::after { background: var(--yellow); }
.theme-chalk .wiki-nav a:hover { color: var(--yellow); }
.theme-chalk .wiki-nav a.active { color: var(--chalk); background: var(--hatch); border-left-color: var(--accent); }
.theme-chalk .wiki-layout.is-solo { grid-template-columns: minmax(0, 1fr); }
.theme-chalk .wiki-layout.is-solo .wiki-nav { display: none; }

/* read marks written by reader.js */
.theme-chalk .wiki-nav a.is-read::before { content: "✓"; position: absolute; left: 3px; top: 3px; font-size: 12px; color: var(--green); }
.theme-chalk .wiki-nav a.is-part::before { content: "•"; position: absolute; left: 5px; top: 3px; font-size: 13px; color: var(--yellow); }
.theme-chalk .wiki-nav .rd-count { float: right; font-family: var(--f-mono); font-size: 11px; letter-spacing: 0; color: var(--ink-mute); }

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

#wiki-doc::after { content: ""; display: table; clear: both; }

.theme-chalk .wiki-article .wiki-title {
  margin: 2px 0 10px;
  padding-bottom: 10px;
  font-family: var(--f-display);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.18;
  color: var(--chalk);
  border-bottom: 3px double var(--line-c);
}
.theme-chalk .wiki-article .wiki-desc {
  padding-bottom: 0;
  border-bottom: 0;
  font-family: var(--f-pixel);
  font-size: 18px;
  letter-spacing: .2px;
  color: var(--ink-mute);
}
.theme-chalk .sub-panes :is(h2, h3, h4) { font-family: var(--f-display); font-weight: 400; letter-spacing: .3px; }
.theme-chalk .sub-panes h2 { margin-top: 28px; padding-bottom: 4px; font-size: 28px; color: var(--chalk); border-bottom: 3px double var(--line-c); }
.theme-chalk .sub-panes h3 { font-size: 22px; color: var(--accent); }
.theme-chalk .sub-panes h4 { color: var(--yellow); }
.theme-chalk .sub-panes a { color: var(--accent); text-decoration: underline dotted; text-underline-offset: 3px; }
.theme-chalk .sub-panes a:hover { color: var(--yellow); }
.theme-chalk .sub-panes .back-btn,
.theme-chalk .sub-panes .dl-btn { text-decoration: none; }
.theme-chalk .sub-panes strong { color: var(--chalk); }
.theme-chalk .sub-panes :is(code, pre) { background: var(--slate-deep); border-color: var(--line-c); color: var(--hue-2); }
.theme-chalk .sub-panes pre { padding: 12px 14px; border-width: 1.5px; }
.theme-chalk .wiki-article img { border-color: var(--line-c); }
.theme-chalk .wiki-article th { background: oklch(.94 .012 95 / .06); }
.theme-chalk .wiki-article kbd { border-color: var(--line-c); background: var(--slate-deep); color: var(--chalk-dim); }
.theme-chalk .gx-empty { color: var(--yellow); }
.theme-chalk .gx-empty code { background: var(--slate-deep); }

/* callouts: one colour per kind, hatched ground, outlined label */
.theme-chalk .sub-panes :is(.tldr, .tryit, .checkpoint, .challenge, .project, .note, .danger, .tip, .caution) {
  border-left: 4px solid var(--cc);
  border-radius: 0;
  background: repeating-linear-gradient(-45deg, color-mix(in oklch, var(--cc) 13%, transparent) 0 2px, transparent 2px 8px);
  box-shadow: none;
}
.theme-chalk .sub-panes :is(.tldr, .tryit, .checkpoint, .challenge, .project, .note, .danger, .tip, .caution)::before {
  background: transparent;
  color: var(--cc);
  border: 1.5px solid var(--cc);
  font-family: var(--f-pixel);
  letter-spacing: 1.5px;
  text-shadow: none;
  animation: none;
}
.theme-chalk .sub-panes .tldr { --cc: var(--chalk); }
.theme-chalk .sub-panes .tryit { --cc: var(--yellow); }
.theme-chalk .sub-panes .checkpoint,
.theme-chalk .sub-panes .tip { --cc: var(--green); }
.theme-chalk .sub-panes .challenge,
.theme-chalk .sub-panes .project { --cc: var(--accent); }
.theme-chalk .sub-panes .note { --cc: var(--hue-2); }
.theme-chalk .sub-panes .danger { --cc: var(--coral); }
.theme-chalk .sub-panes .caution { --cc: var(--orange); }

.theme-chalk .wiki-steps > ol > li::before { background: var(--yellow); color: oklch(.24 .02 175); font-family: var(--f-pixel); }
.theme-chalk .wiki-steps > ol > li::after { background: var(--line-c); }
.theme-chalk :is(.wiki-filetree, .wiki-tabs) { background: transparent; border-color: var(--line-c); backdrop-filter: none; -webkit-backdrop-filter: none; }
.theme-chalk .wiki-tabbar button { font-family: var(--f-pixel); border-color: var(--line-c); }
.theme-chalk .wiki-tabbar button:hover { color: var(--yellow); border-color: var(--yellow); transform: none; }
.theme-chalk .wiki-tabbar button.active { color: var(--chalk); background: var(--hatch); border-color: var(--accent); box-shadow: none; }

.theme-chalk .wiki-pagenav { clear: both; border-top: 3px double var(--line-c); }
.theme-chalk .wiki-pagenav .wiki-pn-label { font-family: var(--f-pixel); color: var(--ink-mute); }
.theme-chalk .wiki-pagenav .wiki-pn-title { font-family: var(--f-display); font-size: 16px; text-transform: none; color: var(--accent); }
.theme-chalk .wiki-pagenav a:hover .wiki-pn-title { color: var(--yellow); }

/* ------------------------------------------------------------------ form -- */

.theme-chalk .wiki-af-label { font-family: var(--f-pixel); letter-spacing: .5px; color: var(--ink-mute); }
.theme-chalk .wiki-af-input {
  background: var(--slate-deep);
  border: 1.5px solid var(--line-c);
  color: var(--chalk);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.theme-chalk .wiki-af-input:focus { border-color: var(--yellow); box-shadow: 0 0 0 1px oklch(.84 .11 95 / .3); }

/* --------------------------------------------------------- reader pieces -- */

.theme-chalk .wiki-crumbs {
  flex: 1 1 320px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-family: var(--f-pixel);
  font-size: 16px;
  font-weight: 400;
  letter-spacing: .2px;
}
.theme-chalk .wiki-crumbs a { color: var(--accent); text-decoration: underline dotted; text-underline-offset: 3px; white-space: nowrap; }
.theme-chalk .wiki-crumbs a:hover { color: var(--yellow); }
.theme-chalk .wiki-crumbs .sep { color: var(--ink-faint); }
.theme-chalk .wiki-crumb-here { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--chalk); }
.theme-chalk .wiki-tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.theme-chalk .wiki-tools .dl-btn { margin-left: 0; }

.theme-chalk .wiki-hatnote {
  margin: 0 0 12px;
  font-family: var(--f-pixel);
  font-size: 16px;
  font-style: italic;
  color: var(--ink-mute);
}

.theme-chalk .wiki-info {
  float: right;
  width: 250px;
  margin: 6px 0 16px 24px;
  background: oklch(.21 .02 175 / .45);
}
.theme-chalk .wiki-info-h {
  padding: 6px 12px;
  font-family: var(--f-display);
  font-size: 17px;
  color: var(--chalk);
  background: var(--hatch);
  border-bottom: 1.5px solid var(--line-c);
}
.theme-chalk .wiki-info dl {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0;
  padding: 10px 12px 12px;
  font-family: var(--f-pixel);
  font-size: 15px;
}
.theme-chalk .wiki-info dt { color: var(--ink-mute); }
.theme-chalk .wiki-info dd { margin: 0; color: var(--chalk); }

/* flow-root: a block box would slide under the floated info box; this one sits beside it or drops below */
.theme-chalk .wiki-toc { display: flow-root; max-width: 360px; margin: 12px 0 20px; padding: 10px 16px 12px; background: oklch(.94 .012 95 / .04); }
.theme-chalk .wiki-toc[hidden] { display: none; }
.theme-chalk .wiki-toc-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-family: var(--f-display); font-size: 18px; color: var(--chalk); }
.theme-chalk .wiki-toc-toggle { padding: 0; background: none; border: 0; cursor: pointer; font-family: var(--f-pixel); font-size: 14px; color: var(--ink-mute); }
.theme-chalk .wiki-toc-toggle:hover { color: var(--yellow); }
.theme-chalk .wiki-toc ol { margin: 0; padding: 0; list-style: none; }
.theme-chalk .wiki-toc li { margin: 0; padding: 2px 0; font-family: var(--f-pixel); font-size: 16px; line-height: 1.35; }
.theme-chalk .wiki-toc li.l3 { padding-left: 18px; }
.theme-chalk .wiki-toc a { color: var(--chalk-dim); text-decoration: none; }
.theme-chalk .wiki-toc a:hover { color: var(--yellow); }
.theme-chalk .wiki-toc .n { display: inline-block; min-width: 2.2em; color: var(--ink-mute); }

.theme-chalk .wiki-navbox { clear: both; margin: 30px 0 8px; padding: 12px 18px 14px; background: oklch(.94 .012 95 / .035); }
.theme-chalk .wiki-navbox-h { margin-bottom: 6px; font-family: var(--f-display); font-size: 18px; color: var(--accent); }
/* inline flow, not flex: long titles wrap like a sentence, separators follow the text */
.theme-chalk .wiki-navbox ol { margin: 0; padding: 0; list-style: none; line-height: 1.7; }
.theme-chalk .wiki-navbox li { display: inline; margin: 0; font-family: var(--f-pixel); font-size: 16px; line-height: 1.7; }
.theme-chalk .wiki-navbox li:not(:last-child)::after { content: "·"; margin: 0 8px; color: var(--ink-faint); }
.theme-chalk .wiki-navbox a { text-decoration: none; }
.theme-chalk .wiki-navbox a[aria-current] { padding: 0 6px; color: var(--chalk); background: var(--hatch); }
.theme-chalk .wiki-navbox a.is-read::before { content: "✓ "; color: var(--green); }
.theme-chalk .wiki-navbox a.is-part::before { content: "• "; color: var(--yellow); }
.theme-chalk .wiki-navbox-other { margin: 8px 0 0; font-family: var(--f-pixel); font-size: 14px; color: var(--ink-mute); }
.theme-chalk .sub-panes .wiki-navbox li,
.theme-chalk .sub-panes .wiki-navbox-other { font-size: 16px; }

.theme-chalk .wiki-anchor { margin-left: 10px; font-size: .7em; color: var(--ink-faint); text-decoration: none; opacity: 0; }
.theme-chalk :is(h2, h3):hover > .wiki-anchor,
.theme-chalk .wiki-anchor:focus-visible { opacity: 1; }

.theme-chalk .wiki-code { position: relative; }
.theme-chalk .wiki-copy {
  position: absolute;
  top: 10px;
  right: 8px;
  padding: 1px 9px;
  background: var(--slate-deep);
  border: 1.5px solid var(--line-c);
  color: var(--ink-mute);
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: .06em;
  cursor: pointer;
}
.theme-chalk .wiki-copy:hover { color: var(--yellow); border-color: var(--yellow); }

.theme-chalk .read-progress { position: fixed; z-index: 60; top: 0; left: 0; right: 0; height: 5px; pointer-events: none; }
.theme-chalk .read-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 2px, transparent 2px 5px);
  border-bottom: 2px solid var(--accent);
  transition: width .12s linear;
}

/* -------------------------------------------------------- footer as tray -- */

.theme-chalk .statusbar {
  height: 10px;
  padding: 0;
  background: linear-gradient(var(--wood-hi), var(--wood) 45%, var(--wood-lo));
  border-top: 2px solid oklch(.6 .07 65);
}

@media (max-width: 900px) {
  .theme-chalk .wiki-info { float: none; width: auto; margin: 0 0 16px; }
  .theme-chalk .wiki-toc { max-width: none; }
}
@media (max-width: 720px) {
  .theme-chalk .frame { padding: 18px 16px; }
}

/* --------------------------------------------------- readability override --
   Handwriting face is for titles and short labels only (headings, summaries,
   Contents heading, portfolio/sign in, download md, copy link). Anything read
   or scanned for navigation - TOC entries, sidebar page links, the prev/next
   box, the page description - stays in --f-wiki (system sans). */
.theme-chalk .wiki-toc li,
.theme-chalk .wiki-toc a,
.theme-chalk .wiki-nav a,
.theme-chalk .wiki-navbox li,
.theme-chalk .wiki-navbox a,
.theme-chalk .wiki-navbox-other,
.theme-chalk .wiki-article .wiki-desc,
.theme-chalk .wiki-pagenav .wiki-pn-title { font-family: var(--f-wiki); }
