@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@300;400;600&display=swap');

:root {
    --bg-sky: #dceefb;
    --card-bg: rgba(255, 255, 255, 0.6);
    --accent: #fbc02d;
    --text: #2c3e50;
    --text-dim: #546e7a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Fredoka', sans-serif;
}

body {
    background: var(--bg-sky);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.overlay {
    position: relative;
    z-index: 10;
    pointer-events: none;
    height: 100vh;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.overlay > * {
    pointer-events: auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    background: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: 20px;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.4);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 0 10px var(--accent));
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.stat-card {
    background: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: 20px;
    backdrop-filter: blur(12px);
    text-align: right;
    border: 1px solid rgba(255,255,255,0.4);
}

.stat-card .label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 0.2rem;
}

.stat-card .value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent);
}

/* Leaderboard Card */
main {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-grow: 1;
}

.leaderboard-card {
    background: var(--card-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 32px;
    padding: 2rem;
    width: 380px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.count-chip {
    background: var(--accent);
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.rank-list {
    overflow-y: auto;
    padding-right: 0.5rem;
}

.rank-list::-webkit-scrollbar {
    width: 5px;
}

.rank-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.rank-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    margin-bottom: 0.8rem;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
}

.rank-item:hover {
    transform: scale(1.03) translateX(-8px);
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.rank-number {
    font-size: 1.2rem;
    font-weight: 600;
    min-width: 40px;
}

.student-info { flex-grow: 1; }
.name { font-weight: 600; font-size: 1rem; }
.programme { font-size: 0.75rem; color: var(--text-dim); }
.score { font-size: 1.2rem; font-weight: 600; color: var(--text); }

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.4);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: rgba(255, 255, 255, 0.85);
    width: 90%;
    max-width: 600px;
    border-radius: 32px;
    padding: 2.5rem;
    position: relative;
    transform: translateY(40px) scale(0.95);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 40px 100px rgba(0,0,0,0.15);
}

.modal-overlay.active .modal-card {
    transform: translateY(0) scale(1);
}

.close-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-dim);
    transition: color 0.3s;
}

.close-btn:hover { color: #ff5252; }

.modal-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px dashed rgba(0,0,0,0.1);
    padding-bottom: 1.5rem;
}

.modal-rank {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--accent);
    opacity: 0.5;
}

.modal-student-meta h2 {
    font-size: 1.8rem;
    margin-bottom: 0.2rem;
}

.modal-cgpa {
    margin-left: auto;
    text-align: right;
}

.modal-body h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-dim);
}

.table-container {
    max-height: 40vh;
    overflow-y: auto;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0,0,0,0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: rgba(0,0,0,0.03);
    padding: 1rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    position: sticky;
    top: 0;
}

td {
    padding: 1rem;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    font-size: 0.95rem;
}

tr:last-child td { border: none; }

.status-completed { color: #4caf50; font-weight: 600; }
.status-pending { color: #ff9800; font-weight: 600; }

footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 1rem;
}

/* Responsive Optimization */
@media (max-width: 768px) {
    .overlay {
        padding: 1.5rem;
    }

    header {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        text-align: center;
    }

    .logo {
        width: 100%;
        justify-content: center;
    }

    main {
        justify-content: center; /* Center leaderboard on mobile */
        padding-bottom: 2rem;
    }

    .leaderboard-card {
        width: 100%;
        max-width: none;
        max-height: 60vh;
        border-radius: 24px;
        padding: 1.5rem;
    }

    .rank-item {
        padding: 0.8rem;
    }

    .score {
        font-size: 1rem;
    }

    /* Modal Mobile Adjustments */
    .modal-card {
        padding: 1.5rem;
        width: 95%;
        border-radius: 24px;
    }

    .modal-header {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .modal-rank {
        font-size: 1.8rem;
    }

    .modal-student-meta h2 {
        font-size: 1.4rem;
    }

    .modal-cgpa {
        width: 100%;
        text-align: left;
        margin-left: 0;
        background: rgba(0,0,0,0.03);
        padding: 0.5rem 1rem;
        border-radius: 12px;
    }

    td, th {
        padding: 0.8rem 0.5rem;
        font-size: 0.85rem;
    }
}

/* Landscape Mobile Fix */
@media (max-height: 500px) and (orientation: landscape) {
    .overlay {
        padding: 1rem;
        flex-direction: row;
        gap: 1rem;
    }
    
    .leaderboard-card {
        max-height: 80vh;
        width: 300px;
    }
    
    header { display: none; } /* Hide header to save space in low height landscape */
}
