:root {
    --bg-main: #020617;
    --bg-card: rgba(15, 23, 42, 0.6); /* Semi-transparent */
    --bg-hover: rgba(30, 41, 59, 0.8);
    
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.4);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --border: rgba(255, 255, 255, 0.08);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- AMBIENT GLOW BACKGROUND --- */
.glow-effect {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: -1;
    background: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.08) 0%, transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.08) 0%, transparent 25%);
    pointer-events: none;
}

/* --- HERO SECTION --- */
.hero {
    min-height: 90vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
    position: relative;
}

.badge-pill {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    border: 1px solid rgba(59, 130, 246, 0.2);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 20px;
    display: inline-block;
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin: 0 0 15px 0;
    background: linear-gradient(to bottom right, #ffffff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.2rem;
    max-width: 500px;
    margin: 0 auto 40px;
    line-height: 1.5;
}

/* --- MAIN SEARCH BAR --- */
.search-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin-bottom: 40px;
}

.search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

#searchInput {
    width: 100%;
    padding: 20px 20px 20px 55px; /* Room for icon */
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
    color: white;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-sizing: border-box;
}

#searchInput:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1), 0 20px 40px -10px rgba(0,0,0,0.5);
}

/* --- ACTION CARDS (Easiest As, etc) --- */
.quick-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.action-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    padding: 12px 20px;
    border-radius: 12px;
    text-align: left;
    transition: all 0.2s;
    min-width: 200px;

    text-decoration: none;
}

.action-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: rgba(255,255,255,0.2);
}

.action-card .icon { font-size: 1.5rem; }
.action-card .label { display: block; font-weight: 600; font-size: 0.9rem; color: var(--text-main); }
.action-card .sub { display: block; font-size: 0.75rem; color: var(--text-muted); }

.scroll-indicator {
    margin-top: 60px;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0.6;
    animation: float 3s ease-in-out infinite;
}

/* --- MAIN CONTENT & FILTERS --- */
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* Sticky Toolbar */
.toolbar-sticky {
    position: sticky;
    top: 20px;
    z-index: 100;
    background: rgba(2, 6, 23, 0.8); /* Semi-transparent dark */
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5);
}

.filter-group { display: flex; gap: 10px; }

.filter-wrapper { position: relative; }

.filter-select {
    appearance: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 35px 10px 15px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 140px;
    color-scheme: dark;
}

/* Force options to have dark background (Works on Windows/Linux) */
.filter-select option {
    background-color: var(--bg-card);
    color: var(--text-main);
    padding: 10px;
}

.filter-select:hover { background: rgba(255, 255, 255, 0.1); }
.filter-select:focus { outline: none; border-color: var(--primary); }

.chevron {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-muted);
}

.result-count { color: var(--text-muted); font-size: 0.9rem; font-weight: 500; }

/* --- COURSE GRID --- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.card {
    /* ... keep your existing styles ... */
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    
    /* ADD THIS LINE: */
    text-decoration: none; 
    
    /* Optional: Ensure text color doesn't revert to default link blue */
    color: var(--text-main); 
    display: block; /* Good practice for anchor cards */
}

.card:hover {
    transform: translateY(-5px) scale(1.01);
    background: var(--bg-hover);
    border-color: rgba(59, 130, 246, 0.3);
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.5);
}

/* Card Typography */
.card span[style*="font-weight:bold"] { /* The Course Code */
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary) !important;
    background: rgba(59, 130, 246, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.85rem !important;
}

.card h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 15px 0 5px 0;
    color: var(--text-main);
    line-height: 1.4;
}

.card .sem-info { /* Semester info at bottom */
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

/* --- ANIMATIONS --- */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(5px); }
}

@media (max-width: 768px) {
    .hero h1 { font-size: 2.5rem; }
    .toolbar-sticky { flex-direction: column; gap: 15px; align-items: stretch; }
    .filter-group { flex-direction: column; }
    .filter-select { width: 100%; }
}

/* Ensure tables scroll smoothly on mobile */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Make the first column (Course Name) sticky on mobile if desired, 
   or just give it a minimum width so it doesn't wrap awkwardly */
td:first-child {
    min-width: 180px;
}

/* --- INSIGHTS CARD STYLING --- */

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

.code-badge {
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 700;
}

.rank-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    opacity: 0.7;
}

