/* ================================================================
   ML Blog — Design System & Stylesheet
   ================================================================ */

/* --- Tokens --- */
:root {
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-dark: #4f46e5;
  --accent-subtle: #eef2ff;

  --bg: #ffffff;
  --bg-alt: #f8fafc;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-header: #0f172a;
  --bg-code: #f1f5f9;

  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #f1f5f9;
  --text-sidebar: #cbd5e1;
  --text-sidebar-hover: #ffffff;

  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --radius: 8px;
  --radius-sm: 4px;
  --sidebar-width: 280px;
  --header-height: 64px;
  --max-content: 820px;
  --transition: 150ms ease;
}


/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-dark); }
img { max-width: 100%; height: auto; display: block; }
ul, ol { list-style: none; }


/* ================================================================
   HEADER
   ================================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  height: var(--header-height);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 2rem;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-inverse);
  flex-shrink: 0;
}
.logo:hover { color: var(--text-inverse); }
.logo-icon { width: 36px; height: 36px; }
.logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.logo-title { font-weight: 700; font-size: 0.95rem; }
.logo-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Header nav */
.header-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-left: auto;
}
.header-nav a {
  color: var(--text-sidebar);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: color var(--transition);
}
.header-nav a:hover { color: #fff; }

/* Mobile menu toggle */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-sidebar);
  cursor: pointer;
  padding: 0.25rem;
  margin-left: auto;
}


/* ================================================================
   LAYOUT
   ================================================================ */
.layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--header-height));
}


/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  padding: 1.5rem 0;
  overflow-y: auto;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
}
.sidebar-heading {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0 1.25rem;
  margin-bottom: 0.75rem;
}
.sidebar-project { margin-bottom: 0.5rem; }
.sidebar-project-link {
  display: block;
  padding: 0.45rem 1.25rem;
  color: var(--text-sidebar);
  font-weight: 600;
  font-size: 0.875rem;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}
.sidebar-project-link:hover,
.sidebar-project-link.active {
  color: var(--text-sidebar-hover);
  background: var(--bg-sidebar-hover);
  border-left-color: var(--accent);
}
.sidebar-articles { margin-bottom: 0.5rem; }
.sidebar-articles li a {
  display: block;
  padding: 0.3rem 1.25rem 0.3rem 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}
.sidebar-articles li a:hover,
.sidebar-articles li a.active {
  color: var(--text-sidebar-hover);
  border-left-color: var(--accent-light);
}
.see-all {
  font-style: italic;
  opacity: 0.7;
}


/* ================================================================
   MAIN CONTENT
   ================================================================ */
.content {
  flex: 1;
  min-width: 0; /* prevent flex overflow */
  padding: 2.5rem 3rem;
  max-width: calc(var(--max-content) + 6rem);
}


/* --- Home page --- */
.hero { margin-bottom: 2.5rem; }
.hero h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.25rem; }
.hero-sub { color: var(--text-secondary); font-size: 1rem; }

.article-grid {
  display: grid;
  gap: 1rem;
}

/* Article cards */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.card:hover {
  border-color: var(--accent-light);
  box-shadow: 0 2px 12px rgba(99,102,241,0.08);
}
.card-link {
  display: block;
  padding: 1.25rem 1.5rem;
  color: inherit;
}
.card-link:hover { color: inherit; }
.card-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.card-project {
  background: var(--accent-subtle);
  color: var(--accent-dark);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.card-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  line-height: 1.35;
}
.card-summary {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.55;
}
.card-tags { margin-top: 0.6rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }


/* --- Tags --- */
.tag {
  display: inline-block;
  background: var(--bg-alt);
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}


/* --- Project page --- */
.project-header { margin-bottom: 2rem; }
.project-header h1 { font-size: 1.5rem; font-weight: 700; }
.project-description { color: var(--text-secondary); margin-top: 0.25rem; }

.article-list { display: grid; gap: 0; }
.list-item a {
  display: block;
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border-light);
  color: inherit;
  transition: background var(--transition);
}
.list-item a:hover { color: inherit; }
.list-item time {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.list-item h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 0.1rem;
}
.list-item p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}


/* ================================================================
   ARTICLE
   ================================================================ */
