:root {
  --bg: #fbfaf7;
  --bg-nav: rgba(251, 250, 247, 0.85);
  --text: #1c1b19;
  --muted: #6f6b63;
  --rule: #e4e1da;
  --accent: #b4532f;        /* brick: text-safe on --bg (4.8:1) */
  --accent-soft: #d97757;   /* brick: bars, markers, underlines */
  --accent-dark: #8f3f22;   /* brick: link hover */
  --accent-tint: #f7e6dd;   /* brick wash: inline code, selection */
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --code-bg: #f4f2ed;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --width: 44rem;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
}

::selection { background: var(--accent-tint); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  line-height: 1.6;
  font-optical-sizing: auto;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent-soft) 45%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 0.15s, text-decoration-color 0.15s;
}

a:hover {
  color: var(--accent-dark);
  text-decoration-color: currentColor;
}

ul { list-style: none; margin: 0; padding: 0; }

/* Top nav */

.topnav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-nav);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-top: 4px solid var(--accent-soft);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.85rem;
}

.topnav-inner {
  max-width: var(--width);
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Small clay square before the name */
.topnav .brand::before {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  margin-right: 0.5em;
  background: var(--accent-soft);
  border-radius: 2px;
  vertical-align: 0.05em;
}

.topnav .brand {
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.topnav ul { display: flex; gap: 1.25rem; }

.topnav ul a {
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.topnav ul a:hover { color: var(--accent); }

/* Layout */

main {
  max-width: var(--width);
  margin: 0 auto;
  padding: 4.5rem 1rem 3rem;
}

.hero h1,
.page-head h1,
.post-head h1 {
  font-weight: 500;
  font-size: 2.5rem;
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin: 0 0 1rem;
}

.lede { margin: 0; max-width: 36rem; }

section {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

section > h2 {
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1.25rem;
}

.meta {
  display: block;
  font-size: 0.95rem;
  font-style: italic;
  color: var(--muted);
}

.entries li { margin-bottom: 1rem; }

.links { display: flex; flex-wrap: wrap; gap: 0.5rem 1.75rem; }

.more { margin: 1.5rem 0 0; font-size: 1rem; }

/* Social icons */

.icon {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.socials { display: flex; gap: 1.1rem; margin-top: 1.5rem; }

.socials a { color: var(--muted); display: block; padding: 0.15rem; }

.socials a:hover { color: var(--accent); }

.socials.small { margin: 0; gap: 0.9rem; }

.socials.small .icon { width: 1.05rem; height: 1.05rem; }

/* Videos */

.videos {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem 1.5rem;
}

.videos a { color: var(--text); text-decoration: none; display: block; }

.videos a:hover { color: var(--accent); }

.videos img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 4px;
  background: var(--rule);
  transition: opacity 0.15s;
}

.videos a:hover img { opacity: 0.85; }

.vtitle {
  display: block;
  margin-top: 0.6rem;
  line-height: 1.35;
  font-size: 1.1rem;
}

.videos .meta { margin-top: 0.15rem; font-size: 0.9rem; }

/* Blog posts */

.post-date {
  margin: 0 0 0.5rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.post-desc { margin: 0; color: var(--muted); font-style: italic; }

.post-body { margin-top: 2.5rem; }

.post-body h2 { font-size: 1.5rem; font-weight: 500; line-height: 1.25; margin: 2.5rem 0 0.75rem; }

.post-body h3 { font-size: 1.2rem; font-weight: 500; margin: 2rem 0 0.5rem; }

.post-body p, .post-body ul, .post-body ol { margin: 0 0 1.25rem; }

.post-body ul { list-style: disc; padding-left: 1.25rem; }

.post-body ol { padding-left: 1.25rem; }

.post-body li { margin-bottom: 0.4rem; }

.post-body li::marker { color: var(--accent-soft); }

.post-body strong { font-weight: 500; }

.post-body blockquote {
  margin: 1.5rem 0;
  padding-left: 1.25rem;
  border-left: 2px solid var(--accent-soft);
  color: var(--muted);
  font-style: italic;
}

.post-body img { max-width: 100%; height: auto; border-radius: 4px; }

.post-body hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--accent-tint);
  color: #7a3a22;
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

pre {
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.55;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent-soft);
  border-radius: 6px;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  tab-size: 4;
  margin: 0 0 1.5rem;
}

pre code { background: none; color: inherit; padding: 0; font-size: inherit; }

.highlighter-rouge .highlight { background: none; }

/* Syntax colors (Rouge) */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs, .highlight .cp { color: #8c877d; font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kr, .highlight .kt, .highlight .kc { color: #b4532f; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sc, .highlight .se, .highlight .sr { color: #3d6b35; }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh, .highlight .il { color: #7a4f9a; }
.highlight .nf, .highlight .fm { color: #1f5d8a; }
.highlight .nc, .highlight .nn, .highlight .nb { color: #2b6b6b; }
.highlight .o, .highlight .p { color: #5a564f; }
.highlight .err { color: inherit; background: none; }

.post-foot {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
}

/* Contents bar (posts, wide screens only) */

.post-wrap { position: relative; }

.toc { display: none; }

@media (min-width: 1240px) {
  .toc:not([hidden]) {
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    right: calc(100% + 3rem);
    width: 12.5rem;
  }
}

.toc-inner {
  position: sticky;
  top: 6rem;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 0.8rem;
  line-height: 1.4;
}

.toc-title {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.toc-list { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }

.toc-list li { margin: 0; }

.toc-list a {
  display: block;
  padding: 0.3rem 0 0.3rem 0.85rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
}

.toc-list .toc-h3 a { padding-left: 1.6rem; font-size: 0.75rem; }

.toc-list a:hover { color: var(--text); }

.toc-list a.active {
  color: var(--accent);
  border-left-color: var(--accent-soft);
}

/* Diagrams */

.diagram {
  margin: 2rem 0 2.25rem;
  padding: 1.25rem 1.25rem 1rem;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
}

.diagram svg { display: block; width: 100%; height: auto; }

/* Keep wide diagrams legible on phones: scroll instead of shrinking */
.gf { overflow-x: auto; }
.gf svg { min-width: 600px; }

.diagram figcaption {
  margin-top: 0.85rem;
  font-size: 0.9rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--muted);
}

.dg-box { fill: var(--bg); stroke: #c9c3b8; stroke-width: 1.25; }
.dg-l { stroke: #a39d93; stroke-width: 1.25; fill: none; }
.dg-head { fill: #a39d93; }
.dg-t { font-family: var(--sans); font-size: 12px; fill: var(--text); text-anchor: middle; }
.dg-op { font-size: 15px; }
.dg-in, .dg-lab { fill: var(--muted); }
.dg-cap { font-size: 11px; fill: var(--muted); font-style: italic; }
.dg-start { text-anchor: start; }

/* GCM fault diagram */
.gf .gf-group { fill: none; stroke: var(--rule); stroke-width: 1.25; stroke-dasharray: 4 4; }
.gf .gf-grouplab { text-anchor: end; font-size: 11px; letter-spacing: 0.08em; }
.gf .gf-bad { stroke: var(--accent-soft); stroke-width: 1.75; }
.gf .gf-bad-t { fill: var(--accent); }
.gf .gf-l-bad { stroke: var(--accent-soft); stroke-width: 2; }
.gf .gf-head-bad { fill: var(--accent-soft); }
.gf .gf-burst path { fill: var(--accent-soft); }
.gf .gf-note { fill: var(--accent); font-size: 11px; }
.gf .gf-tag { fill: var(--accent-tint); stroke: var(--accent-soft); stroke-width: 1.75; }
.gf .gf-tag-t { fill: var(--accent); font-weight: 600; }

/* Fault search (interactive) */
.fs-tags { display: grid; gap: 0.35rem; }
.fs-row { display: flex; align-items: baseline; gap: 0.75rem; min-width: 0; }
.fs-label {
  flex: none;
  width: 4.75rem;
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.fs-tag {
  background: none;
  color: var(--text);
  padding: 0;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}
.fs-diff { color: var(--accent-soft); }
.fs-matched [data-emulated] { color: var(--accent); font-weight: 600; }

.fs .fs-step {
  display: block;
  margin: 1.1rem 0 0.45rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--muted);
}
.fs-step output { font-family: var(--mono); color: var(--text); }

.fs-trace { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.fs button {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.25rem 0.45rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--muted);
  background: var(--bg);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.fs button:hover { border-color: var(--accent-soft); color: var(--accent); }
.fs button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-soft); color: #fff; }
.fs button:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.fs-controls { display: flex; flex-wrap: wrap; gap: 0 2rem; align-items: flex-start; }
.fs-ctl { display: block; }
.fs-seg { display: flex; gap: 0.3rem; }
.fs input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 14rem;
  max-width: 100%;
  height: 1.6rem;
  background: transparent;
  cursor: pointer;
}
.fs input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--rule); }
.fs input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--rule); }
.fs input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: -6px;
  border-radius: 50%; border: 2px solid #fff;
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent-soft);
}
.fs input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%; border: 2px solid #fff;
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent-soft);
}
.fs input[type="range"]:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.fs .fs-status {
  margin: 1.1rem 0 0.6rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
}
.fs-matched .fs-status { color: var(--accent); font-weight: 500; }

.fs .fs-find {
  font-family: var(--sans);
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  color: var(--accent);
  border-color: var(--accent-soft);
  background: #fff;
}

/* Evidence bits */
.eb-row + .eb-row { margin-top: 1.25rem; }
.eb-title { margin: 0 0 0.4rem; font-size: 1rem; }
.eb-dim { color: var(--muted); font-size: 0.9rem; }
.eb-bar { display: grid; grid-template-columns: repeat(64, 1fr); gap: 2px; margin-bottom: 0.2rem; }
.eb-bar span {
  height: 9px;
  border-radius: 1px;
  background: #ece9e2;
  transition: background 0.25s;
}
.eb-on .eb-bar span.spent { background: #b8b2a8; }
.eb-on .eb-bar span.left { background: var(--accent-soft); }
.eb-legend {
  line-height: 1.6;
  margin: 0.45rem 0 0;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--muted);
}
.eb-key { display: inline-block; width: 0.7em; height: 0.7em; border-radius: 1px; margin: 0 0.35em 0 0; vertical-align: -0.05em; }
.eb-key + .eb-key, .eb-legend .eb-key-left { margin-left: 0.9em; }
.eb-key-spent { background: #b8b2a8; }
.eb-key-left { background: var(--accent-soft); }

/* Footer */

footer { border-top: 1px solid var(--rule); }

.footer-inner {
  max-width: var(--width);
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 560px) {
  body { font-size: 1.125rem; }
  main { padding-top: 3rem; }
  .hero h1, .page-head h1, .post-head h1 { font-size: 2rem; }
  .topnav .brand { display: none; }
  .topnav-inner { justify-content: center; }
  .videos { grid-template-columns: 1fr; }
}
