* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f0f0f0;
    font-family: 'Hiragino Kaku Gothic ProN', 'メイリオ', sans-serif;
}

.game-container {
    width: 100%;
    max-width: 400px;
    padding: 10px;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.score-container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 1.2em;
    padding: 0 10px;
}

.game-area {
    width: 360px;
    height: 480px;
    border: 2px solid #333;
    position: relative;
    overflow: hidden;
    background-color: #fff;
    background-image: 
        linear-gradient(#ddd 1px, transparent 1px),
        linear-gradient(90deg, #ddd 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: 0 0;
    margin: 0 auto;
    touch-action: none;
}

.falling-kanji {
    position: absolute;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: left 0.1s ease-out;
    user-select: none;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 2;
}

.stack {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100%;
}

.stacked-kanji {
    position: absolute;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s ease-out;
    user-select: none;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 1;
}

.stacked-kanji.matched {
    animation: matched 0.5s ease-out;
    background-color: rgba(255, 255, 0, 0.3);
}

@keyframes matched {
    0% {
        transform: scale(1);
        background-color: rgba(255, 255, 0, 0.3);
    }
    50% {
        transform: scale(1.2);
        background-color: rgba(255, 255, 0, 0.5);
    }
    100% {
        transform: scale(1);
        background-color: rgba(255, 255, 0, 0.3);
    }
}

.controls {
    margin-top: 20px;
    text-align: center;
}

.mobile-controls {
    display: none;
    justify-content: space-between;
    margin-top: 10px;
    padding: 0 20px;
}

@media (max-width: 480px) {
    .game-container {
        padding: 5px;
    }

    .game-area {
        width: 320px;
        height: 400px;
    }

    .mobile-controls {
        display: flex;
    }

    .instructions {
        font-size: 0.8em;
    }
}

button {
    padding: 10px 20px;
    font-size: 1.1em;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #45a049;
}

.control-btn {
    width: 60px;
    height: 60px;
    font-size: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(76, 175, 80, 0.8);
    border-radius: 50%;
}

.game-over {
    margin-top: 15px;
    font-size: 1.5em;
    color: #ff0000;
}

.hidden {
    display: none;
}

#restartBtn {
    margin-top: 10px;
    background-color: #2196F3;
}

#restartBtn:hover {
    background-color: #1976D2;
}

.instructions {
    margin-top: 15px;
    font-size: 0.9em;
    color: #666;
    text-align: left;
    padding: 10px;
    border-top: 1px solid #ddd;
}

.instructions ul {
    list-style-type: none;
    margin-top: 5px;
}

.instructions li {
    margin: 3px 0;
}
