:root {
    --bg-color: #ffe6e6;
    --primary-color: #ff6b6b;
    --secondary-color: #4ecdc4;
    --text-color: #4a4a4a;
    --card-bg: #fff;
    --card-shadow: rgba(255, 107, 107, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-image: radial-gradient(#ffb6b9 3px, transparent 3px);
    background-size: 40px 40px;
}

.container {
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem 1rem;
    border-radius: 25px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
    text-align: center;
    max-width: 1400px;
    width: 98%;
    border: 5px solid #ffe6e6;
}

h1 {
    color: var(--primary-color);
    font-size: 2.8rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 0px #ffe6e6, 4px 4px 0px rgba(0,0,0,0.1);
    animation: wiggle 2s infinite ease-in-out;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-2deg); }
    50% { transform: rotate(2deg); }
}

.stats {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    font-weight: bold;
    align-items: center;
    color: #555;
    background: #fff0f0;
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px dashed #ffb6b9;
}

#moves, #matches {
    color: var(--primary-color);
    font-size: 1.8rem;
}

button {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.8rem 1.8rem;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 6px 0 #3b9b94, 0 6px 10px rgba(0,0,0,0.2);
}

button:hover {
    background-color: #45b7af;
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #3b9b94, 0 8px 15px rgba(0,0,0,0.2);
}

button:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #3b9b94, 0 2px 5px rgba(0,0,0,0.2);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    justify-content: center;
    gap: 15px;
    perspective: 1000px;
    padding: 10px;
}

.card {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
    border-radius: 16px;
}

.card:hover {
    box-shadow: 0 10px 20px var(--card-shadow);
    transform: scale(1.02);
}

.card.flip {
    transform: rotateY(180deg);
}

.card .front,
.card .back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px;
}

.card .front {
    background-color: var(--card-bg);
    transform: rotateY(180deg);
    border: 4px solid var(--secondary-color);
}

.card .front img {
    width: 65%;
    height: 65%;
    object-fit: contain;
    transition: transform 0.3s;
}

.card.flip:hover .front img {
    transform: scale(1.1) rotate(5deg);
}

.card.matched .front {
    border-color: #ffb6b9;
    box-shadow: inset 0 0 15px rgba(255, 182, 185, 0.5), 0 0 10px rgba(255, 182, 185, 0.4);
    background-color: #fff9f9;
}

.card.matched {
    cursor: default;
}

.card.matched:hover {
    transform: rotateY(180deg) scale(1.0);
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
}

.card .front span {
    margin-top: 8px;
    font-size: 1.1rem;
    font-weight: 900;
    color: var(--primary-color);
    text-align: center;
    line-height: 1.1;
}

.card.comparing .front {
    padding: 6px 4px;
}

.card.comparing .front img {
    width: 58%;
    height: 58%;
}

.card.comparing .front span {
    font-size: 1.5rem;
    margin-top: 6px;
    line-height: 1.15;
    white-space: nowrap;
}

.card .back {
    background-color: var(--primary-color);
    background-image: url('images/card_back_1773773419396.png');
    background-size: cover;
    background-position: center;
    border: 4px solid #fff;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}

@media (max-width: 768px) {
    h1 {
        font-size: 2.2rem;
    }
    .stats {
        flex-wrap: wrap;
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .game-board {
        gap: 8px;
    }
    .card .front {
        padding: 4px;
        border-width: 2px;
    }
    .card .front span {
        font-size: 0.7rem;
        margin-top: 2px;
    }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

#pause-modal {
    z-index: 2000;
}

.modal-content {
    background: white;
    padding: 3rem 2rem;
    border-radius: 30px;
    text-align: center;
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 8px solid var(--secondary-color);
    max-width: 90%;
}

.modal-content h2 {
    color: var(--primary-color);
    font-size: 3rem;
    margin-bottom: 1rem;
    text-shadow: 2px 2px 0px #ffe6e6;
}

.bounce {
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

.modal-content p {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    color: #555;
    line-height: 1.5;
    font-weight: bold;
}

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

.pause-content {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 3rem 4rem;
    border-radius: 20px;
    text-align: center;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 4px solid var(--primary-color);
}

.pause-content h2 {
    color: white;
    font-size: 3rem;
    margin-bottom: 1rem;
    text-shadow: 2px 2px 0px var(--primary-color);
}

.pause-content p {
    font-size: 1.5rem;
    color: #ffd700;
    font-weight: bold;
}

.central-overlay--practice {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.match-presentation {
    width: min(940px, 100%);
    display: flex;
    flex-direction: column;
    gap: 20px;
    pointer-events: none;
}

.match-card-space {
    height: clamp(100px, 30vh, 300px);
}

.word-practice {
    background: #fffefb;
    border: 4px solid var(--secondary-color);
    border-radius: 24px;
    padding: 16px 20px;
    text-align: center;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.2);
}

.word-practice h2 {
    color: #287e79;
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    margin-bottom: 8px;
}

.word-practice-sheet svg {
    display: block;
    width: 100%;
    max-height: 28vh;
}

.handwriting-line {
    stroke: #80b5d6;
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.handwriting-line-1 {
    stroke-dasharray: 9 7;
}

.handwriting-line-2 {
    stroke: #e594a0;
}

.handwriting-word {
    fill: #303a48;
    font-weight: normal;
}

@media (max-height: 500px) {
    .match-presentation {
        gap: 10px;
    }

    .match-card-space {
        height: 25vh;
    }

    .word-practice {
        padding: 8px 12px;
        border-radius: 16px;
    }

    .word-practice h2 {
        font-size: 1.1rem;
        margin-bottom: 4px;
    }

    .word-practice-sheet svg {
        max-height: 24vh;
    }

}
