:root {
    --brand-blue: #1515d4;
    --brand-red: #e51636;
    --brand-purple: #74158e;
    --success: #168453;
    --page: #f4f6fb;
    --surface: #ffffff;
    --surface-soft: #f8f9fd;
    --text: #17192b;
    --muted: #667085;
    --border: #d9deea;
    --header: rgba(255, 255, 255, 0.96);
    --shadow: 0 12px 30px rgba(24, 31, 70, 0.09);
}

:root[data-theme="dark"] {
    --page: #0d1020;
    --surface: #171b2f;
    --surface-soft: #111528;
    --text: #f4f6ff;
    --muted: #a8b0c8;
    --border: #303751;
    --header: rgba(13, 16, 32, 0.96);
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    background: var(--page);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    transition: background-color 180ms ease, color 180ms ease;
}

button,
a {
    font: inherit;
}

#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    min-height: 112px;
    padding: 18px 36px;
    background: var(--header);
    border-bottom: 3px solid transparent;
    border-image: linear-gradient(90deg, var(--brand-blue), var(--brand-purple), var(--brand-red)) 1;
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    min-width: 0;
}

.brand-primary {
    display: flex;
    align-items: center;
}

.brand-logo {
    display: block;
    width: clamp(220px, 22vw, 340px);
    height: auto;
}

#title-main {
    display: block;
    font-size: clamp(1.25rem, 2vw, 1.8rem);
    font-weight: 750;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

#subtitle {
    margin-top: 5px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 18px;
}

.avatar-picker {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.avatar-label {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#icons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
    max-width: 370px;
}

.player-icon {
    width: 32px !important;
    height: 32px !important;
    max-width: 32px;
    max-height: 32px;
    object-fit: contain;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.player-icon:hover,
.player-icon.selected {
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-blue) 18%, transparent);
    transform: translateY(-1px);
}

.theme-toggle {
    min-width: 82px;
    padding: 9px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
}

.theme-toggle:hover {
    border-color: var(--brand-blue);
}

#main-body {
    display: flex;
    flex-direction: row-reverse;
    gap: 32px;
    width: min(100%, 1600px);
    margin: 0 auto;
    padding: 38px 36px 52px;
}

#instructions {
    flex: 0 0 290px;
    align-self: flex-start;
    position: sticky;
    top: 24px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 4px solid var(--brand-red);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

#instructions h2 {
    margin: 0 0 14px;
    font-size: 1rem;
}

#instructions p {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.65;
}

#instructions strong {
    color: var(--text);
}

#competitions {
    flex: 1;
    min-width: 0;
}

.challenge-selection {
    margin-bottom: 30px;
}

.competition-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.challenge-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 750;
}

.competition-progress {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 650;
}

.challenge-cards {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 13px;
}

.challenge-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    padding: 18px;
    color: #fff;
    background-color: #282c40;
    background-position: center;
    background-size: cover;
    background-blend-mode: luminosity;
    border: 2px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: clamp(0.75rem, 1vw, 0.9rem);
    font-weight: 750;
    text-align: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.challenge-card:hover {
    border-color: var(--brand-blue);
    box-shadow: 0 14px 28px rgba(21, 21, 212, 0.16);
    transform: translateY(-3px);
    background-blend-mode: normal;
}

.challenge-card::after {
    content: "Unsolved";
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 4px 7px;
    color: #fff;
    background: rgba(20, 23, 42, 0.8);
    border-radius: 6px;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.challenge-card.solved {
    border-color: var(--success);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 20%, transparent);
    background-blend-mode: normal;
}

.challenge-card.solved::before {
    content: "✓";
    position: absolute;
    top: 8px;
    right: 8px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    color: #fff;
    background: var(--success);
    border-radius: 50%;
    font-size: 0.9rem;
    text-shadow: none;
}

.challenge-card.solved::after {
    content: "Completed";
    background: var(--success);
}

.flag-box {
    margin-top: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--success);
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.flag-box summary {
    padding: 14px 16px;
    cursor: pointer;
    font-weight: 700;
}

.flag-box code {
    display: block;
    margin: 0 16px 16px;
    padding: 12px;
    overflow-wrap: anywhere;
    color: var(--text);
    background: var(--surface-soft);
    border-radius: 7px;
}

#footer {
    padding: 22px;
    color: var(--muted);
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.78rem;
}

@media (max-width: 1250px) {
    .challenge-cards {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .avatar-picker {
        display: none;
    }
}

@media (max-width: 850px) {
    #header {
        align-items: flex-start;
        padding: 16px 20px;
    }

    .brand-logo {
        width: 220px;
    }

    #main-body {
        flex-direction: column;
        padding: 24px 20px 40px;
    }

    #instructions {
        position: static;
        flex: auto;
        width: 100%;
    }
}

@media (max-width: 560px) {
    .brand-logo {
        width: 175px;
    }

    .challenge-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
