/* === GOOGLE FONTS IMPORT === */
@import url('https://fonts.googleapis.com/css2?family=Sofia+Sans:wght@400;600;700&display=swap');

/* === THEME VARIABLES === */
:root {
    /* Colors */
    --theme-body-background: #343B4C;
    --theme-content-background: #0B0B28;
    --theme-content-background-secondary: #1A0B28;
    --theme-content-border: #9432a1;
    --theme-content-text: #D5F4F5;
    --theme-content-text-muted: #7e8791;
    --theme-content-heading: #3bd2d4;
    --theme-content-link: #F2009D;
    --theme-accent: #cc33ba;
    --theme-accent-hover: #f544e6;
    --theme-accent-label: #fff;
    --fresh-file-border: #fd801c;
    
    /* RGB for rgba() usage */
    --theme-content-bg-rgb: 11, 11, 40;
    --fresh-file-bg-rgb: 253, 128, 28;
    
    /* Backgrounds */
    --wiki-body-background-image: url("https://windblown.wiki.gg/images/Site-background-3.jpg?51ba32");
    
    /* Typography */
    --theme-font-family: 'Sofia Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* === RESET & BASE === */
* {
    box-sizing: border-box;
}

body {
    font-family: var(--theme-font-family);
    background-image: var(--wiki-body-background-image);
    background-size: cover;
    background-position: top center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    margin: 0;
    padding: 0;
}

/* === LAYOUT === */
main {
    display: grid;
    margin: 25px auto;
    grid-template-columns: 1fr 650px;
    gap: 1rem;
    padding: 1.5rem;
    max-width: 1800px;
}

/* === FIXED HEADER === */
.fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    background-color: rgba(var(--theme-content-bg-rgb), 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.logo-container {
    text-align: center;
}

.version-selector {
    margin-left: auto;
    padding: 0.5rem;
}

#version-select {
    background: var(--theme-content-background-secondary);
    color: var(--theme-content-text);
    border: 1px solid var(--theme-content-border);
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
}

#version-select:focus {
    outline: none;
    border-color: var(--theme-accent);
}

/* === TABS === */
.tabs-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    background: var(--theme-content-background-secondary);
    border: 1px solid var(--theme-content-border);
    border-bottom: none;
    margin-bottom: -1px;
}

.tab-btn {
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--theme-content-text-muted);
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    flex: 1;
    justify-content: center;
}

.tab-btn.active {
    color: var(--theme-content-heading);
    border-bottom-color: var(--theme-accent);
    background: var(--theme-content-background);
}

.tab-btn:not(.valid) .tab-info {
    color: #c00;
}

.tab-info {
    font-size: 0.75rem;
    color: var(--theme-accent);
    font-weight: 600;
}

.tab-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: brightness(0.2);
    transition: filter 0.15s;
}

.tab-btn.active .tab-icon {
    filter: brightness(0.85);
}

/* === CATEGORY PANELS === */
.category-panel {
    display: none;
    border: 1px solid var(--theme-content-border);
    background: var(--theme-content-background);
    padding: 1rem;
    max-height: calc(100vh - 265px);  
    overflow-y: auto;
    position: relative;
}

.category-panel.active {
    display: block;
}

.section-header {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--theme-content-heading);
    border-bottom: 1px solid var(--theme-accent);
    padding: 0.5rem 0.5rem;
    grid-column: 1 / -1;
}

/* === SEARCH BOX === */
.search-box {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--theme-content-background);
}

.search-box input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--theme-content-border);
    font-size: 0.9rem;
    border-radius: 4px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--theme-accent);
}

/* === ITEM GRID & CARDS === */
.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 1ex;
    padding-top: 0.5rem;
}

.item-card {
    background: var(--theme-content-background);
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

.item-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.8;
    pointer-events: none;
    z-index: 0;
    filter: grayscale();
    transition: 0.15s;
    scale: 0.92;
    width: 145px;
}

.item-card[data-category="weapons"]::before {
    background-image: url('./assets/IconFrameRed.png');
}

.item-card[data-category="trinkets"]::before,
.item-card[data-category="magifishes"]::before {
    background-image: url('./assets/IconFramePurple.png');
}

.item-card[data-category="gifts"]::before,
.item-card[data-category="hexes"]::before {
    background-image: url('./assets/IconFrameBlue.png');
}

