/* oliverfletcher.io — a quiet, readable, monochrome-first stylesheet. */

:root {
  --bg: #fbfaf8;
  --surface: #f2f0ec;
  --text: #1c1b19;
  --muted: #6b6862;
  --border: #e3e0da;
  --accent: #1f5f8b;
  --accent-soft: #e5eef5;
  --code-bg: #f2f0ec;
  --panel: rgba(251, 250, 248, 0.3);

  --font-sans: "Suisse Intl", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --measure: 39rem;
  /* Secondary text: metadata, captions, tables, footer. */
  --text-small: 0.875rem;
  --text-xsmall: 0.8125rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1c1c1c;
    --text: #e8e6e3;
    --muted: #9c9891;
    --border: #2c2b29;
    --accent: #7db4dc;
    --accent-soft: #1b2a35;
    --code-bg: #1c1c1c;
    --panel: rgba(18, 18, 18, 0.25);
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.75 var(--font-sans);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Animated ASCII factory, drawn by factory.js behind everything else. */
.factory-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* Switch in the top-right corner that turns the factory off, leaving the
   plain background. The panels go transparent too, since they only exist to
   keep text readable over the factory. */
.factory-toggle {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 10;
  width: 2.25rem;
  height: 1.25rem;
  padding: 0;
  border: 1px solid var(--muted);
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
}
.factory-toggle::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.25rem - 6px);
  height: calc(1.25rem - 6px);
  border-radius: 50%;
  background: var(--muted);
  transition: transform 150ms ease, background-color 150ms ease;
}
.factory-toggle[aria-checked="true"]::before {
  transform: translateX(1rem);
  background: var(--text);
}
.factory-toggle::after,
.music-toggle::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font: 500 var(--text-xsmall)/1.4 var(--font-sans);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}
.factory-toggle:hover::after,
.factory-toggle:focus-visible::after,
.music-toggle:hover::after,
.music-toggle:focus-visible::after { opacity: 1; }

/* The piano button, just left of the factory switch (see music.js). */
.music-toggle {
  position: fixed;
  top: 0.75rem;
  right: 3.5rem;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.music-toggle:hover, .music-toggle[aria-pressed="true"] { color: var(--text); }
.music-toggle .icon {
  grid-area: 1 / 1;
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.music-toggle .icon-pause,
.music-toggle[aria-pressed="true"] .icon-play { display: none; }
.music-toggle[aria-pressed="true"] .icon-pause { display: block; }

:root.factory-off { --panel: transparent; }

/* The factory reacts to clicks on the bare page around the content (see
   factory.js), so hint at it there and nowhere else. */
@media (prefers-reduced-motion: no-preference) {
  :root:not(.factory-off) body { cursor: crosshair; }
  .site-header, main, .site-footer { cursor: auto; }
}
.factory-off .factory-bg { display: none; }

.site-header, main, .site-footer {
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main { flex: 1; padding-block: 2.5rem 4rem; }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--border);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 120ms ease, text-decoration-color 120ms ease;
}
a:hover { color: var(--text); text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -3rem;
  padding: 0.5rem 0.75rem;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  z-index: 10;
}
.skip-link:focus { top: 0.75rem; }

/* Hidden on screen, still read by screen readers. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Header & footer */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-block: 2rem 0;
}

.brand {
  font-weight: 600;
  font-size: 1.0625rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.site-header nav { display: flex; gap: 1.25rem; font-size: var(--text-small); }
.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  padding-block: 0.25rem;
}
.site-header nav a:hover,
.site-header nav a[aria-current="page"] { color: var(--text); }
.site-header nav a[aria-current="page"] {
  box-shadow: inset 0 -2px 0 currentColor;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-block: 1.5rem 2.5rem;
  background: linear-gradient(var(--border), var(--border)) center top / calc(100% - 2 * var(--gutter)) 1px no-repeat;
  color: var(--muted);
  font-size: var(--text-small);
}
.site-footer p { margin: 0; }
.site-footer .links { display: flex; flex-wrap: wrap; gap: 1rem; list-style: none; margin: 0; padding: 0; }
.site-footer a { text-decoration: none; }
.site-footer .links { align-items: center; }
.site-footer .links a { display: inline-flex; padding: 0.25rem; margin: -0.25rem; }
.site-footer .icon {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Headings & page structure */

h1, h2, h3, h4 {
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 600;
  text-wrap: balance;
}
/* Headings stay close to body size, as on mitchellh.com: hierarchy comes
   from weight and space, not size. There is always more space above a
   heading than below it, so it reads with what follows. */
h1 { font-size: 1.0625rem; line-height: 1.5; letter-spacing: -0.01em; margin: 0 0 0.75rem; }
h2 { font-size: 0.9375rem; margin: 2.5rem 0 0.75rem; }
h3 { font-size: 0.9375rem; margin: 2rem 0 0.5rem; }
h4 { font-size: 0.9375rem; font-weight: 500; margin: 1.75rem 0 0.5rem; }
h2 + h3, h3 + h4 { margin-top: 1rem; }
.prose > :first-child { margin-top: 0; }

.page-header { margin-bottom: 2rem; }
.lede { color: var(--muted); margin: 0; }
.meta { color: var(--muted); font-size: var(--text-small); margin: 0; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.section-header h2 { margin-bottom: 0.5rem; }
.section-header a { color: var(--muted); font-size: var(--text-small); text-decoration: none; }

.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; padding: 0; margin: 1rem 0 0; }
.tags li {
  font-size: var(--text-xsmall);
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
}

/* Home */

/* Semi-transparent panels keep text readable over the factory. */
.intro,
.recent,
.principles details,
.post,
.page,
.writing {
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--panel);
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
}
.intro > :first-child,
.recent h2 { margin-top: 0; }
.intro > :last-child { margin-bottom: 0; }
.recent { margin-top: 2.5rem; }


