* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: #e6e6fa; 
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
    padding: 20px;
}

.screen.active {
    display: flex;
}

/* --- Lobby Styles --- */
#lobbyScreen {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.logo {
    font-size: clamp(2rem, 6vw, 4rem);
    font-weight: 800;
    color: #1a1a4b;
    margin-bottom: 40px;
    white-space: nowrap; /* Forces single line */
}

.logo span {
    color: #7b5ff0;
}

.btn {
    border: none;
    cursor: pointer;
    padding: 15px 40px;
    border-radius: 100px;
    font-size: 18px;
    font-weight: bold;
    transition: 0.2s;
}

.btn:hover { transform: scale(1.05); }

.primary-btn {
    background: #7b5ff0;
    color: white;
    box-shadow: 0 5px 15px rgba(123, 95, 240, 0.3);
}

.outline-btn {
    background: transparent;
    color: #7b5ff0;
    border: 2px solid #7b5ff0;
}

/* --- Gameplay Styles --- */
#gameScreen {
    max-width: 800px;
    margin: 0 auto;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    width: 100%;
}

/* Backgrounds for top bar items */
.stat-pill, .icon-pill {
    background: #ffffff;
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    color: #1a1a4b;
}

.stat-pill {
    padding: 10px 20px;
    gap: 10px;
    font-size: 20px;
    font-weight: bold;
}

.controls {
    display: flex;
    gap: 15px;
}

.icon-pill {
    width: 48px;
    height: 48px;
    border: none;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.icon-pill:hover {
    background: #f0ecff;
    transform: scale(1.05);
}

/* --- Game Board --- */
.board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.game-board {
    background: #ffffff; /* Background holding the boxes */
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 500px; 
}

.card {
    aspect-ratio: 1 / 1; 
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.5s;
}

.card.flip { transform: rotateY(180deg); }
.card.matched { pointer-events: none; }

.front, .back {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    backface-visibility: hidden;
}

.front {
    background: #7b5ff0;
    box-shadow: 0 4px 8px rgba(123, 95, 240, 0.2);
}

.back {
    background: #f0ecff; /* Soft purple tint */
    border: 2px solid #d4cbf9; /* Slightly darker purple border */
    font-size: clamp(2rem, 6vw, 3.5rem);
    transform: rotateY(180deg);
}

/* --- Popup Styles --- */
.popup {
    position: fixed;
    inset: 0;
    background: rgba(230, 230, 250, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.popup.show { display: flex; }

.popup-content {
    background: white;
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.1);
    max-width: 90%;
}

.popup-content h2 { margin-bottom: 15px; color: #7b5ff0; }
.popup-content p { margin-bottom: 30px; font-size: 18px; font-weight: 500; }

.popup-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* --- Responsive Layout Rules --- */
@media (max-width: 500px) {
    .game-board { padding: 15px; gap: 10px; }
    .front, .back { border-radius: 8px; }
    .stat-pill { font-size: 16px; padding: 8px 16px; }
    .icon-pill { width: 40px; height: 40px; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .game-board { max-width: 350px; padding: 10px; gap: 8px; }
    .top-bar { margin-bottom: 10px; }
    .front, .back { border-radius: 8px; }
    .stat-pill { font-size: 16px; padding: 6px 12px; }
    .icon-pill { width: 36px; height: 36px; }
}