/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Sidebar Container */
.sidebar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100%;
    background-color: var(--color-surface);
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-container.active {
    transform: translateX(0);
}

/* Sidebar Header */
.sidebar-header {
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 56px;
}

/* Close Button */
.sidebar-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
    transition: background-color 0.2s ease;
}

/* Header Account/Login Button */
.sidebar-header-account {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.sidebar-header-account:hover {
    opacity: 0.8;
}

/* Logged out: text button */
.sidebar-header-login {
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-primary);
}

.sidebar-header-login:hover {
    background-color: var(--color-surface-hover);
}

/* Logged in: avatar circle */
.sidebar-header-logged-in {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    background: var(--color-surface);
    padding: 0;
    overflow: hidden;
}

.sidebar-header-logged-in:hover {
    border-color: var(--color-text-muted);
}

.sidebar-avatar-initial {
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    line-height: 1;
}

.sidebar-avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Header account: hidden on desktop (study mode shows pc-toggle instead) */
@media screen and (min-width: 851px) {
    html:not(.study-sidebar-active) .sidebar-header-account {
        display: none;
    }
}

/* Study mode desktop: hide account button in header (only show on mobile) */
@media screen and (min-width: 1025px) {
    html.study-sidebar-active .sidebar-header-account {
        display: none;
    }
}

.sidebar-close-btn:hover {
    background-color: rgba(128, 128, 128, 0.2);
}

.sidebar-close-btn .material-symbols-outlined {
    font-size: 24px;
}

/* PC Toggle Button */
.sidebar-pc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.sidebar-pc-toggle:hover {
    background-color: var(--color-surface-hover);
}

.sidebar-pc-toggle img {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    flex-shrink: 0;
}

:root[data-theme="dark"] .sidebar-pc-toggle img {
    filter: brightness(0) invert(1);
}

/* Sidebar Menu */
.sidebar-menu {
    padding: 0.5rem 0;
    list-style: none;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.sidebar-item {
    display: block;
}


.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.75rem;
    margin: 2px 8px;
    color: var(--color-text);
    text-decoration: none;
    transition: background-color 0.2s;
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
    border-radius: 12px;
    overflow: hidden;
}

.sidebar-link:hover {
    background-color: var(--color-surface);
}

.sidebar-icon {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    flex-shrink: 0;
    margin-right: 0.75rem;
    object-fit: contain;
}

.sidebar-text {
    font-weight: 500;
    white-space: nowrap;
    transition: opacity 0.2s ease;
}

/* External link indicator icon */
.sidebar-external-icon {
    font-size: 14px;
    width: 14px;
    min-width: 14px;
    height: 14px;
    margin-left: 4px;
    color: var(--color-text-muted);
    opacity: 0.5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Tree connector lines */
.sidebar-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
    position: relative;
    padding-left: 28px;
}

.sidebar-submenu::before {
    content: '';
    position: absolute;
    left: 18px;
    top: 0;
    bottom: 8px;
    width: 1px;
    background-color: var(--color-border);
}

.sidebar-submenu.open {
    max-height: 2000px;
}

.sidebar-submenu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    margin: 1px 8px 1px 0;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    transition: background-color 0.2s, color 0.2s;
    cursor: pointer;
    border-radius: 12px;
    position: relative;
}

/* Horizontal branch line from vertical line to item */
.sidebar-submenu-item::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    width: 10px;
    height: 1px;
    background-color: var(--color-border);
}

:root[data-theme="dark"] .sidebar-submenu-item {
    color: #94a3b8;
}

.sidebar-submenu-item.has-children {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-submenu-text {
    flex: 1;
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.sidebar-submenu-item.has-children:hover .sidebar-submenu-text {
    color: var(--color-primary);
}

:root[data-theme="dark"] .sidebar-submenu-text {
    color: #94a3b8;
}

:root[data-theme="dark"] .sidebar-submenu-item.has-children:hover .sidebar-submenu-text {
    color: #60a5fa;
}

.sidebar-submenu-arrow {
    width: 12px;
    height: 12px;
    transition: transform 0.3s ease;
    opacity: 0.6;
    filter: brightness(0.7);
}

.sidebar-submenu-item.has-children.open .sidebar-submenu-arrow {
    transform: rotate(180deg);
}

.sidebar-submenu-item:hover,
.sidebar-submenu-item.has-children:hover {
    background-color: var(--color-surface);
}

:root[data-theme="dark"] .sidebar-submenu-item:hover,
:root[data-theme="dark"] .sidebar-submenu-item.has-children:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Third Level Menu */
.sidebar-third-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    position: relative;
    padding-left: 20px;
}

.sidebar-third-menu::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 8px;
    width: 1px;
    background-color: var(--color-border);
}