.article-header { margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.article-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.article-project {
  background: var(--accent-subtle);
  color: var(--accent-dark);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.article-header h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.25; }
.article-summary {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  line-height: 1.6;
}
.article-tags { margin-top: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* Article body wrapper for TOC layout */
.article-body-wrapper {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
}
.article-body { flex: 1; min-width: 0; }


/* --- Table of Contents --- */
.toc {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: calc(var(--header-height) + 2rem);
  order: 1;
  font-size: 0.78rem;
  max-height: calc(100vh - var(--header-height) - 4rem);
  overflow-y: auto;
}
.toc-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.toc ul { padding-left: 0; }
.toc li { margin-bottom: 0.3rem; }
.toc li ul { padding-left: 0.85rem; margin-top: 0.3rem; }
.toc a {
  color: var(--text-muted);
  transition: color var(--transition);
  line-height: 1.4;
}
.toc a:hover { color: var(--accent); }
.toc-anchor {
  color: var(--text-muted);
  font-size: 0.85em;
  margin-left: 0.3rem;
  opacity: 0;
  transition: opacity var(--transition);
}
*:hover > .toc-anchor { opacity: 0.5; }


/* ================================================================
   PROSE — article body typographic treatment
   ================================================================ */
.prose h2 { font-size: 1.4rem; font-weight: 700; margin: 2rem 0 0.75rem; }
.prose h3 { font-size: 1.15rem; font-weight: 600; margin: 1.75rem 0 0.5rem; }
.prose h4 { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
.prose p { margin-bottom: 1rem; }
.prose ul, .prose ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}
.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li { margin-bottom: 0.35rem; }
.prose li > ul, .prose li > ol { margin-top: 0.35rem; margin-bottom: 0; }
.prose blockquote {
  border-left: 3px solid var(--accent-light);
  padding: 0.5rem 1rem;
  margin: 1.25rem 0;
  color: var(--text-secondary);
  background: var(--accent-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.prose a { font-weight: 500; text-decoration: underline; text-underline-offset: 2px; }
.prose img {
  border-radius: var(--radius);
  margin: 1.25rem 0;
  border: 1px solid var(--border);
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.9rem;
}
.prose th, .prose td {
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  text-align: left;
}
.prose th {
  background: var(--bg-alt);
  font-weight: 600;
}
.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}


/* --- Code blocks --- */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
}
.prose pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  margin: 1.25rem 0;
  font-size: 0.85rem;
  line-height: 1.65;
}
.prose pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* Pygments highlight overrides for dark code blocks */
.highlight { background: #1e293b; color: #e2e8f0; padding: 1.25rem 1.5rem; border-radius: var(--radius); margin: 1.25rem 0; }
.highlight pre { background: none; padding: 0; margin: 0; color: inherit; white-space: pre-wrap; overflow-wrap: break-word; }
.highlight .hll { background: #334155; }
.highlight .c, .highlight .cm, .highlight .c1, .highlight .cs { color: #64748b; }
.highlight .k, .highlight .kn, .highlight .kd { color: #c084fc; }
.highlight .s, .highlight .s2, .highlight .s1 { color: #86efac; }
.highlight .n { color: #e2e8f0; }
.highlight .o { color: #94a3b8; }
.highlight .mi, .highlight .mf { color: #fbbf24; }
.highlight .nf, .highlight .nb { color: #67e8f9; }
.highlight .nc { color: #fbbf24; }
.highlight .nn { color: #e2e8f0; }
.highlight .p { color: #94a3b8; }
.highlight .na { color: #67e8f9; }
.highlight .nt { color: #c084fc; }


/* --- Video embeds --- */
.video-embed {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  overflow: hidden;
  margin: 1.25rem 0;
  border-radius: var(--radius);
}
.video-embed iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}


/* ================================================================
   SEARCH PAGE
   ================================================================ */
.page-search h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.25rem; }
.search-box {
  position: relative;
  margin-bottom: 1.5rem;
}
.search-box input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
}
.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-results { display: grid; gap: 0.5rem; }
.search-result {
  display: block;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  transition: border-color var(--transition);
}
.search-result:hover { border-color: var(--accent-light); color: inherit; }
.search-result-project {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.search-result-title { display: block; font-weight: 600; margin-top: 0.1rem; }
.search-result-summary { display: block; font-size: 0.88rem; color: var(--text-secondary); margin-top: 0.15rem; }
.no-results { color: var(--text-muted); font-style: italic; }


/* --- Error page --- */
.page-error { text-align: center; padding: 4rem 0; }
.page-error h1 { font-size: 4rem; font-weight: 700; color: var(--accent); }
.page-error p { color: var(--text-secondary); margin: 0.5rem 0 1.5rem; }
.btn {
  display: inline-block;
  padding: 0.6rem 1.4rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.9rem;
  transition: background var(--transition);
}
.btn:hover { background: var(--accent-dark); color: #fff; }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}


/* ================================================================
   FOOTER
   ================================================================ */
.site-footer {
  background: var(--bg-header);
  color: var(--text-sidebar);
  padding: 1.5rem 0;
  font-size: 0.8rem;
  margin-top: auto;
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.footer-col nav { display: flex; gap: 1.25rem; }
.footer-col nav a { color: var(--text-muted); transition: color var(--transition); }
.footer-col nav a:hover { color: #fff; }
.footer-powered { color: var(--text-muted); }


/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 1100px) {
  .toc { display: none; } /* hide TOC on narrower screens */
}

@media (max-width: 768px) {
  .header-nav { display: none; }
  .menu-toggle { display: block; }

  .layout { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 250ms ease;
    z-index: 90;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }

  .content { padding: 1.5rem 1.25rem; }

  .hero h1 { font-size: 1.4rem; }
  .article-header h1 { font-size: 1.4rem; }

  .footer-inner { flex-direction: column; text-align: center; }
}

/* Overlay when mobile sidebar is open */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--header-height);
  background: rgba(0,0,0,0.4);
  z-index: 85;
}
.sidebar-overlay.active { display: block; }
