/* Markhound site. Two voices: the Markdown source (monospace, on the icon's apricot)
   and the finished page (serif, on white, like the dog's chest). No web fonts: the
   audience is on a Mac, so ui-serif is New York and ui-monospace is SF Mono. */

:root {
  --brindle: #231f1c;      /* text: the dog's coat */
  --chest: #ffffff;        /* the finished page */
  --apricot: #fbd6b2;      /* the source pane: the icon's background */
  --apricot-soft: #fdeedf; /* quiet fills */
  --marker: #8a4718;       /* Markdown syntax (#, ```, |): 7.4:1 on white */
  --muted: #5d544e;
  --rule: #e9d6c3;
  --focus: #2f5fd0;

  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: 36rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brindle: #f3ece6;
    --chest: #1c1917;
    --apricot: #3b2a1e;
    --apricot-soft: #2a211b;
    --marker: #f0a868;
    --muted: #bcb0a6;
    --rule: #43362c;
    --focus: #8fb0ff;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--chest);
  color: var(--brindle);
  font: 1.125rem/1.6 var(--serif);
  font-kerning: normal;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--marker); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 2px; }

.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; background: var(--chest); padding: 0.5rem 0.75rem; z-index: 2; }

/* ---------- top bar ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; font-size: 1.15rem; }
.brand img { width: 32px; height: 32px; }
.bar nav { display: flex; gap: 1.4rem; font-size: 1rem; }
.bar nav a { text-decoration: none; white-space: nowrap; }
@media (max-width: 480px) { .bar { flex-wrap: wrap; row-gap: 0.4rem; } .bar nav { flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.95rem; } }
.bar nav a[aria-current="page"] { text-decoration: underline; }

/* ---------- the split: source | page ---------- */

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: min(78vh, 44rem);
  border-bottom: 1px solid var(--rule);
}

.source {
  background: var(--apricot);
  padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1rem, 4vw, 3rem);
  font: 0.95rem/1.65 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
}
.source .m { color: var(--marker); }
.caret {
  display: inline-block;
  width: 0.55em;
  height: 1.15em;
  vertical-align: -0.2em;
  background: var(--brindle);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* The working editor (try.js): a transparent textarea over a highlighted copy, same metrics, so the
   Markdown markers keep their colour while you type. */
.editor { position: relative; padding: 0; }
.editor .hl, .editor textarea {
  margin: 0;
  padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1rem, 4vw, 3rem);
  font: inherit;
  letter-spacing: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
  border: 0;
}
.editor .hl { min-height: 100%; }
.editor textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  caret-color: var(--brindle);
  outline: none;
}
.editor textarea::selection { background: rgba(47, 95, 208, 0.25); color: transparent; }
.editor:focus-within { box-shadow: inset 0 0 0 2px var(--focus); }

.rendered .diagram { margin: 0 0 1.5rem; max-width: 100%; }
.rendered .diagram svg { max-width: 100%; height: auto; }
/* Diagram colours come from the page, so they follow light and dark mode live. */
.rendered .diagram .node rect, .rendered .diagram .node polygon, .rendered .diagram .node circle,
.rendered .diagram .node path { fill: var(--chest) !important; stroke: var(--brindle) !important; filter: none !important; }
.rendered .diagram .flowchart-link, .rendered .diagram .edgePath path { stroke: var(--brindle) !important; }
.rendered .diagram marker path, .rendered .diagram .arrowheadPath, .rendered .diagram .arrowMarkerPath { fill: var(--brindle) !important; stroke: var(--brindle) !important; }
.rendered .diagram .nodeLabel, .rendered .diagram .edgeLabel, .rendered .diagram text, .rendered .diagram span { color: var(--brindle) !important; fill: var(--brindle) !important; }
.rendered .diagram .edgeLabel, .rendered .diagram .labelBkg { background: var(--chest) !important; }
.rendered .diagram.broken { font-size: 1rem; color: var(--muted); }
.rendered .katex-display { font-size: 1.25rem; margin: 0 0 1.5rem; text-align: left; }
.rendered .katex-display > .katex { text-align: left; }
.rendered > h1 + p { font-size: 1.3rem; line-height: 1.45; margin: 0 0 1.75rem; max-width: 30ch; }
.rendered pre { font: 0.9rem/1.5 var(--mono); background: var(--apricot-soft); padding: 0.75rem 1rem; overflow-x: auto; }
.rendered code { font-family: var(--mono); font-size: 0.9em; }
.rendered img { max-width: 100%; }
@media (prefers-reduced-motion: reduce) { .caret { animation: none; } }

