:root {
    --bg: #0f172a;
    --card-back: #1e293b;
    --accent: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.4);
    --text: #f8fafc;
    --glass: rgba(30, 41, 59, 0.85);
    --success: #10b981;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    background-image: radial-gradient(circle at top right, #1e293b 0%, #0f172a 100%);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    /* Use dvh (dynamic viewport height) for mobile browser address bars */
    min-height: 100vh;
    min-height: 100dvh; 
    overflow: hidden; /* Prevent body-level scrolling */
}

#main-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 10px;
    box-sizing: border-box;
}

.overlay {
    text-align: center;
    background: var(--glass);
    padding: 2rem;
    border-radius: 28px;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px rgba(0,0,0,0.6);
    width: 90%;
    max-width: 400px;
    box-sizing: border-box;
}

h1 { font-weight: 800; letter-spacing: -1px; margin-bottom: 0.5rem; font-size: clamp(1.5rem, 8vw, 2.5rem); }
.highlight { color: var(--accent); text-shadow: 0 0 20px var(--accent-glow); }

.selector-group {
    margin: 20px 0;
    text-align: left;
}

label { display: block; margin-bottom: 8px; font-size: 0.9rem; font-weight: 600; opacity: 0.9; }

select {
    width: 100%;
    padding: 12px;
    background: #334155;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    outline: none;
}

.menu-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 14px;
    background: var(--accent);
    color: #0f172a;
    border: none;
    border-radius: 14px;
    font-weight: 800;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.menu-btn:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 8px 20px var(--accent-glow); 
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-height: 95vh; /* Ensure game doesn't cut off */
}

.stats-bar {
    width: 100%;
    max-width: 500px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(255,255,255,0.07);
    border-radius: 16px;
    margin-bottom: 15px;
    box-sizing: border-box;
    backdrop-filter: blur(5px);
}

.grid {
    display: grid;
    gap: 8px; /* Slightly tighter gap for small screens */
    perspective: 1000px;
    justify-items: center;
    /* Prevent the grid from exceeding screen width/height */
    max-width: 100%;
    max-height: 70vh; 
}

.card {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

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

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.card-back { 
    background: var(--card-back); 
    border: 1px solid rgba(255,255,255,0.1);
    background-image: linear-gradient(135deg, #1e293b 25%, #2a3a52 100%);
}

.card-front { 
    background: var(--accent); 
    transform: rotateY(180deg); 
    color: #0f172a; 
}

dialog {
    background: #1e293b;
    color: white;
    border: 1px solid var(--accent);
    border-radius: 24px;
    padding: 0;
    max-width: 90vw;
    width: 360px;
    box-shadow: 0 0 60px rgba(0,0,0,0.9);
    overflow: hidden;
}

dialog::backdrop { background: rgba(10, 15, 26, 0.92); backdrop-filter: blur(8px); }

.dialog-header {
    background: rgba(255,255,255,0.03);
    padding: 1.5rem;
    text-align: center;
}

.dialog-body { padding: 1rem 1.5rem 1.5rem; text-align: center; }

.contact-card {
    background: rgba(0,0,0,0.25);
    padding: 15px;
    border-radius: 12px;
    font-size: 0.85rem;
    margin: 10px 0;
    border-left: 4px solid var(--accent);
    text-align: left;
}

.win-score {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--success);
    margin: 5px 0;
}

.hidden { display: none !important; }

/* Media Query for very small devices */
@media (max-width: 360px) {
    .stats-bar { padding: 8px 12px; font-size: 0.8rem; }
    .grid { gap: 5px; }
}