:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #0b0d12;
  --muted: #5e6573;
  --line: #d7dce4;
  --accent: #111827;
  --accent-soft: #e8ecf3;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f7f8fa 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  line-height: 1.7;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.site-shell {
  width: min(1040px, 94vw);
  margin: 1.25rem auto;
  padding: 0 1rem 1rem;
  border: 1px solid var(--line);
  background: var(--surface);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.85rem;
}

.site-nav a {
  position: relative;
  padding: 0.2rem 0;
  color: var(--muted);
  font-size: 0.96rem;
}

.site-nav a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -0.15rem;
  width: 100%;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 180ms ease;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
}

.site-nav a:hover::after,
.site-nav a[aria-current="page"]::after {
  transform: scaleX(1);
}

main {
  padding: 1rem 0 0.25rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: clamp(1.25rem, 4vw, 3rem);
  background: #fbfcfe;
}

.hero h1 {
  max-width: 20ch;
  margin-top: 0.5rem;
  font-size: clamp(2rem, 6vw, 3.7rem);
}

.hero-copy {
  margin: 0.95rem 0 0;
  max-width: 62ch;
  color: var(--muted);
}

.hero-cta {
  display: inline-block;
  margin-top: 1.25rem;
  padding: 0.65rem 0.95rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #f8fafc;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 180ms ease;
}

.hero-cta:hover {
  opacity: 0.85;
}

.section-head {
  margin: 1.9rem 0 1rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.85rem;
}

.section-head h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}

.section-head a {
  color: var(--muted);
  font-size: 0.92rem;
}

.section-head a:hover {
  color: var(--ink);
}

.post-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 0.85rem;
}

.post-card {
  grid-column: span 6;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  transition: transform 180ms ease, border-color 180ms ease;
  animation: fade-up 260ms ease both;
}

.post-card:hover {
  transform: translateY(-2px);
  border-color: #b4bcc8;
}

.post-card-media {
  display: block;
  aspect-ratio: 16 / 10;
  background: linear-gradient(120deg, #eceff4 0%, #e2e8f0 100%);
}

.post-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.88) contrast(1.02);
}

.post-card.text-only .post-card-body {
  padding-top: 1rem;
}

.post-card-body {
  padding: 0.9rem;
}

.post-meta {
  margin: 0;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.post-card h3 {
  margin-top: 0.45rem;
  font-size: 1.18rem;
}

.post-card p {
  margin: 0.55rem 0 0;
  color: var(--muted);
}

.page-intro,
.content-page,
.post {
  border: 1px solid var(--line);
  padding: clamp(1.15rem, 3vw, 2.2rem);
  background: #fcfdff;
}

.page-intro h1,
.content-page h1 {
  margin-top: 0.35rem;
  font-size: clamp(1.8rem, 4.2vw, 2.8rem);
}

.page-intro p,
.content-body {
  color: var(--muted);
}

.content-body p,
.content-body li {
  max-width: 72ch;
}

.post-header {
  max-width: 760px;
  margin: 0 auto 2rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--line);
}

.post-header .post-meta {
  margin-bottom: 0.9rem;
}

.post-header h1 {
  font-size: clamp(2.2rem, 7vw, 4.2rem);
  letter-spacing: -0.03em;
  line-height: 1.02;
}

.post-header .lede {
  margin: 1rem 0 0;
  max-width: 54ch;
  color: #363e4b;
  font-size: 1.16rem;
  line-height: 1.55;
}

.post-cover {
  margin-top: 1rem;
  border: 1px solid var(--line);
}

.post-content {
  max-width: 760px;
  margin: 0 auto;
}

.post-content > * + * {
  margin-top: 1rem;
}

.post-content p,
.post-content li {
  color: #1c2430;
  font-size: 1.06rem;
  line-height: 1.84;
}

