/* Tufte-style Typography - Grayscale Dark Mode */

:root {
  /* Grayscale palette for dark mode */
  --bg-primary: #1a1a1a;
  --bg-secondary: #242424;
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-muted: #808080;
  --border-color: #404040;
  --code-bg: #2a2a2a;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: #0f0f0f;
  color: var(--text-primary);
  font-family: 'Source Serif 4', 'Georgia', 'Times New Roman', serif;
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.6;
  max-width: 875px;
  margin: 0 auto;
  padding: 3rem 2rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 400;
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

h1 {
  font-size: 2.5rem;
  margin-top: 0;
}

.site-title {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', 'Source Code Pro', Menlo, Monaco, Consolas, monospace;
  font-size: 3.5rem;
  text-align: center;
  margin-bottom: 4rem;
}

.site-title .errata {
  color: #c44;
}

h2 {
  font-size: 1.8rem;
}

h3 {
  font-size: 1.4rem;
  font-style: italic;
}

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

/* Paragraphs: 1.5em indent, 0 margins (one blank line = indent only; two+ = use .after-break) */
p {
  text-indent: 1.5em;
  margin-top: 0;
  margin-bottom: 0;
  text-align: justify;
  font-size: 1.15rem;
  line-height: 1.6;
  hyphens: auto;
  -webkit-hyphenate-limit-before: 4;
  -webkit-hyphenate-limit-after: 4;
  hyphenate-limit-chars: 9 4 4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: normal;
  text-justify: inter-word;
  word-spacing: 0.08em;
  letter-spacing: 0.015em;
}

/* Exception: First paragraph after heading or blockquote has no indent */
h1 + p,
h2 + p,
h3 + p,
h4 + p,
h5 + p,
h6 + p,
blockquote + p {
  text-indent: 0;
}

/* Also reset indent for first paragraph in article/section */
article > p:first-of-type,
section > p:first-of-type,
.content > p:first-of-type {
  text-indent: 0;
}

/* Paragraph after 2+ blank lines in markdown: no indent, extra space above */
p.after-break {
  text-indent: 0;
  margin-top: 1.5em;
}

/* Paragraphs that are only bold/italic (subheadings, epigraphs): no indent */
p.no-indent {
  text-indent: 0;
}

/* Emphasis: Italics and bold */
em, i {
  font-style: italic;
}

strong, b {
  font-weight: 600;
}

/* Links */
a {
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 1px solid var(--border-color);
  transition: border-color 0.2s ease;
}

a:hover {
  border-bottom-color: var(--text-primary);
}

/* Blockquotes - Tufte style */
blockquote {
  margin: 2rem auto;
  padding: 0;
  border: none;
  font-family: 'Courier New', Courier, monospace;
  font-style: normal;
  color: var(--text-primary);
  width: 70%;
  position: relative;
}

blockquote::before {
  content: '\201C';
  font-family: 'Times New Roman', Times, serif;
  font-size: 3rem;
  line-height: 1;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.5rem;
  margin-left: -2.5rem;
  font-style: italic;
}

blockquote::after {
  content: '\201D';
  font-family: 'Times New Roman', Times, serif;
  font-size: 3rem;
  line-height: 1;
  color: var(--text-muted);
  display: block;
  margin-top: 0.5rem;
  margin-right: -2.5rem;
  text-align: right;
  font-style: italic;
}

blockquote p {
  text-indent: 0;
}

blockquote footer {
  text-align: right;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-top: 0.5rem;
  font-style: normal;
}

/* Compact quote - smaller with reduced vertical height */
.quote-small {
  margin: 0.75rem auto;
  padding: 0;
  border: none;
  font-family: 'Courier New', Courier, monospace;
  font-style: normal;
  color: var(--text-primary);
  width: 70%;
  position: relative;
  font-size: 0.95rem;
  line-height: 1.3;
}

.quote-small::before {
  content: '\201C';
  font-family: 'Times New Roman', Times, serif;
  font-size: 2rem;
  line-height: 1;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.25rem;
  margin-left: -2.5rem;
  font-style: italic;
}

.quote-small::after {
  content: '\201D';
  font-family: 'Times New Roman', Times, serif;
  font-size: 2rem;
  line-height: 1;
  color: var(--text-muted);
  display: block;
  margin-top: 0.25rem;
  margin-right: -2.5rem;
  text-align: right;
  font-style: italic;
}

.quote-small p {
  text-indent: 0;
  line-height: 1.3;
}

.quote-small footer {
  text-align: right;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-top: 0.25rem;
  font-style: normal;
}

/* Container - general purpose content box */
.container {
  margin: 1.5rem 0;
  padding: 1.5rem;
  border: 1px solid #eee;
  background-color: rgba(255, 255, 255, 0.05);
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.6;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphenate-limit-before: 4;
  -webkit-hyphenate-limit-after: 4;
  hyphenate-limit-chars: 9 4 4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: normal;
  text-justify: inter-word;
  word-spacing: 0.08em;
  letter-spacing: 0.015em;
}

/* Images */
.content-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.5rem auto;
  border: 1px solid var(--border-color);
}

