/* =========================================
   1. ZÁKLADNÍ NASTAVENÍ A RESET
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

body, html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #111;
    color: #ccc;
    font-family: 'Press Start 2P', cursive; 
    touch-action: none;
    user-select: none;
    line-height: 1.5;
}

/* =========================================
   2. HLAVNÍ LAYOUT (FLEXBOX) - VYCENTROVÁNÍ
   ========================================= */
#appLayout {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center; /* Vodorovně */
    background: #111;
}

/* HERNÍ KONTEJNER */
#gameContainer {
    flex: 0 0 auto; /* Nepružný, drží si svůj poměr stran */
    position: relative;
    aspect-ratio: 3 / 2;
    height: 100%; 
    max-width: 100%;
    background: #000;
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
    overflow: hidden;
    border: 4px solid #333; 
    box-sizing: border-box;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
}

/* =========================================
   3. UI PRVKY HRY
   ========================================= */

/* Horní lišta (Skóre a Čas) */
#ui-hud {
    position: absolute;
    top: 0; left: 0; width: 100%;
    padding: 20px;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    align-items: start;
    font-size: 16px; 
    pointer-events: none;
    text-shadow: 2px 2px 0 #000;
    color: #fff;
    z-index: 50;
}

#scoreDisplay { 
    justify-self: start; 
    grid-column: 1; 
}
#timeDisplay { 
    justify-self: center; 
    grid-column: 2;
    color: #ff0; 
}

/* Notifikace (Kafe, Bonusy) */
.notification {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ff0;
    font-size: 24px; 
    text-shadow: 4px 4px 0 #000;
    opacity: 0;
    transition: opacity 0.5s;
    z-index: 60;
    pointer-events: none;
    text-align: center;
    width: 100%;
    line-height: 1.5;
}

/* Tlačítka vpravo nahoře */
.top-controls {
    position: absolute; 
    top: 15px; 
    right: 15px;
    display: flex; 
    gap: 15px; 
    z-index: 200;
}

.top-controls button {
    background: #000;
    border: 4px solid #ccc;
    color: #ccc;
    font-family: 'Press Start 2P', cursive; 
    font-size: 10px;
    line-height: 1;
    width: 50px; 
    height: 50px;
    border-radius: 0;
    cursor: pointer;
    display: flex; 
    align-items: center; 
    justify-content: center;
    box-shadow: 6px 6px 0px #000; 
    transition: transform 0.1s, box-shadow 0.1s;
}

.top-controls button:hover {
    background: #222;
    border-color: #fff;
    color: #ff0;
    transform: translate(-1px, -1px);
    box-shadow: 8px 8px 0px #000;
}

.top-controls button:active {
    transform: translate(4px, 4px);
    box-shadow: 2px 2px 0px #000;
    border-color: #555;
    color: #aaa;
}

/* Overlay (Menu, Win, Fail) */
.overlay {
    position: absolute; 
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    text-align: center;
    z-index: 100;
}

/* Styl pro finální skóre na Win obrazovce */
.final-score {
    font-size: 20px;
    color: #fff;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 #000;
}

/* 8-bit Nadpisy */
h1 { 
    font-size: 30px;
    color: #fff; 
    text-shadow: 4px 4px 0 #d00; 
    margin-bottom: 20px; 
    letter-spacing: 2px;
    line-height: 1.4;
}
h2 { font-size: 14px; color: #888; margin-bottom: 20px; }
h3 { color: #aaa; margin-top: 20px; margin-bottom: 10px; font-size: 12px; }

/* Manuál Box */
.manual-box {
    border: 2px dashed #555;
    padding: 15px;
    margin-bottom: 15px;
    background: #111;
    width: 80%;
    max-width: 600px;
}
.manual-box p {
    margin: 5px 0;
    font-size: 10px;
    color: #ccc;
    text-align: left;
}
.blink-text {
    animation: blinker 1.5s linear infinite;
    text-align: center !important;
    margin-top: 10px !important;
}
@keyframes blinker { 50% { opacity: 0; } }

/* Tlačítka Menu */
.btn-group { display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; justify-content: center;}

.btn {
    background: #222; color: #fff; 
    border: 2px solid #555;
    padding: 10px 15px; 
    font-size: 10px; 
    font-family: inherit;
    cursor: pointer; 
    text-transform: uppercase; 
    border-radius: 0;
    box-shadow: 3px 3px 0 #000;
}
.btn:hover { 
    background: #fff; color: #000; border-color: #fff; 
    box-shadow: 1px 1px 0 #000; transform: translate(2px, 2px);
}
.btn.selected { 
    background: #fff; color: #000; border-color: #fff; 
    box-shadow: 0 0 10px #fff; 
}

.start-btn {
    padding: 15px 30px; font-size: 14px; border: 4px solid #fff;
    margin-top: 10px; background: #000;
    animation: pulse 2s infinite;
}
.start-btn:hover { background: #d00; border-color: #f00; color: #fff; animation: none; }

@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* =========================================
   LEADERBOARD - TOP 6 & 3 SLOUPCE
   ========================================= */
#leaderboard {
    margin-top: 10px;
    border: 4px solid #444; 
    background: #000;
    width: 95%; 
    max-width: 650px; 
    padding: 5px;
    height: auto;
    min-height: 140px; /* Zvětšeno pro 6 řádků */
}

#lb-content {
    display: flex;
    flex-direction: row; 
    justify-content: space-around;
    align-items: flex-start;
    width: 100%;
    height: 100%;
}

.lb-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-right: 2px dashed #333; 
}

.lb-column:last-child {
    border-right: none;
}

