:root {
    /* Material You Theme: Himalayan Pine */
    --md-sys-color-primary: #006D42;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #9AF6B7;
    --md-sys-color-on-primary-container: #002111;

    --md-sys-color-secondary: #4D6356;
    --md-sys-color-secondary-container: #D0E8D7;
    --md-sys-color-on-secondary-container: #0B1F15;

    --md-sys-color-tertiary: #386666;
    --md-sys-color-tertiary-container: #BBEBEC;
    --md-sys-color-on-tertiary-container: #002020;

    --md-sys-color-surface: #F5FBF6;
    --md-sys-color-on-surface: #171D19;
    --md-sys-color-surface-variant: #DCE5DD;
    --md-sys-color-on-surface-variant: #404943;
    --md-sys-color-outline: #707973;
    --md-sys-color-outline-variant: #C0C9C2;
    
    --card-bg: #F0F5F1;
    --card-hover: #E6F1E9;
    --badge-bg: rgba(255,255,255,0.8);
    --glass-bg: rgba(245, 251, 246, 0.85);

    --radius-xl: 24px;
    --radius-l: 16px;
    --radius-full: 9999px;

    --font-main: 'Outfit', sans-serif;
    
    /* Aesthetic tokens */
    --surface-tint: rgba(0, 109, 66, 0.04);
    --glow-primary: rgba(0, 109, 66, 0.15);
    --glow-secondary: rgba(77, 99, 86, 0.1);
}

