:root {
    --tier-splus-color: #e74c3c;
    --tier-s-color: #ff7675;
    --tier-a-color: #fab1a0;
    --tier-b-color: #ffeaa7;
    --tier-c-color: #55efc4;
    --tier-d-color: #74b9ff;
    --tier-f-color: #a29bfe;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    background-color: #231e3f;
    background-image: radial-gradient(ellipse at 50% 40%,
            rgba(115, 99, 218, 0.25) 0%,
            #231e3f 60%);

    font-family: 'Lilita One', cursive;
    min-height: 100vh;
    color: #fff;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 95%;
    margin: 0 auto;
    padding: 10px;
    flex-grow: 1;
}

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* --- Header & Navigation --- */
.top-nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 25px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 20px;
    margin-bottom: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 98vw;
    height: 5vw;
    min-height: 50px;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
}

.nav-center-title {
    text-align: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.header h1 {
    font-size: 2.2rem;
    margin-bottom: 0;
    color: #fff;
    text-align: center;
}

.author-credit {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: normal;
    display: block;
    text-align: center;
    margin: -2px auto 0;
    width: fit-content;
}

.nav-links-right {
    position: relative;
    display: flex;
    align-items: center;
}

.discord-link {
    display: flex;
    align-items: center;
    gap: 0;
    background-color: rgba(88, 101, 242, 0.8);
    padding: 8px 10px;
    border-radius: 15px;
    border: 1px solid rgba(88, 101, 242, 1);
    color: #fff;
    text-decoration: none;
    font-size: clamp(0.9rem, 1.2vw, 1.0rem);
    margin-right: 10px;
    transition: all 0.3s ease;
    overflow: hidden;
    white-space: nowrap;
}

.discord-link span {
    max-width: 0;
    opacity: 0;
    transition: all 0.3s ease;
    overflow: hidden;
}

.discord-link:hover {
    background-color: rgba(88, 101, 242, 1);
    gap: 8px;
    padding: 8px 12px;
}

.discord-link:hover span {
    max-width: 200px;
    opacity: 1;
}

.discord-link i {
    font-size: 1.2rem;
}

.bmc-link {
    display: flex;
    align-items: center;
    gap: 0;
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.9) 0%, rgba(255, 152, 0, 0.9) 100%);
    padding: 8px 10px;
    border-radius: 15px;
    border: none;
    color: #fff;
    text-decoration: none;
    font-size: clamp(0.9rem, 1.2vw, 1.0rem);
    margin-right: 10px;
    transition: all 0.3s ease;
    overflow: hidden;
    white-space: nowrap;
}

.bmc-link span {
    max-width: 0;
    opacity: 0;
    transition: all 0.3s ease;
    overflow: hidden;
}

.bmc-link:hover {
    background: linear-gradient(135deg, rgba(255, 193, 7, 1) 0%, rgba(255, 152, 0, 1) 100%);
    gap: 8px;
    padding: 8px 12px;
}

.bmc-link:hover span {
    max-width: 200px;
    opacity: 1;
}

.bmc-link .fas {
    font-size: 1.2rem;
}

.bmc-icon {
    width: 1.2rem;
    height: 1.2rem;
    filter: invert(1);
}

/* --- Burger Menu & Overlay --- */
.burger-menu {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 2.2rem;
    height: 2.2rem;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 2010;
    position: relative;
}

.burger-menu span {
    width: 2.2rem;
    height: 0.25rem;
    background: #fff;
    border-radius: 10px;
    transition: all 0.3s linear;
    position: relative;
    transform-origin: 1px;
}

.burger-menu.active span:nth-child(1) {
    transform: rotate(45deg);
}

.burger-menu.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(20px);
}

.burger-menu.active span:nth-child(3) {
    transform: rotate(-45deg);
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-in-out;
}

.menu-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.menu-overlay a {
    color: #fff;
    text-decoration: none;
    font-size: 2.5rem;
    margin: 15px 0;
    transition: color 0.3s ease, transform 0.3s ease;
}

.menu-overlay a:hover,
.menu-overlay a.active {
    color: #f1c40f;
    transform: scale(1.05);
}

.menu-close {
    position: absolute;
    top: 30px;
    right: 50px;
    font-size: 3rem;
    color: #fff;
    cursor: pointer;
    transition: color 0.3s ease, transform 0.3s ease;
    z-index: 2010;
}

