/* vm.fail: a quiet editorial notebook. Reasons for each choice are in DESIGN.md. */

:root {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #1c1c1a;
  --muted: #5b5b56;
  --line: #e8e8e6;
  --line-strong: #cfcfcb;
  --line-input: #8a877d;
  --wash: #f6f6f5;
  --accent: #1b4d86;
  --measure: 42rem;
  --serif: "CMU Serif", "Latin Modern Roman", Georgia, "Times New Roman", serif;
  --sans: "CMU Sans Serif", "CMU Serif", ui-sans-serif, system-ui, sans-serif;
  --mono: "CMU Typewriter Text", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(1.8rem, 4.5vw, 4rem) 1.35rem clamp(3.5rem, 7vw, 6rem);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.08rem, 1.02rem + 0.2vw, 1.18rem);
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Links keep a visible underline at rest (not colour alone) and darken it on hover. */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: var(--line-strong);
  transition: text-decoration-color .12s ease;
}
a:hover { text-decoration-color: currentColor; }

a:focus-visible, button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Masthead */
.site {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  flex-wrap: wrap;
  padding-bottom: 1.4rem;
  margin-bottom: 2.6rem;
  border-bottom: 1px solid var(--line);
}
.site h1 { margin: 0; font: 600 1.55rem/1.2 var(--sans); letter-spacing: -.015em; }
.site h1 a { color: var(--ink); text-decoration: none; }
.site nav { font: 500 .9rem/1.5 var(--sans); }
.site nav a { color: var(--muted); text-decoration: none; }
.site nav a:hover { color: var(--accent); text-decoration: underline; text-decoration-color: currentColor; }

/* Home */
ul.posts { list-style: disc; margin: 0; padding-left: 1.3rem; }
ul.posts li { padding: 1.35rem 0; border-bottom: 1px solid var(--line); }
ul.posts li:first-child { padding-top: 0; }
ul.posts a.title { font: 600 1.15rem/1.3 var(--sans); letter-spacing: -.01em; text-decoration: none; }
ul.posts a.title:hover { text-decoration: underline; text-decoration-color: currentColor; }
ul.posts .desc { margin: .5rem 0 0; font-size: .98rem; color: var(--muted); }

/* Article */
article.post > h1 {
  margin: 0 0 .6rem;
  font: 600 clamp(1.75rem, 1.5rem + 1.1vw, 2.25rem)/1.2 var(--sans);
  letter-spacing: -.02em;
}

h2 {
  margin: 3.4rem 0 1rem;
  padding-bottom: .45rem;
  font: 600 1.34rem/1.3 var(--sans);
  letter-spacing: -.01em;
  border-bottom: 1px solid var(--line);
}
h3 { margin: 2.2rem 0 .6rem; font: 600 1.08rem/1.35 var(--sans); }
p { margin: 1.1rem 0; }
ul, ol { padding-left: 1.4rem; }
li { margin: .4rem 0; }
strong { font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--line); margin: 3rem 0; }
blockquote {
  margin: 1.6rem 0;
  padding: .2rem 0 .2rem 1.2rem;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
}

/* Code */
code {
  font-family: var(--mono);
  font-size: .86em;
  background: var(--wash);
  padding: .12em .34em;
  border-radius: 3px;
}
pre {
  margin: 1.5rem 0;
  padding: 1.05rem 1.15rem;
  background: var(--wash);
  border: 0;
  border-radius: 5px;
  overflow-x: auto;
  font-size: .84rem;
  line-height: 1.6;
}
pre code, pre code.hljs { background: none; padding: 0; border-radius: 0; font-size: inherit; }

/* Figures: shown at the reading width, with a larger overlay for detail. */
figure { margin: 2.4rem 0; }

.figure-open {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
}
.figure-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.figure-body {
  display: block;
  max-height: 72vh;
  overflow: auto;
}
.figure-body > svg, .figure-body > img { display: block; width: 100%; height: auto; }

