:root {
            /* Light Theme Defaults */
            --bg-color: #ffffff;
            --sidebar-bg: #f0f4f9;
            --text-primary: #1f1f1f;
            --text-secondary: #444746;
            --border-color: #e0e3e1;
            --hover-bg: #dfe4ea;
            --accent-blue: #0b57d0;
            --accent-green: #14ae5c;
            --font-main: 'Outfit', sans-serif;
            --font-serif: 'Georgia', serif;
            --accent-light: #eff6ff;
            
            --tag-bg: #e0e7ff;
            --tag-text: #3730a3;
            --progress-bg: #e2e8f0;

            /* Component specific vars for theming */
            --card-bg: #ffffff;
            --card-header-bg: #fafafa;
            --header-bg: #ffffff;
            --input-bg: #ffffff;
            --active-nav-bg: #c2e7ff;
            --active-nav-text: #001d35;
            --topic-hover: #fdfdfd;
            --fab-shadow: rgba(0, 0, 0, 0.2);
            --countdown-start: #fff1f2;
            --countdown-end: #ffe4e6;
            --countdown-border: #fecdd3;
            --countdown-text: #881337;
            --tooltip-bg: #2d2d2d;
            --tooltip-text: #ffffff;
            --btn-text-color: #ffffff;
        }

        /* Dark Theme Overrides */
        [data-theme="dark"] {
            --bg-color: #121212;
            --sidebar-bg: #1e1e1e;
            --text-primary: #e2e2e2;
            --text-secondary: #9ca3af;
            --border-color: #2e2e2e;
            --hover-bg: #2d2d2d;
            --accent-blue: #60a5fa; /* Lighter blue for dark bg */
            --accent-green: #4ade80;
            --accent-light: rgba(59, 130, 246, 0.15);
            
            --card-bg: #1e1e1e;
            --card-header-bg: #252525;
            --header-bg: #18181b;
            --input-bg: #1e1e1e;
            --active-nav-bg: #1e3a8a;
            --active-nav-text: #bfdbfe;
            --topic-hover: #262626;
            --fab-shadow: rgba(0, 0, 0, 0.5);
            
            /* Countdown colors removed to persist light mode look */
            
            --tooltip-bg: #e2e2e2;
            --tooltip-text: #121212;
            --btn-text-color: #000000;
        }

        html, body {
            max-width: 100%;
            overflow-x: hidden;
            position: relative;
            /* This prevents the "rubber-band" effect on iPad that breaks sticky headers */
            width: 100%;
            margin: 0;
            padding: 0;
        }

        * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
        body { margin: 0; font-family: var(--font-main); background: var(--bg-color); color: var(--text-primary); height: 100vh; display: flex; overflow: hidden; transition: background 0.3s, color 0.3s; }

        /* Scrollbar */
        ::-webkit-scrollbar { width: 8px; }
        ::-webkit-scrollbar-track { background: transparent; }
        ::-webkit-scrollbar-thumb { background: #c4c7c5; border-radius: 4px; }
        ::-webkit-scrollbar-thumb:hover { background: #8e918f; }

        /* Brand Container (Wrapper for Logo + Toggle) */
        .brand-wrapper {
            position: absolute;
            top: 0;
            right: 32px;
            height: 64px; /* Matches header height for vertical centering */
            z-index: 100;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        /*Logo Text*/
        .top-logo {
            font-family: var(--font-main);
            font-size: 20px;
            font-weight: 700;
            color: var(--text-primary);
            text-decoration: none;
            letter-spacing: -0.5px;
            display: flex;
            align-items: center;
        }
        
        .logo-accent { color: var(--accent-blue); }

        /* Master Badge */
        .master-badge {
            font-size: 10px;
            background: var(--accent-blue);
            color: white;
            padding: 3px 8px;
            border-radius: 12px;
            margin-left: 8px;
            vertical-align: middle;
            box-shadow: 0 0 8px var(--accent-blue);
            animation: pulse-glow 2s infinite;
            display: none; /* Hidden by default */
        }
        
        @keyframes pulse-glow {
            0% { box-shadow: 0 0 5px var(--accent-blue); opacity: 0.9; }
            50% { box-shadow: 0 0 15px #60a5fa; opacity: 1; }
            100% { box-shadow: 0 0 5px var(--accent-blue); opacity: 0.9; }
        }

        /* App Title Style (Bold, Blue, Bigger) */
        .app-title {
            font-family: var(--font-main);
            font-weight: 700;
            font-size: 20px;
            color: var(--accent-blue);
            white-space: nowrap;
        }

        /* Sidebar */
        #sidebar { 
            width: 300px; 
            background: var(--header-bg); 
            display: flex; 
            flex-direction: column; 
            flex-shrink: 0; 
            transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s; 
            z-index: 50; 
            overflow: hidden;
            white-space: nowrap;
            border-right: 1px solid var(--border-color);
        }
        body.sidebar-collapsed #sidebar { width: 0; border: none; }
        
        /* Mobile Overlay */
        #mobile-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 40; display: none; }
        body.mobile-sidebar-open #mobile-overlay { display: block; }
        
        @media (max-width: 1024px) {
            #sidebar { position: fixed; height: 100%; left: 0; top: 0; transform: translateX(-100%); width: 280px; transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
            body.mobile-sidebar-open #sidebar { transform: translateX(0); }
            body.sidebar-collapsed #sidebar { width: 280px; }
        }

        /* Sidebar Elements */
        .sidebar-header { padding-left: 20px; display: flex; align-items: center; height: 64px; border-bottom: 1px solid var(--border-color); }
        .btn-icon { background: none; border: none; cursor: pointer; padding: 8px; border-radius: 25%; color: var(--text-secondary); display: flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; transition: background 0.2s, border-radius 0.2s;/* Larger Touch Target */ }
        .btn-icon:hover { background: var(--hover-bg); }
        .brand-text { margin-left: 8px; font-weight: 500; color: var(--text-secondary); opacity: 1; transition: opacity 0.2s; }
        
        /* --- COUNTDOWN TIMER --- */
        .countdown-card {
            margin: 16px;
            padding: 16px;
            background: linear-gradient(135deg, var(--countdown-start) 0%, var(--countdown-end) 100%);
            border: 1px solid var(--countdown-border);
            border-radius: 12px;
            text-align: center;
            box-shadow: 0 2px 4px rgba(225, 29, 72, 0.05);
        }
        .countdown-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: #be123c; margin-bottom: 6px; letter-spacing: 0.5px; }
        .countdown-timer { font-family: var(--font-main); font-size: 22px; font-weight: 700; color: var(--countdown-text); margin-bottom: 6px; line-height: 1; }
        .countdown-timer span { font-variant-numeric: tabular-nums; }
        .countdown-unit { font-size: 12px; font-weight: 500; color: #9f1239; margin-left: 2px; }
        .countdown-msg { font-size: 13px; color: #be123c; font-weight: 500; margin-top: 8px; font-style: italic; border-top: 1px solid rgba(190, 18, 60, 0.1); padding-top: 8px;}

        .progress-dashboard { padding: 20px 16px; border-bottom: 1px solid var(--border-color); margin-bottom: 10px; }
        .overall-label { font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--text-secondary); display: flex; justify-content: space-between; margin-bottom: 8px; }
        .progress-bar-bg { width: 100%; height: 8px; background: var(--hover-bg); border-radius: 4px; overflow: hidden; }
        .progress-bar-fill { height: 100%; background: var(--accent-blue); width: 0%; transition: width 0.5s ease-out; }

        .archive-container { flex: 1; overflow-y: auto; padding: 8px; }
        .archive-label { padding: 8px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 4px; }
        
        .nav-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-radius: 50px; cursor: pointer; font-size: 14px; margin-bottom: 4px; color: var(--text-primary); transition: 0.2s; }
        .nav-item:hover { background: var(--hover-bg); }
        .nav-item.active { background: var(--active-nav-bg); color: var(--active-nav-text); font-weight: 500; }
        .nav-percent { font-size: 11px; font-weight: 600; color: var(--text-secondary); background: rgba(255,255,255,0.5); padding: 2px 6px; border-radius: 4px; }
        [data-theme="dark"] .nav-percent { background: rgba(0,0,0,0.3); }

        /* Main Content */
        main {
            flex: 1;
            display: flex;
            flex-direction: column;
            width: 100%;
            min-width: 0; /* CRITICAL: Prevents flex children from pushing width */
            overflow-x: hidden;
        }
        header { 
            height: 64px; 
            display: flex; 
            align-items: center; 
            justify-content: space-between; 
            padding: 0 20px; position: sticky; 
            top: 0; 
            background: var(--header-bg); 
            z-index: 10; 
            border-bottom: 1px solid var(--border-color); 
            transition: background-color 0.3s; 
        }
        .header-title { display: flex; align-items: center; gap: 12px; font-size: 20px; color: var(--text-secondary); }
        .header-actions { display: flex; align-items: center; gap: 8px; }

        /* Hide header title on desktop when sidebar is open */
        @media (min-width: 1025px) {
            .header-app-title {
                display: none;
            }
            body.sidebar-collapsed .header-app-title {
                display: block;
                margin-left: 12px;
            }
        }

        /* On mobile, sidebar is hidden by default, so show header title */
        @media (max-width: 1024px) {
            .header-app-title {
                display: block;
                margin-left: 12px;
            }
        }

        #content-scroll { flex: 1; overflow-y: auto; padding-bottom: 80px; }
        .container {
            width: 100%;
            max-width: 1000px; /* Ensures it never goes wider than the screen */
            margin: 0 auto;
            padding: 20px;
            box-sizing: border-box; /* Includes padding in the width calculation */
        }
        .page-header { text-align: center; margin-bottom: 40px; }
        .paper-badge { display: inline-block; background: var(--active-nav-bg); color: var(--active-nav-text); padding: 4px 12px; border-radius: 50px; font-size: 12px; font-weight: 600; text-transform: uppercase; margin-bottom: 12px; }
        .main-headline { font-size: 32px; font-weight: 500; margin: 0; line-height: 1.2; }
        .sub-headline { color: var(--text-secondary); margin-top: 8px; font-size: 16px; }

        /* Subject Card */
        .subject-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 16px; padding: 0; margin-bottom: 24px; transition: 0.2s; position: relative; overflow: hidden; }
        .subject-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); border-color: #c7c7c7; }
        [data-theme="dark"] .subject-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.3); border-color: #555; }
        
        .card-header { padding: 20px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--card-header-bg); }
        .subject-title { font-family: var(--font-serif); font-size: 20px; font-weight: 500; margin: 0; color: var(--text-primary); }
        .subject-progress { font-size: 12px; font-weight: 600; color: var(--accent-blue); }

        .card-body { padding: 12px 0; }
        
        /* Topic List Item */
        .topic-item { 
            display: flex; 
            align-items: flex-start; 
            padding: 12px 24px; 
            border-bottom: 1px solid var(--border-color); 
            transition: background 0.2s;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            position: relative;
        }
        .topic-item:last-child { border-bottom: none; }
        .topic-item:hover { background: var(--topic-hover); }
        .topic-item:active { background: var(--hover-bg); }
        
        /* Custom Checkbox */
        .checkbox-wrapper { 
            position: relative; 
            width: 20px; 
            height: 20px; 
            margin-right: 16px; 
            margin-top: 2px;
            flex-shrink: 0;
        }
        .custom-checkbox {
            appearance: none;
            width: 20px; 
            height: 20px;
            border: 2px solid var(--text-secondary);
            border-radius: 4px;
            background: transparent;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .custom-checkbox:checked {
            background-color: var(--accent-blue);
            border-color: var(--accent-blue);
        }
        .custom-checkbox:checked::after {
            content: '';
            width: 5px;
            height: 10px;
            border: solid var(--card-bg); /* Checkmark color matches card bg for contrast */
            border-width: 0 2px 2px 0;
            transform: rotate(45deg) translate(-1px, -1px);
        }
        
        .topic-text { 
            font-size: 15px; 
            line-height: 1.5; 
            color: var(--text-primary); 
            transition: color 0.2s; 
            flex: 1;
        }
        
        /* Checked State */
        .topic-item.completed .topic-text {
            text-decoration: line-through;
            color: var(--text-secondary);
        }
        .topic-item.completed .custom-checkbox {
            background-color: var(--accent-green);
            border-color: var(--accent-green);
        }
        
        /* Subject Mini Progress Bar */
        .mini-progress { height: 4px; width: 100%; background: var(--hover-bg); position: absolute; bottom: 0; left: 0; }
        .mini-fill { height: 100%; background: var(--accent-green); width: 0%; transition: width 0.3s; }

        /* --- TOOLTIPS FOR TOPICS --- */
        .topic-info-icon {
            display: none;
            margin-left: 8px;
            color: var(--accent-blue);
            cursor: pointer;
            flex-shrink: 0;
        }
        
        /* Desktop Tooltip */
        .topic-tooltip {
            visibility: hidden;
            background-color: var(--tooltip-bg);
            color: var(--tooltip-text);
            text-align: left;
            border-radius: 6px;
            padding: 10px;
            position: absolute;
            z-index: 10;
            width: 250px;
            font-size: 12px;
            box-shadow: 0 4px 15px var(--fab-shadow);
            opacity: 0;
            transition: opacity 0.3s;
            pointer-events: none; /* Let clicks pass through on desktop */
            left: 50%;
            bottom: 100%; /* Position above */
            margin-bottom: 10px;
            transform: translateX(-50%);
            border: 1px solid var(--border-color);
        }
        
        /* Desktop Hover */
        @media (min-width: 769px) {
            .topic-item:hover .topic-tooltip {
                visibility: visible;
                opacity: 1;
            }
        }

        /* Mobile specific styles */
        @media (max-width: 768px) {
            .topic-info-icon {
                display: block; /* Show info icon on mobile */
            }
            .topic-tooltip {
                position: static; /* Flow naturally below item on mobile */
                width: 100%;
                margin-top: 8px;
                transform: none;
                display: none; /* Controlled by JS */
                opacity: 1;
                visibility: visible;
                pointer-events: auto;
            }
            .topic-tooltip.show-mobile {
                display: block;
                animation: slideDown 0.2s ease-out;
            }
            .topic-item {
                flex-wrap: wrap; /* Allow tooltip to wrap to next line */
            }
        }
        
        @keyframes slideDown {
            from { opacity: 0; transform: translateY(-5px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* --- NOTEPAD & HIGHLIGHTER STYLES --- */
        .fab-container {
            position: fixed;
            bottom: 30px;
            right: 30px;
            display: flex;
            flex-direction: column;
            gap: 16px;
            z-index: 90;
            align-items: center;
        }

        .fab {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4px 15px var(--fab-shadow);
            cursor: pointer;
            transition: transform 0.2s, background-color 0.2s;
            color: white;
        }
        .fab:hover { transform: scale(1.05); }

        #notepad-fab { background-color: var(--accent-blue); }
        #notepad-fab:hover { background-color: #0842a0; }

        #pdf-fab { background-color: #3b82f6; } /* Blue for Print */
        #pdf-fab:hover { background-color: #2563eb; }
        
        /* Notepad Container */
        #notepad-container {
            position: fixed;
            bottom: 170px;
            right: 30px;
            width: 320px;
            height: 450px;
            background: var(--card-bg);
            border-radius: 20px;
            box-shadow: 0 8px 30px var(--fab-shadow);
            display: flex;
            flex-direction: column;
            z-index: 90;
            transform: scale(0.9) translateY(20px);
            opacity: 0;
            pointer-events: none;
            transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
            border: 1px solid var(--border-color);
        }
        #notepad-container.active {
            transform: scale(1) translateY(0);
            opacity: 1;
            pointer-events: auto;
        }
        .notepad-header {
            padding: 16px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: var(--card-header-bg);
            border-radius: 20px 20px 0 0;
        }
        .notepad-title { font-weight: 600; color: var(--text-primary); font-size: 16px; }
        .notepad-actions button { background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 4px; margin-left: 4px; }
        .notepad-actions button:hover { color: var(--accent-blue); }
        
        #notepad-area {
            flex: 1;
            border: none;
            padding: 16px;
            font-family: 'Roboto', sans-serif;
            font-size: 14px;
            line-height: 1.6;
            color: var(--text-primary);
            resize: none;
            outline: none;
            background: var(--input-bg);
        }
        #notepad-area::placeholder { color: var(--text-secondary); }
        
        /* Empty State */
        .empty-state {
            text-align: center;
            padding: 40px;
            color: var(--text-secondary);
        }

        /* --- MOBILE FIRST OVERRIDES --- */
        @media (max-width: 768px) {
            /* Adjust wrapper for mobile */
            .brand-wrapper {
                top: 0;
                right: 20px;
                height: 64px; /* Ensure centering on mobile too */
                gap: 8px;
            }
            
            /* Move Toggle Button below header on mobile */
            .brand-wrapper .btn-icon {
                position: fixed;
                top: 74px; /* Below the 64px header */
                right: 16px;
                background-color: var(--card-bg);
                border: 1px solid var(--border-color);
                box-shadow: 0 2px 8px rgba(0,0,0,0.15);
                z-index: 95; /* Above content */
                width: 36px;
                height: 36px;
            }

            .top-logo { font-size: 18px; }

            /* Main container padding */
            .container { padding: 16px 16px 96px 16px; /* Added bottom padding for FABs */ }
            
            /* Header fonts */
            .main-headline { font-size: 26px; }
            .sub-headline { font-size: 15px; }
            
            /* Card Padding - Tighter on mobile */
            .card-header { padding: 16px 20px; }
            .subject-title { font-size: 18px; }
            .topic-item { padding: 14px 20px; } /* Comfortable touch target */
            
            /* Notepad: Transform into Bottom Sheet */
            #notepad-container {
                width: 100%;
                left: 0;
                right: 0;
                bottom: 0;
                border-radius: 20px 20px 0 0;
                height: 50vh; /* Half screen */
                transform: translateY(100%);
                border-left: none;
                border-right: none;
                border-bottom: none;
                box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
            }
            #notepad-container.active {
                transform: translateY(0);
            }
            
            /* FAB adjustments - Respect Safe Area */
            .fab-container {
                bottom: 24px;
                right: 24px;
                bottom: calc(24px + env(safe-area-inset-bottom)); 
            }

            /* Better header spacing */
            header { padding: 0 16px; }
            .header-title { font-size: 18px; }
        }

        /* --- EXCEL-STYLE TAB BAR --- */