.menu-close:hover {
    color: #f1c40f;
    transform: scale(1.1);
}

/* --- Setup & Main Layout --- */
.setup-panel {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 20;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 1.1rem;
}

.loading-indicator {
    text-align: center;
    font-size: 1.2rem;
    padding: 20px;
}

.main-content {
    display: flex;
    gap: 30px;
    position: relative;
    z-index: 10;
}

.map-display-container {
    flex: 0 0 25%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.map-display-container h3 {
    text-align: center;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

#mapImage {
    width: 100%;
    border-radius: 10px;
}

.tierlist-display-container {
    flex-grow: 1;
}

/* --- Tier List Styles --- */
.tier-list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tier-row {
    display: flex;
    align-items: stretch;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 80px;
}

.tier-label {
    flex-shrink: 0;
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
}

.brawlers-in-tier {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 10px;
    flex-grow: 1;
    align-content: center;
    transition: all 0.3s ease;
}

body.debug-mode .brawlers-in-tier {
    row-gap: 30px;
    padding-bottom: 25px;
}

.brawler-card {
    width: 46px;
    height: 46px;
    transition: transform 0.2s ease-in-out;
    cursor: pointer;
    position: relative;
}

.brawler-card:hover {
    transform: scale(1.15);
}

.brawler-card img {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    object-fit: cover;
}

.brawler-score {
    display: none;
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 2;
}

body.debug-mode .brawler-card .brawler-score {
    display: block;
}

.tier-splus {
    background-color: var(--tier-splus-color);
}

.tier-s {
    background-color: var(--tier-s-color);
}

.tier-a {
    background-color: var(--tier-a-color);
}

.tier-b {
    background-color: var(--tier-b-color);
}

.tier-c {
    background-color: var(--tier-c-color);
}

.tier-d {
    background-color: var(--tier-d-color);
}

.tier-f {
    background-color: var(--tier-f-color);
}

/* --- Custom Select --- */
.custom-select-container {
    position: relative;
    width: 100%;
    font-family: 'Lilita One', cursive;
}

.custom-select-trigger {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 1rem;
    transition: all 0.3s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.custom-select-trigger .trigger-content {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-trigger .trigger-content img {
    width: 24px;
    height: 24px;
}

.custom-options-wrapper {
    display: none;
    position: absolute;
    top: 105%;
    left: 0;
    right: 0;
    z-index: 1010;
    background: #2c2c2c;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    max-height: 400px;
    overflow-y: auto;
    backdrop-filter: blur(5px);
}

.custom-select-container.open .custom-options-wrapper {
    display: block;
}

.custom-optgroup-label {
    padding: 10px 15px;
    font-size: 1rem;
    text-transform: uppercase;
    color: #f1c40f;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-optgroup-label:hover {
    background-color: rgba(241, 196, 15, 0.2);
}

.custom-optgroup-label img {
    width: 24px;
    height: 24px;
}

.custom-option {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.2s ease;
}

.custom-option:hover,
.custom-option.selected {
    background-color: rgba(255, 255, 255, 0.1);
}

.custom-option img {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.custom-option .map-name {
    color: #fff;
    font-size: 1rem;
}

/* --- Language Selector --- */
#languageSelector {
    cursor: pointer;
}

.language-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    transition: background-color 0.2s ease;
    color: #fff;
}

.language-option:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.lang-flag {
    width: 24px;
    height: auto;
    border-radius: 4px;
    vertical-align: middle;
}

#selectedLanguage {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#languageDropdown {
    display: none;
    position: absolute;
    top: 110%;
    right: 0;
    background: #2c2c2c;
    border-radius: 10px;
    overflow: hidden;
    z-index: 1001;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#languageSelector.open #languageDropdown {
    display: block;
}

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

.modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #2c2c2c;
    padding: 30px;
    border-radius: 20px;
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    display: flex;
    flex-direction: column;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2.5rem;
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s;
    z-index: 10;
}

.modal-close:hover {
    transform: scale(1.2);
}

#modalHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Spread name and export button */
    margin-bottom: 25px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 20px;
    padding-right: 40px;
    /* Space for close button */
}

.modal-header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

