:root {
  --bg-color: #0d0d0d;
  --text-color: #e0e0e0;
  --text-muted: #a0a0a0;
  --accent-color: #64b5f6;
  --sidebar-bg: #141414;
  --topbar-bg: #141414;
  --border-color: #2a2a2a;
  --heading-color: #ffffff;
  --code-bg: #1f1f1f;
  --search-bg: #2a2a2a;
}

* {
  box-sizing: border-box;
}

html {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  font-size: 16px;
  -webkit-overflow-scrolling: touch;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

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

a:hover {
  color: var(--accent-color);
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* --- SIDEBAR (Desktop Default: Open) --- */
.sidebar {
  width: 280px;
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s ease;
  /* Add transition for smoothness */
  transform: translateX(0);
}

.sidebar nav {
  padding: 0;
  /* Remove default padding, handle in elements */
  display: flex;
  flex-direction: column;
}

.sidebar .site-title {
  font-size: 1.3rem;
  /* Align with top-bar height (50px) roughly */
  display: flex;
  align-items: center;
  height: 50px;
  padding: 0 1rem;
  margin-bottom: 1rem;
  font-weight: bold;
  color: var(--heading-color);
  border-bottom: 1px solid var(--border-color);
}

/* PRELOAD: Disable transitions on load */
.preload * {
  transition: none !important;
}

.sidebar a {
  color: var(--text-muted);
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
}

.sidebar a:hover,
.sidebar a.current {
  color: var(--heading-color);
  background-color: rgba(255, 255, 255, 0.05);
}

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.page-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-left: 280px;
  min-width: 0;
  transition: margin-left 0.3s ease;
}

.top-bar {
  height: 50px;
  background-color: var(--topbar-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 90;
}

.page-title {
  color: var(--heading-color);
  font-weight: 600;
  font-size: 1.1rem;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

#sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
}

#sidebar-toggle:hover {
  color: var(--heading-color);
}

.search-container {
  display: flex;
  align-items: center;
  position: relative;
}

#search-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
}

#search-toggle:hover {
  color: var(--heading-color);
}

#search-input {
  width: 0;
  background-color: var(--search-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-color);
  padding: 0.4rem 0.8rem;
  font-family: inherit;
  opacity: 0;
  transition: width 0.2s, opacity 0.2s;
}

.search-container.expanded #search-input {
  width: 250px;
  opacity: 1;
}

#search-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

#search-results {
  position: absolute;
  top: 100%;
  right: 0;
  background-color: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  border-radius: 0 0 4px 4px;
  max-height: 300px;
  overflow-y: auto;
  display: none;
  z-index: 200;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  min-width: 250px;
}

.search-result-item {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

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

.search-result-item a {
  display: block;
}

.search-result-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.content {
  padding: 2rem 4rem;
  max-width: 75%;
  margin: 0 auto;
  width: 100%;
}

.content h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: var(--heading-color);
  line-height: 1.2;
}

.content h2 {
  font-size: 1.8rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  color: var(--heading-color);
}

/* ... (existing typography styles) ... */
.content h3 {
  font-size: 1.4rem;
  margin-top: 2rem;
  margin-bottom: 0.8rem;
  color: var(--heading-color);
}

.content p {
  margin-bottom: 1.2rem;
  color: var(--text-color);
}

.content ul,
.content ol {
  margin-bottom: 1.2rem;
  padding-left: 1.5rem;
}

.content li {
  margin-bottom: 0.4rem;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background-color: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

pre {
  background-color: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

pre code {
  background: transparent;
  padding: 0;
}

blockquote {
  border-left: 4px solid var(--accent-color);
  margin: 1.5rem 0;
  padding: 1rem;
  color: var(--text-muted);
  font-style: italic;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 0 8px 8px 0;
}

img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}


/* --- DESKTOP TOGGLED STATE (Closed) --- */
body.sidebar-toggled .sidebar {
  transform: translateX(-100%);
}

body.sidebar-toggled .page-wrapper {
  margin-left: 0;
}


/* --- MOBILE STYLES (Default: Closed) --- */
@media screen and (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 85%;
    max-width: 300px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
  }

  .page-wrapper {
    margin-left: 0;
  }

  /* Mobile Toggled State (Open) */
  body.sidebar-toggled .sidebar {
    transform: translateX(0);
  }

  body.sidebar-toggled .overlay {
    display: block;
  }

  .page-title {
    font-size: 0.95rem;
  }

  .content {
    padding: 1.5rem 1rem;
    max-width: 100%;
  }
}

/* Search Snippet */
.search-snippet {
  font-size: 0.8em;
  color: var(--text-muted);
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- NESTED SIDEBAR NAVIGATION --- */
.nav-group {
  margin-bottom: 0.5rem;
}

/* Site Title in Sidebar */
.site-title {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--heading-color);
  padding: 1rem 0.75rem 0.5rem;
  /* Reduced bottom padding */
  margin-bottom: 0.5rem;
  /* Reduced margin */
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.site-title:hover {
  color: var(--primary-color);
}

.nav-header {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  /* Reduced padding from 0.75rem */
  color: var(--heading-color);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 6px;
  user-select: none;
  gap: 0.5rem;
  transition: background-color 0.2s;
}

.nav-header:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  transition: transform 0.3s ease;
  width: 1.5rem;
  /* Fixed width container */
  height: 1.5rem;
  font-size: 1.2rem;
  opacity: 0.7;
}

/* Expanded state (rotate ASCII 90deg) */
.nav-group.expanded .nav-icon {
  transform: rotate(90deg);
  opacity: 1;
}

.nav-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-left: 0;
}

.nav-group.expanded .nav-items {
  max-height: 1000px;
  transition: max-height 0.5s ease-in;
}

/* Sub-links indentation and style */
.nav-items a {
  display: block;
  padding: 0.35rem 0.75rem 0.35rem 3.25rem !important;
  /* Reduced vertical padding */
  font-size: 0.95rem !important;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  /* subtle marker indicator */
  margin-left: 0.75rem;
  margin-bottom: 2px;
  /* Slight separation */
}

.nav-items a:hover {
  color: var(--text-color);
  background-color: rgba(255, 255, 255, 0.03);
  border-left-color: var(--primary-color);
}

.nav-items a:hover,
.nav-items a.current {
  color: var(--text-color);
  background-color: rgba(255, 255, 255, 0.03);
  border-left-color: var(--primary-color);
}