/* ============================================
   The AI Stack — style.css
   Dark tech theme, documentation-style
   ============================================ */

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

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

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #16161f;
  --bg-code: #1a1a2e;
  --bg-hover: #1e1e2e;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --text-muted: #6a6a7a;
  --accent-blue: #4f8fff;
  --accent-purple: #a855f7;
  --accent-gradient: linear-gradient(135deg, #4f8fff, #a855f7);
  --accent-gradient-hover: linear-gradient(135deg, #6ba0ff, #b96fff);
  --border-color: #2a2a3a;
  --border-light: #1e1e2e;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --max-width: 1200px;
  --content-width: 860px;
  --sidebar-width: 240px;
  --header-height: 64px;
  --transition: 0.2s ease;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-blue);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover {
  color: var(--accent-purple);
}

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

/* ---------- Header / Nav ---------- */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
  display: flex;
  align-items: center;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent-gradient);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
}

.nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
}

.nav-links a {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  white-space: nowrap;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* Hamburger */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  z-index: 10000;
  position: relative;
}
.hamburger span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text-primary);
  margin: 5px 0;
  transition: all 0.3s ease;
  border-radius: 2px;
}
.hamburger.open span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}
.hamburger.open span:nth-child(2) {
  opacity: 0;
}
.hamburger.open span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

.mobile-menu {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: #0a0a0f;
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mobile-menu.open {
  display: flex;
}
/* Hide page content when mobile menu is open */
body:has(.mobile-menu.open) main,
body:has(.mobile-menu.open) .site-footer {
  display: none !important;
}
body:has(.mobile-menu.open) .site-header {
  background: #0a0a0f;
  backdrop-filter: none;
}
.mobile-menu a {
  font-size: 1.1rem;
  padding: 14px 32px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  transition: all var(--transition);
  font-weight: 500;
  width: 80%;
  max-width: 300px;
  text-align: center;
}
.mobile-menu a:hover,
.mobile-menu a.active {
  color: var(--text-primary);
  background: var(--bg-hover);
}

@media (max-width: 768px) {
  .nav-links { display: none; }
  .hamburger { display: block; }
}

/* ---------- Main Content ---------- */
main {
  padding-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 100px 24px 80px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 800px;
  height: 800px;
  background: radial-gradient(circle, rgba(79,143,255,0.08) 0%, rgba(168,85,247,0.04) 40%, transparent 70%);
  pointer-events: none;
}
.hero h1 {
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 20px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero .subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 40px;
  line-height: 1.6;
}

/* ---------- Section ---------- */
.section {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 60px 24px;
}

/* ---------- Cards Grid ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  transition: all 0.3s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}
.card:hover {
  border-color: var(--accent-blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  color: inherit;
}
.card-icon {
  font-size: 2rem;
  margin-bottom: 14px;
  display: block;
}
.card h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.card p {
  color: var(--text-secondary);
  font-size: 0.93rem;
  line-height: 1.6;
}

/* ---------- Article Layout ---------- */
.article-layout {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 24px 80px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 48px;
}

.toc-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--header-height) - 48px);
  overflow-y: auto;
  padding-right: 16px;
}

.toc-sidebar h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}

.toc-sidebar ul {
  list-style: none;
  padding: 0;
}
.toc-sidebar li {
  margin-bottom: 4px;
}
.toc-sidebar a {
  display: block;
  padding: 5px 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  transition: all var(--transition);
  line-height: 1.4;
}
.toc-sidebar a:hover,
.toc-sidebar a.active {
  color: var(--accent-blue);
  border-left-color: var(--accent-blue);
  background: rgba(79,143,255,0.05);
}
.toc-sidebar .toc-h3 {
  padding-left: 24px;
  font-size: 0.82rem;
}

.article-content {
  max-width: var(--content-width);
  min-width: 0;
}

@media (max-width: 968px) {
  .article-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .toc-sidebar {
    position: relative;
    top: 0;
    max-height: none;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    margin-bottom: 16px;
  }
}

