/* EnglishSpeak — normalize text size in Android in-app browsers (Zalo, etc.) */
html {
  -webkit-text-size-adjust: 100% !important;
  text-size-adjust: 100% !important;
}

:root {
    --primary: #5b57e8;
    --primary-dark: #403bc2;
    --gold: #ffb800;
    --silver: #9fa8bc;
    --bronze: #c47b4d;
    --surface: #ffffff;
    --surface-soft: #f6f6fb;
    --text: #20233c;
    --muted: #747891;
    --border: #e5e7f0;
    --shadow: 0 18px 55px rgba(36, 40, 81, .12);
}

* {
    box-sizing: border-box;
}

html {
    background: #f4f5fa;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(91, 87, 232, .13), transparent 28rem),
        #f4f5fa;
}

button,
select {
    font: inherit;
}

.ranking-shell {
    width: min(900px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: 22px 18px 110px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.brand-kicker {
    display: block;
    margin-bottom: 3px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.page-header h1 {
    margin: 0;
    font-size: clamp(28px, 5vw, 40px);
}

.settings-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 15px;
    border: 1px solid var(--border);
    border-radius: 15px;
    color: var(--text);
    background: #fff;
    box-shadow: 0 8px 24px rgba(36, 40, 81, .08);
    font-weight: 800;
    cursor: pointer;
}

.settings-button:hover {
    border-color: rgba(91, 87, 232, .35);
    transform: translateY(-1px);
}

.settings-icon {
    font-size: 18px;
}

.ranking-title-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border: 1px solid rgba(91, 87, 232, .14);
    border-radius: 23px;
    background: linear-gradient(135deg, #ffffff, #f1f0ff);
    box-shadow: 0 14px 38px rgba(44, 47, 95, .09);
}

.ranking-crown {
    display: grid;
    width: 62px;
    height: 62px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 20px;
    background: linear-gradient(135deg, #fff6d7, #ffdf77);
    box-shadow: inset 0 0 0 1px rgba(255, 184, 0, .2);
    font-size: 29px;
}

.ranking-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.ranking-title-card h2 {
    margin: 4px 0 5px;
    font-size: clamp(21px, 4vw, 30px);
}

.ranking-title-card p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.ranking-title-card p span {
    margin: 0 5px;
    color: #b0b3c4;
}

.podium {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
    gap: 12px;
    margin: 44px 0 24px;
}

.podium-card {
    position: relative;
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    padding: 20px 10px 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 24px;
    text-align: center;
    background: #fff;
    box-shadow: 0 16px 44px rgba(36, 40, 81, .1);
}

.podium-first {
    transform: translateY(-20px);
    border-color: rgba(255, 184, 0, .38);
    background: linear-gradient(180deg, #fffaf0, #fff);
}

.podium-second {
    background: linear-gradient(180deg, #f7f8fc, #fff);
}

.podium-third {
    background: linear-gradient(180deg, #fff7f2, #fff);
}

.medal {
    position: absolute;
    top: 10px;
    right: 11px;
    font-size: 24px;
}

.avatar {
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 3px solid #fff;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #6d68f0, #8f8bff);
    box-shadow: 0 6px 18px rgba(70, 65, 190, .24);
    font-weight: 900;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-large {
    width: 72px;
    height: 72px;
    margin-top: 11px;
    font-size: 24px;
}

.avatar-medium {
    width: 60px;
    height: 60px;
    margin-top: 11px;
    font-size: 20px;
}

.avatar-small {
    width: 46px;
    height: 46px;
    font-size: 16px;
}

.podium-card h3 {
    width: 100%;
    margin: 14px 0 6px;
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.podium-card strong {
    color: var(--primary-dark);
    font-size: 14px;
}

.podium-block {
    width: calc(100% + 20px);
    margin-top: 16px;
    padding: 14px;
    color: #fff;
    background: var(--primary);
    font-size: 21px;
    font-weight: 900;
}

.podium-first .podium-block {
    padding: 22px 14px;
    background: linear-gradient(135deg, #eea300, #ffc62a);
}

.podium-second .podium-block {
    background: linear-gradient(135deg, #8d96aa, #bdc4d1);
}

.podium-third .podium-block {
    background: linear-gradient(135deg, #af663d, #d99369);
}

.ranking-list {
    display: grid;
    gap: 10px;
}

.ranking-item {
    display: grid;
    grid-template-columns: 40px 46px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 13px 15px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(36, 40, 81, .055);
}

.rank-badge {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 12px;
    color: var(--primary-dark);
    background: #f0efff;
    font-weight: 900;
}

.student-details {
    min-width: 0;
}

.student-details strong,
.student-details span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.student-details span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.student-xp {
    color: var(--primary-dark);
    font-size: 14px;
    font-weight: 900;
    white-space: nowrap;
}

.my-rank-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    margin-top: 22px;
    padding: 18px;
    border-radius: 22px;
    color: #fff;
    background: linear-gradient(135deg, #5752dc, #7772ef);
    box-shadow: 0 18px 44px rgba(69, 64, 199, .25);
}

.my-rank-pin {
    display: grid;
    width: 50px;
    height: 50px;
    place-items: center;
    border-radius: 16px;
    background: rgba(255, 255, 255, .15);
    font-size: 22px;
}

.my-rank-info span,
.my-rank-info strong,
.my-rank-info small {
    display: block;
}

.my-rank-info span {
    font-size: 12px;
    opacity: .75;
}

.my-rank-info strong {
    margin: 3px 0;
    font-size: 17px;
}

.my-rank-info small {
    font-size: 12px;
    opacity: .9;
}

.my-rank-number {
    font-size: clamp(25px, 6vw, 38px);
    font-weight: 900;
}

.empty-card {
    margin: 28px 0;
    padding: 44px 20px;
    border: 1px dashed #ccd0df;
    border-radius: 24px;
    text-align: center;
    background: rgba(255, 255, 255, .72);
}

.empty-trophy {
    font-size: 44px;
}

.empty-card h2 {
    margin: 12px 0 6px;
}

.empty-card p {
    margin: 0;
    color: var(--muted);
}

.filter-overlay {
    position: fixed;
    z-index: 2000;
    inset: 0;
    background: rgba(24, 27, 56, .5);
    backdrop-filter: blur(3px);
}

.filter-panel {
    position: fixed;
    z-index: 2001;
    top: 50%;
    left: 50%;
    width: min(520px, calc(100% - 28px));
    max-height: calc(100vh - 28px);
    padding: 18px;
    overflow-y: auto;
    border-radius: 26px;
    background: #fff;
    box-shadow: 0 28px 80px rgba(24, 27, 56, .28);
    opacity: 0;
    transform: translate(-50%, -47%) scale(.97);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}

.filter-panel.is-open {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

.filter-handle {
    display: none;
}

.filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eceef5;
}

.filter-header span {
    color: var(--primary);
    font-size: 13px;
    font-weight: 900;
    text-transform: uppercase;
}

.filter-header h2 {
    margin: 3px 0 0;
    font-size: 22px;
}

.filter-header button {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 0;
    border-radius: 13px;
    color: var(--text);
    background: #f0f1f6;
    font-size: 26px;
    cursor: pointer;
}

.filter-form {
    display: grid;
    gap: 15px;
    padding-top: 16px;
}

.field > span,
.field legend {
    display: block;
    margin-bottom: 7px;
    color: #4e536d;
    font-size: 13px;
    font-weight: 800;
}

.field {
    margin: 0;
    padding: 0;
    border: 0;
}

.field select {
    width: 100%;
    min-height: 48px;
    padding: 0 13px;
    border: 1px solid #dfe2ec;
    border-radius: 14px;
    outline: none;
    color: var(--text);
    background: #fff;
}

.field select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(91, 87, 232, .1);
}

.scope-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 4px;
    border-radius: 15px;
    background: #f0f1f6;
}

.scope-switch label {
    cursor: pointer;
}

.scope-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.scope-switch span {
    display: block;
    padding: 11px;
    border-radius: 11px;
    text-align: center;
    color: #666b84;
    font-size: 13px;
    font-weight: 800;
}

.scope-switch input:checked + span {
    color: var(--primary-dark);
    background: #fff;
    box-shadow: 0 5px 15px rgba(36, 40, 81, .08);
}

.reset-filter {
    justify-self: center;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.apply-filter {
    min-height: 50px;
    border: 0;
    border-radius: 15px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #7772ef);
    box-shadow: 0 12px 27px rgba(91, 87, 232, .24);
    font-weight: 900;
    cursor: pointer;
}

body.filter-open {
    overflow: hidden;
}

@media (max-width: 620px) {
    .ranking-shell {
        padding: 17px 13px 106px;
    }

    .settings-button {
        width: 44px;
        padding: 0;
    }

    .settings-button span:last-child {
        display: none;
    }

    .ranking-title-card {
        padding: 16px;
        border-radius: 20px;
    }

    .ranking-crown {
        width: 54px;
        height: 54px;
        border-radius: 17px;
    }

    .ranking-title-card p {
        line-height: 1.55;
    }

    .podium {
        gap: 7px;
        margin-top: 40px;
    }

    .podium-card {
        padding-right: 7px;
        padding-left: 7px;
        border-radius: 19px;
    }

    .avatar-large {
        width: 59px;
        height: 59px;
    }

    .avatar-medium {
        width: 51px;
        height: 51px;
    }

    .podium-card h3 {
        font-size: 12px;
    }

    .podium-card strong {
        font-size: 11px;
    }

    .podium-block {
        width: calc(100% + 14px);
    }

    .ranking-item {
        grid-template-columns: 35px 43px minmax(0, 1fr) auto;
        gap: 9px;
        padding: 11px;
    }

    .student-xp {
        font-size: 12px;
    }

    .filter-panel {
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 91vh;
        border-radius: 26px 26px 0 0;
        opacity: 1;
        transform: translateY(105%);
    }

    .filter-panel.is-open {
        transform: translateY(0);
    }

    .filter-handle {
        display: block;
        width: 42px;
        height: 5px;
        margin: -5px auto 12px;
        border-radius: 999px;
        background: #d6d8e4;
    }
}