.lb-cat-title {
    color: #ff0;
    font-weight: bold;
    font-size: 12px;
    text-transform: uppercase;
    border-bottom: 2px solid #ff0;
    margin-bottom: 8px;
    padding-bottom: 4px;
    width: 90%;
    text-align: center;
}

.lb-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1px 8px; /* Menší padding do stran */
    box-sizing: border-box;
    font-size: 10px;
    line-height: 1.4;
    color: #fff;
}

.lb-name { color: #fff; text-align: left; }
.lb-score { color: #0f0; text-align: right; font-weight: bold; }
.empty { color: #555; justify-content: center; }

/* Datum bude šedivé a malé (pro Síň slávy) */
.lb-date {
    font-family: monospace; 
}

/* Input */
#nameInputContainer { display: none; flex-direction: column; align-items: center; }
#playerNameInput { 
    background: #000; border: 2px solid #0f0; color: #0f0; 
    font-family: inherit; font-size: 20px; text-align: center; 
    width: 200px; padding: 10px; margin-bottom: 20px;
    border-radius: 0; outline: none;
}

/* Podpis autorů */
.credits {
    position: absolute;
    bottom: 5px;
    width: 100%;
    text-align: center;
    font-size: 8px;
    color: #444;
    font-family: 'Press Start 2P', cursive;
    pointer-events: none;
}

/* =========================================
   4. MOBILNÍ PRVKY - CENTROVÁNÍ A JOYSTICK
   ========================================= */
#rotateMessage {
    display: none; 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #000; color: #fff; 
    z-index: 2000;
    align-items: center; justify-content: center; text-align: center;
    flex-direction: column;
}
#rotateMessage h1 { font-size: 20px; line-height: 1.5; padding: 20px; }

/* OPRAVA CENTROVÁNÍ HRY: flex:1 zajistí rovnoměrné rozložení */
.mobile-zone {
    display: none; 
    flex: 1; 
    height: 100%;
    align-items: center; justify-content: center;
    background: #111; 
    z-index: 50; position: relative;
    touch-action: none; /* Důležité pro joystick */
}

/* Styly mobilních tlačítek */
.ctrl-btn {
    background: #222;
    border: 4px solid #555;
    color: #fff; font-size: 24px;
    width: 60px; height: 60px; 
    border-radius: 0;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
    box-shadow: 4px 4px 0 #000;
}
.ctrl-btn:active, .ctrl-btn.active {
    background: #444; border-color: #888;
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #000;
}
.big-btn {
    width: 100px; height: 100px; font-size: 14px; 
    background: #004400; border-color: #008800;
}
.big-btn:active, .big-btn.active { background: #006600; }

/* --- PLOVOUCÍ JOYSTICK (Starý dobrý, co se objeví pod prstem) --- */
#joystick-base {
    position: absolute;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.1); 
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%; 
    display: none; /* Skrytý, dokud nesáhneš */
    pointer-events: none; 
    z-index: 10;
}

#joystick-stick {
    position: absolute;
    width: 40px;
    height: 40px;
    background: rgba(0, 255, 0, 0.5); 
    border-radius: 50%;
    display: none;
    pointer-events: none;
    z-index: 11;
    box-shadow: 0 0 10px #0f0;
}

/* =========================================
   5. MEDIA QUERIES (RESPONZIVITA)
   ========================================= */

/* PC s myší (skryjeme mobilní zóny) */
@media (hover: hover) and (pointer: fine) {
    .mobile-zone { display: none !important; }
}

/* Portrait mód (mobil na výšku) */
@media screen and (orientation: portrait) {
    #appLayout { display: none !important; }
    #rotateMessage { display: flex !important; }
}

/* Landscape + Dotyk + Žádná myš (MOBIL/TABLET VE HŘE) */
@media screen and (orientation: landscape) and (pointer: coarse) {
    
    /* 1. Zobrazíme ovládání */
    .mobile-zone { display: flex !important; }
    
    /* 2. Zmenšíme HUD a odstraníme stíny */
    #ui-hud { font-size: 10px; padding: 5px; }
    #gameContainer { box-shadow: none; border: none; }
    
    /* 3. Texty a tlačítka */
    h1 { font-size: 16px; margin-bottom: 5px; margin-top: 5px; }
    .manual-box { display: none; } /* Návod pryč */
    .btn { font-size: 8px; padding: 6px 10px; }
    .start-btn { font-size: 10px; padding: 8px 15px; margin-top: 5px; }
    .btn-group { margin-bottom: 5px; gap: 5px; }
    .final-score { font-size: 12px; margin-bottom: 5px; }

    /* 4. Fix pro horní ovládací tlačítka (zvuk) */
    .top-controls {
        position: fixed; 
        top: 20px;
        right: 20px;
        display: flex;
        flex-direction: row;
        gap: 15px;
        z-index: 1000;
    }
    .top-controls button {
        width: 40px; 
        height: 40px;
        font-size: 8px;
    }
    .overlay h1 { font-size: 20px; margin-bottom: 10px; }
    
    /* 5. AGRESIVNÍ ZMENŠENÍ ŽEBŘÍČKU */
    #leaderboard {
        margin-top: 2px;
        padding: 2px;
        border-width: 2px;
        
        /* Zde je 110px podle tvého přání */
        min-height: 0 !important;   
        height: auto !important;    
        max-height: 110px !important; 
        
        overflow-y: auto; 
        width: 85%;       
    }

    /* Zmenšení obsahu žebříčku */
    .lb-cat-title {
        font-size: 7px;
        margin-bottom: 1px;
        padding-bottom: 1px;
        border-bottom-width: 1px;
    }
    
    .lb-row {
        font-size: 6px; 
        padding: 0 2px;
        line-height: 1.2;
        min-height: 10px; 
    }
}