:root {
    --bg-color: #1a1a2e;
    --panel-bg: rgba(255, 255, 255, 0.1);
    --primary: #f72585;
    --secondary: #4cc9f0;
    --text-main: #ffffff;
    --grid-color: rgba(255, 255, 255, 0.2);
    --grid-axis: rgba(255, 255, 255, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none; /* Empeche la selection sur TNI */
    -webkit-user-select: none;
}

body {
    background: linear-gradient(135deg, #10002b, #240046, #3c096c);
    color: var(--text-main);
    font-family: 'Quicksand', sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#app {
    margin: auto;
    display: flex;
    width: 95vw;
    height: 95vh;
    gap: 20px;
}

.welcome-text {
    display: block;
    margin-bottom: 5px;
    font-family: 'Fredoka One', cursive;
    color: #ffb703;
    font-size: 1.4rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

#school-logo {
    max-width: 100%;
    height: auto;
    max-height: 80px;
    margin-top: auto;
    align-self: center;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* Zone de jeu */
#game-area {
    flex: 3;
    background: var(--panel-bg);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

#header {
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    font-family: 'Fredoka One', cursive;
    color: var(--secondary);
    font-size: 2.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    margin-bottom: 10px;
}

#instruction {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffb703;
    background: rgba(0,0,0,0.3);
    padding: 10px 20px;
    border-radius: 15px;
    display: inline-block;
}

#canvas-container {
    flex: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    overflow: hidden;
    border: 2px solid var(--grid-color);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none; /* Important pour dessiner sur ecran tactile */
}

/* UI par dessus le canvas */
#score-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(26, 26, 46, 0.95);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    border: 2px solid var(--primary);
    box-shadow: 0 0 30px var(--primary);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

#score-popup.hidden {
    display: none;
}

#score-text {
    font-family: 'Fredoka One', cursive;
    font-size: 4rem;
    color: var(--primary);
    margin-bottom: 10px;
}

#score-feedback {
    font-size: 1.8rem;
    margin-bottom: 20px;
}

#controls {
    margin-top: 20px;
    display: flex;
    justify-content: center;
}

/* Zone Classement */
#leaderboard-area {
    flex: 1;
    background: var(--panel-bg);
    border-radius: 20px;
    padding: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    position: relative;
}

#btn-reset-leaderboard {
    position: absolute;
    bottom: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.2rem;
    opacity: 0.15;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

#btn-reset-leaderboard:hover {
    opacity: 0.8;
    transform: scale(1.1);
}

#leaderboard-area h2 {
    font-family: 'Fredoka One', cursive;
    text-align: center;
    color: #ffb703;
    font-size: 2rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#leaderboard-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* Chrome, Safari, Edge (Webkit) */
#leaderboard-list::-webkit-scrollbar {
    display: none;
}

.leaderboard-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2rem;
    font-weight: bold;
    border-left: 5px solid var(--secondary);
}

.leaderboard-item:nth-child(1) { border-left-color: #ffd700; background: rgba(255, 215, 0, 0.2); }
.leaderboard-item:nth-child(2) { border-left-color: #c0c0c0; background: rgba(192, 192, 192, 0.2); }
.leaderboard-item:nth-child(3) { border-left-color: #cd7f32; background: rgba(205, 127, 50, 0.2); }

/* Boutons et inputs */
.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2rem;
    font-family: 'Fredoka One', cursive;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(247, 37, 133, 0.4);
}

.btn:hover, .btn:active {
    transform: scale(1.05);
}

.btn-play-anim {
    background: #06d6a0; /* Vert très visible */
    margin-right: 15px;
    font-size: 1.4rem;
    padding: 15px 40px;
    box-shadow: 0 0 20px rgba(6, 214, 160, 0.6);
    animation: pulsePlay 1.5s infinite;
}

.btn-play-anim:hover {
    background: #05b88b;
}

@keyframes pulsePlay {
    0% { transform: scale(1); box-shadow: 0 0 20px rgba(6, 214, 160, 0.6); }
    50% { transform: scale(1.05); box-shadow: 0 0 30px rgba(6, 214, 160, 0.9); }
    100% { transform: scale(1); box-shadow: 0 0 20px rgba(6, 214, 160, 0.6); }
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: none;
    font-family: 'Quicksand', sans-serif;
    font-weight: bold;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #3a0ca3, #7209b7);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 2px solid var(--secondary);
    box-shadow: 0 0 40px rgba(76, 201, 240, 0.5);
    animation: popIn 0.3s ease-out forwards;
}

.modal-content h2 {
    font-family: 'Fredoka One', cursive;
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.modal-content p {
    font-size: 1.5rem;
    margin-bottom: 20px;
}

input[type="text"] {
    width: 100%;
    padding: 15px;
    font-size: 1.5rem;
    border: 2px solid white;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    margin-bottom: 20px;
    font-family: 'Quicksand', sans-serif;
    outline: none;
}

input[type="text"]::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

/* Clavier Virtuel */
#virtual-keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.kb-key {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-family: 'Fredoka One', cursive;
    font-size: 1.2rem;
    padding: 12px 0;
    width: 45px;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    transition: transform 0.1s, background 0.1s;
}

.kb-key:active {
    transform: scale(0.95) translateY(2px);
    box-shadow: 0 2px 3px rgba(0,0,0,0.3);
}

.kb-key:hover {
    background: rgba(255, 255, 255, 0.3);
}

.kb-backspace {
    width: 65px;
    background: #f72585;
}

.kb-space {
    width: 220px;
}

/* Animations */
@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.modal-content {
    transform: none !important;
    animation: popInModal 0.3s ease-out forwards;
}

@keyframes popInModal {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
