:root {
    --bg-color: #0d1117;
    --text-color: #e6edf3;
    --accent-red: #ff4757;
    --accent-blue: #1e90ff;
    --accent-purple: #9b59b6;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    user-select: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    transition: opacity 0.3s ease;
    z-index: 10;
}

.hidden {
    opacity: 0;
    pointer-events: none;
}

@keyframes shake {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    20% {
        transform: translate(-3px, 0px) rotate(1deg);
    }

    30% {
        transform: translate(3px, 2px) rotate(0deg);
    }

    40% {
        transform: translate(1px, -1px) rotate(1deg);
    }

    50% {
        transform: translate(-1px, 2px) rotate(-1deg);
    }

    60% {
        transform: translate(-3px, 1px) rotate(0deg);
    }

    70% {
        transform: translate(3px, 1px) rotate(-1deg);
    }

    80% {
        transform: translate(-1px, -1px) rotate(1deg);
    }

    90% {
        transform: translate(1px, 2px) rotate(0deg);
    }

    100% {
        transform: translate(1px, -2px) rotate(-1deg);
    }
}

.shake {
    animation: shake 0.2s;
    animation-iteration-count: 1;
}

.shake-hard {
    animation: shake 0.1s infinite;
}

h1,
h2,
h3 {
    margin-bottom: 1rem;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* Glassmorphism Buttons */
button {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 10px 20px;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.2s;
    margin-top: 20px;
}

button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.bottom-right-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 100;
    display: flex;
    gap: 10px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    background: var(--glass-bg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-color);
    margin-top: 0;
    padding: 0;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.footer {
    margin-top: 30px;
    font-size: 0.8rem;
    color: #888;
    text-align: center;
    line-height: 1.5;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    font-size: 1.5rem;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
}

.hud-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#xp-bar-container,
#hp-bar-container {
    width: 60%;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--glass-border);
}

#xp-bar-container {
    height: 18px;
}

#hp-bar-container {
    height: 24px;
    width: 40%;
}

#xp-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #0984e3, #74b9ff);
    transition: width 0.2s;
}

#hp-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #d63031, #ff7675);
    transition: width 0.2s;
}

#xp-text,
#hp-text {
    position: absolute;
    width: 100%;
    text-align: center;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    pointer-events: none;
    z-index: 2;
}

#hp-text {
    font-size: 0.9rem;
}

.subtitle {
    margin-bottom: 2rem;
    color: #ccc;
    text-align: center;
}

/* Ability Selection Grid */
#selection-screen {
    overflow-y: auto;
    justify-content: flex-start;
    padding: 30px 0 80px 0;
}

.selection-container {
    display: flex;
    gap: 40px;
    align-items: flex-start;
    margin-bottom: 30px;
    height: 60vh;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, 100px);
    grid-template-rows: repeat(3, 100px);
    gap: 10px;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.grid-cell {
    background: rgba(255, 255, 255, 0.05);
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    /* overflow: hidden; removed to stop clipping remove-btn */
}

.grid-cell:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.grid-cell.filled {
    border-style: solid;
}

.grid-cell.selected-slot {
    border-color: #f1c40f !important;
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.5);
    transform: scale(1.05);
    z-index: 10;
}

.bingo-active {
    border-color: #ffd700 !important;
    box-shadow: 0 0 10px #ffd700;
    animation: pulse-bingo 1.5s infinite;
}

@keyframes pulse-bingo {
    0% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    }

    50% {
        box-shadow: 0 0 15px rgba(255, 215, 0, 1);
    }

    100% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    }
}

.list-container {
    width: 350px;
    height: 100%;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
    width: 100%;
    max-width: 500px;
    justify-content: center;
    padding: 0 10px;
}

.action-buttons button {
    flex: 1;
    min-width: 80px;
    margin-top: 0;
    white-space: nowrap;
}

#start-btn {
    flex-basis: 100%;
}

.ability-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s;
}

.ability-item:active {
    cursor: grabbing;
}

.ability-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(5px);
}

.ability-item.selected {
    opacity: 0.5;
    pointer-events: none;
}

.ability-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
}

/* Colors for attribute */
.attr-attack {
    background: linear-gradient(135deg, var(--accent-red), #ff6b81);
    box-shadow: 0 0 10px rgba(255, 71, 87, 0.5);
}

.attr-defense {
    background: linear-gradient(135deg, var(--accent-blue), #70a1ff);
    box-shadow: 0 0 10px rgba(30, 144, 255, 0.5);
}

.attr-special {
    background: linear-gradient(135deg, var(--accent-purple), #cd84f1);
    box-shadow: 0 0 10px rgba(155, 89, 182, 0.5);
}

.ability-info {
    flex-grow: 1;
}

.ability-name {
    font-weight: bold;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.ability-desc {
    font-size: 0.75rem;
    color: #aaa;
    line-height: 1.2;
}

.remove-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--accent-red);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.2s;
}

.grid-cell:hover .remove-btn {
    opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .selection-container {
        flex-direction: column;
        align-items: center;
        height: auto;
        gap: 20px;
    }

    .list-container {
        width: 100%;
        max-width: 400px;
        height: 35vh;
    }

    h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.8rem;
        margin-bottom: 15px;
    }

    .grid {
        grid-template-columns: repeat(3, 80px);
        grid-template-rows: repeat(3, 80px);
        gap: 8px;
    }

    .remove-btn {
        opacity: 1;
        /* Always show close button on mobile, instead of hover */
        top: -8px;
        right: -8px;
        width: 24px;
        height: 24px;
        font-size: 14px;
    }

    #hud {
        padding: 10px;
    }

    .hud-top {
        font-size: 1.2rem;
    }

    .ability-icon {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }
}

/* Ranking List Styles */
.ranking-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.02);
}

.ranking-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.rank-info {
    font-size: 1.2rem;
    font-weight: bold;
    color: #fca311;
    width: 60px;
}

.score-info {
    font-size: 1rem;
    flex-grow: 1;
}

.abilities-mini-grid {
    display: flex;
    gap: 2px;
    margin-right: 15px;
}

.mini-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
    margin-top: 0;
}