:root {
  --bg: #ffffff;
  --paper: #f6f7f8;
  --ink: #2b2f33;
  --body: #555a60;
  --muted: #646e7c;
  --line: #e7e9ec;
  --accent: #0970a8;
  --accent-strong: #08689a;
  --accent-bright: #13aff0;
  --sans: "Open Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #15181b;
  --paper: #1c2125;
  --ink: #eef1f3;
  --body: #b9c0c7;
  --muted: #828a93;
  --line: #2a3036;
  --accent: #3cc0f2;
  --accent-strong: #6fd0f7;
  --accent-bright: #3cc0f2;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181b;
    --paper: #1c2125;
    --ink: #eef1f3;
    --body: #b9c0c7;
    --muted: #828a93;
    --line: #2a3036;
    --accent: #3cc0f2;
    --accent-strong: #6fd0f7;
    --accent-bright: #3cc0f2;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--body);
  font-size: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--body);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.15;
}

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

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

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

a:focus-visible,
button:focus-visible {
  outline: 0.18rem solid var(--accent);
  outline-offset: 0.2rem;
  border-radius: 0.15rem;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--bg);
  z-index: 10;
}

.skip-link:focus {
  left: 0.75rem;
  top: 0.75rem;
}

.site-shell {
  width: min(100% - 4rem, 72rem);
  margin: 0 auto;
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.6rem 0;
}

.site-brand {
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  color: var(--ink);
}

.site-brand:hover {
  color: var(--ink);
}

