        :root {
            /* --- Material 3 Color System (Dark - Expressive Indigo/Amber) --- */

            /* Primary (Indigo) - Core Actions */
            --md-sys-color-primary: #b0c6ff;
            /* Was light indigo */
            --md-sys-color-on-primary: #002d6f;
            --md-sys-color-primary-container: #194398;
            --md-sys-color-on-primary-container: #d9e2ff;

            /* Secondary (Violet) - Less prominent */
            --md-sys-color-secondary: #c0c6dc;
            --md-sys-color-on-secondary: #2a3042;
            --md-sys-color-secondary-container: #404659;
            --md-sys-color-on-secondary-container: #dce2f9;

            /* Tertiary (Amber) - Expressive/Accents */
            --md-sys-color-tertiary: #efbd00;
            /* Vibrant Amber */
            --md-sys-color-on-tertiary: #412d00;
            --md-sys-color-tertiary-container: #5d4200;
            --md-sys-color-on-tertiary-container: #ffe088;

            /* Error */
            --md-sys-color-error: #ffb4ab;
            --md-sys-color-on-error: #690005;
            --md-sys-color-error-container: #93000a;
            --md-sys-color-on-error-container: #ffdad6;

            /* Surface (Deep Indigo/Slate) */
            --md-sys-color-background: #1b1b1f;
            --md-sys-color-on-background: #e4e2e6;

            --md-sys-color-surface: #1b1b1f;
            /* Base */
            --md-sys-color-surface-dim: #121215;
            --md-sys-color-surface-bright: #38383e;

            /* Surface Containers (for depth) */
            --md-sys-color-surface-container-lowest: #0d0d10;
            --md-sys-color-surface-container-low: #1e1b4b;
            /* Deep Indigo (Legacy bg-dark) */
            --md-sys-color-surface-container: #23222b;
            --md-sys-color-surface-container-high: #2e2d36;
            --md-sys-color-surface-container-highest: #312e81;
            /* Legacy bg-card equivalent */

            --md-sys-color-on-surface: #e4e2e6;
            --md-sys-color-on-surface-variant: #c4c6d0;
            --md-sys-color-outline: #8e9099;
            --md-sys-color-outline-variant: #44474f;

            /* --- M3 Typescale (Outfit) --- */
            --md-sys-typescale-display-large: 400 57px/64px 'Outfit', sans-serif;
            --md-sys-typescale-display-medium: 400 45px/52px 'Outfit', sans-serif;
            --md-sys-typescale-display-small: 400 36px/44px 'Outfit', sans-serif;

            --md-sys-typescale-headline-large: 400 32px/40px 'Outfit', sans-serif;
            --md-sys-typescale-headline-medium: 400 28px/36px 'Outfit', sans-serif;
            --md-sys-typescale-headline-small: 400 24px/32px 'Outfit', sans-serif;

            --md-sys-typescale-title-large: 400 22px/28px 'Outfit', sans-serif;
            --md-sys-typescale-title-medium: 500 16px/24px 'Outfit', sans-serif;
            --md-sys-typescale-title-small: 500 14px/20px 'Outfit', sans-serif;

            --md-sys-typescale-label-large: 500 14px/20px 'Outfit', sans-serif;
            --md-sys-typescale-label-medium: 500 12px/16px 'Outfit', sans-serif;
            --md-sys-typescale-label-small: 500 11px/16px 'Outfit', sans-serif;

            --md-sys-typescale-body-large: 400 16px/24px 'Outfit', sans-serif;
            --md-sys-typescale-body-medium: 400 14px/20px 'Outfit', sans-serif;
            --md-sys-typescale-body-small: 400 12px/16px 'Outfit', sans-serif;

            /* --- M3 Shape --- */
            --md-sys-shape-corner-none: 0px;
            --md-sys-shape-corner-extra-small: 4px;
            --md-sys-shape-corner-small: 8px;
            --md-sys-shape-corner-medium: 12px;
            --md-sys-shape-corner-large: 16px;
            --md-sys-shape-corner-extra-large: 28px;
            --md-sys-shape-corner-full: 9999px;

            /* --- Legacy Mappings (Bridge) --- */
            --bg-dark: var(--md-sys-color-surface-container-low);
            --bg-card: var(--md-sys-color-surface-container-highest);
            --text-light: var(--md-sys-color-on-surface);
            --primary: var(--md-sys-color-primary);
            --warning: var(--md-sys-color-tertiary);
            /* Mapping amber to tertiary */
            --success: #60d297;
            /* Adjusted for dark mode */
        }

        body {
            font: var(--md-sys-typescale-body-medium);
            margin: 0;
            padding: 0;
            display: flex;
            height: 100vh;
            background-color: var(--md-sys-color-background);
            color: var(--md-sys-color-on-background);
            overflow: hidden;
            user-select: none;
            -webkit-user-select: none;
        }

        /* Iframe Guard: Hide Shell if app is loaded inside an iframe */
        body.is-iframe #sidebar,
        body.is-iframe .header-container,
        body.is-iframe #login-overlay {
            display: none !important;
        }

        body.is-iframe #main-view {
            width: 100vw !important;
            margin: 0 !important;
        }

        button:disabled {
            opacity: 0.38;
            /* M3 disabled opacity */
            cursor: not-allowed;
        }

        input,
        textarea {
            user-select: text !important;
            -webkit-user-select: text !important;
        }

        /* Responsive Grid System */
        .responsive-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 16px;
            /* M3 Spacing */
        }

        @media (max-width: 1200px) {
            .responsive-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 768px) {
            #sidebar {
                position: fixed;
                height: 100vh;
                z-index: 1000;
                transform: translateX(-100%);
                transition: transform 0.3s var(--md-sys-motion-easing-emphasized);
                /* M3 Motion */
            }

            #sidebar.open {
                transform: translateX(0);
            }

            .responsive-grid {
                grid-template-columns: 1fr;
            }
        }

        /* Sidebar */
        .paper-card.disabled {
            opacity: 0.38;
            cursor: not-allowed;
            background: var(--md-sys-color-surface-dim);
        }

        .paper-card.disabled:hover {
            transform: none;
            box-shadow: none;
        }

        .badge.local-only {
            background: var(--md-sys-color-surface-variant);
            color: var(--md-sys-color-on-surface-variant);
        }

        #sidebar {
            width: 360px;
            /* Standard navigation drawer width */
            background: var(--md-sys-color-surface-container-low);
            border-right: 1px solid var(--md-sys-color-outline-variant);
            display: flex;
            flex-direction: column;
            overflow-y: auto;
            overflow-x: hidden;
            flex-shrink: 0;
            padding: 0;
            /* Remove padding, header has its own */
        }

        #header {
            padding: 24px 24px 16px 24px;
            background: var(--md-sys-color-surface-container);
            color: var(--md-sys-color-on-surface);
            box-shadow: none;
            /* Removed shadow for flat M3 look */
            border-bottom: 1px solid var(--md-sys-color-outline-variant);
        }

        #header h1 {
            margin: 0;
            font: var(--md-sys-typescale-headline-small);
            display: flex;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            color: var(--md-sys-color-primary);
        }

        #user-avatar-display {
            width: 40px;
            height: 40px;
            background-image: url('../avatars.webp');
            background-size: 800% 800%;
            background-position: 0 0;
            border-radius: 50%;
            border: 2px solid white;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
            display: inline-block;
        }

        /* Avatar Modal */
        #avatar-grid {
            display: grid;
            grid-template-columns: repeat(8, 1fr);
            gap: 8px;
            max-height: 400px;
            overflow-y: auto;
            overflow-x: hidden;
            padding: 10px;
        }

        .avatar-option {
            width: 32px;
            height: 32px;
            background-image: url('../avatars.webp');
            background-size: 800% 800%;
            border-radius: 50%;
            cursor: pointer;
            border: 2px solid transparent;
            transition: transform 0.2s;
        }

        .avatar-option:hover {
            transform: scale(1.2);
            border-color: white;
            z-index: 10;
        }

        .avatar-option.selected {
            border-color: #fbbf24;
            transform: scale(1.1);
        }

        #stats-grid {
            margin-top: 16px;
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            /* Compact grid as per M3 expressive dense layouts */
            padding: 0 24px 24px 24px;
            /* Integrated padding */
        }

        .stat-card-mini {
            background: var(--md-sys-color-surface-container);
            padding: 12px 6px;
            border-radius: var(--md-sys-shape-corner-medium);
            text-align: center;
            cursor: pointer;
            transition: all 0.2s var(--md-sys-motion-easing-emphasized);
            border: 1px solid transparent;
        }

        .stat-card-mini.yellow-card {
            background: var(--md-sys-color-tertiary-container);
            color: var(--md-sys-color-on-tertiary-container);
        }

        .stat-card-mini.yellow-card .stat-val-big,
        .stat-card-mini.yellow-card .stat-label-mini {
            color: var(--md-sys-color-on-tertiary-container);
        }

        .stat-card-mini:hover {
            transform: translateY(-2px);
            background: var(--md-sys-color-surface-container-high);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .stat-card-mini.yellow-card:hover {
            background: var(--md-sys-color-tertiary);
            color: var(--md-sys-color-on-tertiary);
        }

        /* When hovering yellow card, make inner text contrast with valid tertiary color */
        .stat-card-mini.yellow-card:hover .stat-val-big,
        .stat-card-mini.yellow-card:hover .stat-label-mini {
            color: var(--md-sys-color-on-tertiary);
        }

        .stat-card-mini.span-2 {
            grid-column: span 2;
            text-align: left;
        }

        .stat-val-big {
            font: var(--md-sys-typescale-headline-small);
            color: var(--md-sys-color-primary);
            display: block;
        }

        .stat-label-mini {
            font: var(--md-sys-typescale-label-small);
            opacity: 0.8;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-weight: 500;
            margin-top: 4px;
        }

        /* XP Card Style */
        .xp-card-content {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .xp-header {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .lvl-badge-sidebar {
            background: var(--md-sys-color-tertiary-container);
            color: var(--md-sys-color-on-tertiary-container);
            padding: 4px 8px;
            border-radius: var(--md-sys-shape-corner-extra-small);
            font: var(--md-sys-typescale-label-medium);
        }

        .xp-text-sidebar {
            font: var(--md-sys-typescale-title-small);
            color: var(--md-sys-color-on-surface);
        }

        .xp-progress-fill {
            height: 100%;
            background: var(--md-sys-color-tertiary);
            border-radius: var(--md-sys-shape-corner-extra-small);
            transition: width 0.5s var(--md-sys-motion-easing-emphasized);
        }

        /* Refined Profile Card (Added Jan 2026) */
        #profile-container {
            background: var(--md-sys-color-surface-container);
            border-radius: var(--md-sys-shape-corner-large);
            padding: 16px;
            display: flex;
            gap: 16px;
            align-items: center;
            border: none;
            cursor: pointer;
            margin: 0 24px 16px 24px;
            /* Inset from sidebar edges */
        }

        #profile-container:hover {
            background: var(--md-sys-color-surface-container-high);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .profile-left {
            flex-shrink: 0;
            padding-top: 0;
        }

        .profile-right {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 2px;
        }

        .profile-header-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 8px;
            margin-bottom: 2px;
        }

        .profile-name-text {
            font: var(--md-sys-typescale-title-medium);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            color: var(--md-sys-color-on-surface);
        }

        .profile-name-text:hover {
            text-decoration: none;
            /* Removed underline */
        }

        .profile-lvl-badge {
            font: var(--md-sys-typescale-label-small);
            background: var(--md-sys-color-tertiary-container);
            color: var(--md-sys-color-on-tertiary-container);
            padding: 2px 6px;
            border-radius: var(--md-sys-shape-corner-small);
            flex-shrink: 0;
            box-shadow: none;
        }

        .profile-rank-text {
            font: var(--md-sys-typescale-body-small);
            color: var(--md-sys-color-on-surface-variant);
        }

        .xp-bar-container {
            height: 4px;
            background: var(--md-sys-color-surface-container-highest);
            border-radius: var(--md-sys-shape-corner-full);
            width: 100%;
            overflow: hidden;
            margin-top: 8px;
        }

        .xp-bar-fill {
            height: 100%;
            background: var(--md-sys-color-primary);
            border-radius: var(--md-sys-shape-corner-full);
            transition: width 0.5s var(--md-sys-motion-easing-emphasized);
        }

        .profile-xp-row {
            display: flex;
            justify-content: flex-end;
            font: var(--md-sys-typescale-label-small);
            color: var(--md-sys-color-on-surface-variant);
            margin-top: 4px;
        }

        .sync-status-indicator {
            font-size: 0.65rem;
            opacity: 0.6;
            font-style: italic;
        }

        /* Login Overlay */
        #login-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: var(--md-sys-color-background);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9999;
            flex-direction: column;
            color: var(--md-sys-color-on-background);
            text-align: center;
        }

        .entry-card {
            background: var(--md-sys-color-surface-container-high);
            padding: 40px;
            border-radius: var(--md-sys-shape-corner-extra-large);
            /* 28px */
            border: none;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
            max-width: 400px;
            width: 90%;
            animation: fadeIn 0.8s var(--md-sys-motion-easing-emphasized);
        }

        .btn-google-login {
            width: 100%;
            padding: 12px 16px;
            background-color: white;
            /* Branding requirement */
            color: #1f1f1f;
            border: none;
            border-radius: var(--md-sys-shape-corner-full);
            /* Stadium */
            font: var(--md-sys-typescale-label-large);
            font-size: 1.1rem;
            /* Adjust to match previous size */
            font-weight: 500;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 12px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            transition: all 0.2s var(--md-sys-motion-easing-emphasized);
            margin-top: 8px;
            /* Spacing */
        }

        .btn-google-login:hover {
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
            background-color: #f2f2f2;
            transform: translateY(-1px);
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .entry-title {
            font: var(--md-sys-typescale-display-small);
            margin-bottom: 8px;
            color: var(--md-sys-color-primary);
        }

        .entry-subtitle {
            font: var(--md-sys-typescale-body-large);
            color: var(--md-sys-color-on-surface-variant);
            margin-bottom: 32px;
        }


        /* Filter Grid */
        #filters {
            padding: 16px 24px;
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 12px;
            border-bottom: 1px solid var(--md-sys-color-outline-variant);
        }

        #filter-stats-display {
            grid-column: 1 / -1;
            font: var(--md-sys-typescale-body-small);
            color: var(--md-sys-color-on-surface-variant);
            margin-bottom: 4px;
            text-align: right;
        }

        .span-1 {
            grid-column: span 1;
        }

        .span-2 {
            grid-column: span 2;
        }

        .span-3 {
            grid-column: span 2;
        }

        /* Multi-Select Styles - Updated for M3 */
        .multi-select {
            position: relative;
            width: 100%;
        }

        .select-box {
            background: var(--md-sys-color-surface-container-highest);
            border: 1px solid transparent;
            border-radius: var(--md-sys-shape-corner-extra-large);
            /* Stadium shape */
            padding: 10px 16px;
            color: var(--md-sys-color-on-surface);
            font: var(--md-sys-typescale-label-large);
            cursor: pointer;
            display: flex;
            justify-content: space-between;
            align-items: center;
            user-select: none;
            white-space: nowrap;
            overflow: hidden;
            transition: background 0.2s;
        }

        .select-box:hover {
            background: var(--md-sys-color-surface-container-high);
            border-color: var(--md-sys-color-outline);
        }

        .arrow {
            font-size: 1rem;
            transition: transform 0.2s var(--md-sys-motion-easing-emphasized);
            color: var(--md-sys-color-on-surface-variant);
        }

        .multi-select.open .arrow {
            transform: rotate(180deg);
            color: var(--md-sys-color-primary);
        }

        .options-container {
            position: absolute;
            top: 100%;
            left: 0;
            width: 100%;
            min-width: 200px;
            background: var(--md-sys-color-surface-container-high);
            border-radius: var(--md-sys-shape-corner-medium);
            margin-top: 4px;
            max-height: 300px;
            overflow-y: auto;
            overflow-x: hidden;
            z-index: 100;
            display: none;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
            border: none;
        }

        .multi-select.open .options-container {
            display: block;
        }

        .search-container {
            padding: 8px;
            border-bottom: 1px solid var(--md-sys-color-outline-variant);
            background: var(--md-sys-color-surface-container-high);
            position: sticky;
            top: 0;
        }

        .dropdown-search {
            width: 100%;
            padding: 10px 12px;
            background: var(--md-sys-color-surface-container-highest);
            border: 1px solid transparent;
            border-radius: var(--md-sys-shape-corner-small);
            color: var(--md-sys-color-on-surface);
            font: var(--md-sys-typescale-body-medium);
            box-sizing: border-box;
            outline: none;
        }

        .dropdown-search:focus {
            border-bottom: 2px solid var(--md-sys-color-primary);
            background: var(--md-sys-color-surface-container);
        }

        .option-item {
            padding: 12px 16px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 12px;
            font: var(--md-sys-typescale-body-medium);
            color: var(--md-sys-color-on-surface);
            transition: background 0.1s;
        }

        .option-item:hover {
            background: var(--md-sys-color-surface-container-highest);
        }

        .option-item:last-child {
            border-bottom: none;
        }

        .option-item.hidden {
            display: none;
        }

        .option-item input[type="checkbox"] {
            accent-color: var(--md-sys-color-primary);
            width: 18px;
            height: 18px;
            cursor: pointer;
        }

        .select-actions {
            padding: 12px;
            border-bottom: 1px solid var(--md-sys-color-outline-variant);
            display: flex;
            justify-content: space-between;
            background: var(--md-sys-color-surface-container-high);
        }

        .action-link {
            font: var(--md-sys-typescale-label-medium);
            color: var(--md-sys-color-primary);
            cursor: pointer;
            text-decoration: none;
        }

        .action-link:hover {
            color: var(--md-sys-color-primary-container);
            text-decoration: underline;
        }



        #paper-list {
            padding: 24px;
            display: block;
            /* Changed from flex column to support grid inside */
            /* gap: 20px; */
            overflow-y: auto;
            overflow-x: hidden;
            box-sizing: border-box;
            max-width: 1200px;
            /* Increased from 900px */
            margin: 0 auto;
            width: 100%;
            content-visibility: auto;
            contain-intrinsic-size: 1000px;
        }

        .view-pane {
            flex: 1;
            display: flex;
            flex-direction: column;
            height: 100%;
            overflow: hidden;
            position: relative;
        }

        #main-view {
            flex: 1;
            height: 100vh;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            background: var(--md-sys-color-background);
            /* Match bg-dark */
        }

        #results-view,
        #analytics-view,
        #exam-view,
        #xp-view {
            overflow-y: auto;
            overflow-x: auto;
            /* Changed from hidden to auto per user request */
            flex: 1;
            /* Allow to take full height of main-view */
            padding: 24px;
            box-sizing: border-box;
        }

        #analytics-view .analytics-container {
            max-width: 1000px;
            margin: 0 auto;
            background: var(--md-sys-color-surface-container);
            border-radius: var(--md-sys-shape-corner-extra-large);
            padding: 32px;
            /* Remove fixed positioning from modal style */
        }

        .paper-card {
            background: var(--md-sys-color-surface-container-highest);
            padding: 16px 24px;
            border-radius: var(--md-sys-shape-corner-large);
            border: 1px solid transparent;
            /* No visible border by default */
            cursor: pointer;
            transition: all 0.3s var(--md-sys-motion-easing-emphasized);
            position: relative;
            overflow: visible;
            /* Allowed for badges potentially */
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 24px;
            min-height: 72px;
            /* Taller MD cards */
        }

        .paper-card:hover {
            transform: translateY(-2px);
            background: var(--md-sys-color-surface-container-high);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            /* Elevation 2 */
        }

        .paper-card.active {
            border: 2px solid var(--md-sys-color-primary);
            background: var(--md-sys-color-surface-container);
        }

        .paper-card.completed {
            border-left: 8px solid var(--md-sys-color-primary);
            /* Use Primary for completed */
        }

        .paper-title {
            font: var(--md-sys-typescale-title-medium);
            margin-bottom: 8px;
            line-height: 1.4;
            padding-right: 24px;
            color: var(--md-sys-color-on-surface);
        }

        .badges {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }

        .badge {
            padding: 6px 12px;
            border-radius: var(--md-sys-shape-corner-small);
            font: var(--md-sys-typescale-label-small);
            text-transform: uppercase;
        }

        .bg-level {
            background: var(--md-sys-color-secondary-container);
            color: var(--md-sys-color-on-secondary-container);
        }

        .bg-year {
            background: var(--md-sys-color-surface-variant);
            color: var(--md-sys-color-on-surface-variant);
        }

        .bg-term {
            background: var(--md-sys-color-tertiary-container);
            color: var(--md-sys-color-on-tertiary-container);
        }

        .bg-school {
            background: var(--md-sys-color-primary-container);
            color: var(--md-sys-color-on-primary-container);
        }

        .bg-subject {
            background: var(--md-sys-color-error-container);
            color: var(--md-sys-color-on-error-container);
        }

        .check-btn {
            position: absolute;
            top: 24px;
            right: 24px;
            width: 32px;
            height: 32px;
            border-radius: 50%;
            border: 2px solid var(--md-sys-color-outline);
            background: transparent;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            z-index: 5;
            transition: all 0.2s;
        }

        .check-btn:hover {
            transform: scale(1.1);
            border-color: var(--md-sys-color-primary);
            background: var(--md-sys-color-surface-container-high);
        }

        .checked-icon {
            display: none;
            color: var(--md-sys-color-on-primary-container);
            font-size: 20px;
            font-weight: bold;
        }

        .paper-card.completed .checked-icon {
            display: block;
        }

        .paper-card.completed .check-btn {
            border-color: var(--md-sys-color-primary);
            background: var(--md-sys-color-primary);
            /* Fill check */
        }


        /* Main Content */
        #main-view {
            flex: 1;
            display: flex;
            flex-direction: column;
            background: var(--md-sys-color-background);
            position: relative;
        }

        #top-toolbar {
            height: 64px;
            /* Standard M3 height */
            background: var(--md-sys-color-surface-container);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 24px;
            color: var(--md-sys-color-on-surface);
            border-bottom: 1px solid var(--md-sys-color-outline-variant);
        }

        #paper-info h2 {
            font: var(--md-sys-typescale-title-medium);
            margin: 0;
            color: var(--md-sys-color-on-surface);
        }

        #paper-info p {
            font: var(--md-sys-typescale-body-small);
            color: var(--md-sys-color-on-surface-variant);
            margin: 0;
        }

        .btn-action {
            padding: 10px 24px;
            border-radius: var(--md-sys-shape-corner-full);
            /* Stadium */
            font: var(--md-sys-typescale-label-large);
            cursor: pointer;
            border: none;
            transition: all 0.2s var(--md-sys-motion-easing-emphasized);
            text-decoration: none;
            display: inline-block;
        }

        .btn-mark {
            background: var(--md-sys-color-tertiary);
            color: var(--md-sys-color-on-tertiary);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }

        .btn-mark:hover {
            background: var(--md-sys-color-tertiary-container);
            color: var(--md-sys-color-on-tertiary-container);
            transform: translateY(-1px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
        }

        .btn-mark.done {
            background: #60d297;
            /* Keeping success green but using variable if possible, or mapping */
            color: #00391c;
            box-shadow: none;
            cursor: default;
        }

        .btn-open {
            background: var(--md-sys-color-secondary-container);
            color: var(--md-sys-color-on-secondary-container);
            margin-left: 10px;
        }

        .btn-open:hover {
            background: var(--md-sys-color-secondary);
            color: var(--md-sys-color-on-secondary);
        }

        iframe {
            width: 100%;
            height: 100%;
            border: none;
        }

        #empty-screen {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: var(--md-sys-color-background);
            color: var(--md-sys-color-primary);
            text-align: center;
        }

        /* Notes Pane */
        #notes-pane {
            height: 140px;
            background: var(--md-sys-color-surface-container-low);
            border-top: 1px solid var(--md-sys-color-outline-variant);
            display: flex;
            flex-direction: column;
            padding: 0;
            transition: height 0.3s var(--md-sys-motion-easing-emphasized);
            flex-shrink: 0;
        }

        #notes-header {
            background: var(--md-sys-color-surface-container-high);
            color: var(--md-sys-color-on-surface-variant);
            padding: 8px 16px;
            font: var(--md-sys-typescale-label-small);
            text-transform: uppercase;
            letter-spacing: 1px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid var(--md-sys-color-outline-variant);
            cursor: pointer;
        }

        #notes-input {
            flex: 1;
            background: var(--md-sys-color-surface-container-low);
            color: var(--md-sys-color-on-surface);
            border: none;
            padding: 12px 16px;
            font-family: 'Outfit', sans-serif;
            /* Unify font */
            font-size: 0.95rem;
            resize: none;
            outline: none;
            line-height: 1.5;
        }

        #notes-input::placeholder {
            color: var(--md-sys-color-outline);
        }

        .toggle-icon {
            transition: transform 0.3s var(--md-sys-motion-easing-emphasized);
        }

        .collapsed .toggle-icon {
            transform: rotate(180deg);
        }

        .collapsed #notes-pane {
            height: 40px;
        }

        /* User Switch Button */
        .switch-btn {
            background: var(--md-sys-color-surface-container-highest);
            border: 1px solid var(--md-sys-color-outline);
            color: var(--md-sys-color-on-surface);
            padding: 6px 12px;
            border-radius: var(--md-sys-shape-corner-medium);
            font: var(--md-sys-typescale-label-small);
            cursor: pointer;
            margin-top: 5px;
            align-self: flex-start;
        }

        .switch-btn:hover {
            background: var(--md-sys-color-surface-container-high);
        }

        /* Toggle Group */
        .toggle-group {
            display: flex;
            background: var(--md-sys-color-surface-container-high);
            padding: 4px;
            border-radius: var(--md-sys-shape-corner-full);
            border: 1px solid var(--md-sys-color-outline-variant);
        }

        .toggle-btn {
            background: transparent;
            border: none;
            color: var(--md-sys-color-on-surface-variant);
            padding: 8px 16px;
            border-radius: var(--md-sys-shape-corner-full);
            font: var(--md-sys-typescale-label-large);
            cursor: pointer;
            transition: all 0.2s var(--md-sys-motion-easing-emphasized);
            opacity: 1;
            /* Reset opacity */
        }

        .toggle-btn.active {
            background: var(--md-sys-color-primary);
            color: var(--md-sys-color-on-primary);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .toggle-btn:hover:not(.active) {
            background: var(--md-sys-color-surface-container-highest);
            color: var(--md-sys-color-on-surface);
        }

        /* Exam Dashboard Cards */
        .exam-subject-card {
            background: var(--md-sys-color-surface-container);
            border-radius: var(--md-sys-shape-corner-large);
            padding: 24px;
            border: none;
            display: flex;
            flex-direction: column;
            gap: 16px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }

        .subject-progress {
            height: 8px;
            background: var(--md-sys-color-surface-container-highest);
            border-radius: var(--md-sys-shape-corner-full);
            overflow: hidden;
        }

        .subject-progress-fill {
            height: 100%;
            transition: width 0.5s var(--md-sys-motion-easing-emphasized);
        }


        /* Scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
            /* Slightly wider for touch targets */
            height: 8px;
        }

        ::-webkit-scrollbar-track {
            background: transparent;
        }

        ::-webkit-scrollbar-thumb {
            background: var(--md-sys-color-outline-variant);
            border-radius: var(--md-sys-shape-corner-full);
            border: 2px solid var(--md-sys-color-background);
            /* Creates padding effect */
        }

        ::-webkit-scrollbar-thumb:hover {
            background: var(--md-sys-color-outline);
        }

        /* Modal Info */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
            /* Dimmer */
            backdrop-filter: blur(4px);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 1000;
        }

        .modal-overlay.show {
            display: flex;
        }

        #avatar-modal .modal-card,
        #exam-dates-modal .modal-card {
            width: 500px;
            max-width: 95vw;
            background: var(--md-sys-color-surface-container);
            color: var(--md-sys-color-on-surface);
            border: none;
            display: flex;
            flex-direction: column;
            max-height: 85vh;
            border-radius: var(--md-sys-shape-corner-extra-large);
        }

        #avatar-grid {
            display: grid;
            grid-template-columns: repeat(8, 1fr);
            gap: 12px;
            margin-top: 24px;
            padding: 4px;
            overflow-y: auto;
            max-height: 400px;
        }

        .avatar-option {
            aspect-ratio: 1/1;
            background-image: url('avatars.png');
            background-size: 800% 800%;
            border-radius: 50%;
            border: 2px solid transparent;
            cursor: pointer;
            transition: all 0.2s var(--md-sys-motion-easing-emphasized);
        }

        .avatar-option.selected {
            border-color: var(--md-sys-color-primary);
            box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
        }

        .avatar-option:hover {
            transform: scale(1.15);
        }

        .modal-card {
            background: var(--md-sys-color-surface-container);
            color: var(--md-sys-color-on-surface);
            padding: 32px;
            border-radius: var(--md-sys-shape-corner-extra-large);
            min-width: 350px;
            text-align: center;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
            animation: popIn 0.3s var(--md-sys-motion-easing-emphasized);
            border: none;
        }

        @keyframes popIn {
            from {
                transform: scale(0.9);
                opacity: 0;
            }

            to {
                transform: scale(1);
                opacity: 1;
            }
        }

        .modal-card h2 {
            margin-top: 0;
            color: var(--md-sys-color-primary);
            font: var(--md-sys-typescale-headline-small);
        }

        .date-input {
            width: 100%;
            padding: 12px 16px;
            background: var(--md-sys-color-surface-container-highest);
            border: 1px solid transparent;
            color: var(--md-sys-color-on-surface);
            border-radius: var(--md-sys-shape-corner-small);
            margin: 16px 0;
            font-size: 1rem;
            box-sizing: border-box;
            outline: none;
        }

        .date-input:focus {
            border-bottom: 2px solid var(--md-sys-color-primary);
            background: var(--md-sys-color-surface-container-high);
        }

        .btn-save {
            background: var(--md-sys-color-primary);
            color: var(--md-sys-color-on-primary);
            width: 100%;
            padding: 12px;
            border: none;
            border-radius: var(--md-sys-shape-corner-full);
            font: var(--md-sys-typescale-label-large);
            cursor: pointer;
            transition: background 0.2s;
        }

        .btn-save:hover {
            background: var(--md-sys-color-primary-container);
            /* Check mapping? Actually primary container is lighter. Should ideally darken or use state layer. */
            opacity: 0.9;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        /* Welcome Modal Specifics */
        #welcome-modal .modal-card {
            width: 480px;
            text-align: left;
            padding: 40px;
        }

        #welcome-modal h2 {
            font: var(--md-sys-typescale-display-small);
            margin-bottom: 24px;
        }

        .summary-box {
            background: var(--md-sys-color-surface-container-high);
            border: 1px solid var(--md-sys-color-outline-variant);
            border-radius: var(--md-sys-shape-corner-large);
            padding: 24px;
            margin-bottom: 24px;
        }

        .summary-item {
            display: flex;
            justify-content: space-between;
            margin-bottom: 12px;
            font: var(--md-sys-typescale-body-large);
        }

        .summary-item:last-child {
            margin-bottom: 0;
        }

        .summary-label {
            color: var(--md-sys-color-on-surface-variant);
        }

        .summary-value {
            font-weight: 700;
            color: var(--md-sys-color-tertiary);
            /* Use tertiary for highlights */
        }

        .milestone-alert {
            display: flex;
            align-items: center;
            gap: 16px;
            background: var(--md-sys-color-tertiary-container);
            color: var(--md-sys-color-on-tertiary-container);
            border-left: 4px solid var(--md-sys-color-tertiary);
            padding: 16px;
            border-radius: 0 var(--md-sys-shape-corner-medium) var(--md-sys-shape-corner-medium) 0;
            margin-bottom: 32px;
        }

        .milestone-alert div {
            /* Icon placeholder or text wrapper */
        }

        .btn-cancel {
            background: transparent;
            color: var(--md-sys-color-primary);
            border: none;
            margin-top: 16px;
            cursor: pointer;
            font: var(--md-sys-typescale-label-large);
            text-decoration: none;
        }

        .btn-cancel:hover {
            text-decoration: underline;
        }

        /* Analytics Modal */
        .analytics-btn {
            background: transparent;
            border: none;
            font-size: 1.5rem;
            cursor: pointer;
            margin-left: 12px;
            color: var(--md-sys-color-on-surface-variant);
            transition: opacity 0.2s, transform 0.2s;
        }

        .analytics-btn:hover {
            color: var(--md-sys-color-primary);
            transform: scale(1.1);
        }

        #analytics-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.6);
            backdrop-filter: blur(8px);
            z-index: 1000;
            padding: 40px;
            overflow-y: auto;
        }

        #analytics-modal.show {
            display: block;
        }

        .analytics-container {
            max-width: 1000px;
            margin: 0 auto;
            background: var(--md-sys-color-surface-container);
            border-radius: var(--md-sys-shape-corner-extra-large);
            padding: 40px;
        }

        .analytics-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 32px;
        }

        .analytics-header h2 {
            margin: 0;
            font: var(--md-sys-typescale-headline-medium);
            color: var(--md-sys-color-on-surface);
        }

        .analytics-close {
            background: transparent;
            border: none;
            font-size: 2rem;
            cursor: pointer;
            color: var(--md-sys-color-on-surface-variant);
        }

        .analytics-controls {
            display: flex;
            gap: 20px;
            margin-bottom: 32px;
            flex-wrap: wrap;
        }

        .toggle-group {
            display: flex;
            background: #334155;
            border-radius: 8px;
            overflow: hidden;
            height: 34px;
            /* Explicit height */
            align-items: center;
        }

        .toggle-btn {
            padding: 0 12px;
            /* Reduced vertical padding, rely on flex alignment */
            height: 100%;
            /* Fill the container */
            border: none;
            background: transparent;
            color: #94a3b8;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.9rem;
        }

        .toggle-btn.active {
            background: #3b82f6;
            color: white;
        }

        .analytics-grid {
            display: grid;
            gap: 24px;
        }

        .subject-section {
            background: var(--md-sys-color-surface-container-low);
            border-radius: var(--md-sys-shape-corner-large);
            padding: 24px;
        }

        .subject-title {
            font: var(--md-sys-typescale-title-large);
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 12px;
            color: var(--md-sys-color-on-surface);
        }

        .term-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 12px;
        }

        .term-card {
            background: var(--md-sys-color-surface-container-high);
            border-radius: var(--md-sys-shape-corner-medium);
            padding: 16px;
            text-align: center;
            cursor: pointer;
            transition: transform 0.2s var(--md-sys-motion-easing-emphasized);
        }

        .term-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            background: var(--md-sys-color-surface-container-highest);
        }

        .term-name {
            font: var(--md-sys-typescale-label-small);
            color: var(--md-sys-color-on-surface-variant);
            margin-bottom: 8px;
        }

        .term-value {
            font: var(--md-sys-typescale-headline-small);
        }

        .term-value.high {
            color: #4ade80;
            /* Success light */
        }

        .term-value.medium {
            color: #facc15;
            /* Warning light */
        }

        .term-value.low {
            color: #f87171;
            /* Error light */
        }

        .summary-stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
            gap: 16px;
            margin-bottom: 32px;
        }

        .summary-card {
            background: linear-gradient(135deg, var(--md-sys-color-primary) 0%, var(--md-sys-color-primary-container) 100%);
            border-radius: var(--md-sys-shape-corner-large);
            padding: 24px;
            text-align: center;
            color: var(--md-sys-color-on-primary);
        }

        .summary-card .value {
            font: var(--md-sys-typescale-display-small);
            font-weight: 700;
        }

        .summary-card .label {
            font: var(--md-sys-typescale-body-medium);
            opacity: 0.9;
        }

        /* Exam Planner */
        #exam-planner {
            background: #1e293b;
            border-radius: 12px;
            padding: 15px;
            margin: 20px 10px 0 10px;
            border: 1px solid #334155;
        }

        .plan-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .plan-title {
            font-weight: 700;
            color: #fbbf24;
        }

        .days-left {
            font-size: 0.8rem;
            color: #94a3b8;
        }

        .plan-list {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .plan-item {
            background: #0f172a;
            padding: 10px;
            border-radius: 6px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 0.9rem;
            cursor: pointer;
            transition: background 0.2s;
            width: 100%;
            box-sizing: border-box;
        }

        .toggle-group {
            display: flex;
            background: #1e293b;
            border: 1px solid #334155;
            border-radius: 8px;
            overflow: hidden;
            height: 34px;
            /* Reduced from 48px */
            align-items: center;
        }

        .toggle-btn {
            background: none;
            border: none;
            color: #94a3b8;
            padding: 0 12px;
            font-size: 0.85rem;
            cursor: pointer;
            transition: all 0.2s;
            flex: 1;
            font-weight: 500;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .plan-subj {
            font-weight: 600;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.7rem;
            margin-right: 8px;
        }

        .plan-subj.ma {
            background: #3b82f6;
        }

        .plan-subj.sc {
            background: #10b981;
        }

        .plan-subj.en {
            background: #f43f5e;
        }

        .plan-text {
            flex: 1;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .plan-start {
            font-size: 1.2rem;
            margin-left: 8px;
            text-decoration: none;
        }

        .lvl-badge {
            background: #fbbf24;
            color: #1e1b4b;
            padding: 2px 6px;
            border-radius: 4px;
            font-weight: 700;
            font-size: 0.7rem;
            margin-left: 10px;
        }

        .exam-subject-card h2 {
            display: flex;
            align-items: center;
        }

        /* Contribution Graph Styles */
        .contrib-wrapper {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            padding: 0 12px;
        }

        .contrib-container {
            display: flex;
            gap: 5px;
            overflow-x: auto;
            /* Support fixed Jan-Aug 2026 */
            padding-bottom: 8px;
            padding-top: 35px;
            /* Prevent tooltip clipping on top row */
        }

        /* Custom Scrollbar for Graph */
        .contrib-container::-webkit-scrollbar {
            height: 6px;
        }

        .contrib-container::-webkit-scrollbar-track {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 10px;
        }

        .contrib-container::-webkit-scrollbar-thumb {
            background: #475569;
            border-radius: 10px;
        }

        .contrib-container::-webkit-scrollbar-thumb:hover {
            background: #64748b;
        }

        .contrib-days-label {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            padding-top: 15px;
            /* Align with first row approx */
            height: 86px;
            /* 7 * (10+2) = 84 approx */
            font-size: 0.6rem;
            color: #94a3b8;
            padding-right: 5px;
        }

        .contrib-months-label {
            display: flex;
            gap: 2px;
            margin-bottom: 5px;
            margin-left: 25px;
            /* Space for day labels */
            font-size: 0.6rem;
            color: #94a3b8;
        }

        .contrib-grid {
            display: flex;
            gap: 2px;
        }

        .contrib-column {
            display: flex;
            flex-direction: column;
            gap: 2px;
        }

        .contrib-day {
            width: 10px;
            height: 10px;
            border-radius: 2px;
            background: rgba(255, 255, 255, 0.05);
            position: relative;
        }

        .contrib-day:hover::after {
            content: attr(title);
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            background: #0f172a;
            color: #fff;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.7rem;
            white-space: nowrap;
            z-index: 10;
            border: 1px solid #334155;
            pointer-events: none;
        }

        .contrib-legend {
            display: flex;
            align-items: center;
            gap: 4px;
            margin-top: 8px;
            font-size: 0.7rem;
            color: #94a3b8;
        }

        /* Color Scale */
        .contrib-day.l0 {
            background: #1e293b;
        }

        /* Empty */
        .contrib-day.l1 {
            background: #312e81;
        }

        .contrib-day.l2 {
            background: #4338ca;
        }

        .contrib-day.l3 {
            background: #6366f1;
        }

        .contrib-day.l4 {
            background: #a5b4fc;
        }

        .empty-future {
            opacity: 0;
        }

        /* Utility */
        .hidden {
            display: none !important;
        }

        /* Sync Animation */
        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        .sync-spinner {
            display: inline-block;
            width: 14px;
            height: 14px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: #fff;
            animation: spin 1s linear infinite;
            margin-right: 8px;
        }

        .sync-status {
            position: absolute;
            top: 20px;
            right: 20px;
            background: rgba(0, 0, 0, 0.6);
            color: white;
            padding: 8px 12px;
            border-radius: 20px;
            font-size: 0.8rem;
            display: flex;
            align-items: center;
            backdrop-filter: blur(4px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            z-index: 1000;
            opacity: 0;
            transition: opacity 0.3s ease;
            pointer-events: none;
        }

        .sync-status.visible {
            opacity: 1;
        }