.sidebar-third-menu.open {
    max-height: 1000px;
}

.sidebar-third-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.75rem;
    margin: 1px 8px 1px 0;
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 300;
    transition: background-color 0.2s, color 0.2s;
    border-radius: 12px;
    position: relative;
}

/* Horizontal branch line for third level */
.sidebar-third-item::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    width: 10px;
    height: 1px;
    background-color: var(--color-border);
}

.sidebar-third-item:hover {
    color: var(--color-primary);
    background-color: var(--color-surface);
}

:root[data-theme="dark"] .sidebar-third-item {
    color: #94a3b8;
}

:root[data-theme="dark"] .sidebar-third-item:hover {
    color: #60a5fa;
    background-color: rgba(255, 255, 255, 0.05);
}

:root[data-theme="dark"] .sidebar-submenu-arrow {
    opacity: 1;
    filter: brightness(0) invert(1);
}

:root[data-theme="dark"] .sidebar-submenu::before,
:root[data-theme="dark"] .sidebar-third-menu::before,
:root[data-theme="dark"] .sidebar-submenu-item::before,
:root[data-theme="dark"] .sidebar-third-item::before {
    background-color: #3a3a3a;
}

/* Arrows - only for items with children */
.sidebar-arrow {
    margin-left: auto;
    width: 14px;
    height: 14px;
    transition: transform 0.3s ease;
    opacity: 0.5;
    filter: brightness(0.5);
}

.sidebar-link.open .sidebar-arrow {
    transform: rotate(180deg);
}

:root[data-theme="dark"] img.sidebar-icon {
    filter: brightness(0) invert(0.85);
}

:root[data-theme="dark"] .sidebar-arrow {
    opacity: 0.7;
    filter: brightness(0) invert(1);
}

:root[data-theme="sepia"] .sidebar-arrow {
    opacity: 0.7;
    filter: brightness(0.5) sepia(0.3);
}

/* =========================================
   PC: Sidebar Hidden
   ========================================= */
@media screen and (min-width: 851px) {
    .sidebar-container {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }

    .sidebar-pc-toggle {
        display: none !important;
    }

    body.sidebar-pc-collapsed,
    body.sidebar-pc-expanded {
        margin-left: 0 !important;
    }

    #mobile-top-bar {
        display: none !important;
    }

    .mobile-level-drawer {
        display: none !important;
    }
}

/* Small Screen Overlay Sidebar (< 850px) */
@media screen and (max-width: 850px) {
    .sidebar-container {
        max-width: 320px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .sidebar-container.active {
        transform: translateX(0);
    }

    /* Hide PC toggle and narrow strip */
    .sidebar-pc-toggle {
        display: none !important;
    }

    /* No body push — sidebar floats on top */
    body.sidebar-pc-collapsed,
    body.sidebar-pc-expanded {
        margin-left: 0 !important;
    }
}

/* Very small screens: full width */
@media screen and (max-width: 400px) {
    .sidebar-container {
        max-width: 100%;
    }
}

/* Navbar Toggle Button Style (Injected) */

.sidebar-toggle-btn {

    background: none;

    border: none;

    cursor: pointer;

    padding: 0;

    margin-right: 10px;

    display: flex;

    align-items: center;

    transition: transform 0.2s ease;

}



.sidebar-toggle-btn img {
    width: 50px; 
    height: auto;
    max-height: 50px; 
    filter: drop-shadow(2px 2px 2px var(--color-shadow-hard));
    transform: rotate(9deg);
    transition: transform 0.2s ease;
}

/* Mobile Top Bar - Force Absolute Consistency */
#mobile-top-bar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 50px !important;
    background-color: #334155 !important;
    z-index: 9999 !important;
    display: none;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 10px !important;
    box-sizing: border-box !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    line-height: 1.2 !important;
    overflow: hidden !important;
    transition: transform 0.3s ease;
}

.mobile-top-bar-title {
    position: absolute !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    color: white !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    letter-spacing: 1px !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    pointer-events: auto !important; /* Make clickable again */
    cursor: pointer !important;
    text-decoration: none !important;
    text-transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    white-space: nowrap !important;
}

/* Mobile Sidebar Button inside Top Bar */
.mobile-sidebar-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.mobile-sidebar-btn img {
    width: 24px;
    height: auto;
    filter: brightness(0) invert(1); /* Ensure it's white */
}

/* Mobile Account Button */
.mobile-account-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    transition: background-color 0.2s;
}

