/* ── Variables ──────────────────────────────────────────── */
:root {
  --radius: 12px;
  --radius-sm: 6px;
  --font: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;

  /* Code blocks stay dark in both themes — the Rouge/Dracula
     syntax palette below is only legible on a dark background. */
  --code-bg: #12121a;
  --code-border: #2a2a38;
  --code-text: #e2e2f0;
  --code-accent: #29d9c2;
}

/* Dark theme (default) */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f13;
  --surface: #18181f;
  --surface-hover: #1f1f28;
  --border: #2a2a38;
  --text: #e2e2f0;
  --text-muted: #888899;
  --accent-1: #7c6af7;
  --accent-2: #f06292;
  --accent-3: #29d9c2;
  --accent-4: #f9a825;
  --link: #7c6af7;
}

/* Light theme */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f5f5fa;
  --surface-hover: #ececf5;
  --border: #e2e2ec;
  --text: #17171f;
  --text-muted: #61616c;
  --accent-1: #6949e8;
  --accent-2: #d6336c;
  --accent-3: #0e9488;
  --accent-4: #92600a;
  --link: #6949e8;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ───────────────────────────────────────────────── */
html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ── Layout ─────────────────────────────────────────────── */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.main-content {
  flex: 1;
  padding: 3rem 0 5rem;
}

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 0;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.site-header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.site-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  text-decoration: none;
}

.logo-accent {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-right: 0.3rem;
}

.site-nav {
  display: flex;
  gap: 2rem;
}

.site-nav a {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.15s;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a.active {
  color: var(--text);
}

/* ── Theme toggle ───────────────────────────────────────── */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.theme-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
}

.theme-btn:hover { color: var(--text); }

.theme-btn.active {
  background: var(--bg);
  color: var(--accent-1);
}

/* ── Hero (home page) ───────────────────────────────────── */
.hero {
  padding: 4rem 0 3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 3rem;
}

.hero-eyebrow {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-1);
  margin-bottom: 1rem;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.15;
  margin-bottom: 1rem;
}

.hero h1 .gradient-text {
  background: linear-gradient(135deg, var(--accent-1) 0%, var(--accent-2) 50%, var(--accent-3) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 520px;
}

/* ── Post list ──────────────────────────────────────────── */
.posts-section h2 {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.post-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  position: relative;
  overflow: hidden;
}

.post-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.2s;
}

.post-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.post-card:hover::before { opacity: 1; }

.post-card a {
  text-decoration: none;
  color: inherit;
}

.post-card a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.post-card-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 0.5rem;
}

.post-card-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.post-card-excerpt {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid;
}

/* Cycle tag colors */
.tag:nth-child(4n+1) { color: var(--accent-1); border-color: var(--accent-1); background: color-mix(in srgb, var(--accent-1) 10%, transparent); }
.tag:nth-child(4n+2) { color: var(--accent-2); border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 10%, transparent); }
.tag:nth-child(4n+3) { color: var(--accent-3); border-color: var(--accent-3); background: color-mix(in srgb, var(--accent-3) 10%, transparent); }
.tag:nth-child(4n)   { color: var(--accent-4); border-color: var(--accent-4); background: color-mix(in srgb, var(--accent-4) 10%, transparent); }

.no-posts {
  text-align: center;
  color: var(--text-muted);
  padding: 4rem 0;
}

/* ── Post page ──────────────────────────────────────────── */
.post {
  width: min(100% - 3rem, 680px);
  margin: 0 auto;
  transition: width 0.2s ease;
}

html[data-post-width="wide"] .post { width: min(100% - 3rem, 1120px); }

.post-header { margin-bottom: 3rem; }

.post-header-tools {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-family: var(--font-mono);
}

.meta-sep { color: var(--border); }

.post-width-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font: 500 0.75rem/1 var(--font);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.post-width-toggle:hover,
.post-width-toggle[aria-pressed="true"] {
  border-color: var(--accent-1);
  background: color-mix(in srgb, var(--accent-1) 10%, var(--surface));
  color: var(--text);
}

.post-width-toggle svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
}

.post-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.post-subtitle {
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Post body typography ───────────────────────────────── */
.post-body { font-size: 1.05rem; line-height: 1.8; }

.post-body h2,
.post-body h3,
.post-body h4 {
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.3;
  margin: 2.5rem 0 1rem;
}

.post-body h2 { font-size: 1.5rem; }
.post-body h3 { font-size: 1.2rem; }

.post-body p { margin-bottom: 1.5rem; }

.post-body ul,
.post-body ol {
  margin: 0 0 1.5rem 1.5rem;
}

.post-body li { margin-bottom: 0.4rem; }

.post-body blockquote {
  border-left: 3px solid var(--accent-1);
  margin: 2rem 0;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  font-style: italic;
}

.post-body a {
  color: var(--accent-1);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.post-body a:hover { color: var(--accent-2); }

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--code-accent);
}

.post-body pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.post-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--code-text);
  font-size: 0.88rem;
}

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

/* ── Post footer ────────────────────────────────────────── */
.post-footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.back-link {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.back-link:hover { color: var(--text); text-decoration: none; }

/* ── Comments ───────────────────────────────────────────── */
.comments {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

/* ── About page ─────────────────────────────────────────── */
.about-page { max-width: 640px; margin: 0 auto; }

.about-page h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin-bottom: 2rem;
}

.about-page p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 1.05rem;
  line-height: 1.8;
}

.about-page a { color: var(--accent-1); }

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

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

/* ── Post images ────────────────────────────────────────── */
.post-body figure {
  margin: 2.5rem 0;
}

.post-body figure img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}

.post-body figcaption {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-style: italic;
  line-height: 1.5;
}

/* ── Series nav ─────────────────────────────────────────── */
.series-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-1);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 3rem;
}

.series-nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-1);
  margin-bottom: 0.75rem;
}

.series-nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.series-nav-list li {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.series-nav-list li.current {
  color: var(--text);
  font-weight: 600;
}

.series-nav-list li.current::before {
  content: "→ ";
  color: var(--accent-1);
}

.series-nav-list a {
  color: inherit;
  text-decoration: none;
}

.series-nav-list a:hover { color: var(--text); }

/* ── Syntax highlighting (Rouge/Monokai-ish) ─────────────── */
.highlight .c  { color: #6272a4; font-style: italic }
.highlight .k  { color: #ff79c6 }
.highlight .n  { color: var(--code-text) }
.highlight .s  { color: #f1fa8c }
.highlight .s1 { color: #f1fa8c }
.highlight .s2 { color: #f1fa8c }
.highlight .o  { color: #ff79c6 }
.highlight .p  { color: var(--code-text) }
.highlight .kd { color: #ff79c6 }
.highlight .kn { color: #ff79c6 }
.highlight .nb { color: #8be9fd }
.highlight .nf { color: #50fa7b }
.highlight .nc { color: #8be9fd; font-style: italic }
.highlight .mi { color: #bd93f9 }
.highlight .mf { color: #bd93f9 }
.highlight .cm { color: #6272a4; font-style: italic }
.highlight .cp { color: #ff79c6 }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 600px) {
  .site-header .container { gap: 1rem; }
  .site-header-right { gap: 1rem; }
  .site-nav { gap: 1.25rem; }
  .hero { padding: 2.5rem 0 2rem; }
  .post-card { padding: 1.25rem; }
  .post { width: min(100% - 2rem, 680px); }
  html[data-post-width="wide"] .post { width: min(100% - 2rem, 680px); }
  .post-width-toggle span { display: none; }
}
