:root {
  --paper: #e7e1cd;
  --wash: #dcd4bc;
  --ink: #15130e;
  --muted: #5b564a;
  --rule: #b4aa92;
  --rule-strong: #2a261c;
  --link: #6a3216;
  --link-hover: #3a180a;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --display: "Fraunces", "Iowan Old Style", Palatino, serif;
}

html[data-theme="dark"] {
  --paper: #10140e;
  --wash: #171c14;
  --ink: #e7e1cf;
  --muted: #a39b86;
  --rule: #3a4033;
  --rule-strong: #c9c1aa;
  --link: #d4a06a;
  --link-hover: #ecc48a;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --paper: #10140e;
    --wash: #171c14;
    --ink: #e7e1cf;
    --muted: #a39b86;
    --rule: #3a4033;
    --rule-strong: #c9c1aa;
    --link: #d4a06a;
    --link-hover: #ecc48a;
  }
}

* { box-sizing: border-box; }

html {
  font-size: 100%;
  color-scheme: light dark;
}

html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image: linear-gradient(180deg, var(--wash) 0, transparent 9rem);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.62;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

a:hover { color: var(--link-hover); }

.wrap {
  width: min(40rem, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.4rem 0 3.4rem;
}

header.mast {
  display: grid;
  gap: 0.85rem;
  padding: 0.15rem 0 1rem;
  border-bottom: 3px double var(--rule-strong);
}

.brand { min-width: 0; }

.site-name {
  display: block;
  font-family: var(--display);
  font-optical-sizing: auto;
  font-size: clamp(1.85rem, 6.4vw, 2.55rem);
  font-weight: 560;
  font-variation-settings: "SOFT" 30, "WONK" 1;
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-decoration: none;
}

.site-name:hover { color: var(--ink); }

.tagline {
  margin: 0.4rem 0 0;
  max-width: 26rem;
  color: var(--muted);
  font-family: var(--ui);
  font-size: 0.78rem;
  line-height: 1.4;
}

.mast-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 1.1rem;
  padding-top: 0.15rem;
}

nav {
  margin: 0;
  font-family: var(--ui);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

nav a {
  margin-right: 1rem;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

nav a:last-child { margin-right: 0; }

nav a:hover,
nav a[aria-current="page"] { border-bottom-color: var(--ink); }

.theme {
  display: flex;
  gap: 0.75rem;
  margin: 0;
  font-family: var(--ui);
  font-size: 0.78rem;
}

.theme button {
  margin: 0;
  padding: 0.05rem 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  font: inherit;
  line-height: 1.3;
  cursor: pointer;
}

.theme button:hover { color: var(--ink); }

.theme button[aria-pressed="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

main { padding-top: 1.7rem; }

.lede { margin: 0 0 2.1rem; }
.lede p { margin: 0 0 0.85rem; }
.lede p:last-child { margin-bottom: 0; }

.contents { margin: 0; }

.contents > h1 {
  margin: 0 0 0.35rem;
  font-family: var(--ui);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.toc li {
  margin: 0;
  border-bottom: 1px solid var(--rule);
}

.toc a {
  display: grid;
  grid-template-columns: 2.1rem minmax(0, 1fr);
  column-gap: 0.85rem;
  padding: 1.05rem 0 1.1rem;
  color: inherit;
  text-decoration: none;
}

.toc a::before {
  grid-row: 1 / span 2;
  content: counter(toc, decimal-leading-zero);
  counter-increment: toc;
  padding-top: 0.28rem;
  color: var(--muted);
  font-family: var(--ui);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.toc-title {
  grid-column: 2;
  font-family: var(--display);
  font-optical-sizing: auto;
  font-size: 1.12rem;
  font-weight: 560;
  line-height: 1.28;
  letter-spacing: -0.015em;
}

.toc-line {
  grid-column: 2;
  margin-top: 0.22rem;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.98rem;
  line-height: 1.4;
}

.toc a:hover .toc-title { color: var(--link); }

h1 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-optical-sizing: auto;
  font-size: clamp(1.55rem, 4.6vw, 2.05rem);
  font-weight: 560;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 560;
  line-height: 1.28;
}

.meta {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-family: var(--ui);
  font-size: 0.78rem;
}

p { margin: 0 0 1rem; }
article p:last-child { margin-bottom: 0; }

footer {
  margin-top: 2.8rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--ui);
  font-size: 0.78rem;
}

footer p { margin: 0; }

@media (min-width: 40rem) {
  body { font-size: 1.15rem; }
  .wrap {
    width: min(40rem, calc(100% - 3.2rem));
    padding-top: 1.8rem;
  }
  header.mast {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 0.6rem 1.5rem;
    padding-bottom: 1.15rem;
  }
  .mast-tools {
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 0.45rem;
    padding-top: 0;
  }
  .toc-title { font-size: 1.2rem; }
}
