/* --- RESET & BASIC SETUP --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

body {
    background-color: #111;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

canvas { display: block; }

/* --- IN-GAME UI LAYER --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#score-board {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 24px;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 0 #000;
}

#instruction-panel {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 30px;
    border-radius: 20px;
    border: 2px solid #4CAF50;
    min-width: 200px;
}

#lesson-name { 
    font-size: 14px; 
    text-transform: uppercase; 
    color: #aaa; 
    margin-bottom: 5px;
}

#instruction-text { 
    font-size: 24px; 
    font-weight: bold; 
    color: #4CAF50; 
}

#minimap-hint { 
    position: absolute; 
    bottom: 20px; 
    right: 20px; 
    color: rgba(255,255,255,0.4); 
    font-size: 0.9rem;
}

/* --- MENU OVERLAY --- */
#menu-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
}

.menu-box {
    background: #222;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    border: 2px solid #3498db;
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.4);
    min-width: 320px;
    position: relative;
}

.menu-box h1 { 
    color: white; 
    margin-bottom: 20px; 
}

.menu-box label { 
    display: block; 
    color: #aaa; 
    margin-bottom: 10px; 
    text-align: left; 
}

/* Input Styling */
#nickname-input {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    font-size: 16px;
    background: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 5px;
    text-align: center;
}

/* Game Selection Area */
#game-selection-container {
    margin-bottom: 20px;
    text-align: left;
}

.select-row {
    display: flex;
    gap: 10px;
}

#lesson-select {
    flex-grow: 1;
    padding: 10px;
    font-size: 16px;
    background: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 5px;
    cursor: pointer;
}

/* Copy Link Button */
#btn-copy-link {
    background: #333;
    border: 1px solid #555;
    color: #ccc;
    width: 44px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#btn-copy-link:hover { 
    background: #444; 
    color: white; 
    border-color: #777; 
}

#btn-copy-link:active { 
    transform: translateY(1px); 
}

/* Play Button */
#btn-start {
    width: 100%;
    padding: 15px;
    font-size: 20px;
    font-weight: bold;
    color: white;
    background: #3498db;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s;
}

#btn-start:hover { 
    background: #2980b9; 
}

/* Flag Picker */
#flag-picker {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
}

.flag-btn {
    background: #333;
    border: 2px solid #555;
    border-radius: 8px;
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flag-btn .fi { 
    font-size: 24px; 
    border-radius: 2px; 
}

.flag-btn:hover { 
    background: #444; 
    transform: translateY(-2px); 
    border-color: #777; 
}

.flag-btn.active { 
    border-color: #4CAF50; 
    background: #222; 
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.4); 
}

/* --- FOOTER LINKS --- */

/* 1. Dashboard Link (Bottom Left) */
.link-dashboard {
    position: absolute;
    bottom: 20px;
    left: 20px;
    color: #666;
    font-size: 0.9rem;
    text-decoration: none;
    border-bottom: 1px dotted #666;
    transition: 0.2s;
    z-index: 30; /* Ensure clickable */
}

.link-dashboard:hover { 
    color: #2196F3; 
    border-color: #2196F3; 
}

/* 2. Credits Box (Bottom Right Container) */
#credits-box {
    position: absolute;
    bottom: 15px;
    right: 20px;
    text-align: right;
    max-width: 350px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    line-height: 1.4;
}

#credits-box p { 
    margin: 5px 0; 
}

.ai-note { 
    font-style: italic; 
    opacity: 0.8; 
    margin-top: 8px; 
    font-size: 0.8rem; 
}

/* 3. Info Link (Inside Credits Box) */
.link-info {
    color: #4CAF50; /* Green */
    text-decoration: none;
    font-size: 0.8rem;
    border-bottom: 1px dotted #4CAF50;
    transition: 0.2s;
    display: inline-block;
    margin-top: 5px;
}

.link-info:hover { 
    color: #81C784; 
    border-bottom-style: solid; 
}

/* --- MOBILE TOUCH CONTROLS --- */
#touch-layer {
    display: none; /* Hidden by default on desktop */
    position: absolute;
    top: 0; 
    left: 0;
    width: 100%; 
    height: 100%;
    z-index: 5; /* Above canvas (0), below UI (10) and Menu (20) */
    pointer-events: none; /* Let clicks pass through generally */
}

.touch-zone {
    position: absolute;
    bottom: 0;
    height: 50%; /* Occupy bottom half of screen */
    width: 50%;
    pointer-events: auto; /* Capture touches here */
    -webkit-tap-highlight-color: transparent; /* No blue flash on tap */
}

#touch-left { left: 0; }
#touch-right { right: 0; }

/* Only show touch layer if we detect mobile class */
body.is-mobile #touch-layer {
    display: block;
}

/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 600px) {
    /* Stack links on small screens to prevent overlap */
    #credits-box {
        position: relative; 
        bottom: auto; 
        right: auto;
        text-align: center; 
        margin-top: 30px;
        width: 100%;
    }

    .link-dashboard { 
        position: relative;
        bottom: auto;
        left: auto;
        display: block;
        text-align: center;
        margin-top: 20px;
        font-size: 0.8rem; 
    }
}