/* Welcome Screen - Proper Containment */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.welcome-content {
    max-width: 500px;
    width: 100%;
    padding: 0 1rem;
    box-sizing: border-box;
}

.welcome-icon {
    font-size: 4rem;
    color: #64b5f6;
    margin-bottom: 2rem;
}

.welcome-content h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: #ffffff;
    font-weight: 600;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.welcome-content p {
    font-size: 1.1rem;
    color: #b0b0b0;
    margin-bottom: 2rem;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Topic Header - Proper Containment */
.topic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.topic-header h2 {
    font-size: 2.2rem;
    color: #ffffff;
    font-weight: 600;
    background: linear-gradient(135deg, #ffffff 0%, #e0e0e0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    flex: 1;
    min-width: 0;
}

.topic-actions {
    display: flex;
    gap: 1rem;
    flex-shrink: 0;
}

/* Section Header - Proper Containment */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.section-header h3 {
    font-size: 1.4rem;
    color: #ffffff;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    flex: 1;
    min-width: 0;
}

.section-header h3::before {
    content: "";
    width: 4px;
    height: 20px;
    background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
    border-radius: 2px;
    flex-shrink: 0;
}

/* Subtopics List - Grid Layout Fix */
.subtopics-list {
    display: grid;
    gap: 1.5rem;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

/* Subtopic Actions - Better Mobile Layout */
.subtopic-actions {
    display: flex;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
}

.subtopic-card:hover .subtopic-actions {
    opacity: 1;
}

.subtopic-content {
    margin-top: 1rem;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

/* Content Section Headers */
.content-section h4 {
    font-size: 1rem;
    font-weight: 600;
    color: #64b5f6;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

/* Code Header - Better Mobile Layout */
.code-header {
    background: rgba(15, 20, 25, 0.9);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #e6e6e6;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.code-language {
    font-weight: 600;
    text-transform: uppercase;
    color: #64b5f6;
    font-size: 0.8rem;
    background: rgba(100, 181, 246, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Enhanced Scroll Behavior for All Containers */
.content-area,
.subtopic-card,
.code-content,
.modal-content {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Better Text Selection on Mobile */
.subtopic-title,
.content-section p,
.bullet-points li {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Prevent Horizontal Scrolling on Body */
body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

.container {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* Long URL/Text Breaking */
.content-section p,
.bullet-points li,
.subtopic-description {
    word-break: break-word;
    overflow-wrap: anywhere;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
    hyphens: auto;
}

/* Code Content - Enhanced Mobile Scrolling */
.code-content pre code {
    display: block;
    white-space: pre;
    overflow-x: auto;
    overflow-y: hidden;
    width: max-content;
    min-width: 100%;
    box-sizing: border-box;
}

/* Table-like content handling */
.content-section table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
}

/* Image handling */
.content-section img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.5rem 0;
}

/* Prevent zoom on double tap for iOS */
.btn,
.topic-item,
.subtopic-card {
    touch-action: manipulation;
}

/* Enhanced focus indicators for keyboard navigation */
.btn:focus-visible,
.topic-item:focus-visible,
.subtopic-card:focus-visible {
    outline: 2px solid #64b5f6;
    outline-offset: 2px;
    border-radius: 8px;
}/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f1419;
    background-image: linear-gradient(135deg, #0f1419 0%, #1a1f2e 50%, #0f1419 100%);
    min-height: 100vh;
    color: #e6e6e6;
    line-height: 1.6;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: transparent;
}

/* Header Styles */
.header {
    background: rgba(15, 20, 25, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 1.2rem 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    transition: transform 0.3s ease-in-out;
}

.header.header-hidden {
    transform: translateY(-100%);
}

.header.header-visible {
    transform: translateY(0);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 50%, #2196f3 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.search-container {
    position: relative;
    max-width: 400px;
    width: 100%;
}

.search-container input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    font-size: 0.9rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.search-container input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.98);
    border-color: #64b5f6;
    box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.2);
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #64b5f6;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    margin-top: 80px; /* Account for fixed header */
}

/* Sidebar Styles */
.sidebar {
    width: 320px;
    background: rgba(21, 26, 35, 0.95);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(15, 20, 25, 0.8);
}

.sidebar-header h3 {
    margin-bottom: 1rem;
    color: #e6e6e6;
    font-weight: 600;
    font-size: 1.1rem;
}

.topics-list {
    flex: 1;
    padding: 1rem;
}

/* Code Annotator Link in Sidebar */
.tools-section {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: auto;
}

.tools-section h4 {
    color: #e6e6e6;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tool-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(100, 181, 246, 0.1);
    border: 1px solid rgba(100, 181, 246, 0.2);
    border-radius: 8px;
    color: #64b5f6;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.tool-link:hover {
    background: rgba(100, 181, 246, 0.15);
    border-color: rgba(100, 181, 246, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(100, 181, 246, 0.2);
}

.tool-link i {
    font-size: 1.1rem;
}

.topic-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-bottom: 0.75rem;
    transition: all 0.3s ease;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.topic-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(100, 181, 246, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(100, 181, 246, 0.1);
}

.topic-item.active {
    background: linear-gradient(135deg, rgba(100, 181, 246, 0.2) 0%, rgba(66, 165, 245, 0.15) 100%);
    border-color: #64b5f6;
    box-shadow: 0 4px 20px rgba(100, 181, 246, 0.2);
}

.topic-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topic-title {
    font-weight: 500;
    flex: 1;
    color: #e6e6e6;
    font-size: 0.95rem;
}

.topic-item.active .topic-title {
    color: #ffffff;
    font-weight: 600;
}

.topic-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.topic-item:hover .topic-actions {
    opacity: 1;
}

.topic-actions button {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #b0b0b0;
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 6px;
    transition: all 0.3s ease;
    font-size: 0.8rem;
}

.topic-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

/* Content Area - Proper Overflow Handling */
.content-area {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal overflow */
    background: transparent;
    color: #e6e6e6;
    width: 100%;
    max-width: 100%;
}

/* Topic Content Container */
.topic-content {
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    overflow-x: hidden; /* Prevent horizontal overflow */
}

/* Subtopic Cards - Prevent Overflow */
.subtopic-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(20px);
    transition: all 0.3s ease;
    width: 100%;
    max-width: 100%;
    overflow: hidden; /* Contain all content */
    word-wrap: break-word;
    box-sizing: border-box;
}

/* Content Sections - Proper Text Wrapping */
.content-section {
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.content-section p {
    color: #d0d0d0;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
}

/* Bullet Points - Better Mobile Wrapping */
.bullet-points {
    list-style: none;
    padding: 0;
    width: 100%;
    max-width: 100%;
}

.bullet-points li {
    padding: 0.4rem 0;
    color: #d0d0d0;
    position: relative;
    padding-left: 1.5rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

/* Code Block - Horizontal Scroll Container */
.code-block {
    background: rgba(8, 12, 16, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    margin: 1rem 0;
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.code-content {
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    position: relative;
}

.code-content pre {
    margin: 0;
    padding: 1rem;
    font-family: 'Fira Code', 'JetBrains Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #e6e6e6;
    background: none;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: pre;
    min-width: 100%;
    box-sizing: border-box;
    
    /* Better scrollbar for code */
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 181, 246, 0.3) rgba(255, 255, 255, 0.05);
}

.code-content pre::-webkit-scrollbar {
    height: 8px;
}

.code-content pre::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.code-content pre::-webkit-scrollbar-thumb {
    background: rgba(100, 181, 246, 0.3);
    border-radius: 4px;
}

.code-content pre::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 181, 246, 0.5);
}

/* Subtopic Headers - Prevent Overflow */
.subtopic-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.subtopic-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.5rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    flex: 1;
    min-width: 0; /* Allow flex item to shrink */
}

.subtopic-description {
    color: #b0b0b0;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
}

/* Button Styles */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-family: inherit;
    backdrop-filter: blur(10px);
}

.btn-primary {
    background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
    color: white;
    border: 1px solid rgba(100, 181, 246, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #42a5f5 0%, #2196f3 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(100, 181, 246, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #e6e6e6;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.1);
}

.btn-danger {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    color: white;
    border: 1px solid rgba(244, 67, 54, 0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.3);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.modal-content {
    background: rgba(21, 26, 35, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin: 5% auto;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
    max-height: 95vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 800px;
}

.modal-small {
    max-width: 400px;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #ffffff;
    font-weight: 600;
    font-size: 1.2rem;
}

.modal-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #b0b0b0;
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #e6e6e6;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.05);
    color: #e6e6e6;
    backdrop-filter: blur(10px);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #64b5f6;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.2);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: #888;
}

.code-language-selector {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.code-language-selector label {
    margin-bottom: 0;
    font-size: 0.9rem;
}

.code-language-selector select {
    width: auto;
    min-width: 150px;
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid #64b5f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    color: white;
    font-size: 1.1rem;
}

/* Mobile-First Responsive Design */

/* Mobile Toggle Button for Sidebar */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.mobile-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Mobile Navigation Overlay */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(8px);
}

.mobile-nav-overlay.active {
    display: block;
}

/* Responsive breakpoints - Mobile First */
@media (max-width: 1024px) {
    .header {
        padding: 1rem 1.5rem;
    }
    
    .sidebar {
        width: 280px;
    }
}

/* Tablet Design */
@media (max-width: 768px) {
    .header {
        padding: 0.75rem 1rem;
    }
    
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .search-container {
        max-width: 250px;
        margin: 0;
    }
    
    .mobile-menu-toggle {
        display: flex;
        order: -1;
    }
    
    .main-content {
        margin-top: 70px;
    }
    
    .sidebar {
        position: fixed;
        top: 70px;
        left: -100%;
        width: 280px;
        height: calc(100vh - 70px);
        z-index: 1000;
        transition: left 0.3s ease;
        border-right: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .sidebar.mobile-open {
        left: 0;
    }
    
    .content-area {
        width: 100%;
        padding: 1.5rem 1rem;
    }
    
    .topic-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }
    
    .topic-header h2 {
        font-size: 1.8rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1rem;
    }
    
    .section-header h3 {
        font-size: 1.2rem;
    }
    
    .subtopics-list {
        gap: 1rem;
    }
    
    .subtopic-card {
        padding: 1.25rem;
    }
    
    .subtopic-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .subtopic-actions {
        opacity: 1;
        width: 100%;
        justify-content: flex-end;
    }
    
    .welcome-content h2 {
        font-size: 2rem;
    }
    
    .welcome-content p {
        font-size: 1rem;
    }
    
    /* Modal adjustments for tablet */
    .modal-content {
        margin: 3% auto;
        width: 92%;
        max-height: 92vh;
    }
    
    .modal-large {
        max-width: 95%;
    }
}

/* Mobile Phone Design */
@media (max-width: 480px) {
    .header {
        padding: 0.5rem 0.75rem;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .search-container {
        max-width: 180px;
    }
    
    .search-container input {
        padding: 0.5rem 0.75rem 0.5rem 2rem;
        font-size: 0.85rem;
    }
    
    .main-content {
        margin-top: 65px;
    }
    
    .sidebar {
        top: 65px;
        height: calc(100vh - 65px);
        width: 260px;
    }
    
    .sidebar-header {
        padding: 1rem 0.75rem;
    }
    
    .topics-list {
        padding: 0.75rem;
    }
    
    .topic-item {
        margin-bottom: 0.5rem;
    }
    
    .topic-header {
        padding: 0.75rem;
    }
    
    .topic-title {
        font-size: 0.9rem;
    }
    
    .content-area {
        padding: 1rem 0.75rem;
    }
    
    .topic-header h2 {
        font-size: 1.6rem;
        line-height: 1.3;
    }
    
    .section-header h3 {
        font-size: 1.1rem;
    }
    
    .subtopic-card {
        padding: 1rem;
        border-radius: 12px;
    }
    
    .subtopic-title {
        font-size: 1.1rem;
        line-height: 1.4;
    }
    
    .subtopic-description {
        font-size: 0.85rem;
        line-height: 1.5;
    }
    
    .content-section h4 {
        font-size: 0.95rem;
    }
    
    .content-section p {
        font-size: 0.9rem;
        line-height: 1.6;
    }
    
    .bullet-points li {
        font-size: 0.9rem;
        padding: 0.3rem 0;
    }
    
    .code-header {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .code-content {
        padding: 0.75rem;
    }
    
    .code-content pre {
        font-size: 0.8rem;
        line-height: 1.5;
    }
    
    .welcome-content {
        padding: 0 1rem;
    }
    
    .welcome-content h2 {
        font-size: 1.7rem;
        line-height: 1.3;
    }
    
    .welcome-content p {
        font-size: 0.95rem;
        line-height: 1.6;
    }
    
    .welcome-icon {
        font-size: 3rem;
        margin-bottom: 1.5rem;
    }
    
    /* Button improvements for mobile */
    .btn {
        padding: 0.65rem 1.25rem;
        font-size: 0.85rem;
        min-height: 44px; /* iOS touch target */
        touch-action: manipulation;
    }
    
    .btn-sm {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        min-height: 36px;
    }
    
    /* Modal improvements for mobile */
    .modal-content {
        margin: 2% auto;
        width: 96%;
        max-height: 95vh;
        border-radius: 12px;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-header h3 {
        font-size: 1.1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
    
    /* Form improvements for mobile */
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.4rem;
    }
    
    .form-group input,
    .form-group textarea,
    .form-group select {
        padding: 0.75rem;
        font-size: 0.9rem;
        border-radius: 8px;
        min-height: 44px; /* iOS touch target */
    }
    
    .form-group textarea {
        min-height: 100px;
        resize: vertical;
    }
    
    .code-language-selector {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
    
    .code-language-selector select {
        width: 100%;
    }
    
    /* Touch-friendly interactions */
    .topic-actions button,
    .subtopic-actions .btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem;
    }
    
    .modal-close {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Ultra-small screens */
@media (max-width: 360px) {
    .header h1 {
        font-size: 1.2rem;
    }
    
    .search-container {
        max-width: 150px;
    }
    
    .sidebar {
        width: 240px;
    }
    
    .content-area {
        padding: 0.75rem 0.5rem;
    }
    
    .subtopic-card {
        padding: 0.75rem;
    }
    
    .topic-header h2 {
        font-size: 1.4rem;
    }
    
    .welcome-content h2 {
        font-size: 1.5rem;
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .code-content pre {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        width: 250px;
    }
    
    .content-area {
        padding: 1rem;
    }
    
    .topic-header h2 {
        font-size: 1.5rem;
    }
    
    .welcome-content h2 {
        font-size: 1.8rem;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark mode preference support */
@media (prefers-color-scheme: dark) {
    /* Already optimized for dark theme */
}

/* Print styles */
@media print {
    .header,
    .sidebar,
    .topic-actions,
    .subtopic-actions,
    .mobile-menu-toggle,
    .btn {
        display: none !important;
    }
    
    .content-area {
        margin: 0;
        padding: 0;
        width: 100%;
        background: white;
        color: black;
    }
    
    .subtopic-card {
        border: 1px solid #ccc;
        background: white;
        break-inside: avoid;
        margin-bottom: 1rem;
    }
}

/* Prism.js Customization */
pre[class*="language-"] {
    background: transparent !important;
    margin: 0 !important;
    border-radius: 0 !important;
}

code[class*="language-"] {
    font-family: 'Fira Code', 'JetBrains Mono', 'Monaco', 'Consolas', monospace !important;
    font-size: 0.9rem !important;
    line-height: 1.6 !important;
    color: #e6e6e6 !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(100, 181, 246, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 181, 246, 0.5);
}

/* Focus styles for accessibility */
.btn:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #64b5f6;
    outline-offset: 2px;
}

/* Animation for new items */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.topic-item,
.subtopic-card {
    animation: fadeInUp 0.3s ease;
}

/* Additional enhancements for better UX */
.topic-item:focus-within {
    outline: 2px solid #64b5f6;
    outline-offset: 2px;
}

.subtopic-card:focus-within {
    border-color: #64b5f6;
    box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.2);
}

/* Glass morphism effect for special elements */
.header,
.sidebar,
.modal-content {
    box-shadow: 
        0 8px 32px 0 rgba(31, 38, 135, 0.37),
        inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
}

/* Smooth transitions for theme consistency */
* {
    transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

/* Header scroll behavior */
@media (min-width: 769px) {
    .main-content {
        margin-top: 88px; /* Slightly larger for desktop */
    }
}

/* Auto-hide header JavaScript integration styles */
.header {
    will-change: transform;
}

.header.scrolling-down {
    transform: translateY(-100%);
}

.header.scrolling-up {
    transform: translateY(0);
}

/* No data state styling */
.topics-list p,
.subtopics-list p {
    text-align: center;
    color: #888;
    padding: 2rem 1rem;
    font-style: italic;
}

/* Status indicators */
.topic-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 70%;
    background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
    border-radius: 0 2px 2px 0;
}

.topic-item {
    position: relative;
}