/* Character Selection Overlay */
.character-selection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 10, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 22000; /* Above achievements (21000) and character-hub (20000) */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

.character-selection-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Main Container */
.character-selection-container {
    position: relative;
    z-index: 10;
    width: 90vw;
    max-width: 1800px;
    height: 92vh;
    padding: 25px;
    background: transparent;
    animation: characterSelectionSlideUp 0.8s ease-out;
}

.character-selection-container.panel > .panel-content {
    overflow-y: auto;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 1vh;
    scrollbar-width: thin;
    scrollbar-color: #4a3a35 #2a1a18;
}

.character-selection-container.panel > .panel-content::-webkit-scrollbar {
    width: 10px;
}

.character-selection-container.panel > .panel-content::-webkit-scrollbar-track {
    background: rgba(26, 15, 31, 0.5);
    border-radius: 5px;
    border: 1px solid #3a2a28;
}

.character-selection-container.panel > .panel-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #5a4a45 0%, #3a2a28 100%);
    border-radius: 5px;
    border: 1px solid #4a3a35;
    box-shadow: inset 0 0 5px rgba(90, 74, 69, 0.3);
}

.character-selection-container.panel > .panel-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #6a5a55 0%, #4a3a35 100%);
    box-shadow: 0 0 8px rgba(90, 74, 69, 0.6);
}

@keyframes characterSelectionSlideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Header - uses menu-header-ornate from menu.css */
.character-selection-header {
    flex-shrink: 0;
}

/* Back Button */
.character-selection-back {
    position: absolute;
    top: calc(7.5vh - 27px);
    left: calc(5vw - 27px);
    z-index: 15;
    cursor: var(--cm-cursor-action, pointer);
}

.character-selection-back.btn.panel {
    width: 36px;
    height: 36px;
    background: transparent;
}

.character-selection-back.panel > .panel-content {
    font-size: 14px;
    line-height: 1;
    color: var(--kit-text-color, #8a7a75);
}

/* Selected state - keyboard/gamepad */
.character-selection-back.gamepad-selected {
    --kit-frame-color: #6a5040;
    --kit-frame-inner: #4a3530;
    --kit-corner-color: #8a6a55;
    --kit-diamond-color: #aa8a70;
}

.character-selection-back.gamepad-selected > .panel-texture {
    background:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
        radial-gradient(ellipse 80px 120px at 30% 25%, rgba(40, 25, 20, 0.15) 0%, transparent 70%),
        radial-gradient(ellipse 100px 80px at 70% 45%, rgba(35, 20, 18, 0.12) 0%, transparent 70%),
        linear-gradient(180deg,
            #18100c 0%,
            #201510 12%,
            #2a1a14 30%,
            #302018 45%,
            #281814 58%,
            #201210 70%,
            #140c08 100%
        );
    background-blend-mode: soft-light, normal, normal, normal;
}

.character-selection-back.gamepad-selected > .panel-content {
    color: var(--text-brown-accent);
}

.character-selection-back.gamepad-selected > .deco-frame::before {
    box-shadow:
        0 0 10px rgba(120, 90, 60, 0.2),
        inset 0 0 0 4px transparent,
        inset 0 0 0 6px var(--kit-frame-inner, #4a3530);
}

/* Hints styling */
.character-selection-hints {
    text-align: center;
    flex-shrink: 0;
}

/* Character Grid */
.character-selection-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 300px));
    grid-auto-rows: max-content;
    justify-content: center;
    align-items: start;
    align-content: start;
    gap: 1vw;
    margin: 1vh 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1vh 1vw;
    scrollbar-width: thin;
    scrollbar-color: #4a3a35 #2a1a18;
}

.character-selection-grid::-webkit-scrollbar {
    width: 10px;
}

.character-selection-grid::-webkit-scrollbar-track {
    background: rgba(26, 15, 31, 0.5);
    border-radius: 5px;
    border: 1px solid #3a2a28;
}

.character-selection-grid::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #5a4a45 0%, #3a2a28 100%);
    border-radius: 5px;
    border: 1px solid #4a3a35;
    box-shadow: inset 0 0 5px rgba(90, 74, 69, 0.3);
}