/* The contact address sits on an IBM 3270 green screen: phosphor glow,
   scanlines, a prompt and a blinking block cursor. */
.intro a[href^="mailto:"] {
  --phosphor: #33ff66;
  font-family: var(--font-mono);
  font-size: 0.9em;
  white-space: nowrap;
  padding: 0.15em 0.45em;
  border-radius: 3px;
  background:
    repeating-linear-gradient(transparent 0 2px, rgba(0, 0, 0, 0.35) 2px 3px),
    #061206;
  color: var(--phosphor);
  text-decoration: none;
  text-shadow: 0 0 2px var(--phosphor), 0 0 8px rgba(51, 255, 102, 0.55);
  box-shadow: inset 0 0 12px rgba(51, 255, 102, 0.15);
}
.intro a[href^="mailto:"]:hover { color: #7dffa0; }
.intro a[href^="mailto:"]::before { content: ">"; margin-right: 0.4em; }
.intro a[href^="mailto:"]::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 0.2em;
  vertical-align: -0.18em;
  background: var(--phosphor);
  box-shadow: 0 0 6px rgba(51, 255, 102, 0.7);
  animation: terminal-blink 1.06s steps(1) infinite;
}
@keyframes terminal-blink { 50% { opacity: 0; } }

.principles details {
  margin-top: 2.5rem;
  padding: 0 1.25rem;
}
.principles summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 1rem;
}
.principles summary::-webkit-details-marker { display: none; }
.principles summary::after {
  content: "+";
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  transition: transform 150ms ease;
}
.principles details[open] summary::after { transform: rotate(45deg); }
.principles summary h2 { margin: 0; }
.principles .prose { padding-bottom: 1.25rem; }
.principles .prose > :first-child { margin-top: 0; }

/* Post lists */

.post-list { list-style: none; padding: 0; margin: 0; }
.post-list li { padding-block: 1rem; border-bottom: 1px solid var(--border); }
.post-list li:last-child { border-bottom: 0; }
.post-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  text-decoration: none;
}
.post-list .post-title { font-size: 1.0625rem; font-weight: 600; }
.post-list a:hover .post-title {
  text-decoration: underline 1px;
  text-underline-offset: 0.2em;
}
.post-list time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: var(--text-small);
  font-variant-numeric: tabular-nums;
}
.post-list p { margin: 0.25rem 0 0; color: var(--muted); font-size: var(--text-small); line-height: 1.6; }

.year h2 {
  font-size: var(--text-small);
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  margin: 2rem 0 0.25rem;
}

/* Prose */

.prose p, .prose ul, .prose ol { margin-block: 0 1.15em; }
.prose ul, .prose ol { padding-left: 1.25rem; }
.prose li + li { margin-top: 0.35em; }
.prose li > ul, .prose li > ol { margin-top: 0.35em; margin-bottom: 0; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 600; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }
.prose img { max-width: 100%; height: auto; border-radius: var(--radius); }

.prose blockquote {
  margin: 1.5rem 0;
  padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.prose pre {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  overflow-x: auto;
  tab-size: 2;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }

.prose pre.mermaid {
  background: transparent;
  border: 0;
  text-align: center;
  padding: 0;
}
.prose pre.mermaid.zoomable { cursor: zoom-in; }

/* Enlarged diagram, opened by clicking one (see mermaid.js). */
.diagram-dialog {
  width: min(96vw, 90rem);
  max-width: none;
  max-height: 92vh;
  padding: 2.5rem 1.5rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}
.diagram-dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
.diagram-view svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(92vh - 4rem - 2px); /* dialog padding and border */
  margin-inline: auto;
}
.diagram-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  padding: 0 0.25rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.diagram-close:hover { color: var(--text); }
:root:has(.diagram-dialog[open]) { overflow: hidden; }

.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-small);
}
.prose th, .prose td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.prose th { font-weight: 600; border-bottom-width: 2px; }

.prose .caption, .prose figcaption { text-align: center; color: var(--muted); font-size: var(--text-small); }

.post-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
}
.post-footer a { text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .intro a[href^="mailto:"]::after { animation: none; }
}

@media print {
  .site-header nav, .site-footer, .post-footer, .skip-link, .factory-bg, .factory-toggle, .music-toggle { display: none; }
  body { background: #fff; color: #000; }
  a { text-decoration: underline; }
}
