:root {
  --bg: #fcfbf8;
  --fg: #1b1a17;
  --muted: #56534d;
  --link: #1f3ea3;
  --focus: #ffb400;
  --surface: #ffffff;
  --surface-alt: #f3f0e9;
  --border: #d7d1c4;
  --border-strong: #beb6a8;
  --quote-border: #8d887f;
  --measure: 46rem;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #16181c;
  --fg: #ece7dc;
  --muted: #b8b0a3;
  --link: #9bb8ff;
  --focus: #ffd166;
  --surface: #20242b;
  --surface-alt: #252a32;
  --border: #3d434d;
  --border-strong: #555d69;
  --quote-border: #6d7684;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, Cambria, serif;
  font-size: clamp(1.08rem, 1rem + 0.38vw, 1.24rem);
  line-height: 1.78;
  letter-spacing: 0.005em;
  text-rendering: optimizeLegibility;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 1000;
  background: var(--surface);
  color: var(--fg);
  padding: 0.5rem 0.75rem;
  outline: 3px solid var(--focus);
}

.site-header,
.content {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.4rem 1rem;
}

.site-nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", Georgia, Cambria, serif;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

.theme-toggle {
  margin-left: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 0.86rem;
  line-height: 1;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--border-strong);
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

a {
  color: var(--link);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.12em;
}

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

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", Georgia, Cambria, serif;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.16;
  text-wrap: balance;
  margin: 2em 0 0.52em;
}

h1 {
  font-size: clamp(1.9rem, 1.45rem + 1.9vw, 3.05rem);
  margin-top: 0.32em;
}

h2 {
  font-size: clamp(1.64rem, 1.3rem + 1.2vw, 2.3rem);
}

h3 {
  font-size: clamp(1.28rem, 1.12rem + 0.74vw, 1.62rem);
}

p,
ul,
ol,
blockquote,
pre,
figure {
  margin: 1.15em 0;
}

blockquote {
  border-left: 3px solid var(--quote-border);
  padding-left: 1.25rem;
  margin-left: 0;
  color: var(--muted);
}

pre,
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
  overflow-x: auto;
  padding: 1rem;
  background: var(--surface-alt);
  border-radius: 0.2rem;
  line-height: 1.55;
}

img {
  max-width: 100%;
  height: auto;
}

iframe {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: 0;
}

figure {
  margin: 1.4em 0;
}

figcaption {
  color: var(--muted);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, Cambria, serif;
  font-size: 0.88rem;
  line-height: 1.45;
}

li + li {
  margin-top: 0.45em;
}

.icon-grid {
  list-style: none;
  padding: 0;
  margin: 2.2rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.85rem;
}

.icon-grid a {
  display: grid;
  place-items: center;
  gap: 0.6rem;
  border: 1px solid var(--border);
  text-decoration: none;
  padding: 1rem 0.8rem;
  min-height: 120px;
  color: inherit;
  background: var(--surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9rem;
}

.icon-grid img {
  width: 28px;
  height: 28px;
}

.icon-grid a:hover {
  border-color: var(--border-strong);
}

.measure-sample {
  max-width: 70ch;
}

.type-scale {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem;
}

.type-scale p {
  margin: 0.45rem 0;
}

.scale-1 {
  font-size: clamp(2.15rem, 1.58rem + 2.32vw, 3.48rem);
  line-height: 1.16;
}

.scale-2 {
  font-size: clamp(1.64rem, 1.3rem + 1.2vw, 2.3rem);
  line-height: 1.2;
}

.scale-3 {
  font-size: clamp(1.28rem, 1.12rem + 0.74vw, 1.62rem);
  line-height: 1.25;
}

.scale-body {
  font-size: clamp(1.08rem, 1rem + 0.38vw, 1.24rem);
}

.scale-small {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.92rem;
}

.ruler {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
}

.ruler span {
  text-align: center;
  padding: 0.35rem 0;
  border-left: 1px solid var(--border);
}

.ruler span:first-child {
  border-left: 0;
}

@media (max-width: 42rem) {
  body {
    line-height: 1.72;
  }

  .site-header,
  .content {
    padding: 1rem 0.85rem;
  }

  .theme-toggle {
    margin-left: 0;
  }
}

/* Table of contents */
.toc {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.85rem 1.2rem 0.85rem 1.1rem;
  margin: 1.8rem 0 2rem;
  font-size: 0.91rem;
  line-height: 1.55;
}

.toc::before {
  content: 'Contents';
  display: block;
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", Georgia, Cambria, serif;
  font-weight: 600;
  font-size: 1em;
  margin-bottom: 0.45em;
}

.toc ol,
.toc ul {
  margin: 0;
  padding-left: 1.3rem;
}

.toc li {
  margin: 0.25em 0;
}

.toc a {
  color: var(--fg);
  text-decoration: none;
}

.toc a:hover {
  color: var(--link);
  text-decoration: underline;
}

@media (min-width: 66rem) {
  .content.has-side-toc {
    max-width: 78rem;
  }

  .content.has-side-toc .post-shell {
    display: grid;
    grid-template-columns: minmax(14rem, 18rem) minmax(0, var(--measure));
    gap: 2rem;
    align-items: start;
  }

  .content.has-side-toc .post-main {
    grid-column: 2;
  }

  .content.has-side-toc .post-toc {
    grid-column: 1;
  }

  .content.has-side-toc .post-toc {
    position: sticky;
    top: 1rem;
    align-self: start;
  }

  .content.has-side-toc .post-toc .toc {
    margin: 0;
    font-size: 0.84rem;
    max-height: calc(100vh - 2rem);
    overflow: auto;
  }
}

/* Collapsible sections */
details.collapsible-section {
  margin: 2em 0;
}

details.collapsible-section > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 0.45em;
  border-top: 1px solid var(--border);
  padding-top: 0.25em;
}

details.collapsible-section > summary::-webkit-details-marker {
  display: none;
}

details.collapsible-section > summary::before {
  content: '▶';
  font-size: 0.6em;
  display: inline-block;
  transition: transform 0.15s ease;
  flex-shrink: 0;
  color: var(--muted);
  position: relative;
  top: -0.1em;
}

details.collapsible-section[open] > summary::before {
  transform: rotate(90deg);
}

details.collapsible-section > summary h2 {
  margin-top: 0.52em;
}

details.collapsible-section > summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
