* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
body, html { width: 100%; height: 100%; overflow: hidden; background: #5B9BD5; font-family: 'Roboto', sans-serif; }

#gameCanvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
.hidden { display: none !important; }
#ui-layer { position: absolute; inset: 0; z-index: 10; pointer-events: none; }

/* =====================================
   DESKTOP LAYOUT
===================================== */

/* --- MINI MAP --- */
#minimap {
    position: absolute; bottom: 175px; left: 25px; z-index: 30; width: 200px; height: 65px;
    border: 3px solid #D4AF37; border-radius: 10px;
    background: rgba(0,0,0,0.65); box-shadow: 0 0 20px rgba(212,175,55,0.5);
}

/* --- TOP HUD --- */
#top-hud {
    position: absolute; top: 15px; left: 0; width: 100%;
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 0 20px; gap: 12px; pointer-events: none;
}
.hud-pill {
    background: rgba(245,240,232,0.97); border: 2px solid #C2A060;
    border-radius: 30px; padding: 10px 20px; display: flex; align-items: center;
    gap: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.8);
    min-width: 155px; flex: 1;
}
.center-pill {
    flex: 1.3; justify-content: center;
    background: rgba(20,15,0,0.92); border-color: #D4AF37; border-width: 3px;
    box-shadow: 0 0 25px rgba(212,175,55,0.5), 0 4px 20px rgba(0,0,0,0.6);
}
.pill-label { font-family: 'Cinzel', serif; font-size: 10px; letter-spacing: 2px; color: #888; text-transform: uppercase; }
.pill-value { font-family: 'Roboto', sans-serif; font-size: 20px; font-weight: 700; color: #111; }
.timer-gold { font-size: 36px; color: #D4AF37; text-shadow: 0 0 12px rgba(212,175,55,0.6); font-family: 'Cinzel', serif; }
.timer-inner .pill-label { color: #aaa; }
.pos-value { font-size: 28px; color: #CC0000; font-family: 'Cinzel', serif; }
.pill-icon { font-size: 22px; }

/* --- TAP GUIDE --- */
#tap-guide {
    position: absolute; top: 115px; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 14px; white-space: nowrap;
    background: rgba(0,0,0,0.75); border: 2px solid #D4AF37;
    border-radius: 30px; padding: 8px 22px;
    font-family: 'Cinzel', serif; color: #fff; font-size: 15px;
    box-shadow: 0 0 20px rgba(212,175,55,0.4); pointer-events: none;
}
.guide-btn { font-size: 18px; font-weight: bold; transition: color 0.1s; color: #555; }
.guide-btn.active-tap { color: #FFD700; text-shadow: 0 0 12px #FFD700; }
#guide-center { color: #ccc; font-size: 13px; letter-spacing: 1px; }

/* --- LEADERBOARD --- */
#leaderboard-panel {
    position: absolute; top: 110px; right: 20px;
    background: rgba(245,240,232,0.97); border: 2px solid #C2A060;
    border-radius: 12px; padding: 14px; width: 220px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.4); pointer-events: none;
}
.panel-header {
    font-family: 'Cinzel', serif; font-size: 14px; font-weight: 700;
    text-align: center; border-bottom: 2px solid #C2A060;
    padding-bottom: 8px; margin-bottom: 10px; color: #333; letter-spacing: 1px;
}
#leaderboard-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.lb-item {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 600; padding: 5px 7px;
    border-radius: 6px; background: rgba(0,0,0,0.04);
}
.lb-item.player-row { background: rgba(212,175,55,0.25); border: 1px solid #D4AF37; }
.lb-rank { font-family: 'Cinzel', serif; font-size: 12px; color: #888; min-width: 20px; }
.lb-color-dot { width: 11px; height: 11px; border-radius: 50%; border: 2px solid rgba(0,0,0,0.25); flex-shrink: 0; }
.lb-name { flex-grow: 1; font-size: 12px; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-time { font-family: 'Cinzel', serif; font-size: 11px; color: #666; }
.lb-medal { font-size: 13px; }

/* --- COUNTDOWN --- */
#countdown-overlay {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    justify-content: center; align-items: center; background: rgba(0,0,0,0.5);
    pointer-events: none; z-index: 40;
}
#countdown-text {
    font-family: 'Cinzel', serif; font-size: 140px; font-weight: 900;
    color: #FFD700; text-shadow: 0 0 40px rgba(255,215,0,0.6), 4px 4px 0 #000;
    animation: countPulse 0.8s ease-in-out;
}
#countdown-sub { font-family: 'Cinzel', serif; font-size: 22px; color: #fff; letter-spacing: 4px; margin-top: -20px; }
@keyframes countPulse { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.2); } 100% { transform: scale(1); opacity: 1; } }

/* --- MOBILE CONTROLS (Desktop default) --- */
#mobile-controls {
    position: absolute; bottom: 30px; left: 0; width: 100%;
    display: flex; align-items: center; justify-content: center;
    gap: 20px; padding: 0 20px; pointer-events: auto;
}
.run-btn {
    width: 95px; height: 95px; border-radius: 50%; border: none;
    background: radial-gradient(circle at 35% 35%, #FFF8E7, #D4AF37);
    box-shadow: 0 8px 0 #8B6914, 0 14px 20px rgba(0,0,0,0.4);
    font-family: 'Cinzel', serif; font-size: 24px; font-weight: 900;
    color: #3a2000; cursor: pointer; transition: transform 0.08s, box-shadow 0.08s;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.run-btn small { font-size: 11px; font-family: 'Roboto', sans-serif; letter-spacing: 1px; }
.run-btn:active { transform: translateY(8px); box-shadow: 0 0 0 #8B6914, 0 4px 10px rgba(0,0,0,0.4); }
.run-btn.lit { box-shadow: 0 8px 0 #8B6914, 0 0 35px rgba(255,215,0,0.9), 0 14px 20px rgba(0,0,0,0.4); }

#speed-gauge { display: flex; flex-direction: column; align-items: center; gap: 5px; flex-grow: 1; max-width: 260px; }
.gauge-label { font-family: 'Cinzel', serif; font-size: 14px; font-weight: 700; color: #FFF; text-shadow: 1px 1px 3px #000; }
.gauge-track { width: 100%; height: 24px; background: rgba(0,0,0,0.65); border: 3px solid #D4AF37; border-radius: 12px; overflow: hidden; }
.gauge-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #00ff88, #FFD700, #FF4444); border-radius: 12px; transition: width 0.1s; }
#speed-val { font-size: 12px; color: #FFD700; font-weight: bold; }

/* =====================================
   MENUS
===================================== */
#start-menu, #ceremony-overlay {
    position: absolute; inset: 0; z-index: 200; pointer-events: auto;
}
.menu-overlay {
    width: 100%; height: 100%;
    background: linear-gradient(180deg, rgba(91,155,213,0.85) 0%, rgba(30,20,5,0.96) 100%);
    display: flex; justify-content: center; align-items: center; padding: 15px;
}
.menu-box {
    background: linear-gradient(135deg, #F5F0E8 0%, #E8DCC8 100%);
    border: 4px solid #C2A060; border-radius: 16px; padding: 30px;
    width: 100%; max-width: 540px; text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.8);
    max-height: 95vh; overflow-y: auto;
}
.olympic-rings { font-size: 36px; letter-spacing: 5px; margin-bottom: 8px; }
.greek-title {
    font-family: 'Cinzel', serif; font-size: clamp(24px, 5vw, 42px);
    font-weight: 900; text-transform: uppercase; color: #2a1a00;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.15); line-height: 1.2; margin-bottom: 6px;
}
.greek-title span { color: #C2A060; }
.subtitle { font-size: 15px; color: #666; margin: 8px 0 20px; font-style: italic; }

.nation-select { margin-bottom: 20px; }
.nation-select h3 { font-family: 'Cinzel', serif; font-size: 14px; color: #555; margin-bottom: 10px; letter-spacing: 2px; }
#nation-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.color-btn {
    height: 48px; border: 3px solid transparent; border-radius: 10px; cursor: pointer;
    transition: all 0.2s; box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    font-family: 'Cinzel', serif; font-size: 9px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; position: relative;
}
.color-btn::after { content: ''; position: absolute; inset: 0; border-radius: 7px; background: rgba(255,255,255,0.15); }
.color-btn.active { border-color: #FFD700; box-shadow: 0 0 20px #FFD700, 0 4px 10px rgba(0,0,0,0.3); transform: scale(1.08); }
.start-btn {
    width: 100%; padding: 15px; font-family: 'Cinzel', serif; font-size: 20px;
    font-weight: 700; background: linear-gradient(to bottom, #FFE566, #D4AF37);
    color: #2a1a00; border: 2px solid #FFF; border-radius: 8px; cursor: pointer;
    box-shadow: 0 6px 0 #8B6914, 0 10px 20px rgba(0,0,0,0.3); transition: 0.1s; letter-spacing: 1px;
}
.start-btn:active { transform: translateY(6px); box-shadow: 0 0 0 #8B6914; }
.controls-info { margin-top: 14px; font-size: 12px; color: #888; line-height: 1.9; }

/* Ceremony */
.ceremony-emoji { font-size: 58px; margin-bottom: 8px; }
.ceremony-stats { font-size: 15px; color: #555; margin: 8px 0 18px; }
#podium-row { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin-bottom: 20px; height: 90px; }
.podium-item {
    width: 75px; border-radius: 6px 6px 0 0; display: flex; flex-direction: column;
    align-items: center; justify-content: flex-start; padding-top: 6px;
    font-family: 'Cinzel', serif; font-size: 11px; font-weight: 700; color: #fff;
    text-shadow: 1px 1px 2px #000;
}

/* =====================================
   MOBILE RESPONSIVE — Max 768px
===================================== */
@media (max-width: 768px) {

    /* Minimap — bottom-left, above controls */
    #minimap {
        width: 130px; height: 42px;
        bottom: 130px; left: 10px;
        border-width: 2px;
    }

    /* --- TOP HUD: compact 3-pill strip --- */
    #top-hud {
        top: 8px; padding: 0 6px; gap: 5px;
    }
    .hud-pill {
        min-width: 0; padding: 5px 8px; gap: 6px; border-radius: 20px;
        border-width: 1.5px; flex: 1;
    }
    .center-pill { flex: 1.4; }
    .pill-label { font-size: 8px; letter-spacing: 1px; }
    .pill-value { font-size: 13px; }
    .timer-gold { font-size: 20px; }
    .pos-value { font-size: 16px; }
    .pill-icon { font-size: 14px; }

    /* --- TAP GUIDE: compact strip below HUD --- */
    #tap-guide {
        top: 78px; padding: 5px 12px; gap: 8px; font-size: 11px;
        border-width: 1.5px; border-radius: 20px;
        max-width: calc(100vw - 20px);
    }
    .guide-btn { font-size: 13px; }
    #guide-center { font-size: 10px; letter-spacing: 0.5px; }

    /* --- LEADERBOARD: compact right panel --- */
    #leaderboard-panel {
        top: 115px; right: 6px;
        width: 140px; padding: 8px; border-radius: 8px;
        border-width: 1.5px;
    }
    .panel-header { font-size: 11px; padding-bottom: 5px; margin-bottom: 7px; }
    #leaderboard-list { gap: 3px; }
    .lb-item { padding: 3px 5px; gap: 4px; font-size: 11px; border-radius: 4px; }
    .lb-rank { font-size: 10px; min-width: 16px; }
    .lb-color-dot { width: 9px; height: 9px; border-width: 1.5px; }
    .lb-name { font-size: 10px; }
    .lb-time { font-size: 9px; }
    .lb-medal { font-size: 11px; }

    /* --- COUNTDOWN --- */
    #countdown-text { font-size: 90px; }
    #countdown-sub { font-size: 16px; }

    /* --- MOBILE CONTROLS: fixed bottom strip --- */
    #mobile-controls {
        bottom: 18px; gap: 10px; padding: 0 10px;
    }
    .run-btn {
        width: 72px; height: 72px; font-size: 20px;
        box-shadow: 0 6px 0 #8B6914, 0 10px 15px rgba(0,0,0,0.4);
    }
    .run-btn:active { transform: translateY(6px); }
    .run-btn small { font-size: 8px; }
    .run-btn.lit { box-shadow: 0 6px 0 #8B6914, 0 0 25px rgba(255,215,0,0.9); }

    #speed-gauge { max-width: 180px; gap: 3px; }
    .gauge-label { font-size: 11px; }
    .gauge-track { height: 18px; border-width: 2px; }
    #speed-val { font-size: 10px; }

    /* Menus */
    .menu-box { padding: 20px 15px; border-width: 3px; border-radius: 12px; }
    .olympic-rings { font-size: 26px; }
    .subtitle { font-size: 13px; margin: 6px 0 16px; }
    #nation-grid { gap: 8px; }
    .color-btn { height: 42px; font-size: 8px; }
    .start-btn { padding: 13px; font-size: 17px; }
    .controls-info { font-size: 11px; }
    .ceremony-emoji { font-size: 44px; }
    #podium-row { height: 70px; gap: 8px; }
    .podium-item { width: 60px; font-size: 10px; }
}

/* Extra small — phones < 400px */
@media (max-width: 400px) {
    #top-hud { gap: 3px; padding: 0 4px; }
    .hud-pill { padding: 4px 6px; }
    .timer-gold { font-size: 17px; }

    #leaderboard-panel { width: 120px; right: 4px; }
    .lb-name { display: none; } /* too narrow — hide name, keep dot+rank+time */

    .run-btn { width: 62px; height: 62px; font-size: 18px; }
    #speed-gauge { max-width: 130px; }
}
