/*  CSS Variables  */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16162b;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --accent-blue: #6b7db3;
  --accent-purple: #8b7eac;
  --accent-soft: #c8b8e8;
  --border: #252540;
  --code-bg: #12121f;
  --font-body: 'Inter', sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 8px;
  --transition: 0.2s ease;
  --sidebar-width: 220px;
}

[data-theme="light"] {
  --bg-primary: #f5f3fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --accent-blue: #4a5f8a;
  --accent-purple: #6b5e8a;
  --accent-soft: #5a4e7a;
  --border: #dddde8;
  --code-bg: #eeeaf5;
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1.05rem;
  line-height: 1.8;
  transition: background-color var(--transition), color var(--transition);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.3;
}

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

a:hover {
  text-decoration: underline;
}

/*  Navbar  */
.navbar {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.nav-container {
  width: 100%;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 1rem;
}

.logo {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-soft);
  text-decoration: none;
  white-space: nowrap;
}

.logo:hover {
  text-decoration: none;
  opacity: 0.85;
}

/*  Search  */
.search-wrapper {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.search-input {
  width: 100%;
  padding: 0.5rem 1rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
}

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

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

.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.search-results.visible {
  display: block;
}

.search-result-item {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: rgba(139, 126, 172, 0.1);
}

.search-result-item .result-title {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.search-result-item .result-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.search-result-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/*  Theme Toggle  */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  transition: all var(--transition);
  white-space: nowrap;
}

.theme-toggle:hover {
  border-color: var(--accent-purple);
  color: var(--accent-soft);
}

/*  Layout  */
.layout {
  display: flex;
  width: 100%;
  min-height: calc(100vh - 60px - 60px);
}

/*  Sidebar  */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  border-right: 1px solid var(--border);
  background-color: var(--bg-secondary);
  padding: 1.5rem 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  overflow-x: visible;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.sidebar nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  height: 100%;
}

.sidebar-category > a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
}

.sidebar-category a:hover {
  color: var(--accent-soft);
  background-color: rgba(139, 126, 172, 0.05);
  text-decoration: none;
}

 .sidebar-subnav {
  list-style: none;
  padding: 0;
  display: none;
}

.sidebar-category.open .sidebar-subnav {
  display: block;
}

.sidebar-subnav li a {
  display: block;
  padding: 0.3rem 1.5rem 0.3rem 2.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: none;
}

.sidebar-subnav li a:hover {
  color: var(--accent-soft);
}

.sidebar-toggle {
  position: absolute;
  right: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 50;
}

.sidebar-toggle:hover {
  color: var(--accent-soft);
  background-color: rgba(139, 126, 172, 0.1);
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: visible;
  border-right: none;
}

.sidebar.collapsed .sidebar-toggle {
  right: -25px;
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: 1px solid var(--border);
  background-color: var(--bg-secondary);
}

.sidebar.collapsed nav,
.sidebar.collapsed .sidebar-nav,
.sidebar.collapsed .sidebar-category {
  display: none;
}

.layout.sidebar-collapsed main {
  max-width: 900px;
  margin: 0 auto;
}

/*  Main Content  */
main {
  flex: 1;
  padding: 3rem 2rem;
  max-width: 800px;
}

/*  Category & About Page Content  */
main h1 {
  font-size: 2rem;
  font-weight: 500;
  margin-bottom: 2rem;
  color: var(--text-primary);
}

main h2 {
  font-size: 1.2rem;
  font-weight: 500;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  color: var(--accent-soft);
}

main p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

main ul {
  list-style: none;
  padding: 0;
}

main ul li {
  padding: 0.4rem 0;
  color: var(--text-secondary);
}

main ul li a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

main ul li a:hover {
  color: var(--accent-soft);
  text-decoration: none;
}

main ul:not(.sidebar-nav):not(.sidebar-subnav):not(.nav-links):not(.dropdown-menu):not(.article-list) {
  list-style: disc;
  padding-left: 1.5rem;
}

main ol {
  padding-left: 1.5rem;
}

