/* ===================================
   Memory Card Game - CSS Styles
   =================================== */

/* Progressive Enhancement:
   ซ่อนส่วนควบคุมเกมไว้ก่อน จะแสดงเมื่อ JS เพิ่ม class .game--ready */
.game-controls,
.game-board,
.game-win {
    display: none;
}

/* เมื่อ JS พร้อม จะเพิ่ม .game--ready ที่ body แล้วแสดงส่วนเหล่านี้ */
.game--ready .game-controls {
    display: block;
}

.game--ready .game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    max-width: 500px;
    margin: 0 auto 1.5rem;
}

/* กฎกติกา */
.game-rules {
    background-color: #f0f4f8;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid var(--accent-color);
}

.game-rules h3 {
    margin-top: 0;
    color: var(--secondary-color);
}

.game-rules ol {
    margin-bottom: 0;
    padding-left: 1.5rem;
}

.game-rules li {
    padding: 0.2rem 0;
}

/* Noscript: แจ้งเตือนเมื่อปิด JavaScript */
.game-noscript {
    background-color: #fff3cd;
    color: #856404;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    border: 1px solid #ffc107;
    margin-bottom: 1.5rem;
    text-align: center;
    font-weight: bold;
}

/* ส่วนควบคุม: สถิติ + ปุ่ม */
.game-controls {
    margin-bottom: 1.5rem;
    text-align: center;
}

.game-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.game-stats__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    background: #f0f4f8;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    min-width: 100px;
}

.game-stats__label {
    font-size: 0.85rem;
    color: var(--text-light);
}

.game-stats__value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* ปุ่มเกม */
.game-btn {
    background-color: var(--primary-color);
    color: var(--bg-white);
    border: none;
    padding: 0.85rem 2rem;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.15s ease;
}

.game-btn:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
}

.game-btn:active {
    transform: translateY(0);
}

/* กระดานเกม: CSS Grid 4x4 */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    max-width: 500px;
    margin: 0 auto 1.5rem;
}

/* === การ์ด: Flip Animation === */
.game-card {
    aspect-ratio: 1;
    perspective: 600px;
    cursor: pointer;
}

.game-card__inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
}

/* เมื่อการ์ดถูกเปิด */
.game-card--flipped .game-card__inner {
    transform: rotateY(180deg);
}

/* หน้า/หลังการ์ด */
.game-card__front,
.game-card__back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    user-select: none;
}

/* หลังการ์ด (แสดงตอนยังไม่เปิด) */
.game-card__back {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--bg-white);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

/* หน้าการ์ด (แสดง Emoji ตอนเปิด) */
.game-card__front {
    background-color: var(--bg-white);
    border: 2px solid var(--accent-color);
    transform: rotateY(180deg);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}

/* เมื่อจับคู่สำเร็จ */
.game-card--matched .game-card__front {
    background-color: #d4edda;
    border-color: #28a745;
}

.game-card--matched {
    cursor: default;
}

/* Disable ขณะตรวจสอบ */
.game-board--locked .game-card {
    pointer-events: none;
}

/* ข้อความชนะ */
.game-win {
    text-align: center;
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    padding: 2rem;
    border-radius: 12px;
    margin-top: 1rem;
}

.game-win__title {
    font-size: 2rem;
    margin-top: 0;
    color: #155724;
}

.game-win__text {
    font-size: 1.1rem;
    color: #155724;
    margin-bottom: 1.5rem;
}

/* =============================================
   Responsive Design - Game Page
   ============================================= */

/* --- Tablet (max-width: 768px) --- */
@media (max-width: 768px) {

    .game--ready .game-board {
        max-width: 400px;
        gap: 0.6rem;
    }

    .game-board {
        max-width: 400px;
        gap: 0.6rem;
    }

    .game-card__front,
    .game-card__back {
        font-size: 2rem;
    }

    .game-rules {
        padding: 1rem 1.25rem;
    }

    .game-rules li {
        font-size: 0.9rem;
    }
}

/* --- มือถือเล็ก (max-width: 480px) --- */
@media (max-width: 480px) {

    .game--ready .game-board {
        max-width: 300px;
        gap: 0.4rem;
    }

    .game-board {
        max-width: 300px;
        gap: 0.4rem;
    }

    .game-card__front,
    .game-card__back {
        font-size: 1.6rem;
        border-radius: 6px;
    }

    .game-card {
        perspective: 400px;
    }

    /* สถิติ */
    .game-stats {
        gap: 0.5rem;
    }

    .game-stats__item {
        padding: 0.4rem 0.6rem;
        min-width: 70px;
    }

    .game-stats__label {
        font-size: 0.75rem;
    }

    .game-stats__value {
        font-size: 1.1rem;
    }

    /* ปุ่ม: เต็มความกว้าง */
    .game-btn {
        width: 100%;
        padding: 0.7rem 1.5rem;
        font-size: 1rem;
    }

    /* กฎกติกา */
    .game-rules {
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
    }

    .game-rules h3 {
        font-size: 1rem;
    }

    /* หน้าจอชนะ */
    .game-win {
        padding: 1.25rem;
    }

    .game-win__title {
        font-size: 1.5rem;
    }

    .game-win__text {
        font-size: 0.95rem;
    }
}