/* ===========================================
   えあわせ (Memory Match)
   =========================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Zen Maru Gothic', sans-serif;
    touch-action: none;
    user-select: none;
}

body {
    background: linear-gradient(135deg, #FFF9C4 0%, #FFECB3 100%);
}

.home-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    width: 48px;
    height: 48px;
    background: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    border: 3px solid #FFCA28;
}

#game-container {
    max-width: 600px; /* Slightly wider for cards */
    height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Header */
.game-header {
    padding: 60px 20px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.level-badge {
    background: #FF6F00;
    color: white;
    padding: 8px 18px;
    border-radius: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    box-shadow: 0 3px 0 #E65100;
}

.score-display {
    background: white;
    padding: 8px 18px;
    border-radius: 20px;
    font-weight: bold;
    color: #5D4037;
    box-shadow: 0 3px 0 #D7CCC8;
}

/* Game Area */
.game-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    overflow: hidden; /* Forbid scrolling as per user request */
    width: 100%;
    overscroll-behavior: none;
}

.card-grid {
    display: grid;
    gap: 10px;
    width: 100%;
    height: 100%;
    max-width: 500px;
    max-height: 70vh; /* Ensure cards fit vertically */
    justify-content: center;
    align-content: center;
    /* Columns set by JS */
}

/* Card Styles */
.card {
    background-color: transparent;
    perspective: 1000px;
    cursor: pointer;
    aspect-ratio: 3/4; /* Standard card ratio */
    width: 100%;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.4s;
    transform-style: preserve-3d;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    border-radius: 12px;
}

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

.card.matched .card-inner {
    transform: rotateY(180deg);
    animation: matchPulse 0.5s ease-out;
}

@keyframes matchPulse {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.15); box-shadow: 0 0 20px #FFD700; }
    100% { transform: rotateY(180deg) scale(1); }
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid white;
}

.card-back {
    background: linear-gradient(135deg, #29B6F6 0%, #03A9F4 100%);
    color: white;
}

/* Pattern for back */
.card-back::after {
    content: '★';
    font-size: 2rem;
    opacity: 0.5;
}

.card-front {
    background: white;
    color: #333;
    transform: rotateY(180deg);
    font-size: 3rem; /* Emoji size */
}

/* Responsive Grid Adjustments handled in JS mainly, but safe defaults here */

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

.overlay.hidden {
    display: none;
}

.message-modal {
    background: white;
    border-radius: 30px;
    padding: 30px;
    text-align: center;
    animation: modalPop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    max-width: 320px;
    width: 90%;
}

@keyframes modalPop {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 10px;
}

.message-modal h2 {
    font-size: 1.8rem;
    margin-bottom: 10px;
    color: #FF6F00;
}

.stars {
    font-size: 2rem;
    margin-bottom: 15px;
}

.btn-primary {
    background: linear-gradient(135deg, #FF6F00 0%, #E65100 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 4px 0 #BF360C;
    transition: transform 0.1s;
}

.btn-primary:active {
    transform: translateY(4px);
    box-shadow: none;
}