/*  Home Hero  */
.home-hero {
  margin-bottom: 3rem;
}

.hero-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  position: relative;
}

.hero-tag {
  display: inline-block;
  background-color: rgba(139, 126, 172, 0.15);
  color: var(--accent-soft);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  margin-bottom: 1rem;
}

.hero-card h1 {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.hero-card p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  max-width: 600px;
}

.hero-link {
  font-weight: 500;
}

/*  Post Cards Grid  */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.post-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color var(--transition);
}

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

.card-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-blue);
  margin-bottom: 0.75rem;
}

.post-card h2 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.post-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.post-card a {
  font-size: 0.9rem;
  font-weight: 500;
}

/*  Footer  */
.footer {
  text-align: center;
  padding: 1.25rem 1.5rem;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

/*  Code Blocks  */
.code-block {
  background-color: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 1.5rem 0;
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background-color: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border);
}

.code-dots {
  display: flex;
  gap: 6px;
}

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

.code-dots span:nth-child(1) { background-color: #ff5f56; }
.code-dots span:nth-child(2) { background-color: #ffbd2e; }
.code-dots span:nth-child(3) { background-color: #27c93f; }

.code-lang {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-family: var(--font-body);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
}

.copy-btn:hover {
  border-color: var(--accent-purple);
  color: var(--accent-soft);
}

.copy-btn.copied {
  border-color: #27c93f;
  color: #27c93f;
}

.code-block pre {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
}

/*  Articles  */
.article-list {
  list-style: none;
  padding: 0;
}

.article-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.article-list li:last-child {
  border-bottom: none;
}

.article-list li a {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
}

.article-list li a:hover {
  color: var(--accent-soft);
  text-decoration: none;
}

.article-desc {
  margin: 0.25rem 0 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/*  Glossary Tooltips  */
.glossary-term {
  color: var(--accent-soft);
  cursor: help;
  border-bottom: 1px dashed var(--accent-purple);
  position: relative;
}

.glossary-term:hover {
  color: var(--accent-purple);
}

.glossary-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  min-width: 260px;
  max-width: 360px;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.glossary-tooltip .tooltip-term {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

.glossary-tooltip .tooltip-def {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/*  OS Tabs  */
.os-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0;
}

.os-tab {
  padding: 0.5rem 1.2rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  transition: all var(--transition);
  margin-right: 2px;
}

.os-tab:hover {
  color: var(--accent-soft);
  background-color: rgba(139, 126, 172, 0.05);
}

.os-tab.active {
  color: var(--accent-soft);
  background-color: var(--code-bg);
  border-color: var(--border);
}

.os-panel {
  display: none;
}

.os-panel.active {
  display: block;
}

.os-panel .code-block {
  margin-top: 0;
  border-radius: 0 var(--radius) var(--radius) var(--radius);
}

/*  Tables  */
main table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
}

main table th,
main table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

main table th {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

main table td {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

main table td:first-child {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-weight: 500;
}

/*  Inline code  */
main strong code,
main code strong {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent-soft);
  background-color: rgba(139, 126, 172, 0.1);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
}

/*  Glossary Page  */
.glossary-entry {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.glossary-entry:last-child {
  border-bottom: none;
}

.glossary-entry h3 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-soft);
  margin-bottom: 0.3rem;
}

.glossary-entry p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0;
}

.subcategory-parent {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.subcategory-parent a {
  color: var(--accent-soft);
}

.empty-state {
  padding: 3rem 0;
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
}

/*  Hamburger  */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background-color: var(--text-secondary);
  transition: all 0.3s ease;
}

.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);
}

.glossary-search {
  margin-bottom: 2rem;
  max-width: 400px;
}

/*  Responsive  */
@media (max-width: 900px) {
  .sidebar {
    display: none;
  }

  .hamburger {
    display: flex;
  }

  .layout {
    flex-direction: column;
  }

  main {
    padding: 1.5rem;
  }

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

  .hero-card {
    padding: 1.5rem;
  }

  .hero-card h1 {
    font-size: 1.5rem;
  }
}