/* =========================================
   1. Variables & Themes
   ========================================= */
:root {
  --bg: #0b0f1a;
  --panel: #161b2c;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #2e374d;
  --link: #60a5fa;
  --accent: #a855f7;
  --glass: rgba(22, 27, 44, 0.7);
}

body.light {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --link: #2563eb;
  --glass: rgba(255, 255, 255, 0.8);
}

/* =========================================
   2. Global Resets
   ========================================= */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

/* =========================================
   3. Navigation (Glassmorphism)
   ========================================= */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 5%;
  background: var(--glass);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--link);
  letter-spacing: -1px;
}

.logo-link {
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* =========================================
   4. Hero Section
   ========================================= */
.hero-section {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 4rem;
  padding: 100px 5%;
  align-items: center;
  min-height: 70vh;
}

.badge {
  background: rgba(96, 165, 250, 0.1);
  color: var(--link);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid rgba(96, 165, 250, 0.2);
}

.hero-content h1 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  line-height: 1.1;
  margin: 1.5rem 0;
  font-weight: 800;
}

.hero-btns {
  display: flex;
  gap: 1rem;
}

/* Code Window Styling */
.code-window {
  background: #011627;
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.window-dots {
  display: flex;
  gap: 6px;
  margin-bottom: 1rem;
}

.window-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.window-dots span:nth-child(1) {
  background: #ff5f56;
}

.window-dots span:nth-child(2) {
  background: #ffbd2e;
}

.window-dots span:nth-child(3) {
  background: #27c93f;
}

/* =========================================
   5. Buttons
   ========================================= */
.btn-primary,
.btn-secondary,
#langToggle,
#themeToggle,
.btn-project {
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.3s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--link);
  color: white;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-2px);
}

.btn-secondary,
#langToggle,
#themeToggle {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

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

/* =========================================
   6. Section Containers & Grid
   ========================================= */
.section-container {
  padding: 80px 5%;
}

.section-title {
  font-size: 2rem;
  margin-bottom: 3rem;
  position: relative;
  display: inline-block;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 40px;
  height: 4px;
  background: var(--link);
  border-radius: 2px;
}

/* Projects & Categories */
.projects-grid,
.categories {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.project-card,
.category-card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 2rem;
  border-radius: 16px;
  transition: 0.3s;
  position: relative;
  text-decoration: none;
  color: inherit;
}

.project-card:hover,
.category-card:not(.disabled):hover {
  border-color: var(--link);
  transform: translateY(-10px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
}

.project-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  color: var(--muted);
}

.project-tag {
  font-size: 0.7rem;
  background: var(--border);
  padding: 4px 10px;
  border-radius: 10px;
  color: var(--link);
}

.card-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.card-link {
  color: var(--link);
  font-weight: 700;
  margin-top: 1rem;
  display: block;
}

/* Coming Soon Cards */
.category-card.disabled {
  opacity: 0.6;
  border-style: dashed;
  cursor: not-allowed;
}

.card-status {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--muted);
}

/* =========================================
   7. Footer
   ========================================= */
.main-footer {
  text-align: center;
  padding: 4rem 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

/* =========================================
   8. Utilities
   ========================================= */
.text-gradient {
  background: linear-gradient(90deg, var(--link), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mono {
  font-family: 'Fira Code', monospace;
}

.c-kw {
  color: #c792ea;
}

.c-obj {
  color: #82aaff;
}

.c-str {
  color: #c3e88d;
}

/* =========================================
   9. Responsive
   ========================================= */
@media (max-width: 900px) {
  .hero-section {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .hero-btns {
    justify-content: center;
  }

  .hero-visual {
    order: -1;
  }
}


/* =========================================
   10. Documentation Viewer (index2.html)
   ========================================= */

/* Sidebar Specifics */
/* Ensure the documentation layout is side-by-side */
body:not(.home-page-layout) {
  display: flex;
  flex-direction: row;
  /* Force horizontal alignment */
  align-items: flex-start;
  width: 100%;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  /* Prevents sidebar from squishing */
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.mainTutorial {
  flex-grow: 1;
  /* Takes up all remaining horizontal space */
  min-width: 0;
  /* Prevents code blocks from breaking the layout */
  height: 100vh;
  overflow-y: auto;
  padding: 40px;
}

.sidebar-controls {
  display: flex;
  gap: 10px;
}

.sidebar-controls button {
  flex: 1;
  padding: 8px;
  font-size: 12px;
}

/* Status Tag */
.status-tag {
  font-size: 0.75rem;
  font-weight: bold;
  color: #10b981;
  /* Success Green */
  background: rgba(16, 185, 129, 0.1);
  padding: 4px 12px;
  border-radius: 20px;
  display: inline-block;
  width: fit-content;
}

/* Search Bar Styling */
#searchInput {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  transition: 0.3s;
}

#searchInput:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

/* Sidebar Navigation List */
#db-items-list {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
}

#db-items-list li {
  margin-bottom: 5px;
}

#db-items-list li a {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: 0.2s;
  cursor: pointer;
}

#db-items-list li a:hover {
  background: var(--border);
  color: var(--text);
}

