/* ========================================================================
   MerMD Blog — Stylesheet
   Inherits design tokens from the main site (../style.css)
   ======================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Custom Properties (mirrored from main site) ─────────────────── */
:root {
  --primary:            #6750A4;
  --primary-light:      #D0BCFF;
  --primary-container:  #EADDFF;
  --on-primary:         #FFFFFF;
  --primary-dark:       #4F378B;
  --bg:                 #0F0E13;
  --bg-elevated:        #1C1B1F;
  --surface:            #1C1B1F;
  --surface-variant:    #49454F;
  --surface-container:  #211F26;
  --text-primary:       #E6E1E5;
  --text-secondary:     #CAC4D0;
  --text-muted:         #938F99;
  --glow-purple:        #2A1F4E;
  --border:             rgba(202, 196, 208, 0.1);
  --glass-bg:           rgba(28, 27, 31, 0.6);
  --glass-border:       rgba(208, 188, 255, 0.12);
  --container-width:    1200px;
  --radius-sm:          8px;
  --radius-md:          16px;
  --radius-lg:          24px;
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-secondary);
  line-height: 1.7;
  overflow-x: hidden;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

a {
  color: var(--primary-light);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: #fff;
}

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

.container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Navbar (mirrored from main site) ────────────────────────────────── */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 16px 0;
  background: transparent;
  transition: background 0.3s ease, padding 0.3s ease, backdrop-filter 0.3s ease;
}

.navbar.scrolled {
  background: rgba(15, 14, 19, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.navbar .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.2rem;
  text-decoration: none;
}

.navbar-brand img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.navbar-links a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease, background 0.2s ease;
  text-decoration: none;
}

.navbar-links a:hover {
  color: var(--text-primary);
  background: rgba(208, 188, 255, 0.08);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none !important;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  padding: 10px 24px;
  font-size: 0.9rem;
}

.btn-primary:hover {
  background: #7B61FF;
  color: #fff;
  box-shadow: 0 8px 32px rgba(103, 80, 164, 0.4);
  transform: translateY(-2px);
}

.navbar-toggle {
  display: none;
}

/* ── Breadcrumbs ─────────────────────────────────────────────────────── */
.breadcrumbs {
  padding: 120px 0 0;
}

.breadcrumbs nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.breadcrumbs a {
  color: var(--text-secondary);
}

.breadcrumbs a:hover {
  color: var(--primary-light);
}

.breadcrumbs .separator {
  color: var(--text-muted);
}

.breadcrumbs .current {
  color: var(--text-primary);
}

/* ── Article Header ──────────────────────────────────────────────────── */
.article-header {
  padding: 32px 0 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 48px;
}

.article-header h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.article-meta .tag {
  display: inline-block;
  background: rgba(103, 80, 164, 0.15);
  color: var(--primary-light);
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 500;
}

/* ── Article Body ────────────────────────────────────────────────────── */
.article-layout {
  display: grid;
  grid-template-columns: 1fr min(720px, 100%) 1fr;
  padding-bottom: 80px;
  overflow-x: hidden;
}

.article-layout > * {
  grid-column: 2;
  min-width: 0;
}

.article-body h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 48px 0 16px;
  letter-spacing: -0.02em;
}

.article-body h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 36px 0 12px;
}

.article-body p {
  margin-bottom: 20px;
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-secondary);
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.article-body strong {
  color: var(--text-primary);
}

.article-body ul, .article-body ol {
  margin: 0 0 24px 24px;
}

.article-body li {
  margin-bottom: 8px;
  font-size: 1.02rem;
  line-height: 1.7;
}

.article-body blockquote {
  border-left: 3px solid var(--primary);
  padding: 16px 24px;
  margin: 24px 0;
  background: rgba(103, 80, 164, 0.06);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--text-secondary);
}

/* ── Tables ──────────────────────────────────────────────────────────── */
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 0.95rem;
  display: table;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.article-body th {
  background: rgba(103, 80, 164, 0.12);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.88rem;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 2px solid rgba(103, 80, 164, 0.3);
  white-space: nowrap;
}