.character-selection-grid::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #6a5a55 0%, #4a3a35 100%);
    box-shadow: 0 0 8px rgba(90, 74, 69, 0.6);
}

/* Shared portrait-card shell. Hero panels can adopt the same roster-card contract. */
.roster-card.panel {
    --roster-card-accent: #7f6046;
    --roster-card-accent-bright: #c49963;
    width: 100%;
    max-width: 300px;
    aspect-ratio: 2 / 3;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    isolation: isolate;
    border-radius: 3px;
    background: #080506;
    box-shadow:
        0 16px 24px rgba(0, 0, 0, 0.54),
        0 3px 0 rgba(116, 84, 57, 0.16);
    transform-origin: 50% 100%;
}

/* Character Item - portrait card using the shared shell */
.character-selection-item.panel {
    cursor: var(--cm-cursor-action, pointer);
    transition: transform 220ms ease, box-shadow 220ms ease, filter 220ms ease;
}

.character-selection-item.panel.frame-compact > .panel-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 13px 13px 10px !important;
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
}

/* Hover state - golden frame */
.character-selection-item.panel:hover:where(body:not(.gamepad-active) *),
.character-selection-item.panel.highlighted {
    transform: translateY(-7px) scale(1.025);
    z-index: 10;
    --kit-frame-color: #6a5040;
    --kit-frame-inner: #4a3530;
    --kit-corner-color: #8a6a55;
    --kit-diamond-color: #aa8a70;
    --roster-card-accent: #a77f55;
    --roster-card-accent-bright: #e0b77b;
    box-shadow:
        0 22px 30px rgba(0, 0, 0, 0.64),
        0 0 16px rgba(166, 121, 75, 0.2);
}

