/**
 * Education Playground - Modern UI Redesign 2025
 * Inspired by Mintlify, Docusaurus, Nextra, and shadcn/ui
 * Three-panel documentation layout with professional aesthetics
 */

/* Import critical TOC positioning fixes */
@import url('toc-fix.css');

/* ============================================
   Phase 1: Core Layout Architecture
   ============================================ */

/* Mintlify/Docusaurus-inspired grid layout */
.bd-container__inner {
    display: grid;
    grid-template-columns: 280px 1fr 240px;
    gap: 0;
    max-width: 1600px;
    margin: 0 auto;
    min-height: 100vh;
}

/* Main content area with optimal reading width */
.bd-main {
    max-width: 860px;
    margin: 0 auto;
    padding: 3rem 3rem;
}

.bd-main .bd-content {
    display: flex;
    gap: 2rem;
}

.bd-article-container {
    padding-top: 2rem;
}

/* Ensure proper flex layout */
.bd-container__inner {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
}

/* Primary sidebar - navigation (GitBook Style) */
.bd-sidebar-primary {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    width: 280px;
    flex-shrink: 0;

    /* Smooth scroll with momentum */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* Hide scrollbar but keep functionality */
.bd-sidebar-primary::-webkit-scrollbar {
    width: 4px;
}

.bd-sidebar-primary::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

/* Secondary sidebar - TOC (Nextra Pattern) */
.bd-sidebar-secondary {
    width: 240px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: calc(100vh - 2rem);
}

.sidebar-secondary-item {
    position: fixed;
    right: max(0px, calc(50% - 45rem));
    top: 5rem;
    width: 240px;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    padding: 0 1.5rem;
}

/* Better visual hierarchy for TOC */
.page-toc {
    border-left: 3px solid var(--border-color);
    padding-left: 1rem;
}

/* Ensure TOC nav is properly aligned */
.bd-toc-nav {
    padding-right: 1rem;
    max-height: calc(100vh - 8rem);
    overflow-y: auto;
}

/* TOC active state indicator */
.bd-toc-nav .nav-link.active {
    color: var(--accent-primary);
    font-weight: 600;
    position: relative;
}

.bd-toc-nav .nav-link.active::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 0.25rem;
    bottom: 0.25rem;
    width: 3px;
    background: linear-gradient(180deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 2px;
}

/* Improve content area flexibility */
.bd-main {
    flex-grow: 1;
    min-width: 0;
}

/* Container improvements */
.bd-container__inner.bd-page-width {
    max-width: 1400px;
    margin: 0 auto;
}

/* Better spacing for content container */
.bd-content > .bd-article-container {
    padding: 0 1.5rem;
}

@media (max-width: 1400px) {
    .bd-container__inner {
        grid-template-columns: 280px 1fr;
    }
    .sidebar-secondary-item {
        display: none;
    }
}

@media (max-width: 1024px) {
    .bd-container__inner {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Phase 2: Modern Design System Variables
   ============================================ */

:root {
    /* Semantic colors (shadcn/Radix inspired) */
    --bg-surface: #ffffff;
    --bg-subtle: #f9fafb;
    --bg-muted: #f3f4f6;
    --bg-inverse: #111827;

    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    --text-inverse: #f9fafb;

    --border-default: #e5e7eb;
    --border-subtle: #f3f4f6;
    --border-strong: #d1d5db;
    --border-color: #e5e7eb; /* Legacy compatibility */

    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;

    /* Legacy color variables for compatibility */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #dbeafe;
    --secondary-color: #8b5cf6;
    --secondary-dark: #7c3aed;

    /* Backgrounds (legacy) */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-code: #f8fafc;

    /* Shadows (Tailwind-inspired) */
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
    --transition-slow: 0.3s ease;
}

/* Dark mode (automatic) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-surface: #0f172a;
        --bg-subtle: #1e293b;
        --bg-muted: #334155;
        --bg-inverse: #f8fafc;

        --text-primary: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        --text-inverse: #0f172a;

        --border-default: #334155;
        --border-subtle: #1e293b;
        --border-strong: #475569;
        --border-color: #334155;

        --accent-primary: #60a5fa;
        --accent-secondary: #a78bfa;

        /* Legacy dark mode colors */
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --bg-code: #1e293b;

        --primary-color: #60a5fa;
        --primary-hover: #93bbfc;
    }
}

/* Manual dark mode support */
html[data-theme="dark"],
html.dark-mode {
    --bg-surface: #0f172a;
    --bg-subtle: #1e293b;
    --bg-muted: #334155;
    --bg-inverse: #f8fafc;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --border-default: #334155;
    --border-subtle: #1e293b;
    --border-strong: #475569;

    --accent-primary: #60a5fa;
    --accent-secondary: #a78bfa;
}

/* ============================================
   Phase 3: Component Enhancements
   ============================================ */

/* Enhanced sidebar header (Mintlify Style) */
.sidebar-header-items {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.sidebar-primary-items__start {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
}

/* Better logo styling */
.navbar-brand.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    transition: opacity 0.2s;
    padding: 0.5rem 0;
}

.navbar-brand.logo:hover {
    opacity: 0.8;
    text-decoration: none;
}

.logo__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

/* Search button with glass morphism */
.search-button-field {
    width: 100%;
    margin: 1rem 0;
    padding: 0.625rem 0.875rem;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-default);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.search-button-field:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.search-button__default-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.search-button__kbd-shortcut {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Keyboard shortcut badges */
.kbd-shortcut__modifier {
    padding: 0.125rem 0.375rem;
    background: var(--bg-muted);
    border: 1px solid var(--border-default);
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-family: ui-monospace, monospace;
    color: var(--text-secondary);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

/* Sidebar navigation links (Docusaurus Inspired) */
.bd-sidenav .nav-link {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 0.375rem;
    transition: all 0.15s;
    position: relative;
}

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

.bd-sidenav .active > .nav-link {
    color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.1);
    font-weight: 500;
}

/* Nested navigation indentation */
.bd-sidenav ul ul {
    margin-left: 0.75rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--border-subtle);
}

/* Collapsible sections with smooth animation */
.toctree-l1.has-children > details > summary {
    cursor: pointer;
    user-select: none;
}

.toctree-l1.has-children > details[open] > summary .fa-chevron-down {
    transform: rotate(180deg);
}

.fa-chevron-down {
    transition: transform 0.2s ease;
}

/* ============================================
   Phase 4: Remove Distracting Elements
   ============================================ */

/* Remove all banner-style distractions */
.continue-learning-banner,
.continue-learning,
.onboarding-banner,
.announcement-banner,
.promotional-banner {
    display: none !important;
}

/* Clean content area spacing */
.bd-article > section:first-child {
    margin-top: 0;
    padding-top: 0;
}

/* ============================================
   Phase 5: Typography & Content
   ============================================ */

/* Modern type scale (GitHub Primer Inspired) */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.75;
    color: var(--text-primary);
    background: var(--bg-surface);
}