.item-card.selected::before {
    opacity: 1.0;
    filter: none;
    scale: 0.95;
}

.item-card:hover {
    border-color: var(--theme-content-border);
}

.item-icon-wrapper {
    z-index: 1;
    width: 145px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-icon-wrapper img {
    width: 108px;
    height: 108px;
    object-fit: scale-down;
    transition: filter 0.15s;
    pointer-events: none;
    filter: drop-shadow(0 0 8px rgba(0, 0, 0, 1));
}

.item-card:not(.selected) .item-icon-wrapper img {
    filter: grayscale(100%) brightness(0.5);
}

.item-info {
    display: none;
}

.item-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.95);
    color: #fff;
    padding: 0.75rem;
    font-size: 0.75rem;
    line-height: 1.4;
    opacity: 0;
    visibility: hidden;
    z-index: 1000;
    pointer-events: none;
    border-radius: 4px;
    width: 220px;
    max-height: 180px;
    overflow-y: auto;
    transition: opacity 0.1s ease, visibility 0.1s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    white-space: normal;
    overflow-wrap: break-word;
}

.item-icon-wrapper:hover .item-tooltip {
    opacity: 1;
    visibility: visible;
}

.item-tooltip .tooltip-name {
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--theme-accent);
    font-size: 0.85rem;
}

.item-tooltip .tooltip-desc {
    color: #eee;
    word-break: break-word;
}

.item-name {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}

/* === DECK SUMMARY SIDEBAR === */
#deck-summary {
    background: var(--theme-content-background);
    border: 1px solid var(--theme-content-border);
    padding: 1rem;
    position: sticky;
    top: 80px;
}

#deck-summary h2 {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--theme-content-background-secondary);
    padding-bottom: 0.5rem;
}

.deck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 0.1rem;
    max-height: 40vh;
    overflow-y: auto;
    padding: 0.25rem;
    background: var(--theme-content-background-secondary);
    border: 1px solid var(--theme-content-background-secondary);
    margin-bottom: 0.5rem;
}

.deck-item {
    width: 48px;
    height: 48px;
    background: var(--theme-content-background);
    border: 2px solid var(--theme-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.deck-item:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.deck-item img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    pointer-events: none;
}

.deck-item.ineligible {
    filter: grayscale(100%) brightness(0.6);
    opacity: 0.6;
}

.deck-item.ineligible:hover {
    filter: grayscale(100%) brightness(0.7);
    opacity: 0.7;
}

.global-total {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.5rem;
    background: var(--theme-content-background-secondary);
    text-align: center;
    margin-bottom: 0.75rem;
}

.global-total.error {
    background: #ffe0e0;
    color: #c00;
}

.global-total.valid {
    background: #e0f0e0;
    color: #2a7a2a;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.actions button {
    padding: 0.5rem;
    border: 1px solid var(--theme-content-border);
    background: var(--theme-content-background);
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s;
}

.actions button:hover {
    background: var(--theme-content-background-secondary);
}

.actions button:first-child {
    border-color: var(--theme-accent);
    color: var(--theme-accent);
    background: rgba(var(--theme-content-bg-rgb), 0.05);
}

/* === CURRENT BUILD SECTION === */
#current-build-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(var(--theme-content-bg-rgb), 0.9);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    border-top: 2px solid var(--theme-accent);
    z-index: 1000;
    transition: transform 0.3s ease-out;
}

#current-build-section.build-collapsed {
    transform: translateY(calc(100% - 44px));
}

#current-build-section.build-expanded {
    transform: translateY(0);
    max-height: 50vh;
    overflow-y: auto;
}

.build-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.25rem;
    flex-wrap: wrap;
}

.build-toggle-btn {
    background: var(--theme-accent);
    color: var(--theme-accent-label);
    border: none;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.build-toggle-btn:hover {
    background: var(--theme-accent-hover);
}

.build-arrow {
    transition: transform 0.25s;
}

.build-count {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--theme-accent);
}

.build-slots-wrapper {
    overflow-y: auto;
    max-height: calc(50vh - 44px);
}

.build-slots-container {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    padding: 0.75rem 1rem;
    justify-content: center;
}

/* === ENDLESS MODE STYLES === */
.endless-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: 0.5rem;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    transition: all 0.15s;
}

.endless-toggle:hover {
    background: var(--theme-content-border);
}