.post-content h2 {
  margin-top: 2.1rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.post-content h3 {
  margin-top: 1.7rem;
  font-size: clamp(1.24rem, 3vw, 1.45rem);
}

.post-content ul,
.post-content ol {
  padding-left: 1.2rem;
}

.post-content a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.post-content blockquote {
  margin: 1.1rem 0;
  padding: 0.15rem 0 0.15rem 0.95rem;
  border-left: 2px solid var(--ink);
  color: #3f4652;
}

/* Inline code */
.post-content code {
  padding: 0.15rem 0.4rem;
  border: 1px solid #d2d8e1;
  border-radius: 3px;
  background: #f3f6fa;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.88em;
}

/* Fenced code blocks */
.post-content pre {
  margin: 1.25rem 0;
  padding: 1.1rem 1.25rem;
  border: 1px solid #d2d8e1;
  border-radius: var(--radius);
  background: #1a1e2a;
  color: #d4dae6;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  line-height: 1.55;
}

.post-content pre code {
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: inherit;
  font-size: 0.85em;
  line-height: inherit;
}

/* Rouge syntax highlighting (dark theme) */
.highlight { background: #1a1e2a; }
.highlight .c,
.highlight .cm,
.highlight .c1,
.highlight .cs   { color: #636d83; font-style: italic; } /* comments */
.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kp,
.highlight .kr,
.highlight .kt   { color: #c678dd; }                     /* keywords */
.highlight .s,
.highlight .s1,
.highlight .s2,
.highlight .sb,
.highlight .sc,
.highlight .sh,
.highlight .sx   { color: #98c379; }                      /* strings */
.highlight .na   { color: #e5c07b; }                      /* attribute names */
.highlight .nb,
.highlight .bp   { color: #61afef; }                      /* builtins */
.highlight .nf,
.highlight .nx   { color: #61afef; }                      /* functions */
.highlight .nn   { color: #e5c07b; }                      /* namespace */
.highlight .no   { color: #d19a66; }                      /* constants */
.highlight .ni   { color: #d4dae6; }                      /* entities */
.highlight .ne   { color: #e06c75; }                      /* exceptions */
.highlight .nv,
.highlight .vi,
.highlight .vc,
.highlight .vg,
.highlight .vm   { color: #e06c75; }                      /* variables */
.highlight .o,
.highlight .ow   { color: #56b6c2; }                      /* operators */
.highlight .m,
.highlight .mi,
.highlight .mf,
.highlight .mh,
.highlight .mo   { color: #d19a66; }                      /* numbers */
.highlight .p    { color: #abb2bf; }                       /* punctuation */
.highlight .gd   { color: #e06c75; }                       /* diff deleted */
.highlight .gi   { color: #98c379; }                       /* diff inserted */

/* Back to top */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 1.1rem;
  text-decoration: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 100;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  transform: translateY(-2px);
  color: var(--ink);
  border-color: var(--ink);
}

/* Highlight wrapper from Rouge */
.post-content div.highlight {
  margin: 1.25rem 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.post-content div.highlight pre {
  margin: 0;
  border-radius: 0;
}

.more-posts {
  max-width: 980px;
  margin: 2.2rem auto 0;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.more-posts h2 {
  margin-bottom: 0.95rem;
  font-size: clamp(1.35rem, 3.4vw, 1.75rem);
}

.site-footer {
  margin-top: 1.5rem;
  padding-top: 0.95rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

/* Table of contents */
.post-toc {
  max-width: 760px;
  margin: 1rem auto 1.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8f9fb;
}

.toc-label {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

.post-toc li {
  margin: 0.3rem 0;
}

.post-toc a {
  color: var(--ink);
  font-size: 0.92rem;
  text-decoration: none;
}

.post-toc a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* Post navigation (prev/next) */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: 760px;
  margin: 2.5rem auto 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.post-nav-link {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 48%;
  text-decoration: none;
}

.post-nav-next {
  margin-left: auto;
  text-align: right;
}

.post-nav-dir {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.post-nav-title {
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.3;
}

a.post-nav-link:hover .post-nav-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* 404 page */
.error-page {
  border: 1px solid var(--line);
  padding: clamp(2rem, 6vw, 4rem) clamp(1.25rem, 4vw, 3rem);
  background: #fcfdff;
  text-align: center;
}

.error-page h1 {
  margin-top: 0.5rem;
  font-size: clamp(2.2rem, 7vw, 3.5rem);
}

.error-copy {
  margin: 1rem auto 0;
  max-width: 42ch;
  color: var(--muted);
  font-size: 1.06rem;
}

.error-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.error-links a {
  color: var(--ink);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.error-links a:hover {
  opacity: 0.7;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .site-shell {
    width: min(96vw, 1040px);
    margin: 0.6rem auto;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .post-card {
    grid-column: span 12;
  }
}

@media (max-width: 560px) {
  .site-shell {
    padding: 0 0.8rem 0.8rem;
  }

  .site-nav {
    width: 100%;
    justify-content: space-between;
  }

  .hero h1 {
    font-size: clamp(1.85rem, 11vw, 2.4rem);
  }
}

/* Dark mode */
[data-theme="dark"] {
  --bg: #0e1117;
  --surface: #161b22;
  --ink: #e6edf3;
  --muted: #8b949e;
  --line: #30363d;
  --accent: #e6edf3;
  --accent-soft: #1c2128;
}

[data-theme="dark"] body {
  background: linear-gradient(180deg, #111318 0%, var(--bg) 100%);
}

[data-theme="dark"] .hero {
  background: #12161e;
  border-color: var(--line);
  border-left-color: var(--accent);
}

[data-theme="dark"] .page-intro,
[data-theme="dark"] .content-page,
[data-theme="dark"] .post {
  background: #12161e;
  border-color: var(--line);
}

[data-theme="dark"] .error-page {
  background: #12161e;
  border-color: var(--line);
}

[data-theme="dark"] .post-content p,
[data-theme="dark"] .post-content li {
  color: #c9d1d9;
}

[data-theme="dark"] .post-content blockquote {
  color: var(--muted);
  border-left-color: var(--muted);
}

[data-theme="dark"] .post-content code {
  background: #1c2128;
  border-color: var(--line);
  color: #e6edf3;
}

[data-theme="dark"] .post-content pre {
  border-color: var(--line);
}

[data-theme="dark"] .post-toc {
  background: #12161e;
  border-color: var(--line);
}

[data-theme="dark"] .post-toc a {
  color: var(--ink);
}

[data-theme="dark"] .post-card {
  background: var(--surface);
  border-color: var(--line);
}

[data-theme="dark"] .post-card:hover {
  border-color: #484f58;
}

[data-theme="dark"] .post-card-media {
  background: linear-gradient(120deg, #1c2128 0%, #21262d 100%);
}

[data-theme="dark"] .hero-cta {
  background: var(--ink);
  border-color: var(--ink);
  color: #0e1117;
}

[data-theme="dark"] .back-to-top {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .post-content a {
  color: var(--ink);
}

[data-theme="dark"] .post-header .lede {
  color: var(--muted);
}

[data-theme="dark"] .post-card p {
  color: var(--muted);
}

[data-theme="dark"] .content-body {
  color: var(--muted);
}

[data-theme="dark"] .page-intro p {
  color: var(--muted);
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem;
  color: var(--muted);
  transition: color 150ms ease;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.theme-toggle svg {
  display: block;
}

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