/* ---------- Article Header ---------- */
.article-header {
  padding: 60px 24px 40px;
  max-width: var(--max-width);
  margin: 0 auto;
}
.article-header .breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.article-header .breadcrumb a {
  color: var(--text-secondary);
}
.article-header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  margin-bottom: 12px;
  line-height: 1.2;
}
.article-header .lead {
  font-size: 1.15rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 720px;
}

/* ---------- Typography ---------- */
.article-content h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 56px 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}
.article-content h2:first-child {
  margin-top: 0;
}
.article-content h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 36px 0 14px;
  color: var(--text-primary);
}
.article-content h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 28px 0 10px;
  color: var(--text-secondary);
}
.article-content p {
  margin-bottom: 16px;
  color: var(--text-primary);
  line-height: 1.8;
}
.article-content ul,
.article-content ol {
  margin-bottom: 16px;
  padding-left: 24px;
}
.article-content li {
  margin-bottom: 8px;
  line-height: 1.7;
  color: var(--text-primary);
}
.article-content strong {
  font-weight: 600;
  color: #fff;
}

/* ---------- Code Blocks ---------- */
code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.88em;
}

:not(pre) > code {
  background: var(--bg-code);
  padding: 2px 7px;
  border-radius: 4px;
  color: #e2b3ff;
  border: 1px solid var(--border-light);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px 24px;
  overflow-x: auto;
  margin-bottom: 24px;
  line-height: 1.6;
  position: relative;
}
pre code {
  color: #c8d6e5;
  font-size: 0.88rem;
  background: none;
  padding: 0;
  border: none;
}