.mobile-account-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.mobile-account-btn img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: brightness(0) invert(1); /* Ensure it's white */
}

/* Mobile Theme Toggle Button */
.mobile-top-bar-right {
    display: flex;
    align-items: center;
    margin-left: auto;
}

.mobile-theme-toggle {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: white;
    transition: opacity 0.2s;
}

.mobile-theme-toggle:active {
    opacity: 0.6;
}

.mobile-theme-toggle .material-symbols-outlined {
    font-size: 22px;
}

/* Hide on desktop */
@media (min-width: 851px) {
    .mobile-theme-toggle {
        display: none;
    }
}

/* Light theme overrides for mobile top bar */
:root[data-theme="light"] #mobile-top-bar {
    background-color: rgba(255, 255, 255, 0.95) !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08) !important;
}

:root[data-theme="light"] #mobile-top-bar .mobile-top-bar-title {
    color: #1f1f1f !important;
}

:root[data-theme="light"] #mobile-top-bar .mobile-sidebar-btn img {
    filter: none !important;
}

:root[data-theme="light"] #mobile-top-bar .mobile-account-btn img {
    filter: none !important;
}

:root[data-theme="light"] #mobile-top-bar .mobile-theme-toggle {
    color: #1f1f1f !important;
}

:root[data-theme="light"] #mobile-top-bar .mobile-level-trigger {
    color: #1f1f1f !important;
}

:root[data-theme="light"] #mobile-top-bar #topBarLevelValue {
    color: #1f1f1f !important;
}

:root[data-theme="light"] #mobile-top-bar .level-arrow {
    border-top-color: #1f1f1f !important;
}

:root[data-theme="light"] #mobile-top-bar .mobile-account-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Light theme overrides for study mode mobile top bar */
:root[data-theme="light"] .study-theme-toggle {
    color: #1f1f1f !important;
}

:root[data-theme="light"] .study-mobile-breadcrumb-home {
    color: #1f1f1f !important;
}

:root[data-theme="light"] .study-mobile-breadcrumb-sep {
    color: #1f1f1f !important;
}

@media (max-width: 850px) {
    html {
        background-color: #334155; /* Match bar color to prevent leaking white on overscroll */
    }

    :root[data-theme="light"] {
        background-color: #f5f5f5 !important;
    }
    body {
        padding-top: 50px;
        background-color: var(--color-bg); /* Ensure body itself keeps its background */
    }
    .bg-wave {
        top: 50px !important;
    }
    #mobile-top-bar {
        display: flex;
    }
}

/* Hide mobile top bar in fullscreen mode */
body.fullscreen-mode #mobile-top-bar,
html.fullscreen-mode #mobile-top-bar {
    display: none !important;
}

/* Remove body padding-top in fullscreen mode */
body.fullscreen-mode,
html.fullscreen-mode body {
    padding-top: 0 !important;
}

/* 
   =========================================
   MINIMALIST MOBILE LEVEL TRIGGER & DRAWER
   =========================================
*/

/* 1. The Trigger (Minimalist Text + Arrow) */
.mobile-level-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    cursor: pointer;
    color: white;
    height: 100%;
    -webkit-tap-highlight-color: transparent;
}

.mobile-level-trigger:active {
    opacity: 0.7;
}

#topBarLevelValue {
    /* font-family: 'Patrick Hand', cursive, sans-serif !important; */
    font-size: 16px !important;
    font-weight: 700 !important;
    letter-spacing: 0.5px !important;
    color: white !important;
}

.level-arrow {
    width: 0 !important;
    height: 0 !important;
    border-left: 4px solid transparent !important;
    border-right: 4px solid transparent !important;
    border-top: 4px solid white !important;
    margin-top: 1px !important;
    transition: transform 0.3s ease !important;
}

/* Rotate arrow when active (class added via JS) */
.mobile-level-trigger.active .level-arrow {
    transform: rotate(180deg);
}


/* 2. The Drawer (Full Width Panel) */
.mobile-level-drawer {
    position: fixed;
    top: 50px; /* Right below the 50px top bar */
    left: 0;
    width: 100%;
    background-color: #334155; /* Matches Top Bar Color */
    z-index: 9998; /* Below top bar (9999) but above content */
    
    /* Animation Props */
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s;
    box-shadow: none;
    
}

.mobile-level-drawer.open {
    max-height: 200px; /* Enough to fit content */
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

/* Drawer Internal Layout */
.side-drawer-content {
    display: flex;
    height: 100%;
    padding: 20px 16px;
    gap: 20px;
}

/* Left Side: Aesthetic Label/Decor */
.drawer-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid rgba(255,255,255,0.1);
    padding-right: 10px;
}

