:root {
  --primary-color: #4f46e5;
  --text-light: #f3f4f6;
  --text-dark: #1f2937;
  --bg-light: #f3f4f6;
  --bg-dark: #111827;
  --bg-sidebar-light: #ffffff;
  --bg-sidebar-dark: #1f2937;
  --border-light: #e5e7eb;
  --border-dark: #374151;
  --text-muted-light: #6b7280;
  --text-muted-dark: #9ca3af;
  --hover-bg-light: #f3f4f6;
  --hover-bg-dark: #374151;
  --active-bg-light: #e0e7ff;
  --active-bg-dark: #312e81;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-light);
  color: var(--text-dark);
  transition: background-color 0.2s, color 0.2s;
}

body.dark {
    background-color: var(--bg-dark);
    color: var(--text-light);
}

.wiki-container {
  display: flex;
  height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 288px; /* w-72 */
  background-color: var(--bg-sidebar-light);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sidebar-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-title .icon {
    width: 2rem;
    height: 2rem;
}

.sidebar-title-link {
    text-decoration: none;
    color: inherit;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: bold;
  margin: 0;
}

.sidebar-header-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted-light);
}
.theme-toggle:hover {
    background-color: var(--hover-bg-light);
}
.theme-toggle .icon {
    width: 1.25rem;
    height: 1.25rem;
}


.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  margin-top: 0.5rem;
}

.category-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: left;
  color: var(--text-muted-light);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 0.375rem;
  transition: background-color 0.2s;
}

.category-toggle:hover {
  background-color: var(--hover-bg-light);
}

.category-toggle .icon {
  width: 1.25rem;
  height: 1.25rem;
  transition: transform 0.2s;
}

.category-pages {
  margin-top: 0.25rem;
  margin-left: 0.75rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border-light);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-in-out;
}

.category-pages.expanded {
   max-height: 1000px; /* Arbitrary large value */
}

.category-toggle.expanded .icon {
  transform: rotate(90deg);
}

.page-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.page-link-container {
  display: flex;
  align-items: center;
  border-radius: 0.375rem;
  transition: background-color 0.2s;
}

.page-link-container:hover {
    background-color: var(--hover-bg-light);
}


.page-link {
  flex-grow: 1;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 0.375rem;
  color: var(--text-muted-light);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s;
}

.page-link.active {
  background-color: var(--active-bg-light);
  color: var(--primary-color);
  font-weight: 500;
}

.page-toggle {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted-light);
  padding: 0.5rem;
  flex-shrink: 0;
  border-radius: 0.375rem;
}

.page-toggle .icon {
    width: 1rem;
    height: 1rem;
    transition: transform 0.2s;
}

.sub-pages {
  padding-left: 0.75rem;
  margin-left: 0.75rem;
  border-left: 1px solid var(--border-light);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-in-out;
}

.page-item.expanded > .sub-pages {
  max-height: 1000px; /* Arbitrary large value */
}

.page-item.expanded > .page-link-container .page-toggle .icon {
    transform: rotate(90deg);
}

/* --- Content --- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}

.content-wrapper {
  max-width: 896px; /* max-w-4xl */
  margin: 0 auto;
}

.content-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted-light);
}
.content-placeholder .icon {
    width: 4rem;
    height: 4rem;
    margin-bottom: 1rem;
}
.content-placeholder h2 {
    font-size: 1.5rem;
    font-weight: bold;
}
.content-placeholder p {
    max-width: 448px;
}
.content-placeholder code {
    background-color: var(--border-light);
    padding: 2px 5px;
    border-radius: 4px;
}