.bd-article {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.75;
    color: var(--text-primary);
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.bd-article h1 {
    font-size: 2.25rem;
    font-weight: 600;
    line-height: 1.25;
    margin-bottom: 1.5rem;
    margin-top: 0;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.bd-article h2 {
    font-size: 1.875rem;
    font-weight: 600;
    line-height: 1.3;
    margin-top: 3rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.bd-article h3 {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.4;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.bd-article h4 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.5;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

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

/* Better link styling */
.bd-article a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: var(--transition-fast);
}

.bd-article a:hover {
    text-decoration: underline;
}

/* Code blocks with syntax highlighting support */
.bd-article pre {
    background: var(--bg-muted);
    border: 1px solid var(--border-default);
    border-radius: 0.5rem;
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.7;
    margin: 1.5rem 0;
}

/* Inline code */
.bd-article code {
    padding: 0.125rem 0.25rem;
    background: var(--bg-muted);
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: ui-monospace, 'Cascadia Code', 'Roboto Mono', monospace;
}

/* Better list spacing */
.bd-article ul,
.bd-article ol {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

.bd-article li {
    margin-bottom: 0.5rem;
}

/* Center images and figures */
.bd-article img,
.bd-article figure {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2rem auto;
}

/* Enhanced Tables */
.bd-article table {
    width: 100%;
    border-collapse: collapse;
    border-radius: 0.5rem;
    overflow: hidden;
    margin: 1.5rem 0;
    box-shadow: var(--shadow-sm);
    background: var(--bg-surface);
}

.bd-article th {
    background: var(--bg-muted);
    color: var(--text-primary);
    font-weight: 600;
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 2px solid var(--border-default);
}

.bd-article td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.bd-article tr:hover {
    background: var(--bg-subtle);
}

/* Admonitions */
.admonition {
    border-left: 4px solid var(--accent-primary);
    background: var(--bg-subtle);
    padding: 1rem;
    margin: 1.5rem 0;
    border-radius: 0.375rem;
}

.admonition-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--accent-primary);
}

/* Warning/Danger admonitions */
.admonition.warning,
.admonition.danger {
    border-left-color: var(--accent-danger);
}

.admonition.warning .admonition-title,
.admonition.danger .admonition-title {
    color: var(--accent-danger);
}

/* ============================================
   Phase 6: Mobile Optimization
   ============================================ */

/* Mobile-first responsive design */
@media (max-width: 768px) {
    /* Full-width content on mobile */
    .bd-container__inner {
        grid-template-columns: 1fr;
        padding: 0;
    }

    /* Hide sidebars by default on mobile */
    .bd-sidebar-primary {
        position: fixed !important;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 9999;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: var(--bg-surface);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .sidebar-secondary-item {
        display: none;
    }

    /* Mobile menu overlay */
    .bd-sidebar-primary.active,
    .bd-sidebar-primary.mobile-active {
        transform: translateX(0);
    }

    /* Content padding adjustment */
    .bd-main {
        padding: 1.5rem;
        max-width: 100%;
    }

    .bd-article {
        padding: 1rem;
        max-width: 100%;
    }

    /* Mobile typography adjustments */
    body {
        font-size: 14px;
        -webkit-text-size-adjust: 100%;
    }

    .bd-article h1 {
        font-size: 1.75rem;
    }

    .bd-article h2 {
        font-size: 1.5rem;
    }

    .bd-article h3 {
        font-size: 1.25rem;
    }

    /* Mobile code blocks */
    .bd-article pre {
        font-size: 0.75rem;
        padding: 0.75rem;
    }

    /* Mobile tables - horizontal scroll */
    .bd-article table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Touch-friendly button sizes */
    a, button, .btn {
        min-height: 44px;
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .bd-article {
        max-width: 100%;
        padding: 1.5rem;
    }

    .bd-sidebar-primary {
        width: 240px;
    }

    .bd-main {
        max-width: 100%;
        padding: 1.5rem;
    }
}

/* Hide mobile menu toggle on larger screens */
@media (min-width: 769px) {
    .mobile-quick-nav,
    .mobile-menu-toggle {
        display: none;
    }
}

/* Hamburger menu button (mobile only) */
.mobile-menu-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 10000;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all 0.2s;
}

.mobile-menu-toggle:hover {
    background: var(--primary-hover);
}

/* ============================================
   Phase 7: Performance Optimizations
   ============================================ */

/* Enable GPU acceleration for smooth animations */
.bd-sidebar-primary,
.sidebar-secondary-item,
.nav-link,
.choice-card,
.btn {
    will-change: transform;
}

/* Optimize scrolling performance */
.bd-sidebar-primary,
.sidebar-secondary-item {
    contain: layout style paint;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   Additional Utilities & Helpers
   ============================================ */

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Focus styles for accessibility */
*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent-primary);
    color: white;
    padding: 0.5rem 1rem;
    text-decoration: none;
    z-index: 10001;
}

.skip-to-content:focus {
    top: 0;
}

/* Badge styling */
img[src*="shields.io"] {
    display: inline-block;
    margin: 4px;
}

/* Print styles */
@media print {
    .onboarding-modal,
    .mobile-quick-nav,
    .mark-complete-btn,
    .completion-toast,
    .bd-sidebar-primary,
    .bd-sidebar-secondary,
    .sidebar-secondary-item,
    .bd-header {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    a {
        text-decoration: underline;
    }

    .bd-main,
    .bd-content,
    .bd-article {
        max-width: 100%;
        width: 100%;
    }
}

/* ============================================
   Legacy Support & Overrides
   ============================================ */

/* Ensure dark mode works with legacy selectors */
@media (prefers-color-scheme: dark) {
    body {
        background-color: var(--bg-surface);
        color: var(--text-primary);
    }

    .bd-sidebar-primary {
        background: var(--bg-surface);
        border-right-color: var(--border-default);
    }

    .bd-article {
        background: var(--bg-surface);
        color: var(--text-primary);
    }
}

/* Dark mode link colors */
html[data-theme="dark"] .bd-sidebar-primary a,
html.dark-mode .bd-sidebar-primary a,
@media (prefers-color-scheme: dark) {
    .bd-sidebar-primary a {
        color: var(--text-secondary) !important;
    }

    .bd-sidebar-primary a:hover {
        color: var(--text-primary) !important;
        background: var(--bg-subtle) !important;
    }

    .bd-sidebar-primary .active > a {
        color: var(--accent-primary) !important;
        background: rgba(96, 165, 250, 0.1) !important;
        border-left: 3px solid var(--accent-primary) !important;
    }
}