/* ========== CSS Variables ========== */
:root {
  --bg: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --accent-subtle: #e0e7ff;
  --code-bg: #0d1117;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 280px;
  --topbar-height: 64px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

/* ========== Reset ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; }

/* ========== Top Bar ========== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-height);
}
.top-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.logo:hover { color: var(--text); }
.logo-icon { width: 36px; height: 36px; }
.logo-highlight { color: var(--accent); }

.top-nav { display: flex; gap: 8px; }
.top-nav a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.top-nav a:hover,
.top-nav a.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ========== Hamburger Menu ========== */
.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}
.menu-toggle:hover { background: var(--bg-tertiary); }
.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.3s;
}
.menu-toggle.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.menu-toggle.active span:nth-child(2) { opacity: 0; }
.menu-toggle.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ========== Page Layout ========== */
.page-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  flex: 1;
  width: 100%;
}
.page-layout.has-sidebar {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 40px;
}

/* ========== Sidebar ========== */
.sidebar {
  position: sticky;
  top: calc(var(--topbar-height) + 24px);
  height: fit-content;
  max-height: calc(100vh - var(--topbar-height) - 48px);
  overflow-y: auto;
  padding: 24px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-section { margin-bottom: 24px; }
.sidebar-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 12px;
  margin-bottom: 8px;
}
.sidebar-nav { list-style: none; }
.sidebar-nav li a {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-secondary);
  border-left: 3px solid transparent;
  transition: all 0.2s;
}
.sidebar-nav li a:hover {
  background: var(--bg-tertiary);
  color: var(--text);
}
.sidebar-nav li a.active {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* ========== Content Area ========== */
.content {
  min-width: 0;
  padding: 32px 0 48px;
}

/* ========== Breadcrumb ========== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .separator {
  color: var(--border);
  user-select: none;
}

/* ========== Article ========== */
.article {
  max-width: 820px;
}
.page-layout:not(.has-sidebar) .article {
  max-width: none;
}
.article h1 {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}
.article h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.article h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
}
.article h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}
.article p {
  margin-bottom: 16px;
  color: var(--text);
}
.article ul, .article ol {
  margin-bottom: 16px;
  padding-left: 24px;
}
.article li {
  margin-bottom: 6px;
}
.article strong { font-weight: 600; }
.article hr {
  border: none;
  border-top: 2px solid var(--border);
  margin: 32px 0;
}
.article blockquote {
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  margin: 16px 0;
  background: var(--accent-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}
.article blockquote p:last-child { margin-bottom: 0; }
.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.9rem;
}
.article th, .article td {
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--border);
}
.article th {
  background: var(--bg-tertiary);
  font-weight: 600;
}
.article tr:nth-child(even) { background: var(--bg-tertiary); }

/* ========== Inline code ========== */
.article code:not(pre code) {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-hover);
}

/* ========== Code Blocks ========== */
.code-block-wrapper {
  position: relative;
  margin: 20px 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
}
.code-block-lang {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.copy-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
}
.copy-btn:hover {
  background: #30363d;
  color: #e6edf3;
}
.copy-btn.copied {
  border-color: #238636;
  color: #3fb950;
}
.copy-btn svg { width: 14px; height: 14px; }
.code-block-wrapper pre {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
  background: var(--code-bg) !important;
  scrollbar-width: thin;
  scrollbar-color: #30363d transparent;
}
.code-block-wrapper pre code {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  tab-size: 4;
}

/* ========== Home Page ========== */
.hero {
  text-align: center;
  padding: 80px 24px 64px;
  max-width: 800px;
  margin: 0 auto;
}
.hero h1 {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 20px;
}
.hero h1 .gradient-text {
  background: linear-gradient(135deg, var(--accent), #a855f7, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.7;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 24px;
  max-width: 900px;
  margin: 0 auto 64px;
  padding: 0 24px;
}
.category-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  transition: all 0.3s;
  text-decoration: none;
  color: inherit;
}
.category-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  color: inherit;
}
.category-card-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}
.category-card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.category-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 20px;
}
.category-card .lesson-count {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
}

.lesson-list-section {
  max-width: 900px;
  margin: 0 auto 48px;
  padding: 0 24px;
}
.lesson-list-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
}
.lesson-list-section h2 i,
.category-header h1 i {
  margin-right: 0.5em;
  opacity: 0.9;
}
.lesson-list {
  list-style: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.lesson-list li { border-bottom: 1px solid var(--border); }
.lesson-list li:last-child { border-bottom: none; }
.lesson-list li a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  color: var(--text);
  transition: all 0.2s;
}
.lesson-list li a:hover {
  background: var(--accent-light);
  color: var(--accent);
}
.lesson-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.lesson-list li a:hover .lesson-number {
  background: var(--accent);
  color: #fff;
}

/* ========== EDA Playground Button ========== */
.eda-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  margin-bottom: 28px;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}
.eda-btn:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
  color: #fff;
}
.eda-btn svg { width: 18px; height: 18px; }

/* ========== Lesson Navigation ========== */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 32px;
  border-top: 2px solid var(--border);
}
.lesson-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: all 0.2s;
  max-width: 45%;
}
.lesson-nav a:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.lesson-nav a .nav-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lesson-nav a .nav-title {
  font-weight: 600;
  font-size: 0.95rem;
}
.lesson-nav a.next { text-align: right; margin-left: auto; }

/* ========== Category Page ========== */
.category-header {
  padding: 48px 0 32px;
  margin-bottom: 8px;
}
.category-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 8px;
}
.category-header p {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

/* ========== Footer ========== */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ========== Mobile Sidebar Overlay ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s;
}
.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .top-nav { display: none; }
  .menu-toggle { display: flex; }

  .page-layout.has-sidebar {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    padding: 24px 16px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 95;
    border-right: 1px solid var(--border);
    max-height: none;
  }
  .sidebar.open { transform: translateX(0); }

  .hero h1 { font-size: 2rem; }
  .hero { padding: 48px 16px 40px; }
  .categories-grid { grid-template-columns: 1fr; padding: 0 16px; }
  .lesson-list-section { padding: 0 16px; }
  .page-layout { padding: 0 16px; }
  .content { padding: 24px 0 32px; }
  .article h1 { font-size: 1.7rem; }
  .article h2 { font-size: 1.3rem; }

  .lesson-nav { flex-direction: column; }
  .lesson-nav a { max-width: 100%; }
  .lesson-nav a.next { text-align: left; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.6rem; }
  .hero p { font-size: 1rem; }
  .category-card { padding: 24px; }
  .code-block-wrapper pre { padding: 14px; }
  .code-block-wrapper pre code { font-size: 0.8rem; }
}