/* Dark Theme */
body.dark-theme {
    --md-sys-color-primary: #9AF6B7;
    --md-sys-color-on-primary: #003822;
    --md-sys-color-primary-container: #005231;
    --md-sys-color-on-primary-container: #9AF6B7;

    --md-sys-color-secondary: #B6CCB8;
    --md-sys-color-secondary-container: #394B3F;
    --md-sys-color-on-secondary-container: #D0E8D7;
    
    --md-sys-color-tertiary: #A0CFD0;
    --md-sys-color-tertiary-container: #1E4E4E;
    --md-sys-color-on-tertiary-container: #BBEBEC;

    --md-sys-color-surface: #101412;
    --md-sys-color-on-surface: #E0E4DF;
    --md-sys-color-surface-variant: #404943;
    --md-sys-color-on-surface-variant: #C0C9C2;
    --md-sys-color-outline: #8A938C;
    --md-sys-color-outline-variant: #404943;

    --card-bg: #1A211E;
    --card-hover: #202623;
    --badge-bg: #2B322F;
    --glass-bg: rgba(16, 20, 18, 0.85);
    
    --surface-tint: rgba(154, 246, 183, 0.03);
    --glow-primary: rgba(154, 246, 183, 0.12);
    --glow-secondary: rgba(182, 204, 184, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body { 
    margin: 0; padding: 0; 
    background-color: var(--md-sys-color-surface); 
    color: var(--md-sys-color-on-surface); 
    font-family: var(--font-main); 
    display: flex; justify-content: center; 
    min-height: 100vh; 
    transition: background-color 0.4s ease, color 0.4s ease;
}

.app-container { 
    width: 100%; 
    max-width: 1600px;
    background-color: var(--md-sys-color-surface); 
    position: relative; 
    padding-bottom: 100px; 
    transition: background-color 0.4s ease; 
    z-index: 1; 
}

/* =========================================
   HEADER — dual gradient + decorative orbs
   ========================================= */
.header-section { 
    padding: 32px 24px 24px 24px; 
    padding-top: 60px; 
    display: flex; 
    flex-direction: column; 
    position: relative; 
    background: 
        radial-gradient(ellipse at 100% 0%, var(--md-sys-color-primary-container) 0%, transparent 55%),
        radial-gradient(ellipse at 0% 100%, var(--md-sys-color-tertiary-container) 0%, transparent 40%);
    margin-bottom: 8px;
    overflow: hidden;
}

.header-section::before {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    opacity: 0.04;
    pointer-events: none;
}
.header-section::after {
    content: '';
    position: absolute;
    bottom: -20px; left: 30%;
    width: 120px; height: 120px;
    border-radius: 50%;
    background: var(--md-sys-color-tertiary);
    opacity: 0.03;
    pointer-events: none;
}

@media (min-width: 1024px) {
    .header-section { 
        background: 
            radial-gradient(ellipse at 100% 0%, var(--md-sys-color-primary-container) 0%, transparent 50%),
            radial-gradient(ellipse at 0% 100%, var(--md-sys-color-tertiary-container) 0%, transparent 35%);
    }
}
@media (min-width: 1440px) {
    .header-section { 
        background: 
            radial-gradient(ellipse at 100% 0%, var(--md-sys-color-primary-container) 0%, transparent 60%),
            radial-gradient(ellipse at 0% 100%, var(--md-sys-color-tertiary-container) 0%, transparent 40%);
    }
}

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

.theme-toggle { 
    position: relative; 
    width: 44px; height: 44px; border-radius: 50%; border: none; 
    background-color: rgba(255,255,255,0.5); 
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    color: var(--md-sys-color-on-surface-variant); 
    display: flex; align-items: center; justify-content: center; 
    cursor: pointer; 
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1); 
    z-index: 20; 
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
body.dark-theme .theme-toggle { background-color: rgba(255,255,255,0.08); color: var(--md-sys-color-primary); }
.theme-toggle:hover { transform: scale(1.1) rotate(15deg); background-color: var(--md-sys-color-surface-variant); box-shadow: 0 4px 20px var(--glow-primary); }
.theme-toggle:active { transform: scale(0.9); }

.at-a-glance { 
    display: inline-flex; align-items: center; gap: 8px; 
    background-color: rgba(255,255,255,0.5); 
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    padding: 8px 16px; border-radius: 24px; 
    color: var(--md-sys-color-on-surface-variant); 
    font-weight: 600; font-size: 0.85rem; 
    box-shadow: 0 2px 12px rgba(0,0,0,0.06); 
}
body.dark-theme .at-a-glance { background-color: rgba(255,255,255,0.08); }

.header-title-area { display: flex; flex-direction: column; gap: 4px; position: relative; z-index: 2; }
.uni-supertitle { font-size: 13px; font-weight: 700; color: var(--md-sys-color-primary); text-transform: uppercase; letter-spacing: 2.5px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }

.page-title { 
    font-size: clamp(36px, 8vw, 56px); 
    font-weight: 300; 
    margin: 0; 
    color: var(--md-sys-color-on-surface); 
    line-height: 1; 
    letter-spacing: -2px; 
}
.page-title strong { font-weight: 700; }
.uni-subtitle { font-size: 18px; color: var(--md-sys-color-outline); font-weight: 400; margin-top: 8px; letter-spacing: -0.5px; }

/* =========================================
   SEARCH — glow on focus
   ========================================= */
.search-container { 
    padding: 12px 24px; 
    position: sticky; top: 0; z-index: 100; 
    background-color: transparent; 
    transition: all 0.35s ease; 
}

.search-container.scrolled { 
    background-color: var(--glass-bg); 
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); 
    border-bottom: 1px solid var(--md-sys-color-outline-variant); 
    box-shadow: 0 4px 24px rgba(0,0,0,0.05);
}

.search-bar { 
    height: 56px; 
    border-radius: var(--radius-full); 
    display: flex; align-items: center; padding: 0 20px; 
    transition: all 0.25s ease; 
    border: 1.5px solid transparent; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.03); 
}
body:not(.dark-theme) .search-bar { background-color: #ECF2ED; }
body.dark-theme .search-bar { background-color: #242A27; }

.search-bar:focus-within { 
    border-color: var(--md-sys-color-primary); 
    transform: scale(1.01); 
    box-shadow: 0 4px 24px var(--glow-primary);
}
.search-icon { color: var(--md-sys-color-on-surface-variant); font-size: 24px; margin-right: 12px; transition: color 0.2s; }
.search-bar:focus-within .search-icon { color: var(--md-sys-color-primary); }
.search-input { border: none; background: transparent; font-family: var(--font-main); font-size: 16px; color: var(--md-sys-color-on-surface); flex: 1; outline: none; }

/* =========================================
   FILTER CHIPS — pill style
   ========================================= */
.filters-container { display: flex; gap: 8px; flex-wrap: nowrap; padding: 0 24px 16px 24px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.filters-container::-webkit-scrollbar { display: none; }

.chip { 
    height: 36px; 
    border: 1.5px solid var(--md-sys-color-outline-variant); 
    border-radius: 18px; 
    padding: 0 14px; 
    display: flex; align-items: center; gap: 6px; 
    font-size: 13px; font-weight: 500; 
    color: var(--md-sys-color-on-surface-variant); 
    background: transparent; 
    white-space: nowrap; cursor: pointer; 
    transition: all 0.25s cubic-bezier(0.4, 0.0, 0.2, 1); 
    user-select: none; 
}
.chip:hover { transform: translateY(-2px); background-color: var(--surface-tint); box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.chip.active { 
    background-color: var(--md-sys-color-secondary-container); 
    color: var(--md-sys-color-on-secondary-container); 
    border-color: transparent; 
    box-shadow: 0 2px 8px var(--glow-secondary);
}
body.dark-theme .chip.active { color: #E0E4DF; }
.chip-icon { font-size: 18px; }
.chip-wrapper { position: relative; display: inline-flex; flex-shrink: 0; }
.chip-wrapper select { position: absolute; width: 100%; height: 100%; left: 0; top: 0; opacity: 0; cursor: pointer; z-index: 2; -webkit-appearance: none; }

/* =========================================
   STAT WIDGETS — with decorative orb
   ========================================= */
.stats-row { display: flex; gap: 12px; overflow-x: auto; padding: 0 24px 24px 24px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.stats-row::-webkit-scrollbar { display: none; }

.stat-widget { 
    min-width: 160px; flex: 1; 
    padding: 20px; border-radius: 24px; 
    display: flex; flex-direction: column; gap: 6px; 
    transition: all 0.35s cubic-bezier(0.4, 0.0, 0.2, 1); 
    position: relative; overflow: hidden;
}
.stat-widget::after {
    content: '';
    position: absolute;
    top: -15px; right: -15px;
    width: 60px; height: 60px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.06;
    pointer-events: none;
}
.stat-widget:hover { transform: translateY(-4px); box-shadow: 0 12px 32px rgba(0,0,0,0.1); }
.stat-widget.primary { background-color: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.stat-widget.secondary { background-color: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.stat-widget.tertiary { background-color: var(--md-sys-color-tertiary-container); color: var(--md-sys-color-on-tertiary-container); }
.stat-label { font-size: 11px; font-weight: 700; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.8px; }
.stat-value { font-size: 28px; font-weight: 600; line-height: 1; }
.stat-icon { font-size: 28px; margin-bottom: 4px; opacity: 0.85; }

/* =========================================
   CARDS GRID — DESKTOP (square cards)
   ========================================= */
.results-grid { 
    padding: 0 24px; 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); 
    gap: 16px; 
}

@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.student-card { 
    aspect-ratio: 1 / 1; 
    border-radius: 28px; 
    padding: 20px; 
    display: flex; flex-direction: column; align-items: center; gap: 8px; 
    box-shadow: 0 2px 12px rgba(0,0,0,0.04); 
    cursor: pointer; position: relative; 
    background-color: var(--card-bg); 
    border: 1px solid var(--md-sys-color-outline-variant); 
    color: var(--md-sys-color-on-surface); 
    transform-style: preserve-3d; perspective: 1000px; 
    opacity: 0; 
    animation: fadeInUp 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    transition: box-shadow 0.35s ease, border-color 0.35s ease;
    overflow: hidden;
}

/* Subtle gradient overlay on card top */
.student-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 50%;
    background: linear-gradient(180deg, var(--surface-tint) 0%, transparent 100%);
    border-radius: 28px 28px 0 0;
    pointer-events: none;
    z-index: 0;
}
.student-card > * { position: relative; z-index: 1; }

@media (hover: hover) { 
    .student-card:hover { 
        box-shadow: 0 16px 40px rgba(0,0,0,0.12), 0 0 0 1.5px var(--md-sys-color-primary); 
        border-color: var(--md-sys-color-primary); 
        z-index: 10; 
    }
}
.student-card:active { transform: scale(0.97) !important; transition: transform 0.1s; }

.card-header-row { width: 100%; display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }

.card-avatar { 
    width: 56px; height: 56px; border-radius: 18px; 
    display: flex; align-items: center; justify-content: center; 
    font-weight: 700; font-size: 20px; margin-bottom: 4px; 
    background-color: var(--md-sys-color-primary-container); 
    color: var(--md-sys-color-on-primary-container); 
    box-shadow: 0 4px 12px var(--glow-primary);
}

.card-info-area { text-align: center; width: 100%; flex-grow: 1; display: flex; flex-direction: column; justify-content: center; pointer-events: none; }
.card-name { font-size: 16px; font-weight: 700; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: var(--md-sys-color-on-surface); margin-bottom: 2px; }
.card-roll { font-size: 11px; font-weight: 600; color: var(--md-sys-color-outline); letter-spacing: 0.5px; }

.card-stats-row { width: 100%; display: flex; gap: 8px; margin-top: 8px; }
.stat-box { 
    flex: 1; 
    background-color: var(--md-sys-color-surface-variant); 
    padding: 10px 4px; border-radius: 16px; 
    display: flex; flex-direction: column; align-items: center; justify-content: center; 
    transition: all 0.25s; 
}
body.dark-theme .stat-box { background-color: rgba(255,255,255,0.05); }
.stat-box-value { font-size: 16px; font-weight: 700; color: var(--md-sys-color-primary); line-height: 1; }
.stat-box-label { font-size: 9px; text-transform: uppercase; font-weight: 700; color: var(--md-sys-color-on-surface-variant); margin-top: 3px; opacity: 0.7; }

.mini-badge { 
    font-size: 10px; font-weight: 700; padding: 4px 8px; 
    background: var(--badge-bg); 
    color: var(--md-sys-color-on-surface-variant); 
    border-radius: 8px; 
    border: 1px solid var(--md-sys-color-outline-variant); 
}

/* Rank Badge */
.rank-badge {
    font-size: 12px; font-weight: 800;
    color: var(--md-sys-color-on-primary);
    background-color: var(--md-sys-color-primary);
    padding: 4px 10px; border-radius: 12px;
    box-shadow: 0 2px 8px var(--glow-primary);
    display: flex; align-items: center; justify-content: center;
}

.rank-1 { background: linear-gradient(135deg, #FFD700, #FDB931); color: #7a5f00; text-shadow: 0 1px 0 rgba(255,255,255,0.4); box-shadow: 0 4px 16px rgba(253, 185, 49, 0.4); }
.rank-2 { background: linear-gradient(135deg, #E8E8E8, #C0C0C0); color: #4a4a4a; box-shadow: 0 4px 16px rgba(192, 192, 192, 0.4); }
.rank-3 { background: linear-gradient(135deg, #D4905C, #CD7F32); color: #4a2800; text-shadow: 0 1px 0 rgba(255,255,255,0.2); box-shadow: 0 4px 16px rgba(205, 127, 50, 0.3); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--md-sys-color-outline); grid-column: 1 / -1; }
.empty-icon { font-size: 56px; margin-bottom: 12px; color: var(--md-sys-color-outline-variant); }

/* Tablet 2-col grid */
@media (min-width: 601px) and (max-width: 900px) {
    .results-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
}

/* =========================================
   MOBILE LAYOUT — Horizontal list cards
   ========================================= */
@media (max-width: 600px) {
    .header-section {
        padding: 20px 16px 16px 16px;
        padding-top: 52px;
        margin-bottom: 4px;
        background: 
            radial-gradient(ellipse at 100% 0%, var(--md-sys-color-primary-container) 0%, transparent 70%),
            radial-gradient(ellipse at 0% 100%, var(--md-sys-color-tertiary-container) 0%, transparent 50%);
    }
    .header-section::before { width: 140px; height: 140px; top: -30px; right: -30px; }
    .header-top-bar { margin-bottom: 20px; }
    .uni-supertitle { font-size: 11px; letter-spacing: 2px; margin-bottom: 4px; }
    .page-title { font-size: clamp(28px, 9vw, 40px); letter-spacing: -1.5px; }
    .uni-subtitle { font-size: 13px; margin-top: 4px; }
    
    .search-container { padding: 8px 16px; }
    .search-bar { height: 48px; padding: 0 16px; border-radius: 16px; }
    .search-input { font-size: 15px; }
    .search-icon { font-size: 22px; margin-right: 10px; }
    
    .filters-container { 
        padding: 0 16px 12px 16px; 
        gap: 6px; 
        flex-wrap: wrap; 
        overflow-x: visible; 
    }
    .chip { height: 32px; font-size: 12px; padding: 0 10px; border-radius: 16px; }
    .chip-icon { font-size: 16px; }
    .chip-wrapper { flex-shrink: 1; }
    
    .stats-row { 
        padding: 0 16px 16px 16px; 
        gap: 8px; 
        display: grid; 
        grid-template-columns: 1fr 1fr; 
        overflow-x: visible; 
    }
    .stat-widget { 
        min-width: unset; 
        padding: 14px; 
        border-radius: 20px; 
        gap: 2px;
    }
    .stat-widget:last-child { 
        grid-column: 1 / -1; 
    }
    .stat-widget::after { width: 40px; height: 40px; top: -10px; right: -10px; }
    .stat-icon { font-size: 22px; margin-bottom: 2px; }
    .stat-label { font-size: 10px; }
    .stat-value { font-size: 22px; }
    
    /* Mobile Grid → single column list layout */
    .results-grid { 
        padding: 0 16px; 
        display: flex;
        flex-direction: column;
        gap: 8px; 
    }
    
    /* Mobile card = horizontal list item */
    .student-card {
        aspect-ratio: unset;
        border-radius: 20px;
        padding: 14px 16px;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        min-height: unset;
        box-shadow: 0 1px 4px rgba(0,0,0,0.04);
        border-width: 1px;
    }
    .student-card::before { display: none; }
    .student-card:active { transform: scale(0.98) !important; }
    
    /* Hide desktop header row on mobile */
    .card-header-row { display: none; }
    
    /* Smaller avatar */
    .card-avatar {
        width: 44px; height: 44px; min-width: 44px;
        border-radius: 14px;
        font-size: 16px;
        margin-bottom: 0;
        box-shadow: 0 2px 8px var(--glow-primary);
    }
    
    .card-info-area {
        text-align: left;
        align-items: flex-start;
        flex: 1;
        min-width: 0;
    }
    .card-name { font-size: 15px; font-weight: 600; -webkit-line-clamp: 1; margin-bottom: 1px; }
    .card-roll { font-size: 11px; }
    
    /* Mobile stats: stacked on the right */
    .card-stats-row {
        flex-direction: column;
        width: auto;
        gap: 4px;
        margin-top: 0;
        min-width: 52px;
    }
    .stat-box { padding: 6px 8px; border-radius: 10px; }
    .stat-box-value { font-size: 14px; }
    .stat-box-label { font-size: 8px; margin-top: 1px; }
    
    /* Mobile rank/branch badge elements (JS injects these) */
    .mobile-rank-badge {
        font-size: 10px; font-weight: 800;
        color: var(--md-sys-color-on-primary);
        background-color: var(--md-sys-color-primary);
        padding: 2px 7px; border-radius: 8px;
        display: inline-flex; align-items: center;
        box-shadow: 0 1px 4px var(--glow-primary);
        flex-shrink: 0;
    }
    .mobile-rank-badge.rank-1 { background: linear-gradient(135deg, #FFD700, #FDB931); color: #7a5f00; }
    .mobile-rank-badge.rank-2 { background: linear-gradient(135deg, #E8E8E8, #C0C0C0); color: #4a4a4a; }
    .mobile-rank-badge.rank-3 { background: linear-gradient(135deg, #D4905C, #CD7F32); color: #4a2800; }
    
    .mobile-branch-tag {
        display: inline-flex;
        font-size: 10px; font-weight: 600;
        color: var(--md-sys-color-outline);
        background: var(--badge-bg);
        padding: 1px 6px; border-radius: 6px;
    }
    
    .mobile-meta-row {
        display: flex;
        align-items: center;
        gap: 4px;
        margin-top: 2px;
    }
}

/* =========================================
   MODAL — glass overlay + pull handle
   ========================================= */
.modal-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.5); 
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    z-index: 1000; display: flex; align-items: center; justify-content: center; 
    opacity: 0; pointer-events: none; transition: opacity 0.35s ease; 
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-card { 
    width: 95%; max-width: 800px; max-height: 85vh; 
    background-color: var(--md-sys-color-surface); 
    border-radius: 28px; 
    box-shadow: 0 24px 80px rgba(0,0,0,0.25), 0 0 0 1px var(--md-sys-color-outline-variant); 
    transform: translateY(20px) scale(0.95); 
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); 
    display: flex; flex-direction: column; overflow: hidden; 
    border: none;
}

/* Mobile bottom sheet */
@media (max-width: 600px) { 
    .modal-overlay { align-items: flex-end; } 
    .modal-card { 
        width: 100%; max-width: 100%; 
        border-radius: 24px 24px 0 0;
        max-height: 92vh; 
        padding-bottom: env(safe-area-inset-bottom);
        transform: translateY(100%); 
        box-shadow: 0 -8px 40px rgba(0,0,0,0.2);
    } 
    .modal-overlay.open .modal-card { transform: translateY(0); } 
    
    /* Pull handle */
    .modal-header::before {
        content: '';
        display: block;
        width: 36px; height: 4px;
        border-radius: 2px;
        background: var(--md-sys-color-outline-variant);
        margin: 0 auto 12px auto;
    }
}

@media (max-height: 500px) { .modal-card { max-height: 95vh; } }
@media (min-width: 601px) { .modal-overlay.open .modal-card { transform: translateY(0) scale(1); } }

.modal-header { 
    padding: 24px 24px 12px 24px; 
    display: flex; justify-content: space-between; align-items: center; 
    background: var(--md-sys-color-surface); 
    flex-wrap: wrap;
}
.modal-title-area { display: flex; flex-direction: column; }
.modal-name { font-size: 24px; font-weight: 700; color: var(--md-sys-color-on-surface); }
.modal-subtitle { font-size: 15px; color: var(--md-sys-color-on-surface-variant); font-weight: 500; }

.close-btn { 
    background: var(--md-sys-color-surface-variant); 
    border: none; width: 40px; height: 40px; border-radius: 50%; 
    display: flex; align-items: center; justify-content: center; 
    color: var(--md-sys-color-on-surface-variant); cursor: pointer; 
    transition: all 0.25s; 
}
.close-btn:hover { background-color: var(--md-sys-color-outline-variant); transform: rotate(90deg); }

/* Semester Tabs */
.sem-tabs-row { 
    display: flex; gap: 8px; 
    overflow-x: auto; 
    padding: 8px 24px 12px 24px; 
    margin-bottom: 8px; 
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    scrollbar-width: thin;
    scrollbar-color: var(--md-sys-color-outline-variant) transparent;
}
.sem-tabs-row::-webkit-scrollbar { height: 4px; }
.sem-tabs-row::-webkit-scrollbar-track { background: transparent; }
.sem-tabs-row::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline-variant); border-radius: 4px; }

.sem-tab { 
    padding: 10px 20px; border-radius: 12px; 
    background: var(--md-sys-color-surface-variant); 
    color: var(--md-sys-color-on-surface-variant); 
    font-size: 13px; font-weight: 600; 
    white-space: nowrap; cursor: pointer; border: none; 
    transition: all 0.25s cubic-bezier(0.4, 0.0, 0.2, 1); 
    flex-shrink: 0; 
}
.sem-tab:hover { transform: translateY(-2px); background: var(--md-sys-color-outline-variant); box-shadow: 0 4px 8px rgba(0,0,0,0.08); }
.sem-tab.active { 
    background: var(--md-sys-color-primary); 
    color: var(--md-sys-color-on-primary); 
    box-shadow: 0 4px 16px var(--glow-primary);
}

.modal-content-body { padding: 0 24px 24px 24px; overflow-y: auto; scrollbar-width: thin; }

@media (max-width: 600px) { 
    .modal-content-body { padding: 0 16px 16px 16px; }
    .modal-header { padding: 16px 16px 8px 16px; }
    .modal-name { font-size: 20px; }
    .modal-subtitle { font-size: 13px; }
    .sem-tabs-row { padding: 6px 16px 10px 16px; gap: 6px; }
    .sem-tab { padding: 8px 14px; font-size: 12px; border-radius: 10px; }
}

/* Graph Container */
.graph-container {
    height: 260px;
    margin-bottom: 24px;
    background-color: var(--md-sys-color-surface);
    border-radius: 20px;
    padding: 16px;
    border: 1px solid var(--md-sys-color-outline-variant);
    position: relative;
}
@media (max-width: 600px) {
    .graph-container {
        height: 200px;
        padding: 10px;
        border-radius: 16px;
        margin-bottom: 16px;
    }
}

/* Info Section */
.info-section { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 20px; margin-bottom: 12px; }

.info-block { 
    background: var(--md-sys-color-surface-variant); 
    padding: 12px 16px; border-radius: 16px; 
    transition: background-color 0.2s;
}
.info-block label { font-size: 10px; text-transform: uppercase; color: var(--md-sys-color-on-surface-variant); font-weight: 700; display: block; margin-bottom: 4px; letter-spacing: 0.5px; }
.info-block span { font-size: 15px; font-weight: 600; color: var(--md-sys-color-on-surface); }

@media (max-width: 450px) { 
    .info-section { grid-template-columns: 1fr; gap: 8px; } 
    .info-block { padding: 10px 14px; border-radius: 14px; }
    .info-block span { font-size: 14px; }
}

.sem-content-pane { display: none; animation: fadeIn 0.4s ease; }
.sem-content-pane.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Table */
.table-responsive-wrapper {
    width: 100%;
    overflow-x: hidden;
    padding-bottom: 4px;
}

.result-table { width: 100%; border-collapse: separate; border-spacing: 0 6px; font-size: 14px; }
.result-table th { text-align: left; padding: 0 8px 6px 8px; color: var(--md-sys-color-outline); font-weight: 700; text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; }
.result-table tr.row-item { background-color: var(--md-sys-color-surface-variant); transition: all 0.2s; }
.result-table tr.row-item td:first-child { border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
.result-table tr.row-item td:last-child { border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
.result-table tr.row-item:hover { transform: scale(1.01); background-color: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.result-table td { padding: 14px 8px; color: var(--md-sys-color-on-surface); }

@media (max-width: 480px) {
    .result-table { font-size: 12px; border-spacing: 0 4px; }
    .result-table td { padding: 10px 6px; }
    .result-table th { padding: 0 6px 4px 6px; font-size: 9px; }
}

.grade-tag { 
    display: inline-block; width: 32px; height: 32px; line-height: 32px; 
    text-align: center; border-radius: 10px; font-weight: 700; font-size: 13px; 
    background-color: #FFFFFF; box-shadow: 0 2px 4px rgba(0,0,0,0.05); 
}
.grade-tag.AB { background-color: #dcfce7; color: #14532d; } 
.grade-tag.A  { background-color: #dcfce7; color: #14532d; } 
.grade-tag.AA { background-color: #dcfce7; color: #14532d; }
.grade-tag.BB { background-color: #fefce8; color: #854d0e; }
.grade-tag.B  { background-color: #fefce8; color: #854d0e; }
.grade-tag.BC { background-color: #fefce8; color: #854d0e; }
.grade-tag.CC { background-color: #fef3c7; color: #92400e; }
.grade-tag.C  { background-color: #ffedd5; color: #9a3412; }
.grade-tag.CD { background-color: #ffedd5; color: #9a3412; }
.grade-tag.D  { background-color: #fee2e2; color: #991b1b; }
.grade-tag.F  { background-color: #fee2e2; color: #991b1b; }

@media (max-width: 480px) {
    .grade-tag { width: 28px; height: 28px; line-height: 28px; font-size: 11px; border-radius: 8px; }
}

/* Result Summary */
.result-summary-row {
    margin-top: 12px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 16px 20px;
    border-radius: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    box-shadow: 0 4px 16px var(--glow-primary);
}
.summary-block { display: flex; flex-direction: column; align-items: flex-start; }
.summary-block.end { align-items: flex-end; }
.summary-label { font-size: 10px; text-transform: uppercase; opacity: 0.7; font-weight: 700; letter-spacing: 0.5px; }
.summary-value { font-size: 22px; font-weight: 700; line-height: 1.1; }

@media (max-width: 600px) {
    .result-summary-row { padding: 12px 16px; border-radius: 16px; }
    .summary-value { font-size: 18px; }
}

/* Dark theme grade overrides */
body.dark-theme .result-table tr.row-item { background-color: rgba(255,255,255,0.05); }
body.dark-theme .result-table tr.row-item:hover { background-color: var(--md-sys-color-secondary-container); }
body.dark-theme .grade-tag.AB, body.dark-theme .grade-tag.AA, body.dark-theme .grade-tag.A { background-color: #052e16; color: #bbf7d0; }
body.dark-theme .grade-tag.BB, body.dark-theme .grade-tag.B, body.dark-theme .grade-tag.BC { background-color: #422d08; color: #fef08a; }
body.dark-theme .grade-tag.CC { background-color: #451a03; color: #fcd34d; }
body.dark-theme .grade-tag.C, body.dark-theme .grade-tag.CD { background-color: #431407; color: #fed7aa; }
body.dark-theme .grade-tag.D, body.dark-theme .grade-tag.F { background-color: #450a0a; color: #fecaca; }

/* =========================================
   PAGINATION
   ========================================= */
.pagination-container {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
}

.page-btn {
    min-width: 40px; height: 40px;
    border-radius: 12px;
    border: 1.5px solid var(--md-sys-color-outline-variant);
    background-color: transparent;
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-main);
    font-weight: 600; font-size: 14px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex; align-items: center; justify-content: center;
}
.page-btn:hover { background-color: var(--md-sys-color-surface-variant); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.page-btn.active {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 4px 12px var(--glow-primary);
}
.page-btn:active { transform: scale(0.95); }

@media (max-width: 480px) {
    .pagination-container { padding: 16px; gap: 6px; }
    .page-btn { min-width: 36px; height: 36px; font-size: 13px; border-radius: 10px; }
}

/* =========================================
   FOOTER
   ========================================= */
.footer-credit {
    text-align: center;
    padding: 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    font-size: 13px;
    color: var(--md-sys-color-outline);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0.0, 0.2, 1);
    opacity: 0.7;
}
.footer-credit span { font-weight: 700; color: var(--md-sys-color-primary); }
.footer-credit:hover { opacity: 1; transform: scale(1.03); }

/* =========================================
   LOADING
   ========================================= */
#loadingOverlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--md-sys-color-surface);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 2000;
    transition: opacity 0.4s ease;
}

.spinner {
    width: 48px; height: 48px;
    border: 4px solid var(--md-sys-color-surface-variant);
    border-top: 4px solid var(--md-sys-color-primary);
    border-radius: 50%;
    animation: spin 0.9s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    margin-bottom: 16px;
}

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

.loading-text {
    font-family: var(--font-main);
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
    letter-spacing: 0.5px;
    font-size: 14px;
}

/* =========================================
   SCROLL TO TOP BUTTON
   ========================================= */
.scroll-top-btn {
    position: fixed;
    bottom: 24px; right: 24px;
    width: 48px; height: 48px;
    border-radius: 16px;
    border: none;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    z-index: 100;
    opacity: 0;
    transform: translateY(20px) scale(0.8);
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 6px 20px var(--glow-primary);
}
.scroll-top-btn.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}
.scroll-top-btn:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 8px 28px var(--glow-primary); }
.scroll-top-btn:active { transform: scale(0.92); }

@media (max-width: 600px) {
    .scroll-top-btn {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: 16px;
        width: 44px; height: 44px;
        border-radius: 14px;
    }
}
