/* ============================================
   MIPS XIP Kernel Documentation — Stylesheet
   GitHub Pages Optimized
   ============================================ */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: #1c2128;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --border: #30363d;
  --border-light: #21262d;
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-purple: #bc8cff;
  --accent-red: #f85149;
  --accent-orange: #d29922;
  --accent-cyan: #39d2c0;
  --sidebar-width: 280px;
  --header-height: 56px;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  min-height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
}

.logo-icon {
  font-size: 1.4rem;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.2rem;
}

.sidebar-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition);
}

.sidebar-search input:focus {
  border-color: var(--accent-blue);
}

.sidebar-search input::placeholder {
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-section {
  margin-bottom: 4px;
}

.nav-section-title {
  padding: 8px 16px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.nav-link {
  display: block;
  padding: 6px 16px 6px 24px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  transition: all var(--transition);
  border-left: 2px solid transparent;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.nav-link.active {
  color: var(--accent-blue);
  background: rgba(88,166,255,0.08);
  border-left-color: var(--accent-blue);
  font-weight: 500;
}

/* ============================================
   Mobile Header
   ============================================ */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 90;
  padding: 0 16px;
  align-items: center;
  gap: 12px;
}

.mobile-menu-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
}

.mobile-title {
  font-weight: 600;
  font-size: 1rem;
}

/* ============================================
   Main Content
   ============================================ */
.content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

/* ============================================
   Hero Section
   ============================================ */
.hero {
  padding: 80px 48px 60px;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, rgba(88,166,255,0.05) 100%);
  border-bottom: 1px solid var(--border);
}

.hero-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(88,166,255,0.1);
  border: 1px solid rgba(88,166,255,0.3);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--accent-blue);
  margin-bottom: 20px;
  font-family: monospace;
}

.hero h1 {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 700px;
  line-height: 1.7;
  margin-bottom: 32px;
}

.hero-stats {
  display: flex;
  gap: 32px;
  margin-bottom: 36px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-blue);
  font-family: monospace;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hero-actions {
  display: flex;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}

.btn-primary:hover {
  background: #79b8ff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(88,166,255,0.3);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

/* ============================================
   Documentation Sections
   ============================================ */
.doc-section {
  padding: 48px;
  border-bottom: 1px solid var(--border);
  max-width: 960px;
}

.doc-section h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent-blue);
  display: inline-block;
}

.doc-section h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 32px 0 12px;
  color: var(--text-primary);
}

.doc-section h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text-primary);
}

.doc-section p {
  margin-bottom: 16px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.doc-section p code,
.doc-section li code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.875em;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent-cyan);
  border: 1px solid var(--border);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 0.9rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--border);
}

th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td {
  color: var(--text-secondary);
}

tr:hover td {
  background: rgba(88,166,255,0.03);
}

/* Code Blocks */
.code-block {
  margin: 16px 0 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.code-lang {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
  text-transform: uppercase;
}

.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.copy-btn.copied {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.code-block pre {
  padding: 16px;
  overflow-x: auto;
  background: var(--bg-primary);
}

.code-block code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-primary);
}

/* Callouts */
.callout {
  padding: 16px 20px;
  border-radius: var(--radius);
  margin: 16px 0 24px;
  border-left: 4px solid;
  font-size: 0.9rem;
}

.callout-info {
  background: rgba(88,166,255,0.08);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.callout-warning {
  background: rgba(210,153,34,0.08);
  border-color: var(--accent-orange);
  color: var(--accent-orange);
}

.callout-success {
  background: rgba(63,185,80,0.08);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.callout strong {
  display: block;
  margin-bottom: 4px;
}

/* Lists */
.numbered-list {
  padding-left: 24px;
  margin: 16px 0;
}

.numbered-list li {
  padding: 6px 0;
  color: var(--text-secondary);
  line-height: 1.6;
}

.numbered-list li strong {
  color: var(--text-primary);
}

.styled-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
}

.styled-list li {
  padding: 8px 0 8px 24px;
  position: relative;
  color: var(--text-secondary);
}

.styled-list li::before {
  content: '▸';
  position: absolute;
  left: 4px;
  color: var(--accent-blue);
}

/* Feature Grid */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all var(--transition);
}

.feature-card:hover {
  border-color: var(--accent-blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.feature-icon {
  font-size: 1.8rem;
  margin-bottom: 10px;
}

.feature-card h4 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.feature-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Component Diagram */
.component-diagram {
  display: flex;
  gap: 12px;
  margin: 24px 0;
  flex-wrap: wrap;
}

.component {
  flex: 1;
  min-width: 150px;
  padding: 16px;
  border-radius: var(--radius);
  color: #fff;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
}

.component strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.95rem;
}

/* Pipeline */
.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 24px 0;
}