.insight-body {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Big Stat Number */
.stat-highlight {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.05em;
}
.stat-highlight.av-positive { color: var(--danger); }
.stat-highlight.av-negative { color: var(--success); }
.stat-highlight.text-good { color: var(--success); }

/* Stat Details Column */
.stat-details {
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-row {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.stat-row span:first-child { opacity: 0.7; }
.stat-row span:last-child { font-weight: 600; color: var(--text-main); }

.sem-row {
    margin-top: 4px;
    font-size: 0.75rem;
    opacity: 0.5;
}

/* --- INSIGHTS CARD STYLING --- */

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

.code-badge {
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 700;
}

.rank-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 8px;
    border-radius: 4px;
}

/* The Layout for the Stats */
.insight-body {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-end; /* Align to bottom */
}

/* Big Stat Number (The Hero of the card) */
.stat-highlight {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    line-height: 1;
}
.stat-highlight.av-positive { color: var(--danger); } /* Red for High Av+ */
.stat-highlight.av-negative { color: var(--success); } /* Green for Low Av+ */
.stat-highlight.text-good { color: var(--success); }

/* Right side details */
.stat-details {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-row {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.stat-row span:last-child { 
    color: var(--text-main); 
    font-weight: 600; 
}

.sem-tag {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-top: 4px;
}

/* --- COURSE DETAIL STYLING --- */

/* Header Typography */
.course-code-pill {
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    display: inline-block;
    margin-bottom: 12px;
}

.course-title {
    margin: 0;
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    background: linear-gradient(to bottom right, #ffffff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Semester Section */
.semester-section {
    margin-bottom: 60px;
    animation: fadeIn 0.5s ease-out;
}

.sem-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.sem-header h3 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

/* The Grades Grid (Smaller cards than main grid) */
.grades-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
}

/* Individual Grade Card */
.grade-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    padding: 20px 15px;
}

.grade-letter {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    margin-bottom: 15px;
}

.grade-ranges {
    width: 100%;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.range-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.range-row .val {
    color: var(--text-main);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.grade-footer {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    width: 100%;
    box-sizing: border-box;
}

/* Coloring for Av+ */
.grade-footer.av-positive {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}
.grade-footer.av-negative {
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

/* Mobile Tweak */
@media (max-width: 500px) {
    .grades-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 columns on phone */
    }
}

/* --- GRADE AT AVERAGE HIGHLIGHTS --- */

/* The Highlighted Card */
.grade-card.avg-highlight {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.08); /* Subtle blue tint */
    box-shadow: 0 0 20px -5px rgba(59, 130, 246, 0.3); /* Blue Glow */
    transform: translateY(-2px);
}

/* The "Grade at Average" Label */
.avg-label {
    position: absolute;
    top: 10px;
    font-size: 0.65rem;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: var(--primary);
    background: rgba(59, 130, 246, 0.15);
    padding: 3px 8px;
    border-radius: 12px;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Adjust Grade Letter position when label is present */
.grade-card.avg-highlight .grade-letter {
    margin-top: 15px; /* Push letter down slightly to make room */
}

/* --- Back Navigation Button --- */
.nav-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    
    /* Glassmorphism Base */
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: 30px; /* Pill shape */
    
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 30px;
    
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(4px);
}

.nav-back:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary); /* Blue border on hover */
    transform: translateX(-5px);  /* Subtle slide to the left */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); /* Lift effect */
}

/* Animate the arrow specifically */
.nav-back svg {
    transition: transform 0.2s ease;
}

.nav-back:hover svg {
    transform: translateX(-3px); /* Arrow moves a bit more for depth */
}

/* --- SPLASH SCREEN --- */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-main); /* Matches your dark background */
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.6s;
}

.splash-content {
    text-align: center;
    animation: fadeInUp 0.8s ease-out;
}

.splash-content h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin: 0 0 20px 0;
    /* Uses your existing gradient text style */
    background: linear-gradient(to bottom right, #ffffff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Minimalist breathing line */
.loading-line {
    width: 60px;
    height: 3px;
    background: var(--primary);
    border-radius: 10px;
    margin: 0 auto;
    animation: breathe 1.5s infinite ease-in-out;
    box-shadow: 0 0 10px var(--primary-glow);
}

/* Animations */
@keyframes breathe {
    0%, 100% { width: 40px; opacity: 0.6; }
    50% { width: 100px; opacity: 1; }
}

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

/* Helper to hide it */
.splash-hidden {
    opacity: 0;
    visibility: hidden;
}

/* --- TOP PORTAL LINK (For non-home pages) --- */
.top-portal-header {
    text-align: center;
    padding-bottom: 20px;
    margin-bottom: 10px;
}

.portal-home-link {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-decoration: none;
    
    /* Premium Gradient Text */
    background: linear-gradient(to right, #ffffff 60%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    
    opacity: 0.7;
    transition: opacity 0.2s ease, transform 0.2s ease;
    display: inline-block;
}

.portal-home-link:hover {
    opacity: 1;
    transform: translateY(-1px);
    cursor: pointer;
}

/* --- NAVIGATION HEADER ROW --- */
.nav-header-row {
    position: relative;
    display: flex;
    align-items: center;
    height: 40px; /* Fixed height for alignment */
    margin-bottom: 30px;
}

/* Adjust Back Button to fit in the row */
.nav-back {
    margin-bottom: 0 !important; /* Remove old spacing */
    z-index: 20; /* Ensure button stays on top of title if screen is small */
    position: relative;
    background: rgba(255, 255, 255, 0.05); /* Slightly clearer background */
}

/* Centered Title Wrapper */
.nav-title-center {
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    pointer-events: none; /* Allows clicks to pass through empty space */
    z-index: 10;
}

/* The Link Itself */
.portal-home-link {
    pointer-events: auto; /* Re-enable clicks on the text */
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-decoration: none;
    
    /* Gradient Text */
    background: linear-gradient(to right, #ffffff 60%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    
    opacity: 0.8;
    transition: all 0.2s ease;
}

.portal-home-link:hover {
    opacity: 1;
    transform: scale(1.02);
}

/* Mobile Tweak: Hide the Title text on very small screens to prevent overlap */
@media (max-width: 450px) {
    .portal-home-link { display: none; }
}