#db-items-list li a.active {
  background: rgba(96, 165, 250, 0.15);
  color: var(--link);
  font-weight: 600;
}

/* Documentation Content Area */
#tutorialContent {
  max-width: 850px;
  margin: 0 auto;
  padding-bottom: 100px;
}

#backBtn {
  margin-bottom: 2rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

#backBtn:hover {
  color: var(--text);
  border-color: var(--link);
}

/* Markdown Typography Refinement */
.markdown-body {
  font-size: 1.1rem;
  line-height: 1.8;
}

.markdown-body h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.markdown-body blockquote {
  margin: 2rem 0;
  padding: 1rem 1.5rem;
  border-left: 4px solid var(--link);
  background: var(--panel);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}

/* RTL Support for Sidebar */
[dir="rtl"] .sidebar {
  border-right: none;
  border-left: 1px solid var(--border);
}

[dir="rtl"] .markdown-body blockquote {
  border-left: none;
  border-right: 4px solid var(--link);
  border-radius: 8px 0 0 8px;
}

/* Ensure images in markdown don't overflow */
.markdown-body img {
  max-width: 100%;
  border-radius: 12px;
  margin: 20px 0;
  border: 1px solid var(--border);
}

/* =========================================
   11. Mobile & Tablet Optimization
   ========================================= */
@media (max-width: 768px) {

  /* 1. Layout Reset: Stack Sidebar and Content */
  body:not(.home-page-layout) {
    flex-direction: column;
  }

  /* 2. Responsive Sidebar */
  .sidebar {
    width: 100%;
    height: auto;
    /* No longer full screen height */
    position: relative;
    /* Not sticky on mobile for better scrolling */
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 20px;
  }

  /* 3. Main Content Padding */
  .mainTutorial {
    width: 100%;
    height: auto;
    padding: 25px 15px;
    /* Tighter padding for small screens */
  }

  /* 4. Navbar Tweaks */
  .navbar {
    padding: 1rem 15px;
  }

  .nav-logo {
    font-size: 1.1rem;
  }

  .nav-links {
    gap: 0.5rem;
  }

  .nav-links a {
    display: none;
    /* Hide GitHub text link to save space, keep buttons */
  }

  /* 5. Hero Section Adjustments */
  .hero-section {
    grid-template-columns: 1fr;
    gap: 2rem;
    padding: 60px 20px;
    text-align: center;
  }

  .hero-content h1 {
    font-size: 2.2rem;
  }

  .hero-btns {
    flex-direction: column;
    /* Stack buttons on mobile */
    width: 100%;
  }

  .hero-btns a {
    width: 100%;
  }

  /* 6. Grid Adjustments (Cards) */
  .projects-grid,
  .categories {
    grid-template-columns: 1fr;
    /* Force one column */
    gap: 1.5rem;
  }

  .project-card,
  .category-card {
    padding: 1.5rem;
  }

  /* 7. Markdown Improvements */
  .markdown-body h1 {
    font-size: 1.8rem;
  }

  .markdown-body pre {
    padding: 12px;
    font-size: 0.85rem;
    border-radius: 8px;
  }

  /* Tables are notoriously bad on mobile - this makes them scrollable */
  #markdownBody {
    overflow-x: auto;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Extra small devices */
@media (max-width: 480px) {
  .nav-logo {
    font-size: 1rem;
  }

  #langToggle,
  #themeToggle {
    padding: 8px 12px;
    font-size: 11px;
  }
}


/* --- Toggle Button Styling --- */
.mobile-only {
  display: none;
  /* Hidden by default on desktop */
}

@media (max-width: 768px) {
  .mobile-only {
    display: flex;
    position: fixed;
    top: 15px;
    left: 15px;
    /* Adjust to right: 15px if in RTL mode */
    z-index: 2000;
    /* Must be higher than sidebar */
    background: var(--link);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  /* --- Sidebar Slide Logic --- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 1500;
    transform: translateX(-100%);
    /* Hides sidebar to the left */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--panel);
    box-shadow: 10px 0 20px rgba(0, 0, 0, 0.4);
  }

  /* When JS adds this class, it slides in */
  .sidebar.active {
    transform: translateX(0);
  }

  /* Overlay to dim the background when menu is open */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1400;
  }

  .sidebar.active+.sidebar-overlay {
    display: block;
  }
}