#modalBrawlerIcon {
    width: 80px;
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 15px;
    object-fit: cover;
}

.modal-name-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#modalBrawlerName {
    font-size: 2.5rem;
    color: #f1c40f;
}

.brawler-boost-multiplier {
    display: inline-block;
    color: #f1c40f;
    font-size: 1.1rem;
    margin-top: 5px;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
    line-height: 1.2;
}

.brawler-boost-multiplier.hidden {
    display: none;
}

/* Modal Split Layout */
.modal-body-split {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.modal-maps-panel {
    flex: 1;
    min-width: 300px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding-right: 20px;
}

.modal-gamemodes-panel {
    flex: 0 0 40%;
    min-width: 250px;
}

.modal-section-title {
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 15px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

#modalTierGrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.modal-tier-item {
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease, gap 8px;
}

.modal-tier-item:hover {
    transform: scale(1.05);
    background-color: rgba(255, 255, 255, 0.1);
}

.modal-tier-item img {
    width: 28px;
    height: auto;
    aspect-ratio: 1 / 1;
    margin-bottom: 5px;
    object-fit: cover;
}

.modal-gamemode-name {
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.modal-tier-label {
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 1;
    margin-bottom: 5px;
}

body.debug-mode .modal-score-label {
    display: block;
}

/* Removed top margin to bring it closer to tier label */
.modal-score-label {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 0;
    line-height: 1;
    display: none;
}

/* Modal Map List */
#modalMapsList {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.map-stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.map-stat-row:hover {
    background: rgba(255, 255, 255, 0.1);
}

.map-stat-left {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.map-stat-left img {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.map-stat-name {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Reduced gap from 10px to 5px to bring score closer to tier */
.map-stat-right {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.map-stat-tier {
    font-weight: bold;
    width: 30px;
    text-align: center;
}

body.debug-mode .map-stat-score {
    display: block;
}

.map-stat-score {
    width: 50px;
    text-align: right;
    font-size: 0.85rem;
    color: #ccc;
    display: none;
}

/* --- Boost Warning --- */
.boost-warning {
    background-color: rgba(241, 196, 15, 0.15);
    color: #f1c40f;
    border: 1px solid rgba(241, 196, 15, 0.5);
    padding: 12px;
    margin-bottom: 20px;
    border-radius: 10px;
    text-align: center;
    font-size: 1rem;
    font-family: sans-serif;
    line-height: 1.4;
    width: 100%;
}

/* --- Footer & Media Queries --- */
footer {
    text-align: center;
    padding: 20px;
    margin-top: 40px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#footer-update {
    margin-top: 8px;
    font-size: 0.8rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #555;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: #3498db;
}

input:checked+.slider:before {
    transform: translateX(22px);
}

.slider.round {
    border-radius: 28px;
}

.slider.round:before {
    border-radius: 50%;
}

/* --- Export Button --- */
.tierlist-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 15px;
}

.export-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 10px 18px;
    border-radius: 25px;
    cursor: pointer;
    font-family: 'Lilita One', cursive;
    font-size: 0.9rem;
    transition: background-color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.export-button:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Grids specifically for the export image generation */
/* Adjusted gap to 10px to match map grid */
.export-modes-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
}

/* Updated to 3 columns as requested */
.export-maps-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

@media (max-width: 850px) {
    .discord-link span {
        display: none;
    }

    .discord-link {
        padding: 8px 10px;
        /* Adjust padding for icon-only */
    }

    .bmc-link span {
        display: none;
    }

    .bmc-link {
        padding: 8px 10px;
        /* Adjust padding for icon-only */
    }
}

@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .map-display-container {
        flex: 0 0 auto;
    }

    .modal-body-split {
        flex-direction: column-reverse;
    }

    .modal-maps-panel {
        border-right: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding-right: 0;
        padding-top: 20px;
    }
}

@media (max-width: 768px) {
    .top-nav-bar {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 15px;
        height: auto;
        padding: 15px;
    }

    .nav-center-title {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    .nav-links-right {
        order: 3;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .burger-menu {
        order: 1;
    }

    .nav-center-title {
        order: 2;
    }
}

@media (max-width: 480px) {
    .nav-center-title h1 {
        font-size: 1.5rem;
    }

    .author-credit {
        font-size: 0.8rem;
    }
}