/* Layout & typography — colors come exclusively from theme.css variables. */

:root {
  --masthead-h: 7rem;
  --font-body: system-ui, "Segoe UI", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
    serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono",
    monospace;
}

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

body {
  max-width: 50rem;
  margin: 0 auto;
  padding: 0 2rem 4.5rem;
  background: var(--panel);
  color: var(--text);
  border-left: 1px solid var(--border-strong);
  border-right: 1px solid var(--border-strong);
  min-height: 100vh;
  box-sizing: border-box;
  font: 17px/1.7 var(--font-body);
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.18em;
}

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

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

/* Masthead: blade texture etched into the panel (multiply drops its white
   background in both modes), veiled toward legibility, wordmark on top. */
.masthead {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: var(--masthead-h);
  margin: 0 -2rem;
  padding: 0 2rem;
  background:
    linear-gradient(to bottom, var(--veil), var(--panel) 97%),
    url("/ulfberht.webp") center 42% / cover no-repeat var(--panel);
  background-blend-mode: normal, multiply;
  border-bottom: 1px solid var(--border-strong);
  text-align: center;
}

.masthead-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: var(--heading);
  text-shadow: 0 1px 0 var(--panel);
}

.masthead:hover {
  text-decoration: none;
}

.site-nav {
  display: flex;
  justify-content: center;
  gap: 1.6rem;
  padding: 0.9rem 0;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--border-muted);
  font-size: 0.82rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.site-nav a {
  color: var(--text-muted);
}

.site-nav a:hover {
  color: var(--accent);
  text-decoration: none;
}

#title-block-header {
  margin-bottom: 2.75rem;
}

h1.title {
  margin: 0 0 0.35rem;
  font-size: 2.1rem;
}

p.author,
p.date {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.88rem;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  color: var(--heading);
  line-height: 1.25;
  margin: 2em 0 0.6em;
  text-wrap: balance;
}

h1 {
  font-size: 1.85rem;
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 0.3em;
}

h2 {
  font-size: 1.45rem;
  border-bottom: 1px solid var(--border-muted);
  padding-bottom: 0.25em;
}

h3 {
  font-size: 1.17rem;
}

h4,
h5,
h6 {
  font-size: 1rem;
}

p,
ul,
ol,
dl {
  margin: 0 0 1.15em;
}

p {
  text-wrap: pretty;
}

ul,
ol {
  padding-left: 1.5em;
}

li {
  margin: 0.25em 0;
}

li > ul,
li > ol {
  margin-bottom: 0;
}

code,
pre,
kbd,
samp {
  font-family: var(--font-mono);
}

:not(pre) > code {
  background: var(--surface-1);
  color: var(--accent-code);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.88em;
}

div.sourceCode,
pre {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

pre {
  padding: 0.9em 1.1em;
  overflow-x: auto;
  font-size: 0.88em;
  line-height: 1.55;
}

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

blockquote {
  margin: 0 0 1em;
  padding: 0.1em 1em;
  border-left: 3px solid var(--accent-muted);
  color: var(--text-muted);
}

table {
  border-collapse: collapse;
}

th,
td {
  border: 1px solid var(--border-strong);
  padding: 0.35em 0.7em;
}

th {
  background: var(--surface);
  color: var(--heading);
}

tr:nth-child(even) td {
  background: var(--bg);
}

hr {
  border: none;
  border-top: 1px solid var(--border-strong);
  width: 6rem;
  margin: 2.5rem auto;
}

img {
  max-width: 100%;
}

/* Content media: figures, self-hosted video, remote embeds. */
figure {
  margin: 1.5rem 0;
}

figure img,
p > img:only-child {
  display: block;
  margin: 0 auto;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

figcaption {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85em;
  margin-top: 0.5rem;
}

video {
  display: block;
  max-width: 100%;
  margin: 1.5rem auto;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--code-bg);
}

iframe {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  margin: 1.5rem auto;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--code-bg);
}

mark {
  background: var(--mark-bg);
  color: var(--text);
}

.article-list ul {
  list-style: none;
  padding-left: 0;
}

.article-list li {
  margin-bottom: 0.55rem;
}

.article-date {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-right: 0.6rem;
}

.site-footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-muted);
  font-size: 0.78rem;
  color: var(--text-subtle);
  text-align: center;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--text-muted);
}

/* TOC: inline box by default; on wide screens the page becomes a grid
   (18rem rail + content, one 68rem composition) and the TOC is a sticky
   rail — it scrolls with the masthead, then pins to the viewport top. */
nav#TOC {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8em 1.2em;
  margin-bottom: 1.5em;
  font-size: 0.85em;
}

nav#TOC::before {
  content: "contents";
  display: block;
  color: var(--text-subtle);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.8em;
  margin-bottom: 0.6em;
}

nav#TOC ul {
  list-style: none;
  padding-left: 1em;
  margin: 0.2em 0;
}

nav#TOC > ul {
  padding-left: 0;
}

nav#TOC a {
  color: var(--text-muted);
}

nav#TOC a:hover {
  color: var(--accent);
}

@media (min-width: 70.01rem) {
  body:has(nav#TOC) {
    display: grid;
    grid-template-columns: 18rem minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr auto;
    max-width: 68rem;
    padding: 0;
    /* full-height rail divider, independent of the TOC's own height */
    background: linear-gradient(
      to right,
      var(--panel) calc(18rem - 1px),
      var(--border-strong) calc(18rem - 1px),
      var(--border-strong) 18rem,
      var(--panel) 18rem
    );
  }

  body:has(nav#TOC) .masthead {
    grid-column: 1 / -1;
    margin: 0;
  }

  body:has(nav#TOC) .site-nav,
  body:has(nav#TOC) #title-block-header,
  body:has(nav#TOC) main,
  body:has(nav#TOC) .site-footer {
    grid-column: 2;
    margin-left: 2rem;
    margin-right: 2rem;
  }

  body:has(nav#TOC) main {
    margin-bottom: 4.5rem;
  }

  body:has(nav#TOC) nav#TOC {
    grid-column: 1;
    grid-row: 2 / -1;
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    overflow-y: auto;
    box-sizing: border-box;
    border: none;
    border-radius: 0;
    margin: 0;
    padding: 1.2rem 1rem;
  }
}

@media (max-width: 40rem) {
  body {
    padding: 0 1.25rem 3.5rem;
  }

  .masthead {
    height: 5.2rem;
    margin: 0 -1.25rem;
    padding: 0 1.25rem;
  }

  .masthead-title {
    font-size: 1.15rem;
    letter-spacing: 0.3em;
    text-indent: 0.3em;
  }

  .site-nav {
    gap: 1.1rem;
    flex-wrap: wrap;
  }
}

/* Skylighting token classes on top of the monochrome highlight base. */
pre code span.kw,
pre code span.cf {
  color: var(--accent);
}

pre code span.fu {
  color: var(--accent-hover);
}

pre code span.dt {
  color: var(--secondary);
}

pre code span.st,
pre code span.vs,
pre code span.ss {
  color: var(--success);
}

pre code span.dv,
pre code span.bn,
pre code span.fl {
  color: var(--warning);
}

pre code span.co,
pre code span.do {
  color: var(--text-subtle);
  font-style: italic;
}

pre code span.op {
  color: var(--text-muted);
}

pre code span.va,
pre code span.at {
  color: var(--text);
}

pre code span.pp,
pre code span.ot {
  color: var(--hl);
}

pre code span.er,
pre code span.al {
  color: var(--danger);
}