.article-body td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
  line-height: 1.6;
}

.article-body tbody tr:hover {
  background: rgba(103, 80, 164, 0.04);
}

.article-body tbody tr:last-child td {
  border-bottom: none;
}

.article-body td code, .article-body th code {
  font-size: 0.82em;
  padding: 1px 6px;
}

/* Table alignment support */
.article-body th[align="center"],
.article-body td[align="center"] {
  text-align: center;
}

.article-body th[align="right"],
.article-body td[align="right"] {
  text-align: right;
}

/* ── Horizontal Rules ───────────────────────────────────────────────── */
.article-body hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--surface-variant), transparent);
  margin: 40px 0;
}

/* ── Images ──────────────────────────────────────────────────────────── */
.article-body img {
  border-radius: var(--radius-md);
  margin: 24px 0;
  border: 1px solid var(--border);
}

/* ── Task Lists ─────────────────────────────────────────────────────── */
.article-body ul:has(input[type="checkbox"]) {
  list-style: none;
  margin-left: 0;
  padding-left: 4px;
}

.article-body li:has(> input[type="checkbox"]) {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.article-body input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Definition Lists ───────────────────────────────────────────────── */
.article-body dl {
  margin: 24px 0;
}

.article-body dt {
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 16px;
}

.article-body dd {
  margin-left: 24px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

/* ── Inline Code ────────────────────────────────────────────────────── */
.article-body code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--surface-container);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--primary-light);
}

.article-body pre {
  background: var(--surface-container);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  margin: 24px 0;
  overflow-x: auto;
}

.article-body pre code {
  background: none;
  padding: 0;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.article-body a:not(.btn) {
  color: var(--primary-light);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.article-body a:not(.btn):hover {
  color: #fff;
}

/* ── CTA Box inside articles ─────────────────────────────────────────── */
.article-cta {
  background: linear-gradient(135deg, rgba(103, 80, 164, 0.12), rgba(123, 97, 255, 0.08));
  border: 1px solid rgba(103, 80, 164, 0.3);
  border-radius: var(--radius-lg);
  padding: 40px;
  margin: 48px 0;
  text-align: center;
}

.article-cta h3 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px;
}

.article-cta p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.article-cta .btn-primary,
.article-body a.btn {
  font-size: 1.15rem;
  font-weight: 700;
  padding: 18px 44px;
  border-radius: 100px;
  text-decoration: none !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(103, 80, 164, 0.4);
}

/* ── Related Articles ────────────────────────────────────────────────── */
.related-articles {
  border-top: 1px solid var(--border);
  padding: 60px 0 80px;
}

.related-articles h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 32px;
  text-align: center;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  max-width: 900px;
  margin: 0 auto;
}

.related-card {
  background: var(--surface-container);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 28px;
  transition: border-color 0.3s ease, transform 0.3s ease;
  text-decoration: none;
  display: block;
}

.related-card:hover {
  border-color: rgba(103, 80, 164, 0.4);
  transform: translateY(-4px);
}

.related-card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.related-card p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Blog Listing Page ───────────────────────────────────────────────── */
.blog-hero {
  padding: 140px 0 60px;
  text-align: center;
}

.blog-hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}

.blog-hero p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
}

.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 28px;
  padding-bottom: 100px;
}

.blog-card {
  background: var(--surface-container);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 36px 28px;
  transition: border-color 0.3s ease, transform 0.3s ease;
  text-decoration: none;
  display: flex;
  flex-direction: column;
}

.blog-card:hover {
  border-color: rgba(103, 80, 164, 0.4);
  transform: translateY(-4px);
}

.blog-card .card-tag {
  display: inline-block;
  background: rgba(103, 80, 164, 0.15);
  color: var(--primary-light);
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 16px;
  width: fit-content;
}

.blog-card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  line-height: 1.35;
}

.blog-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
  flex-grow: 1;
}

