:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --border-color: #475569;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.7);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    overflow-x: hidden; /* Previne scrollbar durante a transição do painel */
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
    transition: transform 0.5s ease-in-out;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    text-align: center;
    margin-bottom: 3rem;
}

.title {
    font-size: 3.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.btn {
    padding: 0.75rem 2rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
    z-index: 0;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-secondary {
    background: transparent;
    color: var(--primary-light);
    border: 2px solid var(--primary);
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
}

.btn-difficulty {
    padding: 1.5rem 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    min-width: 120px;
    font-size: 1.1rem;
}

.btn-difficulty:hover {
    border-color: var(--primary);
    background: #334155;
    transform: translateY(-3px);
}

.btn-difficulty small {
    display: block;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.5rem;
    font-weight: 400;
}

.difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stats-panel {
    display: grid;
    /* Preparamos o grid para 3 colunas, para os próximos stats */
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.stat {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    text-align: center;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.stat:hover {
    background: #334155;
    border-color: var(--primary);
    transform: translateY(-2px);
}

.stat-label {
    display: block;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-light);
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.game-board {
    display: grid;
    gap: 1.5rem;
    padding: 3rem;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    /* Perspectiva para o flip 3D funcionar melhor */
    perspective: 1200px;
}

/* Grid responsivo baseado em data-size */
.game-board[data-size="4"] {
    grid-template-columns: repeat(4, 1fr);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    gap: 1.5rem;
}

.game-board[data-size="6"] {
    grid-template-columns: repeat(6, 1fr);
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
    gap: 1.2rem;
}

.game-board[data-size="8"] {
    grid-template-columns: repeat(8, 1fr);
    gap: 1rem;
}

.game-board[data-size="10"] {
    grid-template-columns: repeat(10, 1fr);
    gap: 0.75rem;
    padding: 1.5rem;
}

/* ESTILO DAS CARTAS */
.card {
    aspect-ratio: 1;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: 2px solid var(--primary-light);
    border-radius: 0.5rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 2.5rem;
    font-weight: 700;
    transition: transform 0.6s ease-in-out;
    user-select: none;
    color: var(--text-primary);
    
    /* PROPRIEDADES 3D CRÍTICAS */
    position: relative;
    transform-style: preserve-3d;
    perspective: 1000px;
    min-width: 80px;
    min-height: 80px;
}

.card:hover:not(.disabled):not(.matched):not(.flipped) {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
}

/* ANIMAÇÃO PARA VIRAR AS CARTAS */
.card.flipped {
    background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
    border-color: #ec4899;
    transform: rotateY(180deg);
}

/* Interrogação (verso da carta) */
.card::before {
    content: '?';
    opacity: 1;
    grid-area: 1 / 1;
    
    /* 3D SETUP */
    backface-visibility: hidden;
    transform: rotateY(0deg);
    -webkit-backface-visibility: hidden;
}

/* Emoji (frente da carta) */
.card-inner {
    color: var(--text-primary);
    font-size: 2rem;
    grid-area: 1 / 1;
    
    /* 3D SETUP */
    backface-visibility: hidden;
    transform: rotateY(180deg);
    -webkit-backface-visibility: hidden;
}

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

.card.matched {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-color: #34d399;
    cursor: default;
    animation: matchPulse 0.6s ease-out;
}

@keyframes matchPulse {
    0% { transform: rotateY(180deg) scale(1) translateY(-3px); }
    50% { transform: rotateY(180deg) scale(1.1) translateY(-3px); }
    100% { transform: rotateY(180deg) scale(1) translateY(-3px); }
}

@media (max-width: 768px) {
    .game-board {
        padding: 1.5rem;
        gap: 1rem;
    }
    
    .game-board[data-size="4"] {
        max-width: 100%;
        gap: 1rem;
    }
    
    .game-board[data-size="6"] {
        max-width: 100%;
        gap: 0.8rem;
    }
    
    .card {
        font-size: 2rem;
        min-width: 60px;
        min-height: 60px;
    }
    
    .card-inner {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    .game-board {
        padding: 1rem;
        gap: 0.75rem;
    }
    
    .card {
        font-size: 1.5rem;
        min-width: 50px;
        min-height: 50px;
    }
    
    .card-inner {
        font-size: 1.2rem;
    }
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 3rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
}

.victory-stats {
    margin: 1.5rem 0;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.ranking-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    max-width: 90vw;
    height: 100%;
    z-index: 900; /* Abaixo dos modais */
    transform: translateX(100%);
    transition: transform 0.5s ease-in-out;
    box-shadow: var(--shadow-lg);
}

.ranking-panel.active {
    transform: translateX(0);
}

body.ranking-open .container {
    transform: translateX(-200px); /* Metade da largura do painel */
}

.ranking-content {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-left: 1px solid var(--border-color);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    text-align: center;
}

.ranking-list {
    flex-grow: 1; /* Faz a lista ocupar o espaço disponível */
}

.ranking-item {
    display: grid;
    grid-template-columns: 30px 1fr auto auto;
    gap: 1rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    font-size: 0.95rem;
}

.ranking-item:last-child {
    border-bottom: none;
}

.ranking-position {
    font-weight: 700;
    color: var(--primary-light);
    text-align: center;
}

.ranking-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ranking-name {
    color: var(--text-primary);
    font-weight: 500;
}

.ranking-date {
    color: var(--text-tertiary);
    font-size: 0.85rem;
}

.ranking-stats {
    display: flex;
    gap: 1rem;
    text-align: right;
}

.ranking-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.ranking-stat-label {
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

.ranking-stat-value {
    color: var(--primary-light);
    font-weight: 600;
}

.ranking-filters {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}