/* リセット & ベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
}

.container {
    max-width: 800px;
    width: 100%;
    margin: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    padding: 30px;
}

/* ヘッダー */
.game-header {
    text-align: center;
    margin-bottom: 30px;
}

.game-header h1 {
    font-size: 2.5rem;
    color: #4a5568;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.score-info {
    display: flex;
    gap: 20px;
    font-weight: bold;
    color: #2d3748;
}

.reset-button {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.reset-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

/* ゲームボード */
.game-board {
    margin-bottom: 30px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    max-width: 600px;
    margin: 0 auto;
}

/* カードスタイル */
.card {
    aspect-ratio: 1;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.6s ease;
    transform-style: preserve-3d;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
    perspective: 1000px;
}

.card-content {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.card-back, .card-front {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backface-visibility: hidden;
    color: white;
    font-weight: bold;
}

.card-back {
    background: linear-gradient(135deg, #667eea, #764ba2);
    font-size: 2.5rem;
}

.card-front {
    background: linear-gradient(135deg, #4facfe, #00f2fe);
    transform: rotateY(180deg);
    padding: 10px;
}

.animal-symbol {
    font-size: 3.5rem;
    margin-bottom: 8px;
    line-height: 1;
}

.animal-name {
    font-size: 0.9rem;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.5px;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
    border-radius: 15px;
    pointer-events: none;
}

.card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
}

/* カードの状態 */
.card.flipped .card-content {
    transform: rotateY(180deg);
}

.card.matched .card-front {
    background: linear-gradient(135deg, #43e97b, #38f9d7);
}

.card.matched {
    transform: scale(0.95);
    box-shadow: 0 5px 20px rgba(67, 233, 123, 0.3);
    cursor: default;
}

.card.matched:hover {
    transform: scale(0.95);
}

.card.disabled {
    pointer-events: none;
    opacity: 0.7;
}

/* フッター */
.game-footer {
    text-align: center;
}

.game-status {
    font-size: 1.2rem;
    font-weight: bold;
    color: #4a5568;
    padding: 15px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

/* モーダル */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
}

.modal-content h2 {
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 2rem;
}

.modal-content p {
    color: #718096;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.final-score {
    background: rgba(102, 126, 234, 0.1);
    padding: 15px;
    border-radius: 10px;
    margin: 20px 0;
}

.final-score p {
    font-weight: bold;
    color: #4a5568;
    margin: 0;
}

.play-again-button {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.play-again-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* アニメーション */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes cardFlip {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(-90deg); }
    100% { transform: rotateY(-180deg); }
}

.card.flipping {
    animation: cardFlip 0.6s ease-in-out;
}

/* パーフェクト演出アニメーション */
@keyframes perfectPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes perfectGlow {
    0% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.3); }
    50% { box-shadow: 0 0 40px rgba(255, 215, 0, 0.8), 0 0 60px rgba(255, 255, 255, 0.3); }
    100% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.3); }
}

@keyframes rainbowBorder {
    0% { border-color: #ff0000; }
    16% { border-color: #ff8c00; }
    32% { border-color: #ffd700; }
    48% { border-color: #9acd32; }
    64% { border-color: #00bfff; }
    80% { border-color: #9932cc; }
    100% { border-color: #ff0000; }
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(-100vh) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg);
    }
}

@keyframes fireworksExplode {
    0% {
        opacity: 1;
        transform: scale(0) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.5) rotate(180deg);
    }
    100% {
        opacity: 0;
        transform: scale(2) rotate(360deg);
    }
}

@keyframes perfectShimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

@keyframes sparkleEffect {
    0% {
        opacity: 0;
        transform: scale(0) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.2) rotate(180deg);
    }
    100% {
        opacity: 0;
        transform: scale(0.8) rotate(360deg);
    }
}

@keyframes confettiEnhanced {
    0% {
        opacity: 1;
        transform: translateY(-100vh) rotate(0deg) scale(1);
    }
    50% {
        opacity: 1;
        transform: translateY(50vh) rotate(360deg) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg) scale(0.8);
    }
}

@keyframes screenShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px) rotate(1deg); }
    75% { transform: translateX(10px) rotate(-1deg); }
}