.pipeline-step {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.step-number {
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: var(--accent-blue);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.step-content {
  padding: 4px 0 16px;
}

.step-content strong {
  color: var(--text-primary);
}

.step-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 2px 0 0;
}

.pipeline-connector {
  width: 2px;
  height: 16px;
  background: var(--border);
  margin-left: 15px;
}

/* Memory Layout */
.memory-layout {
  display: flex;
  gap: 4px;
  margin: 24px 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.mem-region {
  padding: 16px;
  text-align: center;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 500;
  flex: 1;
}

.mem-region:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.mem-region:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.mem-label {
  font-weight: 600;
  margin-bottom: 4px;
}

.mem-size {
  font-size: 0.75rem;
  opacity: 0.9;
}

.mem-addr {
  font-size: 0.7rem;
  opacity: 0.7;
  font-family: monospace;
}

/* Constraint Grid */
.constraint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.constraint {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.constraint h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.constraint-bar {
  background: var(--bg-tertiary);
  border-radius: 4px;
  height: 28px;
  overflow: hidden;
  margin-bottom: 8px;
}

.constraint-fill {
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  border-radius: 4px;
}

.constraint p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

/* Patch List */
.patch-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0;
}

.patch-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: border-color var(--transition);
}

.patch-card:hover {
  border-color: var(--accent-purple);
}

.patch-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.patch-number {
  background: var(--accent-purple);
  color: #fff;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.patch-file {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.patch-card h4 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.patch-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Comparison */
.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
}

.comparison-side h4 {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent-blue);
}

.comparison-side .code-block {
  margin: 0;
}

/* Architecture Diagram */
.architecture-diagram {
  margin: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.arch-layer {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.arch-label {
  width: 120px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.arch-boxes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.arch-box {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-secondary);
  flex: 1;
  min-width: 140px;
  text-align: center;
}

.arch-box.highlight {
  border-color: var(--accent-blue);
  background: rgba(88,166,255,0.1);
  color: var(--accent-blue);
  font-weight: 600;
}

.arch-arrow {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 4px 0;
}

/* FAQ */
.faq-list {
  margin: 24px 0;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.faq-question {
  width: 100%;
  padding: 14px 20px;
  background: var(--bg-card);
  border: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background var(--transition);
}

.faq-question:hover {
  background: var(--bg-tertiary);
}

.faq-icon {
  font-size: 1.2rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.faq-item.open .faq-icon {
  transform: rotate(45deg);
}

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.faq-item.open .faq-answer {
  max-height: 300px;
  padding: 0 20px 16px;
}

.faq-answer p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Glossary */
.glossary {
  margin: 24px 0;
}

.glossary dt {
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 16px;
  font-size: 0.95rem;
}

.glossary dd {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-left: 0;
  padding-left: 16px;
  border-left: 2px solid var(--border);
  margin-top: 4px;
}

/* Checklist */
.checklist {
  margin: 16px 0 24px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
}

.check-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-blue);
  cursor: pointer;
}

.check-item:has(input:checked) {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* Footer */
.doc-footer {
  padding: 32px 48px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.doc-footer p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 4px 0;
}

/* Back to Top */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
  z-index: 50;
  box-shadow: var(--shadow-lg);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  transform: translateY(-2px);
  background: #79b8ff;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .mobile-header {
    display: flex;
  }

  .content {
    margin-left: 0;
    padding-top: var(--header-height);
  }

  .hero {
    padding: 48px 24px 40px;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1rem;
  }

  .hero-stats {
    gap: 20px;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .doc-section {
    padding: 32px 24px;
  }

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

  .memory-layout {
    flex-direction: column;
  }

  .mem-region:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .mem-region:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
  }

  .doc-footer {
    padding: 24px;
  }
}

@media (max-width: 600px) {
  .hero h1 {
    font-size: 1.6rem;
  }

  .hero-stats {
    flex-direction: column;
    gap: 12px;
  }

  .hero-actions {
    flex-direction: column;
  }

  .btn {
    justify-content: center;
  }

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

  .component-diagram {
    flex-direction: column;
  }

  .arch-layer {
    flex-direction: column;
    align-items: flex-start;
  }

  .arch-label {
    width: auto;
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-overlay.visible {
  display: block;
}

/* Search highlight */
.search-highlight {
  background: rgba(210,153,34,0.3);
  border-radius: 2px;
  padding: 0 2px;
}

/* Print styles */
@media print {
  .sidebar, .mobile-header, .back-to-top {
    display: none !important;
  }

  .content {
    margin-left: 0;
  }

  .hero {
    padding: 20px;
    background: none;
  }

  .doc-section {
    page-break-inside: avoid;
  }
}