.character-selection-item.panel:hover:where(body:not(.gamepad-active) *) > .deco-frame::before,
.character-selection-item.panel.highlighted > .deco-frame::before {
    box-shadow:
        0 0 10px rgba(120, 90, 60, 0.3),
        inset 0 0 0 2px transparent,
        inset 0 0 0 3px var(--kit-frame-inner, #4a3530);
}

/* Selected state - gold glow */
.character-selection-item.panel.selected {
    --kit-frame-color: rgba(255, 215, 0, 0.7);
    --kit-frame-inner: rgba(218, 165, 32, 0.6);
    --kit-corner-color: rgba(255, 215, 0, 0.8);
    --kit-diamond-color: rgba(255, 215, 0, 0.9);
    --roster-card-accent: #b58a36;
    --roster-card-accent-bright: #f2cf6b;
    box-shadow:
        0 18px 28px rgba(0, 0, 0, 0.58),
        0 0 18px rgba(218, 165, 32, 0.32);
}

/* Legendary Character Item */
.character-selection-item.panel.legendary {
    --kit-frame-color: rgba(255, 140, 0, 0.5);
    --kit-frame-inner: rgba(255, 100, 0, 0.4);
    --kit-corner-color: rgba(255, 140, 0, 0.6);
    --kit-diamond-color: rgba(255, 140, 0, 0.7);
    --roster-card-accent: #a9581f;
    --roster-card-accent-bright: #ff9d33;
    animation: legendaryGlow 3s ease-in-out infinite alternate;
}

@keyframes legendaryGlow {
    from {
        box-shadow: 0 0 10px rgba(255, 140, 0, 0.2);
    }
    to {
        box-shadow: 0 0 20px rgba(255, 140, 0, 0.4);
    }
}

.character-selection-item.panel.legendary:hover:where(body:not(.gamepad-active) *),
.character-selection-item.panel.legendary.highlighted {
    --kit-frame-color: rgba(255, 140, 0, 0.7);
    --kit-frame-inner: rgba(255, 100, 0, 0.6);
    --kit-corner-color: rgba(255, 140, 0, 0.8);
    --kit-diamond-color: rgba(255, 140, 0, 0.9);
    --roster-card-accent: #cf6a20;
    --roster-card-accent-bright: #ffb04f;
    transform: translateY(-7px) scale(1.025);
}

/* Legendary selected - gold frame */
.character-selection-item.panel.legendary.selected {
    --kit-frame-color: rgba(255, 215, 0, 0.7);
    --kit-frame-inner: rgba(218, 165, 32, 0.6);
    --kit-corner-color: rgba(255, 215, 0, 0.8);
    --kit-diamond-color: rgba(255, 215, 0, 0.9);
    --roster-card-accent: #b58a36;
    --roster-card-accent-bright: #f2cf6b;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

/* Locked characters become playable together with their matching hero unlock. */
.character-selection-item.panel.locked,
.character-selection-item.panel.legendary.locked {
    cursor: var(--cm-cursor-disabled, not-allowed);
    animation: none;
    --kit-frame-color: rgba(70, 61, 61, 0.72);
    --kit-frame-inner: rgba(42, 34, 36, 0.78);
    --kit-corner-color: rgba(82, 70, 72, 0.78);
    --kit-diamond-color: rgba(96, 82, 84, 0.78);
    --roster-card-accent: #4d4244;
    --roster-card-accent-bright: #77666a;
    box-shadow: 0 12px 20px rgba(0, 0, 0, 0.48);
}

.character-selection-item.panel.locked:hover:where(body:not(.gamepad-active) *),
.character-selection-item.panel.locked.highlighted,
.character-selection-item.panel.legendary.locked:hover:where(body:not(.gamepad-active) *),
.character-selection-item.panel.legendary.locked.highlighted {
    transform: none;
    --kit-frame-color: rgba(105, 88, 91, 0.82);
    --kit-frame-inner: rgba(58, 46, 49, 0.88);
    --kit-corner-color: rgba(116, 96, 99, 0.88);
    --kit-diamond-color: rgba(130, 108, 111, 0.88);
}

.character-selection-item.panel.locked .character-sprite-preview,
.character-selection-item.panel.locked .character-info,
.character-selection-item.panel.locked .roster-card-footer {
    opacity: 0.28;
    filter: grayscale(1);
}

.character-selection-item.panel.in-roster {
    cursor: var(--cm-cursor-disabled, not-allowed);
}

.character-selection-item.panel.in-roster .character-sprite-preview,
.character-selection-item.panel.in-roster .character-info {
    opacity: 0.45;
}

.character-lock-state {
    padding: 16px;
    text-align: center;
    line-height: 1.45;
    overflow-wrap: anywhere;
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: rgba(200, 184, 184, 0.88);
    background: linear-gradient(180deg, rgba(12, 8, 10, 0.18), rgba(12, 8, 10, 0.62));
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: clamp(13px, 0.78vw, 17px);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
    pointer-events: none;
}

.character-lock-icon {
    position: relative;
    width: 28px;
    height: 22px;
    border: 3px solid rgba(200, 184, 184, 0.82);
    border-radius: 3px;
    box-sizing: border-box;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.8);
}

.character-lock-icon::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 15px;
    width: 15px;
    height: 13px;
    border: 3px solid rgba(200, 184, 184, 0.82);
    border-bottom: 0;
    border-radius: 10px 10px 0 0;
    transform: translateX(-50%);
    box-sizing: border-box;
}

/* Character Sprite Preview */
.character-sprite-preview {
    flex-shrink: 0;
    position: relative;
    width: 100%;
    height: 40%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--roster-card-accent-bright) 54%, transparent);
    background:
        linear-gradient(90deg, transparent 49.5%, rgba(196, 153, 99, 0.08) 50%, transparent 50.5%),
        linear-gradient(0deg, transparent 49.5%, rgba(196, 153, 99, 0.07) 50%, transparent 50.5%),
        radial-gradient(circle at 50% 52%, color-mix(in srgb, var(--roster-card-accent) 30%, transparent), transparent 55%),
        linear-gradient(160deg, rgba(34, 21, 19, 0.96), rgba(8, 6, 8, 0.98));
    box-shadow:
        inset 0 0 28px rgba(0, 0, 0, 0.72),
        0 2px 0 rgba(0, 0, 0, 0.78);
}

