:root {
  --font-body: p22-stickley-pro-text, neue-kabel, Palatino, Georgia, serif;
  --font-heading: neue-kabel, 'Gill Sans', 'Helvetica Neue', sans-serif;

  /* Light theme (default) */
  --color-bg: #fffff8;
  --color-text: #111;
  --color-muted: #666;
  --color-link: #555;
  --color-link-hover: #222;
  --color-border: #ccc;
}

/* System dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1d23;
    --color-text: #dad8d8;
    --color-muted: #888;
    --color-link: #aaa;
    --color-link-hover: #ccc;
    --color-border: #333;
  }
}

/* User preference overrides */
html[data-force-theme="light"],
body.light-mode {
  --color-bg: #fffff8;
  --color-text: #111;
  --color-muted: #666;
  --color-link: #555;
  --color-link-hover: #222;
  --color-border: #ccc;
}

html[data-force-theme="dark"],
body.dark-mode {
  --color-bg: #1a1d23;
  --color-text: #dad8d8;
  --color-muted: #888;
  --color-link: #aaa;
  --color-link-hover: #ccc;
  --color-border: #333;
}

html {
  font-size: clamp(1rem, .8rem + 1vw, 1.25rem);
}

body {
  --measure: min(90%, 48ch);
  background-color: var(--color-bg);
  color: var(--color-text);
  counter-reset: sidenote-counter;
  font-family: var(--font-body);
  margin: 0;
  width: 100vw;
  box-sizing: content-box;
  margin-inline: auto;
  max-inline-size: var(--measure);
  margin-bottom: 3em;
  padding: 0 1rem;
}

h2 + *,
* {
  margin-block: 0;
}

* + * {
  margin-block-start: 1rem;
}

p {
  line-height: 1.6em;
}

h1, h2 {
  font-family: var(--font-heading);
  font-weight: 600;
}

h1 {
  font-size: 3em;
  padding-top: 1em;
  letter-spacing: -1.5px;
}

h2 {
  margin-bottom: .25em;
  text-align: center;
  margin-top: 2em;
}

h3 {
  font-style: italic;
  font-size: inherit;
  font-family: var(--font-heading);
  font-weight: 400;
  margin-bottom: 0;
}

h4 {
  font-family: var(--font-body);
  font-style: italic;
  font-size: inherit;
  font-weight: 600;
  margin-bottom: 0;
  margin-top: 3em;
  text-align: center;
  letter-spacing: -.04em;
}


summary {
  font-size: inherit;
  font-weight: 600;
  margin-bottom: 0;
  margin-top: 3em;
  margin-left: -2em;
  text-align: left;
  letter-spacing: -.04em;
}

details {
  font-family: monospace;
  color: var(--color-muted);
  margin-left: 2em;
  margin-right: 2em;
  font-size: 60%;
  line-height: 1.125;
}

h2 + h4 {
  margin-top: 1em;
}

h4::before, h4::after {
  content: "  \2014  ";
}

blockquote {
  font-style: italic;
  margin-block-start: .25em;
  margin-block-end: 1em;
  margin-inline-start: 1em;
  margin-inline-end: 1em;
  padding-inline-start: 1em;
  border-left: 1px solid var(--color-muted);
}

img {
  width: 100%;
}

.drop::first-letter {
  font-size: 400%;
  float: left;
  line-height: .63;
  margin-right: 0.02em;
}

.drop {
  margin-top: 3em;
}

.first-line::first-line,
.drop::first-line {
  font-variant: small-caps;
  font-size: 120%;
}

a {
  color: var(--color-link);
  text-decoration: none;
}

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

/* Site Navigation */
.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1rem 0;
  font-size: .85rem;
  font-family: var(--font-heading);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2rem;
}

.site-nav-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

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

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

/* Table of Contents */
.toc {
  list-style: none;
  padding: 0;
  margin: 2rem 0;
}

.toc li {
  margin: .5rem 0;
}

.toc a {
  font-size: 1.1rem;
}

/* Chapter Header */
.chapter-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.chapter-header .chapter-number {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin: 0 0 0.5rem;
}

.chapter-header h1 {
  margin: 0;
  padding-top: 0;
}

/* Chapter Navigation */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: baseline;
  margin-top: 3em;
  padding-top: 1em;
  border-top: 1px solid var(--color-border);
  font-size: .9em;
  font-family: var(--font-heading);
}

.chapter-nav-left {
  text-align: left;
}

.chapter-nav-right {
  text-align: right;
}

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

.chapter-nav a:hover {
  color: var(--color-text);
}

/* Theme Switcher */
.theme-switcher {
  position: relative;
}

.theme-toggle {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 1em;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  color: var(--color-muted);
  font-family: inherit;
}

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

.theme-options {
  position: absolute;
  right: 0;
  top: 100%;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  z-index: 10;
  min-width: 7em;
  margin-top: 0.25em;
  font-size: 0.85rem;
}

.theme-options.show {
  display: flex;
}

.theme-option {
  padding: 0.4em 0.8em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  cursor: pointer;
  transition: background-color 0.2s;
  text-decoration: none;
  color: var(--color-text);
}

.theme-option:hover {
  background-color: var(--color-border);
}

.theme-option:first-child {
  border-radius: 4px 4px 0 0;
}

.theme-option:last-child {
  border-radius: 0 0 4px 4px;
}

.theme-option-icon {
  font-size: 0.9em;
  opacity: 0.8;
}

/* Site nav right flexbox */
.site-nav-right {
  display: flex;
  align-items: baseline;
  gap: 1em;
}