.drawer-big-text {
    font-size: 32px;
    font-weight: 900;
    color: rgba(255,255,255,0.1);
    line-height: 1;
    letter-spacing: 2px;
    font-family: sans-serif;
}

.drawer-sub-text {
    font-family: var(--font-family-primary);
    font-size: 12px;
    color: rgba(255,255,255,0.6);
    margin-top: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Right Side: Grid of Options */
.drawer-right {
    flex: 2;
    display: flex;
    align-items: center;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 columns */
    gap: 10px;
    width: 100%;
}

.level-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
    padding: 8px 0;
    text-align: center;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    /* font-family: 'Patrick Hand', cursive, sans-serif !important; */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    cursor: pointer;
    transition: all 0.2s;
}

.level-btn:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

.level-btn.active {
    background: white;
    color: #334155;
    border-color: white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* Mobile Tweaks */
@media (max-width: 400px) {
    .drawer-big-text { font-size: 24px; }
    .side-drawer-content { gap: 10px; padding: 15px 10px; }
}

/* =========================================
   STUDY MODE: Desktop Persistent Sidebar
   Activated via <html class="study-sidebar-active">
   ========================================= */

/* Study mode: hide level trigger at all breakpoints */
html.study-sidebar-active #topBarLevelToggle {
    display: none !important;
}

/* Sidebar bottom area (sticky footer) */
.sidebar-bottom {
    padding: 0.5rem 0;
    flex-shrink: 0;
    margin-top: auto;
    background-color: var(--color-surface);
}