.blog-card .card-meta {
  margin-top: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── CTA Section ────────────────────────────────────────────────────── */
.cta-card {
  text-align: center;
  background: linear-gradient(135deg, #2A1F4E 0%, var(--surface-container) 100%);
  border: 1px solid rgba(208, 188, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: 80px 40px;
  position: relative;
  overflow: hidden;
}

.cta-card::before {
  content: '';
  position: absolute;
  top: -100px;
  right: -100px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(103, 80, 164, 0.2), transparent 70%);
  filter: blur(40px);
}

.cta-card::after {
  content: '';
  position: absolute;
  bottom: -100px;
  left: -100px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(123, 97, 255, 0.15), transparent 70%);
  filter: blur(40px);
}

.cta-card > * {
  position: relative;
  z-index: 1;
}

.cta-card h2 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.cta-card p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 40px;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.7;
}

.cta-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.btn-large {
  padding: 16px 32px;
  font-size: 1.05rem;
  border-radius: 100px;
}

/* ── Footer ──────────────────────────────────────────────────────────── */
.footer {
  padding: 48px 0;
  border-top: 1px solid var(--border);
}

.footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 24px;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.footer-brand img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.footer-links {
  display: flex;
  gap: 24px;
  list-style: none;
}

.footer-links a {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--text-primary);
}

.footer-copy {
  width: 100%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .container {
    padding: 0 16px;
  }

  /* --- Mobile Navbar Menu --- */
  .navbar.menu-open {
    background: rgba(18, 18, 18, 0.92) !important;
    backdrop-filter: blur(24px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(24px) saturate(180%) !important;
    border-bottom: none !important;
  }

  .navbar-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: rgba(18, 18, 18, 0.92);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: none;
    border-bottom: 1px solid rgba(103, 80, 164, 0.2);
    padding: 12px 24px 24px;
    gap: 4px;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4);
  }

  .navbar-links.open {
    display: flex;
  }

  .navbar-links a {
    padding: 12px 16px;
    font-size: 1rem;
    display: block;
    border-radius: var(--radius-sm);
    transition: background 0.2s ease;
  }

  .navbar-links a:hover {
    background: rgba(103, 80, 164, 0.15);
  }

  .navbar-toggle {
    display: flex;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 8px;
    background: none;
    border: none;
    z-index: 10;
  }

  .navbar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.2s ease;
    transform-origin: center;
  }

  /* Animated X when menu is open */
  .navbar-toggle.active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  .navbar-toggle.active span:nth-child(2) {
    opacity: 0;
  }
  .navbar-toggle.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  /* --- Breadcrumbs --- */
  .breadcrumbs {
    padding-top: 80px;
  }

  .breadcrumbs nav {
    font-size: 0.8rem;
    flex-wrap: wrap;
  }

  /* --- Article Header --- */
  .article-header {
    padding: 20px 0 24px;
    margin-bottom: 32px;
  }

  .article-header h1 {
    font-size: 1.5rem;
    line-height: 1.3;
  }

  .article-meta {
    gap: 12px;
    font-size: 0.8rem;
  }

  /* --- Article Body --- */
  .article-layout {
    grid-template-columns: 1fr;
    padding: 0 16px 60px;
  }

  .article-body h2 {
    font-size: 1.3rem;
    margin: 36px 0 12px;
  }

  .article-body h3 {
    font-size: 1.1rem;
  }

  .article-body p {
    font-size: 0.95rem;
  }

  .article-body li {
    font-size: 0.95rem;
  }

  /* --- Code blocks: prevent horizontal overflow --- */
  .article-body pre {
    max-width: 100%;
    overflow-x: auto;
  }

  .article-body code {
    word-break: break-word;
  }

  /* --- Tables: horizontal scroll wrapper --- */
  .article-body table {
    font-size: 0.85rem;
  }

  .article-body th,
  .article-body td {
    padding: 8px 10px;
  }

  /* --- CTA & Related --- */
  .article-cta {
    padding: 28px 20px;
  }

  .related-grid {
    grid-template-columns: 1fr;
  }

  /* --- Blog Index Grid --- */
  .blog-grid {
    grid-template-columns: 1fr;
  }

  /* --- Footer --- */
  .footer .container {
    flex-direction: column;
    text-align: center;
  }

  .footer-links {
    justify-content: center;
  }
}