/* Code syntax colors */
.kw { color: #c792ea; }
.fn { color: #82aaff; }
.str { color: #c3e88d; }
.cm { color: #546e7a; font-style: italic; }
.num { color: #f78c6c; }
.op { color: #89ddff; }
.decorator { color: #ffcb6b; }

pre .lang-label {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
}

/* ---------- Tables ---------- */
.table-wrapper {
  overflow-x: auto;
  margin-bottom: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
thead {
  background: var(--bg-code);
}
th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}
tr:last-child td {
  border-bottom: none;
}
tr:hover td {
  background: rgba(79,143,255,0.03);
}

/* ---------- Blockquotes ---------- */
blockquote {
  border-left: 3px solid var(--accent-blue);
  background: rgba(79,143,255,0.05);
  padding: 16px 20px;
  margin-bottom: 24px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: normal;
}
blockquote p {
  color: var(--text-secondary);
  margin-bottom: 0;
}
blockquote p:not(:last-child) {
  margin-bottom: 8px;
}
blockquote strong {
  color: var(--accent-blue);
}

/* Info/tip boxes */
.info-box {
  padding: 18px 22px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  border: 1px solid;
  font-size: 0.93rem;
}
.info-box.tip {
  background: rgba(34,197,94,0.06);
  border-color: rgba(34,197,94,0.2);
}
.info-box.warning {
  background: rgba(245,158,11,0.06);
  border-color: rgba(245,158,11,0.2);
}
.info-box.note {
  background: rgba(79,143,255,0.06);
  border-color: rgba(79,143,255,0.2);
}
.info-box .box-title {
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
}
.info-box.tip .box-title { color: var(--success); }
.info-box.warning .box-title { color: var(--warning); }
.info-box.note .box-title { color: var(--accent-blue); }

/* ---------- Tags / Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-blue { background: rgba(79,143,255,0.15); color: var(--accent-blue); }
.badge-purple { background: rgba(168,85,247,0.15); color: var(--accent-purple); }
.badge-green { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--warning); }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border-color);
  padding: 48px 24px;
  background: var(--bg-secondary);
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 40px;
  align-items: start;
}
.footer-brand p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 8px;
  line-height: 1.6;
}
.footer-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.footer-col h5 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}
.footer-col a {
  display: block;
  color: var(--text-secondary);
  font-size: 0.88rem;
  padding: 3px 0;
  transition: color var(--transition);
}
.footer-col a:hover {
  color: var(--text-primary);
}
.footer-bottom {
  max-width: var(--max-width);
  margin: 32px auto 0;
  padding-top: 24px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.footer-bottom a {
  color: var(--text-muted);
}
.footer-bottom a:hover {
  color: var(--accent-blue);
}

@media (max-width: 768px) {
  /* Footer */
  .footer-inner {
    grid-template-columns: 1fr;
    gap: 32px;
  }
  .footer-links {
    grid-template-columns: 1fr;
    gap: 24px;
    text-align: center;
  }
  .footer-col a {
    padding: 6px 0;
  }
  .footer-brand {
    text-align: center;
  }
  .footer-brand .logo {
    justify-content: center;
  }
  .footer-bottom {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }

  /* Hero */
  .hero {
    padding: 60px 20px 50px;
  }
  .hero h1 {
    font-size: 2rem;
  }
  .hero .subtitle {
    font-size: 0.95rem;
  }

  /* Article header */
  .article-header {
    padding: 40px 16px 24px;
  }
  .article-header h1 {
    font-size: 1.6rem;
  }
  .article-header .lead {
    font-size: 1rem;
  }

  /* Cards — single column, stacked vertically */
  .cards-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }

  /* Section padding */
  .section {
    padding: 40px 16px;
  }

  /* Article layout */
  .article-layout {
    padding: 24px 16px 60px;
  }

  /* Tables: prevent horizontal scroll by making text smaller */
  table {
    font-size: 0.8rem;
  }
  th, td {
    padding: 8px 10px;
  }

  /* Code blocks: ensure no overflow */
  pre {
    padding: 14px 12px;
    font-size: 0.8rem;
  }
  pre code {
    font-size: 0.8rem;
  }

  /* Diagrams — allow scroll but constrain width */
  .diagram {
    font-size: 0.7rem;
    padding: 16px 12px;
  }

  /* Code block headers */
  .code-block {
    max-width: 100%;
    overflow: hidden;
  }

  /* Info boxes */
  .info-box {
    padding: 14px 16px;
  }

  /* Comparison grid: single column */
  .comparison-grid {
    grid-template-columns: 1fr;
  }

  /* News grid: single column */
  .news-grid {
    grid-template-columns: 1fr;
  }

  /* Blockquotes */
  blockquote {
    padding: 12px 16px;
  }

  /* Back to top */
  #back-to-top {
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

}

/* ---------- Back to Top ---------- */
#back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 44px;
  height: 44px;
  background: var(--accent-gradient);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 20px;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
#back-to-top.visible {
  opacity: 1;
  visibility: visible;
}
#back-to-top:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

/* ---------- News Cards ---------- */
.news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 24px;
}
.news-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all 0.3s ease;
}
.news-card:hover {
  border-color: var(--accent-purple);
  box-shadow: var(--shadow);
}
.news-card .news-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.news-card h3 {
  font-size: 1.05rem;
  margin-bottom: 10px;
  line-height: 1.4;
}
.news-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}
.news-card .news-tag {
  display: inline-block;
  margin-top: 12px;
}

/* ---------- Diagram boxes ---------- */
.diagram {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--text-secondary);
  text-align: center;
  overflow-x: auto;
  white-space: pre;
}

/* ---------- Comparison Box ---------- */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.comparison-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
}
.comparison-item h4 {
  margin-top: 0;
  color: var(--accent-blue);
}

/* ---------- Scroll progress ---------- */
.scroll-progress {
  position: fixed;
  top: var(--header-height);
  left: 0;
  height: 2px;
  background: var(--accent-gradient);
  z-index: 999;
  transition: width 0.1s linear;
}

/* ---------- Page-specific: home cards hover accent ---------- */
.card[data-accent="blue"]:hover { border-color: var(--accent-blue); }
.card[data-accent="purple"]:hover { border-color: var(--accent-purple); }
.card[data-accent="green"]:hover { border-color: var(--success); }
.card[data-accent="yellow"]:hover { border-color: var(--warning); }

/* ---------- Why Features (home page) ---------- */
.why-features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
@media (max-width: 768px) {
  .why-features {
    grid-template-columns: 1fr;
  }
}

/* ---------- Global anti horizontal scroll ---------- */
main, .section, .article-layout, .article-content,
.hero, .article-header, .site-footer {
  overflow-x: hidden;
}

/* Tables and code blocks: scroll within their container, not the page */
.table-wrapper, pre, .diagram {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Utilities */
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent-blue); }
