/* ── Variables ── */
:root {
  --color-text: #2c2c2c;
  --color-text-secondary: #5c5c5c;
  --color-bg: #faf9f7;
  --color-bg-alt: #f2f0ec;
  --color-border: #e0ddd8;
  --color-accent: #3d6b5e;
  --color-accent-hover: #2d5046;
  --color-wip-bg: #fef3c7;
  --color-wip-border: #f59e0b;
  --color-wip-text: #92400e;
}

/* Dark mode: system preference (unless user chose light) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-text: #e8e2da;
    --color-text-secondary: #a8a098;
    --color-bg: #1c1b19;
    --color-bg-alt: #2a2825;
    --color-border: #3d3a35;
    --color-accent: #5e9e8b;
    --color-accent-hover: #7dbaa8;
    --color-wip-bg: #3d3520;
    --color-wip-border: #b87a08;
    --color-wip-text: #fbbf24;
  }
}

/* Dark mode: explicit user toggle */
[data-theme="dark"] {
  --color-text: #e8e2da;
  --color-text-secondary: #a8a098;
  --color-bg: #1c1b19;
  --color-bg-alt: #2a2825;
  --color-border: #3d3a35;
  --color-accent: #5e9e8b;
  --color-accent-hover: #7dbaa8;
  --color-wip-bg: #3d3520;
  --color-wip-border: #b87a08;
  --color-wip-text: #fbbf24;
}

/* ── Base ── */
html {
  scrollbar-gutter: stable;
}

/* Keep scrollbar visible when lightbox opens so GLightbox's
   margin-right compensation doesn't break body centering */
html.glightbox-open {
  overflow-y: scroll !important;
}

body.gscrollbar-fixer {
  margin-right: auto !important;
}

body {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  margin: 0 auto;
  max-width: 46rem;
  padding: 0 1.5rem;
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
  color: var(--color-text);
  font-weight: 600;
  line-height: 1.3;
  margin: 2rem 0 1rem;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

.heading-anchor {
  color: inherit;
  text-decoration: none;
}

.heading-anchor:hover {
  text-decoration: underline;
  text-decoration-color: var(--color-accent);
}

p {
  color: var(--color-text-secondary);
  margin: 1.25rem 0;
}

ul, ol {
  color: var(--color-text-secondary);
  margin: 1.25rem 0;
  padding-left: 1.75rem;
}

ul li, ol li {
  margin: 0.4rem 0;
}

img, figure {
  max-width: 100%;
  height: auto;
  margin: 2rem 0;
  border-radius: 4px;
}

/* ── Header / Nav ── */
header {
  padding: 1.5rem 0 1rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2rem;
}

header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header nav a {
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* ── Article ── */
article .date {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
  margin: -1rem 0 2rem;
}

.last-updated {
  color: var(--color-text-secondary);
  font-style: italic;
}

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

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

a:visited {
  color: var(--color-accent);
}

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

a.glightbox,
a.glightbox:hover {
  border-bottom: none;
}

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 1rem;
  display: block;
  overflow-x: auto;
}

thead {
  display: table;
  width: 100%;
  table-layout: fixed;
}

tbody {
  display: table;
  width: 100%;
  table-layout: fixed;
}

th {
  text-align: left;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-bottom: 2px solid var(--color-text);
  color: var(--color-text);
}

td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  vertical-align: top;
}

tr:last-child td {
  border-bottom: none;
}

/* ── Blockquotes ── */
blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--color-bg-alt);
  border-left: 3px solid var(--color-accent);
  border-radius: 2px;
  font-style: italic;
}

blockquote p {
  color: var(--color-text-secondary);
  margin: 0.5rem 0;
}

blockquote p:first-child { margin-top: 0; }
blockquote p:last-child { margin-bottom: 0; }

/* ── Code ── */
code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.875em;
  background: var(--color-bg-alt);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

pre {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  overflow-x: auto;
  line-height: 1.5;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

/* ── WIP Banner ── */
.wip-banner {
  background-color: var(--color-wip-bg);
  border: 1px solid var(--color-wip-border);
  color: var(--color-wip-text);
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin: 1rem 0;
}

/* ── Table of Contents ── */
.toc {
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

.toc summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-text);
  letter-spacing: 0.02em;
}

.toc summary::marker {
  color: var(--color-accent);
}

.toc nav {
  margin-top: 0.75rem;
}

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

.toc nav ul ul {
  padding-left: 1.25rem;
}

.toc nav li {
  margin: 0.25rem 0;
}

.toc nav a {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  border-bottom: none;
}

.toc nav a:hover {
  color: var(--color-accent);
}

/* ── Footer ── */
footer {
  margin-top: 4rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--color-border);
}

/* ── Theme Toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  color: var(--color-text-secondary);
  font-size: 1.1rem;
  line-height: 1;
  transition: color 0.15s ease, border-color 0.15s ease;
}

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

html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

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

  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }
}
