/* === Theme variables === */
:root {
  --color-bg: #ffffff;
  --color-bg-alt: #f7f7f8;
  --color-text: #1a1a1a;
  --color-text-muted: #555;
  --color-heading: #111;
  --color-link: #1a5c8a;
  --color-link-hover: #0d3d5e;
  --color-border: #ddd;
  --color-border-light: #e8e8e8;
  --color-blockquote-bg: #f0f4f7;
  --color-blockquote-border: #9ab;
  --color-table-header-bg: #f0f0f2;
  --color-table-stripe: #fafafa;
  --color-toc-bg: #f5f7fa;
  --color-toc-border: #ccd;
  --color-hr: #ccc;
  --color-code-bg: #f4f4f5;
  --color-toggle-bg: #e0e0e0;
  --color-toggle-text: #333;
}

@media screen {
  [data-theme="dark"] {
    --color-bg: #1a1a2e;
    --color-bg-alt: #16162a;
    --color-text: #d4d4dc;
    --color-text-muted: #999;
    --color-heading: #e8e8f0;
    --color-link: #6aafe6;
    --color-link-hover: #8ec5f0;
    --color-border: #333;
    --color-border-light: #2a2a3e;
    --color-blockquote-bg: #1e1e36;
    --color-blockquote-border: #4a5a7a;
    --color-table-header-bg: #22223a;
    --color-table-stripe: #1e1e32;
    --color-toc-bg: #1e1e36;
    --color-toc-border: #3a3a5a;
    --color-hr: #444;
    --color-code-bg: #22223a;
    --color-toggle-bg: #333;
    --color-toggle-text: #ddd;
  }
}

/* === Base === */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 17px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: 'Georgia', 'Times New Roman', serif;
  line-height: 1.7;
  transition: background-color 0.3s, color 0.3s;
}

article {
  max-width: 44rem;
  margin: 2rem auto;
  padding: 0 1.5rem 4rem;
}

/* === Typography === */
h1, h2, h3, h4 {
  color: var(--color-heading);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  line-height: 1.3;
  margin-top: 2.2rem;
  margin-bottom: 0.6rem;
}

h1 {
  font-size: 1.8rem;
  margin-top: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--color-border);
}

h2 {
  font-size: 1.35rem;
  margin-top: 2.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border-light);
}

h3 {
  font-size: 1.12rem;
  margin-top: 1.8rem;
}

h4 {
  font-size: 1rem;
  font-style: italic;
}

p {
  margin: 0.8rem 0;
}

a {
  color: var(--color-link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

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

strong {
  color: var(--color-heading);
}

em {
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid var(--color-hr);
  margin: 2.5rem 0;
}

/* === Lists === */
ul, ol {
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.35rem;
}

li > p {
  margin: 0.3rem 0;
}

/* === Blockquotes === */
blockquote {
  margin: 1.2rem 0;
  padding: 0.8rem 1.2rem;
  background: var(--color-blockquote-bg);
  border-left: 4px solid var(--color-blockquote-border);
  border-radius: 0 4px 4px 0;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

blockquote p {
  margin: 0.4rem 0;
}

/* === Tables === */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.88rem;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

thead th {
  background: var(--color-table-header-bg);
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
  color: var(--color-heading);
}

tbody td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: var(--color-table-stripe);
}

/* === Code === */
code {
  background: var(--color-code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.9rem;
}

pre {
  background: var(--color-code-bg);
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

/* === Table of Contents === */
.toc {
  background: var(--color-toc-bg);
  border: 1px solid var(--color-toc-border);
  border-radius: 6px;
  padding: 1rem 1.5rem;
  margin: 1.5rem 0 2rem;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 0.9rem;
}

.toc summary {
  font-size: 1rem;
  margin: 0 0 0.6rem;
  padding: 0;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 600;
  cursor: pointer;
  list-style: revert;
}

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

.toc li {
  margin-bottom: 0.25rem;
}

.toc li.toc-sub {
  padding-left: 1.2rem;
  font-size: 0.85rem;
}

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

/* === Theme toggle === */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  background: var(--color-toggle-bg);
  color: var(--color-toggle-text);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s, color 0.3s;
  opacity: 0.6;
  line-height: 1;
}

.theme-toggle:hover {
  opacity: 1;
}

/* Show sun in dark mode, moon in light mode */
.theme-icon-dark { display: inline; }
.theme-icon-light { display: none; }

[data-theme="dark"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: inline; }

/* === Italic disclaimer at end === */
article > p:last-child > em:only-child {
  display: block;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border-light);
}

/* === Responsive === */
@media (max-width: 600px) {
  html {
    font-size: 15px;
  }

  article {
    padding: 0 1rem 3rem;
  }

  table {
    font-size: 0.8rem;
  }

  thead th, tbody td {
    padding: 0.4rem 0.5rem;
  }
}

/* === Print === */
@media print {
  .theme-toggle { display: none; }
  .toc { display: none; }

  body { background: white; color: black; }
  a { color: #1a5c8a; }
  article { max-width: none; }
}