.character-sprite-preview::before {
    content: '';
    position: absolute;
    width: 72%;
    aspect-ratio: 1;
    border: 1px solid color-mix(in srgb, var(--roster-card-accent-bright) 22%, transparent);
    transform: rotate(45deg);
    box-shadow:
        0 0 0 10px rgba(8, 5, 7, 0.12),
        0 0 24px color-mix(in srgb, var(--roster-card-accent) 18%, transparent);
}

.character-sprite-preview::after {
    content: '';
    position: absolute;
    right: 8%;
    bottom: 7px;
    left: 8%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--roster-card-accent-bright), transparent);
    opacity: 0.54;
}

/* Legendary Badge */
.legendary-badge {
    position: absolute;
    right: 8px;
    bottom: 8px;
    left: auto;
    transform: none;
    background: linear-gradient(135deg, #ff8c00 0%, #ff6600 100%);
    color: #3a1a00;
    font-size: 12px;
    font-weight: bold;
    padding: 1px 6px;
    border-radius: 8px;
    border: 1px solid #ff6600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 6px rgba(255, 140, 0, 0.4);
    z-index: 10;
    white-space: nowrap;
}

.character-sprite-image {
    z-index: 2;
    width: 100%;
    height: 100%;
    margin: 0;
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Legendary Character Sprite */
.character-selection-item.panel.legendary .character-sprite-image {
    filter: drop-shadow(0 0 8px rgba(255, 140, 0, 0.5));
}

/* Character Info */
.character-info {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    text-align: center;
}

.character-card-nameplate {
    position: relative;
    z-index: 4;
    min-height: 32px;
    margin: -9px 10px 6px;
    padding: 6px 12px 5px;
    box-sizing: border-box;
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--roster-card-accent) 54%, #2a1916), #130c0d 72%);
    clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 8px 100%, 0 50%);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--roster-card-accent-bright) 58%, transparent);
}

.character-card-nameplate::before,
.character-card-nameplate::after {
    content: '◆';
    position: absolute;
    top: 50%;
    color: var(--roster-card-accent-bright);
    font-size: 7px;
    line-height: 1;
    transform: translateY(-50%);
    opacity: 0.72;
}

.character-card-nameplate::before { left: 5px; }
.character-card-nameplate::after { right: 5px; }