@keyframes fullScreenConfetti {
    0% {
        opacity: 1;
        transform: translateY(-20vh) rotate(0deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(120vh) rotate(1080deg) scale(0.5);
    }
}

/* パーフェクト演出スタイル */
.modal.perfect-backdrop {
    background: radial-gradient(circle, rgba(255, 215, 0, 0.3) 0%, rgba(0, 0, 0, 0.8) 100%);
    animation: perfectGlow 2s ease-in-out infinite;
}

.modal-content.perfect-clear {
    background: linear-gradient(135deg, #ffd700, #ffed4a, #f7b801);
    border: 4px solid transparent;
    animation: perfectPulse 2s ease-in-out infinite, rainbowBorder 3s linear infinite;
    position: relative;
    overflow: hidden;
}

.modal-content.perfect-clear::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    background-size: 200% 100%;
    animation: perfectShimmer 2s ease-in-out infinite;
    pointer-events: none;
}

.modal-content.perfect-clear h2 {
    color: #8b4513;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: perfectPulse 1.5s ease-in-out infinite;
}

.modal-content.perfect-clear .final-score {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #ffd700;
    animation: perfectGlow 2.5s ease-in-out infinite;
}

.confetti {
    position: absolute;
    font-size: 3rem;
    pointer-events: none;
    animation: confettiEnhanced 4s linear forwards;
    z-index: 1001;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
    filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.7));
}

.confetti.full-screen {
    position: fixed;
    font-size: 4rem;
    animation: fullScreenConfetti 5s linear forwards;
    z-index: 9999;
    text-shadow: 0 0 20px rgba(255, 255, 255, 1);
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 1));
}

.sparkle {
    position: absolute;
    font-size: 2rem;
    pointer-events: none;
    animation: sparkleEffect 2s ease-in-out forwards;
    z-index: 1001;
    text-shadow: 0 0 15px rgba(255, 255, 255, 1);
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.9));
}

.fireworks {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    pointer-events: none;
    animation: fireworksExplode 3s ease-out forwards;
    z-index: 1001;
}

.retry-encourage {
    color: #e53e3e !important;
    font-weight: bold !important;
    font-size: 1.1rem !important;
    margin-top: 10px !important;
    animation: perfectPulse 2s ease-in-out infinite;
}

/* パーフェクト時の特別なボタンスタイル */
.modal-content.perfect-clear .play-again-button {
    background: linear-gradient(135deg, #ffd700, #ffed4a);
    color: #8b4513;
    border: 2px solid #f7b801;
    animation: perfectGlow 2s ease-in-out infinite;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
}

.modal-content.perfect-clear .play-again-button:hover {
    background: linear-gradient(135deg, #ffed4a, #ffd700);
    transform: translateY(-3px) scale(1.05);
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    .container {
        margin: 10px;
        padding: 20px;
    }

    .game-header h1 {
        font-size: 2rem;
    }

    .game-info {
        flex-direction: column;
        text-align: center;
    }

    .score-info {
        flex-direction: column;
        gap: 10px;
    }

    .card-grid {
        gap: 10px;
    }

    .animal-symbol {
        font-size: 2.8rem;
    }

    .animal-name {
        font-size: 0.8rem;
    }

    .modal-content {
        padding: 30px 20px;
    }

    .confetti {
        font-size: 1.5rem;
    }

    .fireworks {
        font-size: 3rem;
    }
}

@media (max-width: 480px) {
    .card-grid {
        gap: 8px;
    }

    .animal-symbol {
        font-size: 2.2rem;
    }

    .animal-name {
        font-size: 0.7rem;
    }

    .card {
        border-radius: 10px;
    }

    .game-header h1 {
        font-size: 1.8rem;
    }

    .container {
        padding: 15px;
    }

    .confetti {
        font-size: 1.2rem;
    }

    .fireworks {
        font-size: 2.5rem;
    }
}