figcaption {
  margin-top: .8rem;
  font-size: .86rem;
  line-height: 1.55;
  color: var(--muted);
  text-align: center;
}
figcaption code { font-size: .9em; }

/* Figure 1 pairs two diagrams; at the reading width they stack so each stays legible. */
.two-up { display: grid; grid-template-columns: 1fr; gap: 1.1rem; }

/* Enlarge overlay */
dialog.zoom {
  width: min(96vw, 1400px);
  max-width: none;
  height: 92vh;
  max-height: none;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  overflow: hidden;
}
dialog.zoom::backdrop { background: rgba(20, 20, 18, .74); }
.zoom-body { width: 100%; height: 100%; overflow: auto; padding: 1rem; }
.zoom-body > svg { display: block; width: 100%; min-width: 880px; height: auto; }
.zoom-close {
  position: absolute;
  top: .6rem;
  right: .6rem;
  z-index: 1;
  padding: .45rem .8rem;
  border: 1px solid var(--line-input);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font: 500 .82rem/1 var(--sans);
  cursor: pointer;
}
.zoom-close:hover { background: var(--wash); }
.zoom-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Results table: scrolls rather than squeezing eight columns into a phone. */
.table-scroll { overflow-x: auto; margin: 1.6rem 0; }
table.results { width: 100%; border-collapse: collapse; font: .8rem/1.5 var(--mono); }
table.results th, table.results td {
  padding: .45rem .6rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
table.results th:first-child, table.results td:first-child { text-align: left; }
table.results thead th { color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line-strong); }
table.results tbody tr:last-child td { border-bottom: 0; }

/* KaTeX display maths can be wide; let it scroll instead of overflowing. */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .35rem 0; }

/* Source note */
.source-note { margin: 0 0 2.4rem; font-size: .9rem; font-style: italic; color: var(--muted); }

/* Demo */
.demo { margin-top: 3.4rem; }
.demo h2 { margin-top: 0; }
.demo > p { font-size: .96rem; color: var(--muted); }
.demo-bar {
  display: flex;
  border: 1px solid var(--line-input);
  border-radius: 5px 5px 0 0;
}
.demo-bar textarea {
  flex: 1;
  min-width: 0;
  padding: .65rem .8rem;
  border: 0;
  border-radius: 5px 0 0 0;
  resize: vertical;
  font: .92rem/1.6 var(--mono);
  color: var(--ink);
  background: #fff;
}
.demo-bar textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.demo-bar button {
  min-height: 44px;
  padding: 0 1.2rem;
  border: 0;
  border-left: 1px solid var(--line-input);
  background: var(--wash);
  font: 600 .88rem/1 var(--mono);
  color: var(--ink);
  cursor: pointer;
  transition: background .12s ease;
}
.demo-bar button:hover { background: var(--line); }
.demo-bar button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.demo-bar button[disabled] { opacity: .55; cursor: default; }
.demo-panel { border: 1px solid var(--line-input); border-top: 0; }
.demo-label {
  padding: .4rem .75rem;
  background: var(--wash);
  border-bottom: 1px solid var(--line-input);
  font: 500 .8rem/1.5 var(--mono);
}
.demo-panel pre { margin: 0; min-height: 9rem; background: #fff; border: 0; border-radius: 0; }
.demo-cols { display: grid; grid-template-columns: 1fr 1fr; }
.demo-cols .demo-panel:first-child { border-right: 0; }
@media (max-width: 640px) {
  .demo-cols { grid-template-columns: 1fr; }
  .demo-cols .demo-panel:first-child { border-right: 1px solid var(--line-input); }
}

/* Narrow screens get a tighter register, not the desktop layout shrunk. */
@media (max-width: 620px) {
  body { padding-top: 1.8rem; }
  article.post > h1 { font-size: 1.7rem; }
  ul.posts a.title { font-size: 1.1rem; }
}