.character-info h3 {
    color: var(--text-brown-accent, #c0a080);
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: clamp(16px, 1vw, 22px);
    line-height: 1.08;
    margin: 0;
    padding: 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Legendary Character Name */
.character-selection-item.panel.legendary .character-info h3 {
    color: #ff8c00;
    text-shadow:
        0 2px 4px rgba(0, 0, 0, 0.5),
        0 0 10px rgba(255, 140, 0, 0.4);
    background: linear-gradient(135deg, #ff8c00 0%, #ff6600 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: bold;
}

.character-info p {
    color: var(--text-brown-light, #a89a90);
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: clamp(12px, 0.72vw, 15px);
    margin: 0;
    line-height: 1.4;
    opacity: 0.9;
}

.character-info p.character-card-description {
    min-height: 2.8em;
    margin: 0 7px;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.character-school-badges {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 3px;
    min-height: 19px;
    margin: 0 4px 5px;
}

.character-school-badge {
    padding: 2px 4px;
    border: 1px solid rgba(120, 90, 72, 0.55);
    background: rgba(28, 17, 15, 0.78);
    color: var(--text-brown-light, #a89a90);
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: clamp(8px, 0.52vw, 10px);
    line-height: 1.2;
}

.character-school-badge.primary {
    border-color: rgba(196, 153, 99, 0.8);
    color: var(--text-brown-accent, #c0a080);
}

/* Zdolność wrodzona postaci (pasywka szkół) */
.character-passive {
    flex: 1;
    min-height: 0;
    margin: 7px 5px 2px;
    padding: 6px 7px 5px;
    border: 1px solid color-mix(in srgb, var(--roster-card-accent) 48%, transparent);
    background: linear-gradient(180deg, rgba(11, 7, 8, 0.2), rgba(7, 5, 7, 0.62));
    text-align: left;
}

.character-passive-header {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 4px;
}

.innate-passive-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.innate-passive-icon {
    display: block;
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    object-fit: contain;
    image-rendering: pixelated;
}

@media (max-width: 1920px) {
    .innate-passive-icon { width: 48px; height: 48px; }
}

@media (max-width: 1280px) {
    .innate-passive-icon { width: 40px; height: 40px; }
}

.character-passive-label {
    color: var(--text-brown-light, #a89a90);
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: clamp(9px, 0.52vw, 11px);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.75;
}

.character-passive-name {
    color: #c49963;
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: clamp(12px, 0.74vw, 16px);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.character-selection-item.panel.legendary .character-passive-name {
    color: #ff9d33;
}

.character-info p.character-passive-desc {
    font-size: clamp(10px, 0.62vw, 13px);
    font-style: italic;
    opacity: 0.72;
    margin-bottom: 0;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
}

.roster-card-footer {
    flex: 0 0 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin: 2px 10px 0;
    color: var(--roster-card-accent-bright);
    font-size: 7px;
    line-height: 1;
    opacity: 0.68;
}

.roster-card-footer span {
    width: 34%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--roster-card-accent));
}

.roster-card-footer span:last-child {
    transform: scaleX(-1);
}

.roster-card-footer i {
    font-style: normal;
}

.character-passive-effects {
    list-style: none;
    margin: 0;
    padding: 0;
}

.character-passive-effects li {
    color: var(--text-brown-light, #a89a90);
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: clamp(10px, 0.62vw, 13px);
    line-height: 1.35;
    padding-left: 10px;
    position: relative;
}

.character-passive-effects li::before {
    content: '·';
    position: absolute;
    left: 2px;
    color: rgba(196, 153, 99, 0.9);
}

@media (max-width: 1920px) {
    .character-selection-container {
        max-width: 1500px;
        height: 90vh;
    }

    .character-selection-grid {
        grid-template-columns: repeat(4, minmax(0, 280px));
        gap: 0.8vw;
    }

    .roster-card.panel {
        max-width: 280px;
    }

    .character-sprite-image {
        width: 126px;
        height: 126px;
    }

    .character-selection-item.panel.frame-compact > .panel-content {
        padding: 12px 12px 9px !important;
    }
}

@media (max-width: 1366px) {
    .character-selection-container {
        max-width: 1120px;
    }

    .character-selection-grid {
        grid-template-columns: repeat(3, minmax(0, 255px));
    }

    .roster-card.panel {
        max-width: 255px;
    }

    .character-sprite-image {
        width: 112px;
        height: 112px;
    }
}

@media (max-width: 1280px) {
    .character-selection-container {
        max-width: 960px;
    }

    .character-selection-grid {
        grid-template-columns: repeat(3, minmax(0, 235px));
        gap: 0.6vw;
    }

    .roster-card.panel {
        max-width: 235px;
    }

    .character-sprite-preview {
        height: 37%;
    }

    .character-card-nameplate {
        min-height: 30px;
        margin-bottom: 5px;
        padding-top: 5px;
        padding-bottom: 4px;
    }

    .character-info p.character-card-description {
        min-height: 1.4em;
        -webkit-line-clamp: 1;
    }

    .character-passive {
        margin-top: 5px;
        padding: 5px 6px 4px;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .character-selection-container {
        padding: 20px;
        width: 95%;
    }

    .character-selection-grid {
        grid-template-columns: minmax(0, 230px);
        gap: 15px;
    }

    .roster-card.panel {
        max-width: 230px;
    }

    .character-selection-item.panel.frame-compact > .panel-content {
        padding: 12px 12px 9px !important;
    }

    .character-sprite-image {
        width: 104px;
        height: 104px;
    }

    .character-info h3 {
        font-size: 16px;
    }

    .character-info p {
        font-size: 12px;
    }
}