.site-name {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

.site-tagline {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.primary-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: end;
  gap: 0.4rem 1.25rem;
}

.primary-nav a {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

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

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin-left: 0.4rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

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

.theme-toggle .theme-icon--dark {
  display: none;
}

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

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

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .theme-icon--light {
    display: none;
  }
  :root:not([data-theme="light"]) .theme-toggle .theme-icon--dark {
    display: inline;
  }
}

/* Main */
.site-main {
  padding: clamp(2.5rem, 6vw, 4.5rem) 0 clamp(3rem, 7vw, 5rem);
}

.eyebrow,
.post-card-cat,
.article-meta {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.4;
  text-transform: uppercase;
}

.post-card-cat {
  display: inline-block;
}

.archive-intro {
  max-width: 40rem;
  margin-bottom: clamp(2.25rem, 5vw, 3.5rem);
}

.archive-intro h1 {
  margin: 0.4rem 0 0;
  font-size: clamp(2rem, 4.5vw, 2.9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.archive-intro > p:last-child {
  max-width: 34rem;
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

/* Post card grid */
.post-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2.5rem 2rem;
}

.post-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.post-card-visual {
  display: block;
  overflow: hidden;
  border-radius: 0.4rem;
  background: var(--line);
  margin-bottom: 1rem;
}

.post-card-visual img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

.post-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: start;
}

.post-card h2 {
  margin: 0.45rem 0 0.5rem;
  font-size: clamp(1.2rem, 2vw, 1.45rem);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.post-card h2 a {
  color: inherit;
}

.post-card h2 a:hover {
  color: var(--accent);
}

.post-card-summary {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.post-card-summary > :first-child {
  margin-top: 0;
}

.post-card-summary > :last-child {
  margin-bottom: 0;
}

.post-card-summary a {
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}

.story-link,
.back-link,
.page-link {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.story-link:hover,
.back-link:hover,
.page-link:hover {
  color: var(--accent-strong);
}

.post-card .story-link {
  margin-top: auto;
  padding-top: 1.1rem;
}

/* Pagination */
.page-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: clamp(2.75rem, 6vw, 4rem);
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.page-info {
  color: var(--muted);
  font-size: 0.83rem;
  text-align: center;
}

.page-navigation .page-link {
  margin: 0;
}

/* Article & page */
.article-full,
.page-full {
  max-width: 46rem;
  margin: 0 auto;
}

.article-header,
.page-header {
  max-width: 40rem;
  margin: 0 auto 2.25rem;
  text-align: center;
}

.article-header h1,
.page-header h1 {
  margin: 0.55rem 0 0;
  font-size: clamp(1.9rem, 5vw, 2.9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  text-wrap: balance;
}

.article-meta .article-category {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}

.article-meta .article-category:hover {
  color: var(--accent-strong);
}

.article-content,
.page-content {
  padding: clamp(1.25rem, 4vw, 2.5rem);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  color: var(--body);
  font-family: var(--sans);
  font-size: 1.06rem;
  line-height: 1.75;
}

.article-content > *,
.page-content > * {
  margin-top: 0;
  margin-bottom: 1.4rem;
}

.article-content > p,
.article-content > ul,
.article-content > ol,
.article-content > h2,
.article-content > h3,
.article-content > h4,
.article-content > blockquote,
.article-content > pre,
.article-content > table,
.article-content .gallery,
.page-content > * {
  max-width: 100%;
  margin-right: auto;
  margin-left: auto;
}

.article-content h2,
.article-content h3,
.article-content h4,
.page-content h2,
.page-content h3,
.page-content h4 {
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.article-content h2,
.page-content h2 {
  margin-top: 2.4rem;
  font-size: clamp(1.5rem, 3vw, 1.95rem);
}

.article-content h3,
.page-content h3 {
  margin-top: 2rem;
  font-size: clamp(1.25rem, 2.4vw, 1.5rem);
}

.article-content a,
.page-content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}

.article-content a:hover,
.page-content a:hover {
  color: var(--accent-strong);
}

.article-content .back-link,
.page-content .back-link {
  text-decoration: none;
}

.article-content ul,
.article-content ol,
.page-content ul,
.page-content ol {
  padding-left: 1.35em;
}

.article-content li + li,
.page-content li + li {
  margin-top: 0.4rem;
}

.article-content blockquote,
.page-content blockquote {
  padding-left: 1.25rem;
  border-left: 3px solid var(--accent-bright);
  color: var(--muted);
  font-style: italic;
}

.article-content pre,
.page-content pre {
  overflow-x: auto;
  padding: 1.1rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.84em;
  line-height: 1.55;
}

.article-content code,
.page-content code {
  font-family: var(--mono);
  font-size: 0.84em;
}

.article-content :not(pre) > code,
.page-content :not(pre) > code {
  padding: 0.12em 0.35em;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0.25rem;
}

/* Images & galleries (emitted by prepare_content.py) */
.article-content figure,
.article-content > p:has(> img),
.article-content > p:has(> a > img) {
  max-width: 100%;
  margin-right: auto;
  margin-left: auto;
}

.article-content img,
.page-content img {
  max-width: 100%;
  margin: 2rem auto;
  cursor: zoom-in;
}

.article-content figure img,
.article-content .gallery img {
  margin: 0;
}

.article-content figcaption {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  text-align: center;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.7rem;
}

.gallery figure {
  margin: 0;
}

.gallery a {
  display: block;
  overflow: hidden;
  border-radius: 0.3rem;
  background: var(--line);
}

.gallery img {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.gallery figcaption {
  padding: 0.55rem 0.1rem 0;
  text-align: left;
}

.article-content table,
.page-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88em;
}

.article-content th,
.article-content td,
.page-content th,
.page-content td {
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

/* Article footer */
.article-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  max-width: 46rem;
  margin: 1.5rem auto 0;
}

.article-footer .back-link {
  margin: 0;
}

.empty-state {
  max-width: 44rem;
  margin: 0;
  color: var(--muted);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--line);
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 2rem;
  padding: 1.5rem 0 2.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}

.site-footer a:hover {
  color: var(--accent);
}

/* GLightbox overlay tint */
.goverlay {
  background: rgb(15 18 20 / 92%);
}

@media (max-width: 1024px) {
  .post-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .site-shell {
    width: min(100% - 3rem, 72rem);
  }

  .site-header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem 0;
  }

  .primary-nav {
    justify-content: flex-start;
  }

  .post-grid {
    grid-template-columns: 1fr;
    gap: 2.25rem;
  }

  .article-content,
  .page-content {
    font-size: 1.02rem;
  }

  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  }

  .page-navigation {
    flex-wrap: wrap;
  }

  .page-info {
    order: 3;
    width: 100%;
  }

  .site-footer-inner {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

@media print {
  .site-header,
  .site-footer,
  .article-footer,
  .page-navigation,
  .theme-toggle {
    display: none;
  }

  .site-main {
    padding: 0;
  }

  body,
  html {
    background: #fff;
  }
}