.loader {
    width: 4rem;
    height: 4rem;
    border: 4px dashed var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.error-message {
    color: #ef4444;
}

.error-message code {
    background-color: rgba(239, 68, 68, 0.1);
    padding: 1rem;
    border-radius: 0.375rem;
    display: block;
    margin-top: 1rem;
}


@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- Article Styles (Prose) --- */
.prose {
    color: var(--text-dark);
}
.prose h1, .prose h2, .prose h3 {
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 1em;
}
.prose h1 { font-size: 2.25rem; margin-top: 0; }
.prose h2 { font-size: 1.875rem; }
.prose h3 { font-size: 1.5rem; }
.prose p, .prose ul, .prose ol { line-height: 1.7; margin-bottom: 1em; }
.prose a { color: var(--primary-color); text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose strong { font-weight: 600; }
.prose pre, .prose code {
    font-family: monospace;
    background-color: var(--bg-light);
    border-radius: 0.375rem;
    padding: 0.1em 0.4em;
}
.prose pre {
    padding: 1rem;
    overflow-x: auto;
}
.prose pre code {
    padding: 0;
}
.prose blockquote {
    border-left: 4px solid var(--border-light);
    padding-left: 1rem;
    margin-left: 0;
    color: var(--text-muted-light);
}

/* Responsive Content Elements */
.prose img, .prose video {
    max-width: 100%;
    height: auto;
    border-radius: 0.375rem;
}

.prose table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}


/* --- Mobile Nav Elements --- */
.menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    background-color: var(--bg-sidebar-light);
    border: 1px solid var(--border-light);
    border-radius: 0.375rem;
    padding: 0.5rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    color: var(--text-dark);
}
.menu-toggle .icon {
    width: 1.5rem;
    height: 1.5rem;
}
.sidebar-close {
    display: none; /* Hidden by default, shown in MQ */
}
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.sidebar-backdrop.visible {
    opacity: 1;
    visibility: visible;
}


/* --- Dark Mode Overrides --- */
body.dark .sidebar {
    background-color: var(--bg-sidebar-dark);
    border-right-color: var(--border-dark);
}
body.dark .sidebar-header { border-bottom-color: var(--border-dark); }
body.dark .theme-toggle { color: var(--text-muted-dark); }
body.dark .theme-toggle:hover { background-color: var(--hover-bg-dark); }
body.dark .category-toggle { color: var(--text-muted-dark); }
body.dark .category-toggle:hover { background-color: var(--hover-bg-dark); }
body.dark .page-link-container:hover { background-color: var(--hover-bg-dark); }
body.dark .page-link { color: var(--text-muted-dark); }
body.dark .page-link.active {
    background-color: var(--active-bg-dark);
    color: var(--text-light);
}
body.dark .page-toggle { color: var(--text-muted-dark); }
body.dark .category-pages { border-left-color: var(--border-dark); }
body.dark .sub-pages { border-left-color: var(--border-dark); }
body.dark .content-placeholder { color: var(--text-muted-dark); }
body.dark .content-placeholder code { background-color: var(--hover-bg-dark); }

body.dark .prose { color: var(--text-light); }
body.dark .prose pre, body.dark .prose code { background-color: var(--bg-dark); }
body.dark .prose blockquote { border-left-color: var(--border-dark); color: var(--text-muted-dark); }

body.dark .menu-toggle {
    background-color: var(--bg-sidebar-dark);
    border-color: var(--border-dark);
    color: var(--text-light);
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        max-width: 80vw; /* Prevent sidebar from covering full width on small screens */
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .content {
        padding: 1.5rem;
        padding-top: 4.5rem; /* Ensure content is not hidden behind the fixed menu toggle */
    }
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        cursor: pointer;
        padding: 0.25rem;
        border-radius: 9999px;
        color: var(--text-muted-light);
    }
    .sidebar-close:hover {
        background-color: var(--hover-bg-light);
    }
    .sidebar-close .icon {
        width: 1.5rem;
        height: 1.5rem;
    }
    body.dark .sidebar-close {
        color: var(--text-muted-dark);
    }
    body.dark .sidebar-close:hover {
        background-color: var(--hover-bg-dark);
    }
}