.page {
  padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1rem, 4vw, 3.5rem);
  max-width: 40rem;
}
.page h1 {
  font-size: clamp(2.6rem, 6vw, 4.2rem);
  line-height: 1.02;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
}
.page .lede { font-size: 1.3rem; line-height: 1.45; margin: 0 0 1.75rem; max-width: 30ch; }

.flow { display: block; width: 100%; max-width: 26rem; height: auto; margin: 0 0 1.5rem; }
.flow rect { fill: var(--chest); stroke: var(--brindle); stroke-width: 1.5; }
.flow text { fill: var(--brindle); font: 15px var(--serif); }
.flow path { stroke: var(--brindle); stroke-width: 1.5; fill: none; }
.flow .head { fill: var(--brindle); stroke: none; }

.eq { display: block; font-size: 1.5rem; margin: 0 0 1.5rem; }

table { border-collapse: collapse; font-size: 1rem; }
th, td { text-align: left; padding: 0.35rem 1.4rem 0.35rem 0; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; }

.status { margin: 1.75rem 0 0; font-size: 1rem; color: var(--muted); }

/* ---------- the rest reads as the finished document ---------- */

main.doc, .doc {
  max-width: calc(var(--measure) + 8rem);
  margin: 0 auto;
  padding: clamp(2.5rem, 6vw, 5rem) clamp(1rem, 4vw, 2.5rem) 3rem;
}
.doc section { margin: 0 0 3.25rem; }
.doc h1, .doc h2 { position: relative; line-height: 1.15; font-weight: 700; margin: 0 0 0.9rem; max-width: var(--measure); }
.doc h1 { font-size: clamp(2.2rem, 5vw, 3rem); letter-spacing: -0.015em; }
.doc h2 { font-size: 1.6rem; letter-spacing: -0.01em; }
.doc h3 { font-size: 1.15rem; margin: 2rem 0 0.4rem; max-width: var(--measure); }
.doc p, .doc ul, .doc ol, .doc dl { max-width: var(--measure); margin: 0 0 1rem; }
.doc li { margin: 0 0 0.4rem; }
.doc .updated { color: var(--muted); font-size: 1rem; }

/* The heading's Markdown marker hangs in the left margin: what you typed, beside what you got. */
.doc h1::before, .doc h2::before {
  position: absolute;
  right: calc(100% + 0.6em);
  top: 0.12em;
  font: 400 0.8em/1 var(--mono);
  color: var(--marker);
}
.doc h1::before { content: "#"; }
.doc h2::before { content: "##"; font-size: 0.75em; top: 0.3em; }

.doc code { font: 0.9em var(--mono); background: var(--apricot-soft); padding: 0.05em 0.3em; border-radius: 3px; }

.dog { display: grid; grid-template-columns: 9rem 1fr; gap: 1.75rem; align-items: start; max-width: calc(var(--measure) + 11rem); }
.dog img { width: 9rem; height: auto; }

.mail { font-size: 1.35rem; margin: 0 0 1.25rem; }

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

.foot {
  border-top: 1px solid var(--rule);
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 2.5rem;
  font-size: 0.95rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
}
.foot nav { display: flex; gap: 1.25rem; }

/* ---------- small screens: the source sits above the page ---------- */

@media (max-width: 52rem) {
  .split { grid-template-columns: 1fr; min-height: 0; }
  .source { font-size: 0.85rem; }
  .doc h1::before, .doc h2::before { position: static; display: block; margin: 0 0 0.35rem; }
  .dog { grid-template-columns: 1fr; }
  .dog img { width: 7rem; }
}
