/* A note: header (meta, title, discreet tags, lead) and the rendered Markdown body. */

.note header { max-width: 34rem; margin-top: 30px; }
.note__meta { margin: 0; color: var(--paper-muted); font: .8rem var(--f-ui); }
.note__meta a { text-decoration: none; }
.note__meta a:hover { text-decoration: underline; }
.note h1 { max-width: 18em; margin: 8px 0 10px; font-size: 2.3rem; line-height: 1.1; }

/* Discreet tags: a small square of the tag colour and its name, no chip. */
.note__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  font: .8rem var(--f-ui);
}
.note__tags .tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  background: none;
  color: var(--paper-muted);
  font: inherit;
}
.note__tags .tag::before { content: ""; width: .6em; height: .6em; border-radius: 2px; background: var(--tag); }
.note__tags .tag:hover { color: var(--paper-ink); }

/* The description, on a post-it stuck under the title, so it never reads as the first paragraph.
   As wide as the text column: the header sets it. */
.note__lead {
  position: relative;
  box-sizing: border-box;
  margin: 1.6em 0 .6em;
  padding: 16px 20px 18px;
  rotate: -1.6deg;
  background: var(--postit);
  color: var(--postit-ink);
  box-shadow: 0 14px 16px -10px rgba(0, 0, 0, .4);
  font: 500 1.02rem/1.4 var(--f-hand);
}
.note__lead::before {
  content: "";
  position: absolute;
  top: -11px;
  left: 38%;
  width: 80px;
  height: 22px;
  rotate: 3deg;
  background: rgba(255, 255, 255, .45);
}

.note__body > * { max-width: 34rem; }
.note__body h2 { margin: 1.8em 0 .1em; font-size: 1.45rem; }
.note__body h3 { margin: 1.5em 0 .1em; font-size: 1.15rem; }
.note__body p { margin: .8em 0 0; }
/* Links: blue underline, so they never read as a red pen highlight. */
.note__body a { text-decoration-color: var(--accent); text-decoration-thickness: .08em; text-underline-offset: .15em; }