.tab-bar-wrapper {
    position: sticky;
    top: 64px; /* Matches your 64px header */
    z-index: 9; /* Below the 100 z-index of the brand-wrapper */
    background: var(--header-bg);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
}
.tab-bar-wrapper::before, .tab-bar-wrapper::after {
    content: ''; position: absolute; top: 0; bottom: 0; width: 40px;
    pointer-events: none; z-index: 10; opacity: 0; transition: opacity 0.3s ease;
}
.tab-bar-wrapper::before { left: 0; background: linear-gradient(to right, var(--bg-color) 0%, transparent 100%); }
.tab-bar-wrapper::after { right: 0; background: linear-gradient(to left, var(--bg-color) 0%, transparent 100%); }
.tab-bar-wrapper.can-scroll-left::before { opacity: 1; }
.tab-bar-wrapper.can-scroll-right::after { opacity: 1; }

.excel-tab-bar { display: flex; overflow-x: auto; scrollbar-width: none; 
    white-space: nowrap;
    -webkit-overflow-scrolling: touch; /* Enables smooth finger scrolling on iPad */
    flex-wrap: nowrap; /* Ensures tabs stay in one line */
    width: 100%;
}
.excel-tab-bar::-webkit-scrollbar { display: none; }

.tab-link {
    padding: 14px 20px; white-space: nowrap; color: var(--text-secondary);
    font-size: 14px; font-weight: 600; border-bottom: 3px solid transparent;
    cursor: pointer; transition: all 0.2s ease; display: flex;
    align-items: center; gap: 6px; background: transparent; border-top: none;
    border-left: none; border-right: none; font-family: var(--font-main); text-decoration: none;
}
.tab-link:hover { background: var(--hover-bg); color: var(--text-primary); }
.tab-link.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); background:rgba(37, 99, 235, 0.05); }

/* --- QUICK READS DROPDOWN --- */
.tab-dropdown { position: relative; display: inline-block; }
.tab-dropdown-menu {
    display: none; position: fixed; transform: translateX(-50%);
    background: var(--card-bg); min-width: 250px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    border: 1px solid var(--border-color); border-radius: 12px; z-index: 1000;
    flex-direction: column; overflow: hidden;
}
.tab-dropdown-menu.show { display: flex; animation: fadeIn 0.2s ease-in-out; }
.tab-dropdown-menu a { padding: 12px 16px; color: var(--text-secondary); font-size: 13px; font-weight: 500; border-bottom: 1px solid var(--border-color); transition: 0.2s; text-decoration: none; }
.tab-dropdown-menu a:hover { background: var(--active-nav-bg); color: var(--text-primary); }
.tab-dropdown-menu a:last-child { border-bottom: none; }
.dropdown-toggle.open svg { transform: rotate(180deg); }
.dropdown-toggle svg { transition: transform 0.3s ease; }
