:root {
    --bg: #e0f7fa;
    --pink: #ff4081;
    --blue: #29b6f6;
    --yellow: #ffee58;
    --green: #66bb6a;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Arial Rounded MT Bold', sans-serif;
    background: var(--bg);
    touch-action: none;
    user-select: none;
}

/* Obří Tlačítko Zpět pro děti */
.btn-home {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 4000;
    background: white;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    text-decoration: none;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
    border: 4px solid var(--blue);
    font-size: 3rem;
}

.btn-home:active {
    background: #f0f0f0;
    transform: scale(0.9);
}

/* Horní lišta */
#ui-layer {
    position: fixed;
    top: 0;
    width: 100%;
    height: 160px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 15px 40px;
    box-sizing: border-box;
    z-index: 1000;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    border-bottom: 5px solid var(--blue);
}

.ui-btn {
    position: absolute;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    border: none;
    font-size: 3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.15);
}

.ui-btn:active {
    transform: translateY(8px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

#btn-restart {
    left: 130px;
    top: 30px;
    background: var(--pink);
    color: white;
}

#stats {
    text-align: right;
    font-weight: bold;
    color: #666;
    margin-right: 20px;
}

#score-val {
    color: #ff9800;
    font-size: 3rem;
    display: block;
}

/* Herní plocha - CSS Grid pro karty */
#game-area {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 160px;
    box-sizing: border-box;
}

.memory-board {
    display: grid;
    /* 4 sloupce, 3 řádky pro 12 karet */
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 20px;
    padding: 20px;
    max-width: 900px;
    width: 100%;
}

/* Karta */
.memory-card {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    perspective: 1000px;
    cursor: pointer;
}

.memory-card-inner {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
}

.memory-card.flipped .memory-card-inner {
    transform: rotateY(180deg);
}

.memory-card.matched .memory-card-inner {
    transform: rotateY(180deg);
}

.memory-card.matched .memory-card-front {
    border-color: var(--green);
    box-shadow: 0 0 15px rgba(102, 187, 106, 0.4);
}

/* Líc a rub karty */
.memory-card-front,
.memory-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
    line-height: 1;
    margin: 0;
    padding: 0;
}

.memory-card-front {
    background: white;
    transform: rotateY(180deg);
    border: 5px solid white;
}

.memory-card-back {
    background: linear-gradient(135deg, var(--blue), #00b0ff);
    color: white;
    font-size: 4rem;
    border: 5px solid white;
}

/* Konfety */
.confetti {
    position: absolute;
    pointer-events: none;
    z-index: 3000;
    animation: confettiFly 1s ease-out forwards;
}

@keyframes confettiFly {
    0% {
        transform: translate(0, 0) rotate(0);
        opacity: 1;
    }

    100% {
        transform: translate(var(--dx), var(--dy)) rotate(360deg);
        opacity: 0;
    }
}

.screen {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.btn-start {
    padding: 30px 80px;
    font-size: 3rem;
    background: var(--pink);
    color: white;
    border: none;
    border-radius: 100px;
    cursor: pointer;
    box-shadow: 0 10px 0 #ad1457;
    transition: transform 0.1s;
}

.btn-start:active {
    transform: translateY(10px);
    box-shadow: 0 0 0;
}

@media (max-width: 600px) {
    .memory-board {
        grid-gap: 10px;
        padding: 10px;
    }

    .memory-card-front,
    .memory-card-back {
        border-radius: 15px;
        font-size: 3.5rem;
        border-width: 3px;
    }
}

/* FIX PRO V2 VYGENEROVANÉ OBRÁZKY (Zaoblené čtverce namísto kruhů) */
.btn-home {
    border-radius: 20px !important;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1) !important;
    border: 4px solid var(--blue, #2196f3) !important;
}

.btn-home img {
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    border-radius: 16px !important;
}

#btn-restart {
    width: 90px;
    height: 90px;
    background: transparent !important;
    padding: 0;
    border: none;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1) !important;
    border-radius: 20px !important;
    overflow: hidden;
}

#btn-restart img {
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    border-radius: 20px !important;
}

.btn-start {
    width: 200px;
    height: 200px;
    background: transparent !important;
    padding: 0 !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    border-radius: 40px !important;
    overflow: hidden;
}

.btn-start img {
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    border-radius: 40px !important;
}

/* OPRAVA CENTROVÁNÍ MODÁLNÍCH OKEN START/KONEC */
.overlay-modal {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.modal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    text-align: center;
}

/* --- UNIFIED GAME HEADER V2 --- */
.game-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 40px;
    box-sizing: border-box;
    z-index: 4000;
    pointer-events: none;
}

.game-header>* {
    pointer-events: auto;
}

.game-header .score-display,
.game-header #stats {
    font-size: 3rem;
    font-weight: bold;
    color: #ff9800;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    text-align: center;
    flex-grow: 1;
    margin: 0;
    padding: 0;
    position: static !important;
}

.game-header .btn-home {
    margin-right: auto;
    position: static !important;
}

.game-header .btn-restart {
    margin-left: auto;
    position: static !important;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    margin-top: 0 !important;
}