.endless-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--theme-accent);
    cursor: pointer;
}

.endless-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theme-content-text-muted);
}

.endless-toggle input:checked + .endless-label {
    color: var(--theme-accent);
}

body.endless-mode-active {
    padding-bottom: 240px; 
}

body:not(.endless-mode-active) {
    padding-bottom: 120px;  
}

/* Normal mode layout */
#current-build-section:not(.build-endless) .build-slots-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

#current-build-section:not(.build-endless) .build-category-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

#current-build-section:not(.build-endless) .build-category {
    display: flex;
    gap: 0.25rem;
}

/* Endless mode layout */
#current-build-section.build-endless .build-slots-container {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    align-items: flex-start;
}

#current-build-section.build-endless .build-box-left {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

#current-build-section.build-endless .build-box-right {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#current-build-section.build-endless .build-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

#current-build-section.build-endless #build-weapons,
#current-build-section.build-endless #build-trinkets,
#current-build-section.build-endless #build-magifishes,
#current-build-section.build-endless #build-backpack,
#current-build-section.build-endless #build-hexes {
    display: flex;
    flex-direction: row;
    gap: 0.35rem;
}

#current-build-section.build-endless #build-gifts {
    display: grid;
    grid-template-columns: repeat(6, auto);
    grid-template-rows: repeat(3, auto);
    gap: 0.35rem;
}

/* === BUILD SLOTS === */
.build-category-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.build-category-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--theme-content-heading);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.build-category {
    display: flex;
    gap: 0.25rem;
}

.build-slot {
    width: 52px;
    height: 52px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Weapon slots */
.build-slot[data-slot-type="weapon"] {
    background: none;
    border: 2px solid #fff;
    border-radius: 0;
}

.build-slot[data-slot-type="weapon"][data-index="0"] {
    border-radius: 8px 0 0 8px;
}

.build-slot[data-slot-type="weapon"][data-index="1"] {
    border-radius: 0 8px 8px 0;
}

/* Trinket slots */
.build-slot[data-slot-type="trinket"] {
    background: none;
    border: 2px solid #fff;
    border-radius: 0;
}

.build-slot[data-slot-type="trinket"][data-index="0"] {
    border-radius: 8px 0 0 8px;
}

.build-slot[data-slot-type="trinket"][data-index="1"] {
    border-radius: 0 8px 8px 0;
}

/* Magifish slot */
.build-slot[data-slot-type="magifish"] {
    background: none;
    border: 2px solid #fff;
    border-radius: 8px;
}

/* Backpack slot */
.build-slot[data-slot-type="backpack"] {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
}

.build-slot[data-slot-type="backpack"]::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('./assets/BackpackBack.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 0;
}

.build-slot[data-slot-type="backpack"]::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('./assets/BackpackFront.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 10;
    pointer-events: none;
}

.build-slot[data-slot-type="backpack"].filled::after {
    opacity: 0.7;
}

.build-slot[data-slot-type="backpack"] img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    width: 44px;
    height: 44px;
    object-fit: contain;
    pointer-events: none;
}

/* Hex slot */
.build-slot[data-slot-type="hex"] {
    background-image: url('./assets/HexIconBackground.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 68px;
    border: none;
    border-radius: 0;
}

/* Gift slot */
.build-slot[data-slot-type="gift"] {
    background-image: url('./assets/GiftIconBackground.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border: none;
    border-radius: 0;
}

/* Filled slots */
.build-slot.filled img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    width: 44px;
    height: 44px;
    object-fit: contain;
    pointer-events: none;
}

.build-slot .slot-num {
    display: none;
}

.remove-slot-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: #c00;
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    line-height: 16px;
    z-index: 20;
    pointer-events: auto;
}

/* === CHRYSALIS BONUS === */
.chrysalis-bonus {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: 0.5rem;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    transition: all 0.15s;
}

.chrysalis-bonus:hover:not(.disabled) {
    background: var(--theme-content-border);
}

.chrysalis-bonus.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f0f0f0;
}

.chrysalis-bonus.disabled .bonus-label {
    color: #999;
}

.chrysalis-bonus.enabled {
    background: linear-gradient(135deg, rgba(var(--theme-content-bg-rgb), 0.15) 0%, rgba(var(--theme-content-bg-rgb), 0.25) 100%);
    border-color: #10b981;
}