/* Lists */
ul, ol {
  margin: 1rem 0;
  padding-left: 2rem;
}

li {
  margin: 0.5rem 0;
  font-size: 1.15rem;
  line-height: 1.6;
}

/* Code blocks */
code {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
  background-color: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  color: var(--text-secondary);
}

pre {
  background-color: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1.5rem 0;
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

/* Horizontal rules */
hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2.5rem 0;
  width: 30%;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

th, td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  font-variant: small-caps;
  letter-spacing: 0.05em;
  font-weight: normal;
  color: var(--text-primary);
}

/* Sidenotes - Tufte style (for margin notes) */
.sidenote,
.marginnote {
  float: right;
  clear: right;
  margin-right: -320px;
  width: 280px;
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
  vertical-align: baseline;
  position: relative;
  color: var(--text-muted);
}

.sidenote-number {
  counter-increment: sidenote-counter;
}

.sidenote-number::after {
  content: counter(sidenote-counter);
  font-size: 0.7rem;
  top: -0.5rem;
  left: 0.1rem;
  position: relative;
  vertical-align: baseline;
}

/* Article header */
.article-header {
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 2rem;
}

.article-title {
  font-size: 2.8rem;
  margin-bottom: 0.5rem;
  font-weight: 400;
  line-height: 1.2;
}

.article-meta {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-variant: small-caps;
  letter-spacing: 0.05em;
}

/* Navigation */
nav {
  margin-bottom: 3rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 2rem;
}

nav li {
  margin: 0;
}

nav a {
  font-family: 'Source Serif 4', 'Georgia', 'Times New Roman', serif;
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: 0.05em;
  font-size: 1.2rem;
  border: none;
}

nav a.nav-site-title {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', 'Source Code Pro', Menlo, Monaco, Consolas, monospace;
  font-variant: normal;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0;
}

nav a.nav-site-title .errata {
  color: #c44;
}

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

/* Footer */
footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

/* Post Entry (for index page) */
.post-entry {
  margin-bottom: 1.75rem;
  padding-bottom: 0;
  border-bottom: none;
}

.post-entry:last-child {
  border-bottom: none;
}

.post-entry h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  font-size: 1.6rem;
}

.post-entry h2 a {
  border: none;
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  transition: color 0.2s ease;
}

.post-entry h2 a:hover {
  color: var(--text-secondary);
}

.post-entry .article-meta {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-variant: small-caps;
  letter-spacing: 0.05em;
}

/* Hover Popup/Tooltip */
.popup {
  position: relative;
  border-bottom: 1px dotted var(--text-secondary);
  cursor: help;
  color: var(--text-secondary);
}

.popup-body {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 0.5rem;
  padding: 0.75rem 1rem;
  background-color: #2a2a2a;
  border: 1px solid var(--border-color);
  border-radius: 0;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-style: normal;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 300px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 100;
  pointer-events: none;
  text-indent: 0;
  font-variant: normal;
  letter-spacing: normal;
  word-spacing: normal;
}

.popup:hover .popup-body {
  opacity: 1;
  visibility: visible;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  body {
    font-size: 1rem;
    padding: 2rem 1.5rem;
  }

  p, li {
    font-size: 1rem;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .article-title {
    font-size: 2.2rem;
  }
}

@media (max-width: 768px) {
  body {
    font-size: 1rem;
    padding: 2rem 1.5rem;
  }
  
  p, li {
    font-size: 1rem;
  }
  
  h1 {
    font-size: 2rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
  
  .article-title {
    font-size: 2.2rem;
  }
}
