:root {
    --primary-color: #f7a944;
    --bg-color: #f9f6ef;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-drag: none;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.bg-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('assets/images/backgrounds/bg_main.png');
    background-size: cover;
    background-position: center;
    z-index: -1;
    opacity: 0.8;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

/* UI Controls */
.ui-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    z-index: 100;
}

.hidden {
    display: none !important;
}

.ui-btn {
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
}

.ui-btn:active {
    transform: scale(0.9);
}

.ui-btn img {
    width: 60px;
    height: 60px;
    filter: drop-shadow(0px 4px 6px rgba(0,0,0,0.2));
}

/* Start & Unit Screen */
.title-img {
    max-width: 80%;
    width: 600px;
    margin-bottom: 20px;
    animation: floating 3s ease-in-out infinite;
}

.cover-img {
    max-width: 70%;
    width: 400px;
    margin-bottom: 30px;
}

.unit-title {
    color: var(--primary-color);
    font-size: 2.2rem;
    background: white;
    padding: 10px 40px;
    border-radius: 30px;
    border: 4px solid var(--primary-color);
    font-weight: bold;
    margin-bottom: 20px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.unit-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 80%;
    max-width: 350px;
}

.btn-unit {
    background-color: white;
    border: 4px solid var(--primary-color);
    border-radius: 20px;
    padding: 12px 20px;
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.btn-unit:hover {
    background-color: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.btn-unit:active {
    transform: scale(0.95);
}

.btn-primary {
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
}

.btn-primary:active {
    transform: scale(0.95);
}

.btn-primary img {
    height: 80px;
    filter: drop-shadow(0px 6px 8px rgba(0,0,0,0.3));
}

/* Game Screen */
.game-board {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 90%;
    max-width: 1000px;
    align-items: center;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    width: 100%;
    justify-items: center;
}

.game-progress {
    position: fixed;
    right: 24px;
    bottom: 24px;
    min-width: 104px;
    padding: 12px 18px;
    border: 4px solid #fff;
    border-radius: 24px;
    background: rgba(247, 169, 68, 0.94);
    color: #fff;
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1;
    text-align: center;
    box-shadow: 0 6px 12px rgba(0,0,0,0.22);
}

/* Cards */
.card {
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 160px;
    perspective: 1000px;
    cursor: pointer;
    animation: dealCard 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes dealCard {
    0% { transform: translateY(-100vh) rotate(-10deg); opacity: 0; }
    70% { transform: translateY(15px) rotate(3deg); opacity: 1; }
    100% { transform: translateY(0) rotate(0); opacity: 1; }
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
}

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

.card.matched {
    cursor: default;
}

.card.matched[data-type="audio"] {
    cursor: pointer;
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.card-back {
    background-image: url('assets/images/cards_memory/card_back.png');
    background-size: cover;
    background-position: center;
    border: 4px solid white;
}

.card-front {
    background-color: white;
    transform: rotateY(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid white;
}

.card-front img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.card-front.audio-card img {
    object-fit: contain;
}

.card-front.audio-card {
    position: relative;
}

.card-front.audio-card .audio-answer-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.card-front.audio-card .audio-overlay-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 1;
    object-fit: contain;
    pointer-events: none;
}

@media (max-width: 768px) {
    :root {
        --mobile-card-size: min(42vw, calc((100vh - 150px) / 5));
        --mobile-card-gap: 8px;
    }
    @supports (height: 100svh) {
        :root {
            --mobile-card-size: min(42vw, calc((100svh - 150px) / 5));
        }
    }
    .game-board {
        width: 100%;
        max-height: none;
        padding: 54px 10px 46px;
        overflow: visible;
    }
    .card-grid {
        grid-template-columns: repeat(2, var(--mobile-card-size));
        grid-auto-rows: var(--mobile-card-size);
        justify-content: center;
        align-content: center;
        gap: var(--mobile-card-gap);
        width: auto;
    }
    .card {
        width: var(--mobile-card-size);
        max-width: none;
    }
    .card-grid.level-one-layout .card:nth-child(1) { grid-column: 1; grid-row: 1; }
    .card-grid.level-one-layout .card:nth-child(2) { grid-column: 1; grid-row: 2; }
    .card-grid.level-one-layout .card:nth-child(3) { grid-column: 1; grid-row: 3; }
    .card-grid.level-one-layout .card:nth-child(4) { grid-column: 1; grid-row: 4; }
    .card-grid.level-one-layout .card:nth-child(5) { grid-column: 1; grid-row: 5; }
    .card-grid.level-one-layout .card:nth-child(6) { grid-column: 2; grid-row: 1; }
    .card-grid.level-one-layout .card:nth-child(7) { grid-column: 2; grid-row: 2; }
    .card-grid.level-one-layout .card:nth-child(8) { grid-column: 2; grid-row: 3; }
    .card-grid.level-one-layout .card:nth-child(9) { grid-column: 2; grid-row: 4; }
    .card-grid.level-one-layout .card:nth-child(10) { grid-column: 2; grid-row: 5; }
    .game-progress {
        top: 14px;
        right: auto;
        bottom: auto;
        left: 14px;
        min-width: 82px;
        padding: 9px 13px;
        border-width: 3px;
        border-radius: 18px;
        font-size: 1.35rem;
    }
    .ui-btn img { width: 45px; height: 45px; }
    .btn-primary img { height: 60px; }
}

/* Success Screen */
.success-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    animation: popIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.success-img {
    max-width: 80%;
    width: 600px;
    transform-origin: center;
    animation: wobbleContinuous 3s ease-in-out infinite;
}

@keyframes wobbleContinuous {
    0% { transform: rotate(-4deg) translateY(0); }
    50% { transform: rotate(4deg) translateY(-15px); }
    100% { transform: rotate(-4deg) translateY(0); }
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-content h2 { margin-bottom: 15px; color: #555; }
.modal-content p { margin-bottom: 10px; color: #666; text-align: left; line-height: 1.5; }
.mobile-rule { display: none; }

@media (max-width: 768px) {
    .desktop-rule { display: none; }
    .mobile-rule { display: block; }
}

.btn-text {
    margin-top: 20px;
    padding: 10px 30px;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 1.1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
}

/* Animations */
@keyframes floating {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

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