/* ==Highlight== is a pen stroke under the text; **bold** is circled in pen (short terms only). */
.note__body mark {
  background: none;
  color: inherit;
  text-decoration: underline var(--pen) .13em;
  text-underline-offset: .22em;
  text-decoration-skip-ink: none;
}
.note__body strong {
  padding: 0 .25em;
  border: .1em solid var(--pen);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  font-weight: 600;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.note__body code { padding: .1em .3em; border-radius: 4px; background: var(--code-bg); font: .85em var(--f-mono); }

/* Code blocks: Dracula colours come inline from the highlighter; the language sits top right. */
.note__body pre {
  position: relative;
  margin: 1.1em 0 0;
  padding: 16px 18px 14px;
  overflow-x: auto;
  border-radius: 8px;
  box-shadow: 0 6px 14px -8px rgba(0, 0, 0, .5);
  font: .8rem/1.65 var(--f-mono);
}
.note__body pre code { padding: 0; background: none; font: inherit; }
/* A diagram is drawn on the page, not a block laid on it. */
.note__body pre[lang="mermaid"] { box-shadow: none; }
.note__body pre[lang]:not([lang="mermaid"])::before {
  content: attr(lang);
  position: absolute;
  top: 8px;
  right: 12px;
  color: #6272a4;
  font-size: .68rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

@media (max-width: 640px) {
  .note h1 { font-size: 1.75rem; }
}

/* Table of contents, written in pencil in the left margin and kept in view while reading. */
.note__body h2 { scroll-margin-top: 24px; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

.toc { color: var(--paper-muted); font-size: .95rem; }
.toc__toggle { display: none; }
.toc__title { margin-bottom: 8px; }
.toc__list { display: grid; gap: .4em; margin: 0; padding: 0; list-style: none; }
.toc__list a { display: block; position: relative; padding-left: 20px; line-height: 1.3; text-decoration: none; }
.toc__list a:hover { color: var(--paper-ink); }
.toc__list a[aria-current] { color: var(--paper-ink); }
.toc__list a[aria-current]::before { content: "→"; position: absolute; left: 0; color: var(--pen); font-weight: 700; }

@media (min-width: 981px) {
  .note:has(.toc) { display: grid; grid-template-columns: 150px minmax(0, 1fr); column-gap: 36px; }
  .note:has(.toc) > :not(.toc) { grid-column: 2; }
  .toc { position: sticky; top: 24px; grid-row: 1 / span 2; align-self: start; padding-top: 6.4em; }
}

/* Narrow screens: a "Contents" post-it in the bottom right corner, unfolded on tap. */
@media (max-width: 980px) {
  .toc { position: fixed; right: 16px; bottom: 16px; z-index: 3; }
  .toc__title { display: none; }
  .toc__toggle {
    display: block;
    padding: 10px 14px;
    border: 0;
    rotate: -3deg;
    background: var(--postit);
    color: var(--postit-ink);
    box-shadow: 0 10px 10px -7px rgba(0, 0, 0, .45);
    font: inherit;
    cursor: pointer;
  }
  .toc__list {
    display: none;
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    width: 250px;
    max-width: calc(100vw - 32px);
    box-sizing: border-box;
    padding: 18px 16px;
    rotate: -1.5deg;
    background: var(--postit);
    color: var(--postit-ink);
    box-shadow: 0 14px 18px -8px rgba(0, 0, 0, .5);
    font-size: 1rem;
  }
  .toc--open .toc__list { display: grid; }
  .toc__list a { display: inline-block; padding: 0 4px; border: 2px solid transparent; }
  .toc__list a:hover, .toc__list a[aria-current] { color: inherit; }
  .toc__list a[aria-current] { border-color: var(--pen); border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px; }
  .toc__list a[aria-current]::before { content: none; }
}

/* Footnotes: the call is a red number; the note is written in pen in the right margin, next to its paragraph. */
.note__body sup { color: var(--pen); font: 700 .7em var(--f-ui); }
.note__body sup a { color: inherit; text-decoration: none; }

.annotation { scroll-margin-top: 24px; color: var(--pen); font-size: .95rem; line-height: 1.35; }
.note__body .annotation p { margin: 0; }
.note__body .annotation p + p { margin-top: .4em; }

@media (min-width: 981px) {
  .note__body:has(.annotation) { display: grid; grid-template-columns: minmax(0, 34rem) minmax(0, 190px); column-gap: 36px; align-items: start; }
  .note__body:has(.annotation) > * { grid-column: 1; }
  .note__body > .annotation { grid-column: 2; margin-top: 1.1em; rotate: -1.5deg; }
  /* The header follows the text column, which the margin notes narrow. */
  .note:has(.annotation) header { max-width: min(34rem, 100% - 190px - 36px); }
}

/* Narrow screens: the note goes under its paragraph, with a red line in the margin. */
@media (max-width: 980px) {
  .annotation { margin-top: .7em; padding-left: 10px; border-left: 3px solid var(--pen); }
}

/* Images and GIFs in a note: within the text column, slightly rounded. */
.note__body img { display: block; max-width: 100%; height: auto; margin: 1.1em 0 0; border-radius: 6px; }

/* A drawn diagram opens full screen on click (mermaid_controller.js). */
.note__body pre[lang="mermaid"][role="button"] { cursor: zoom-in; }
.diagram-zoom {
  box-sizing: border-box;
  width: min(96vw, 1400px);
  max-width: none;
  max-height: 92vh;
  padding: 28px;
  border: 0;
  border-radius: 6px;
  background-color: var(--paper);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1.4px);
  background-size: 20px 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
  cursor: zoom-out;
}
.diagram-zoom::backdrop { background: rgba(20, 14, 8, .6); }
.diagram-zoom svg { display: block; width: 100%; height: auto; max-height: calc(92vh - 56px); }
/* Phones: the diagram keeps a readable width, and the dialog scrolls across it. */
@media (max-width: 640px) {
  .diagram-zoom { padding: 18px; overflow: auto; }
  .diagram-zoom svg { width: 760px; max-height: none; }
}

/* Tables: small UI type, ruled like a ledger; they scroll sideways on phones rather than squeeze. */
.note__body table { display: block; overflow-x: auto; margin: 1.3em 0 0; border-collapse: collapse; font: .8rem/1.45 var(--f-ui); }
.note__body th,
.note__body td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--dot); text-align: left; vertical-align: top; }
.note__body th { border-bottom: 2px solid var(--paper-ink); font-weight: 700; white-space: nowrap; }
.note__body td:first-child { font-weight: 700; }

/* Diagrams: `class X accent` marks a node. --mark is a post-it by day; at night the yellow would
   sit under light text, so the node is drawn in red pen instead (application.css).
   A hand-drawn node is two paths: its hatched fill, then its outline (path + path). */
:is(.note__body pre[lang="mermaid"], .diagram-zoom) .rough-node.accent path:first-child { stroke: var(--mark); }
:is(.note__body pre[lang="mermaid"], .diagram-zoom) .rough-node.accent path + path { stroke: var(--mark-ink); }
/* !important: Mermaid scopes its own label colour under the diagram's #id. */
:is(.note__body pre[lang="mermaid"], .diagram-zoom) .rough-node.accent .nodeLabel { color: var(--mark-ink) !important; font-weight: 700; }
