:root {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
}

@font-face {
    font-family: 'Galmuri7';
    src: url('fonts/galmuri/Galmuri7.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Unifont';
    src: url('fonts/GNU-Unifont-Full/GNUUnifont9FullHintInstrUCSUR.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #000000;
    /* Black background for letterboxing */
    font-family: 'Galmuri7', 'Unifont', sans-serif;
}

canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* Pixel perfect rendering */
}

.instructions {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border-radius: 8px;
    color: white;
    pointer-events: none;
    /* Let clicks pass through to canvas if needed */
    z-index: 100;
    /* Increased to be above canvas */
}

.instructions h2 {
    margin-top: 0;
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.instructions ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.instructions li {
    margin: 5px 0;
}

#game-ui {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    pointer-events: none;
    z-index: 100;
    /* Increased to be above canvas */
}

.player-stats {
    background: rgba(0, 0, 0, 0.7);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    min-width: 150px;
    border: 2px solid #555;
    pointer-events: auto;
    /* Allow interaction with stats */
}

.p1 {
    border-color: #4CAF50;
}

.p2 {
    border-color: #F44336;
}

.name {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 5px;
    color: #ddd;
}

.damage {
    font-size: 3rem;
    font-weight: 900;
    text-shadow: 2px 2px 0 #000;
}

.p1 .damage {
    color: #fff;
}

.p2 .damage {
    color: #fff;
}

.stocks {
    font-size: 1.2rem;
    margin-top: 5px;
    color: #aaa;
}

#game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 4px solid white;
    z-index: 100;
    pointer-events: auto;
    /* Enable clicks on game over screen */
}

#game-over button {
    pointer-events: auto;
    /* Ensure restart button is clickable */
    cursor: pointer;
}

.hidden {
    display: none !important;
}

/* Multiplayer Menu */
#multiplayer-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    pointer-events: auto;
}

.menu-container {
    background: #2a2a2a;
    padding: 40px;
    border-radius: 10px;
    border: 2px solid #00ffff;
    text-align: center;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
    min-width: 300px;
}

.menu-container h2 {
    color: #00ffff;
    font-family: 'Galmuri7', sans-serif;
    font-size: 2rem;
    margin-bottom: 30px;
    text-shadow: 0 0 10px #00ffff;
}

.menu-btn {
    display: block;
    width: 100%;
    padding: 15px;
    margin: 10px 0;
    background: #444;
    border: none;
    color: white;
    font-family: 'Galmuri7', sans-serif;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid #666;
}

.menu-btn:hover {
    background: #00ffff;
    color: black;
    box-shadow: 0 0 15px #00ffff;
}

.divider {
    margin: 20px 0;
    color: #888;
    font-family: 'Galmuri7', sans-serif;
}

input[type="text"] {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    background: #111;
    border: 1px solid #444;
    color: white;
    font-family: monospace;
    text-align: center;
}

#host-info p {
    color: #ccc;
    margin-bottom: 5px;
}

#winner-text {
    font-size: 4rem;
    margin: 0 0 20px 0;
    color: gold;
    text-shadow: 0 0 20px orange;
    white-space: nowrap;
}

kbd {
    background-color: #eee;
    border-radius: 3px;
    border: 1px solid #b4b4b4;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .2), 0 2px 0 0 rgba(255, 255, 255, .7) inset;
    color: #333;
    display: inline-block;
    font-size: .85em;
    font-weight: 700;
    line-height: 1;
    padding: 2px 4px;
    white-space: nowrap;
}

.debug-btn {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: 2px solid #666;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s;
    z-index: 100;
    pointer-events: auto;
    /* Ensure button is clickable */
}

.debug-btn:hover {
    background: rgba(50, 50, 50, 0.9);
    border-color: #999;
}

.debug-btn.active {
    background: rgba(0, 150, 0, 0.7);
    border-color: #0f0;
}

/* Portrait Mode Warning for Mobile */
body.portrait-warning::before {
    content: '↻';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    font-size: 10rem;
    color: white;
    animation: rotate-icon 2s ease-in-out infinite;
}

body.portrait-warning::after {
    content: 'Veuillez tourner votre appareil en mode paysage';
    position: fixed;
    top: 60%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    color: white;
    font-size: 1.5rem;
    text-align: center;
    padding: 0 20px;
    font-family: 'Galmuri7', sans-serif;
}

@keyframes rotate-icon {

    0%,
    100% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(90deg);
    }
}

/* Hide game UI when in portrait warning */
body.portrait-warning canvas,
body.portrait-warning #game-ui,
body.portrait-warning .instructions {
    display: none !important;
}

/* --- MOBILE FIRST UI REDESIGN --- */

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas when no menu is active */
    z-index: 500;
}

.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    /* Enable clicks on menus */
    transition: opacity 0.3s ease;
}

.menu-screen.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
    /* Fully hide to prevent layout issues */
}

.game-title {
    font-family: 'Galmuri7', sans-serif;
    font-size: 4rem;
    color: #00ffff;
    text-shadow: 4px 4px 0 #ff00ff;
    margin-bottom: 40px;
    letter-spacing: 5px;
}

.screen-title {
    font-family: 'Galmuri7', sans-serif;
    font-size: 2.5rem;
    color: #fff;
    margin-bottom: 30px;
}

/* Main Menu Grid */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    width: 80%;
    max-width: 600px;
}

.menu-btn-large {
    background: #222;
    border: 2px solid #444;
    border-radius: 15px;
    padding: 20px;
    color: white;
    font-family: 'Galmuri7', sans-serif;
    font-size: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s, border-color 0.2s;
    min-height: 120px;
    /* Large touch target */
}

.menu-btn-large .icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.menu-btn-large:active {
    transform: scale(0.95);
    background: #333;
}

.menu-btn-large:hover {
    /* Desktop hover */
    border-color: #00ffff;
    background: #2a2a2a;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
}

/* Character Select Grid */
.char-grid {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    padding: 20px;
    width: 90%;
    justify-content: center;
    /* Snap scrolling for mobile feel */
    scroll-snap-type: x mandatory;
}

.char-card {
    background: #333;
    border: 3px solid #555;
    border-radius: 10px;
    width: 150px;
    height: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 15px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
    scroll-snap-align: center;
}

.char-card.selected {
    border-color: #00ffff;
    box-shadow: 0 0 20px #00ffff;
    transform: scale(1.05);
    background: #444;
}

.char-card img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.char-card.selected img {
    opacity: 1.0;
}

.char-name {
    font-family: 'Galmuri7', sans-serif;
    font-size: 1.5rem;
    color: white;
    z-index: 2;
    text-shadow: 2px 2px 0 #000;
    background: rgba(0, 0, 0, 0.5);
    width: 100%;
    text-align: center;
    padding: 5px 0;
}

.char-actions {
    margin-top: 20px;
    display: flex;
    gap: 20px;
}

.menu-btn-medium {
    padding: 15px 40px;
    font-family: 'Galmuri7', sans-serif;
    font-size: 1.5rem;
    border: 2px solid #666;
    background: #222;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    min-width: 150px;
}

.menu-btn-medium.primary {
    background: #00ffff;
    color: #000;
    border-color: #00ffff;
    font-weight: bold;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
}

.menu-btn-medium:active {
    transform: scale(0.95);
}