.chrysalis-bonus input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--theme-accent);
}

.bonus-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theme-content-text-muted);
    transition: color 0.15s;
}

.chrysalis-bonus.enabled .bonus-label {
    color: #059669;
}

/* Gift grid rows based on data-rows attribute */
#current-build-section:not(.build-endless) #build-gifts[data-rows="2"] {
    display: grid;
    grid-template-columns: repeat(6, auto);
    grid-template-rows: repeat(2, auto);
    gap: 0.35rem;
}

#current-build-section.build-endless #build-gifts[data-rows="4"] {
    display: grid;
    grid-template-columns: repeat(6, auto);
    grid-template-rows: repeat(4, auto);
    gap: 0.35rem;
}

#build-gifts .build-slot.bonus-slot {
    border-style: solid;
    border-color: #a855f7;
    background: linear-gradient(135deg, rgba(var(--theme-content-bg-rgb), 0.1) 0%, rgba(var(--theme-content-bg-rgb), 0.2) 100%);
}

#build-gifts .build-slot.bonus-slot.filled {
    border-color: var(--theme-accent);
    background: var(--theme-content-background);
}

/* === BUTTONS === */
#btn-import {
    border-color: var(--theme-accent);
    color: var(--theme-accent-label);
    background: var(--theme-accent);
}

#btn-import:hover {
    background: var(--theme-accent-hover);
}

#btn-reset {
    border-color: #c00;
    color: var(--theme-accent-label);
    background: #c00;
}

#btn-reset:hover {
    background: #a00;
}

#btn-fresh-file {
    border-color: var(--fresh-file-border);
    color: #fd801c;
}

#btn-fresh-file:hover {
    background: rgba(var(--fresh-file-bg-rgb), 0.25);
}

.sidebar-copyright {
    font-size: 8pt;
    opacity: 0.8;
    margin-top: 8px;
    line-height: 1.3;
    color: var(--theme-content-text-muted);
    text-align: center;
}

.sidebar-copyright a {
    color: var(--theme-content-link);
}

/* === MEDIA QUERIES === */

/* Tablet view */
@media (max-width: 1360px) {
    main {
        grid-template-columns: 1fr;
    }
    
    #deck-summary {
        position: static;
        order: -1;
    }
}


/* Mobile view */
@media (max-width: 900px) {
    /* Layout */
    main {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    body {
        padding-bottom: 100px;
    }

    body.endless-mode-active {
        padding-bottom: 200px;
    }

    body:not(.endless-mode-active) {
        padding-bottom: 100px;
    }

    /* Tabs */
    #tabs {
        overflow-x: auto;
        padding: 0 0.5rem;
    }

    .tab-btn {
        gap: 0.2rem;
    }

    .tab-icon {
        width: 18px;
        height: 18px;
    }

    /* Items */
    .item-grid {
        grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
        gap: 0ex;
    }

    .item-icon-wrapper {
        width: 62px;
    }

    .item-card::before {
        width: 62px;
    }

    .item-icon-wrapper img {
        width: 48px;
        height: 48px;
        filter: drop-shadow(0 0 4px rgba(0, 0, 0, 1));
    }

    /* Build section */
    #current-build-section.build-collapsed {
        transform: translateY(calc(100% - 38px));
    }

    .build-toggle-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.75rem;
    }

    .build-slot {
        width: 46px;
        height: 46px;
    }

    .build-slot img {
        width: 38px;
        height: 38px;
    }

    .build-slot[data-slot-type="hex"] {
        background-size: 60px;
    }

    .build-slot[data-slot-type="backpack"]::before,
    .build-slot[data-slot-type="backpack"]::after {
        background-size: contain;
    }

    #current-build-section.build-endless .build-slot {
        width: 40px;
        height: 40px;
    }

    #current-build-section.build-endless .build-slot img {
        width: 34px;
        height: 34px;
    }

    #current-build-section.build-endless .build-category-title {
        min-width: 55px;
        font-size: 0.65rem;
    }

    #current-build-section.build-endless #build-gifts {
        grid-template-columns: repeat(6, auto);
        gap: 0.2rem;
    }

    /* Chrysalis bonus */
    .chrysalis-bonus {
        padding: 0.2rem 0.5rem;
    }

    .bonus-label {
        font-size: 0.65rem;
    }
}