/* Group label (not a divider — reset divider styles) */
.sidebar-group-label {
    padding: 1rem 0.75rem 0.35rem;
    margin: 0 8px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    user-select: none;
    list-style: none;
    height: auto;
    background: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Material Symbols icon override for study mode */
html.study-sidebar-active .sidebar-icon.material-symbols-outlined {
    font-size: 20px;
    width: 20px;
    min-width: 20px;
    height: 20px;
    min-height: 20px;
    margin-right: 0.75rem;
    color: var(--color-text-secondary);
    opacity: 0.7;
    object-fit: unset;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
    transition: opacity 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

html.study-sidebar-active .sidebar-link.active .sidebar-icon.material-symbols-outlined {
    opacity: 1;
    color: var(--color-primary);
}

:root[data-theme="dark"] html.study-sidebar-active .sidebar-icon.material-symbols-outlined {
    color: var(--color-text-secondary);
}

:root[data-theme="dark"] html.study-sidebar-active .sidebar-link.active .sidebar-icon.material-symbols-outlined {
    color: #fff;
}

/* Desktop persistent sidebar */
@media screen and (min-width: 1025px) {
    html.study-sidebar-active .sidebar-container {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 240px;
        min-width: 240px;
        height: 100vh;
        transform: none;
        z-index: 100;
        box-shadow: none;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Collapsed state */
    html.study-sidebar-active.study-sidebar-collapsed .sidebar-container {
        width: 76px;
        min-width: 76px;
    }

    /* Show the PC toggle button */
    html.study-sidebar-active .sidebar-pc-toggle {
        display: flex !important;
    }

    /* Hide the close button on desktop */
    html.study-sidebar-active .sidebar-close-btn {
        display: none;
    }

    /* Hide overlay on desktop */
    html.study-sidebar-active .sidebar-overlay {
        display: none !important;
    }


    /* Expanded: icon position matches collapsed (8px margin + 20px padding-left = 28px) */
    html.study-sidebar-active .sidebar-link {
        padding-left: 20px;
    }

    /* Collapsed: hide text labels */
    html.study-sidebar-active.study-sidebar-collapsed .sidebar-text {
        opacity: 0;
        width: 0;
        overflow: hidden;
    }

    /* Collapsed: hide group labels cleanly */
    html.study-sidebar-active.study-sidebar-collapsed .sidebar-group-label {
        opacity: 0;
        height: 0;
        padding: 0;
        margin: 0;
        overflow: hidden;
    }

    /* Collapsed: center icon in 76px strip */
    html.study-sidebar-active.study-sidebar-collapsed .sidebar-link {
        justify-content: flex-start;
        padding: 0.6rem 0;
        margin: 2px 8px;
        padding-left: 20px;
    }

    /* Collapsed: remove icon margin */
    html.study-sidebar-active.study-sidebar-collapsed .sidebar-icon.material-symbols-outlined {
        margin-right: 0;
    }

    /* PC toggle: symmetric padding for balanced hover, margin aligns icon with nav items */
    html.study-sidebar-active .sidebar-header {
        padding: 0.75rem 0;
        justify-content: flex-start;
    }

    html.study-sidebar-active .sidebar-pc-toggle {
        width: auto;
        margin-left: 8px;
        padding: 8px 20px;
        justify-content: flex-start;
    }

    /* Collapsed: pc-toggle same positioning */
    html.study-sidebar-active.study-sidebar-collapsed .sidebar-pc-toggle {
        width: auto;
        margin-left: 8px;
        padding: 8px 20px;
        justify-content: flex-start;
    }

    /* Active nav item style */
    html.study-sidebar-active .sidebar-link.active {
        background-color: var(--color-text-muted-7);
        color: #fff;
        font-weight: 500;
    }

    /* Content area margin */
    html.study-sidebar-active .study-content {
        margin-left: 240px;
        transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    html.study-sidebar-active.study-sidebar-collapsed .study-content {
        margin-left: 76px;
    }

    /* Hide mobile top bar and level drawer on desktop */
    html.study-sidebar-active #mobile-top-bar {
        display: none !important;
    }

    html.study-sidebar-active .mobile-level-drawer {
        display: none !important;
    }
}

/* Study mode: Mobile overlay */
@media screen and (max-width: 1024px) {
    html.study-sidebar-active .sidebar-container {
        display: flex !important;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 260px;
        min-width: 260px;
        max-width: 320px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    html.study-sidebar-active .sidebar-container.active {
        transform: translateX(0);
    }

    /* Show overlay on mobile (override default desktop hide) */
    html.study-sidebar-active .sidebar-overlay {
        display: block !important;
    }

    /* Undo collapsed state on mobile */
    html.study-sidebar-active .sidebar-text {
        opacity: 1;
        width: auto;
        overflow: visible;
    }

    html.study-sidebar-active .sidebar-group-label {
        opacity: 1;
        height: auto;
        padding: 1rem 1.25rem 0.35rem;
        overflow: visible;
    }

    html.study-sidebar-active .sidebar-link {
        padding: 0.6rem 0.75rem;
        margin: 2px 8px;
    }

    html.study-sidebar-active .sidebar-icon.material-symbols-outlined {
        margin-right: 0.75rem;
    }

    html.study-sidebar-active .study-content {
        margin-left: 0 !important;
    }

    /* Hide PC toggle on mobile */
    html.study-sidebar-active .sidebar-pc-toggle {
        display: none !important;
    }

    /* Show close button on mobile */
    html.study-sidebar-active .sidebar-close-btn {
        display: flex;
    }

    /* Show mobile top bar on study page (extend to 1024px breakpoint) */
    html.study-sidebar-active #mobile-top-bar {
        display: flex !important;
    }

    /* Theme cycle button in study mobile top bar */
    html.study-sidebar-active .study-theme-toggle {
        background: none;
        border: none;
        padding: 8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
        color: white;
        transition: opacity 0.2s;
    }

    html.study-sidebar-active .study-theme-toggle:active {
        opacity: 0.6;
    }

    html.study-sidebar-active .study-theme-toggle .material-symbols-outlined {
        font-size: 22px;
    }

    /* Study mode: breadcrumb in mobile top bar */
    html.study-sidebar-active .mobile-top-bar-title {
        font-size: 16px !important;
        font-weight: 500 !important;
        letter-spacing: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        pointer-events: auto !important;
        cursor: default !important;
        text-decoration: none !important;
    }

    html.study-sidebar-active .study-mobile-breadcrumb-home {
        color: white;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        cursor: pointer;
    }

    html.study-sidebar-active .study-mobile-breadcrumb-home .material-symbols-outlined {
        font-size: 18px;
    }

    html.study-sidebar-active .study-mobile-breadcrumb-sep {
        margin: 0 6px;
        opacity: 0.4;
        font-size: 16px;
    }

    html.study-sidebar-active .study-mobile-breadcrumb-module {
        font-weight: 500;
    }

    /* Study mode: hide level trigger */
    html.study-sidebar-active .mobile-level-trigger {
        display: none !important;
    }

    /* Study mode: body padding for mobile top bar at extended breakpoint */
    html.study-sidebar-active body {
        padding-top: 50px;
    }
}

/* Study mode: extend mobile top bar background at wider breakpoint */
@media screen and (max-width: 1024px) {
    html.study-sidebar-active {
        background-color: #334155;
    }

    :root[data-theme="light"].study-sidebar-active {
        background-color: #f5f5f5 !important;
    }
}
