:root {
    --bg-color: #1a1a2e;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text-color: #ffffff;
    --accent-color: #e94560;
    --p1-color: #ff4757;
    --p2-color: #1e90ff;
    --success-color: #2ed573;
    --warning-color: #ffa502;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 50% 50%, #16213e 0%, #1a1a2e 100%);
    color: var(--text-color);
    height: 100vh;
    height: 100dvh;
    /* Mobile support */
    overflow: hidden;
    user-select: none;
}

/* --- GLASSMORPHISM UTILS --- */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 15px 30px;
    /* Larger buttons */
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.2rem;
    /* Larger text */
    transition: all 0.2s;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-primary {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

.btn-p1 {
    background: var(--p1-color);
    border-color: var(--p1-color);
}

.btn-p2 {
    background: var(--p2-color);
    border-color: var(--p2-color);
}

/* --- LAYOUT --- */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    padding: 20px;
    box-sizing: border-box;
    gap: 20px;
    overflow: hidden;
}

/* HEADER */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
}

.score-board {
    display: flex;
    align-items: center;
    gap: 40px;
    font-size: 2rem;
    font-weight: bold;
}

.player-score {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-num {
    font-size: 3rem;
}

.vs-badge {
    font-size: 1.2rem;
    opacity: 0.7;
}

/* MAIN CONTENT AREA via State Machine */
#main-view {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow-y: auto;
    /* Allow scrolling if content is too tall */
    width: 100%;
    padding-bottom: 20px;
}

.phase-container {
    display: none;
    /* Hidden by default */
    width: 100%;
    max-width: 1000px;
    height: 100%;
    animation: fadeIn 0.3s ease;
}

.phase-container.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(233, 69, 96, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(233, 69, 96, 0);
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.9);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- PHASES --- */

/* IDLE */
.player-slots {
    display: flex;
    gap: 40px;
}

.slot {
    width: 200px;
    height: 250px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 12px;
}

.slot.filled {
    border-style: solid;
    border-color: var(--success);
}

/* SHIFUMI */
.rps-buttons {
    display: flex;
    gap: 50px;
    /* More spacing */
}

.rps-btn {
    width: 130px;
    /* Larger */
    height: 130px;
    font-size: 4rem;
    /* Larger emoji */
    border-radius: 50%;
}

/* CHAR SELECT */
/* CHAR SELECT */
/* CHAR SELECT */
/* CHAR SELECT */
.char-grid {
    display: grid;
    /* FIX: Use fixed size instead of minmax to prevent 1 item from filling all width */
    grid-template-columns: repeat(auto-fill, 90px);
    /* FIX: Align content to start to prevent vertical stretching */
    align-content: start;
    justify-content: center;
    gap: 15px;
    width: 100%;
    overflow-y: auto;
    padding: 20px;
    /* Flex to fill space */
    flex: 1;
    min-height: 0;
    margin-top: 10px;
}

.char-card {
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    /* Fix: Match round corners when scaling */
    transition: transform 0.2s;
    border: 2px solid transparent;
    position: relative;
    /* Ensure square tiles */
    padding-bottom: 100%;
    /* Aspect ratio hack for square */
    height: 0;
}

.char-card:hover {
    transform: scale(1.1);
    /* Slightly reduced scale to avoid overlap issues */
    z-index: 10;
}

.char-card.selected {
    border-color: var(--accent-color);
}

.char-card img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Shows full image without cropping */
    padding: 5px;
    /* prevent hitting edges */
    display: block;
}

.search-bar {
    width: 100%;
    padding: 15px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.2rem;
    margin-bottom: 10px;
    /* More spacing */
}

/* BANS */
/* BANS */
/* BANS */
.files-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    /* 3x3 Exact Fit */
    gap: 15px;
    width: 100%;
    height: 100%;
    /* Fill parent */
    /* Removed max-height, using flex to fill */
    flex: 1;
    min-height: 0;
    overflow: hidden;
    /* No scrolling */
    padding: 10px;
}

.stage-card {
    position: relative;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    height: 100%;
    /* Fill grid cell */
    display: flex;
    flex-direction: column;
}

.stage-card.banned {
    filter: grayscale(100%);
    opacity: 0.4;
    pointer-events: none;
}

.stage-card.banned::after {
    content: "❌";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
}

.stage-card img {
    width: 100%;
    height: 100%;
    /* Fill card */
    object-fit: cover;
}

/* ADMIN PANEL (Floating or Sidebar) */
#admin-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 20px;
    z-index: 1000;
    display: none;
    /* Shown only if role=admin */
}

/* HELPERS */
.hidden {
    display: none !important;
}

.dimmed {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(100%);
}

.highlight-turn {
    border: 2px solid var(--accent-color);
    animation: pulse 2s infinite;
}

#shifumi-status {
    margin-top: 60px;
    margin-bottom: 40px;
    text-align: center;
    min-height: 1.5em;
    /* Prevent jump */
    font-size: 1.5rem;
}

.pulse-text {
    animation: pulse 2s infinite;
    color: var(--warning-color);
}

.selected-move {
    border: 3px solid var(--success-color);
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--success-color);
}

/* LOADING/INIT */
#init-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 20px;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
}

/* --- LOADER --- */
.loader {
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top: 5px solid var(--accent-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    #app {
        padding: 10px;
        gap: 10px;
    }

    header {
        padding: 10px 15px;
        flex-direction: column;
        gap: 10px;
    }

    .logo {
        font-size: 1.2rem;
    }

    .score-board {
        gap: 20px;
        font-size: 1.5rem;
    }

    .score-num {
        font-size: 2rem;
    }

    .player-slots {
        flex-direction: column;
        gap: 20px;
        width: 100%;
    }

    .slot {
        width: 100%;
        height: 150px;
    }

    .rps-buttons {
        gap: 30px;
    }

    .rps-btn {
        width: 100px;
        /* Larger on mobile too */
        height: 100px;
        font-size: 2.5rem;
    }

    .char-grid {
        grid-template-columns: repeat(auto-fill, 70px);
        gap: 10px;
        /* Remove max-height in favor of flex in parent */
        max-height: none;
    }

    .files-grid {
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(3, 1fr);
        gap: 5px;
    }

    .stage-card {
        height: auto;
    }

    .match-visuals {
        flex-direction: column;
        gap: 10px;
    }

    .matchup-display {
        gap: 20px;
    }

    #p1-char-img,
    #p2-char-img {
        width: 60px;
        height: 60px;
    }
}