/* ===================================
   CSS VARIABLES
   =================================== */
:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --dark-bg: #1e293b;
    --light-bg: #f8fafc;
    --white: #ffffff;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-600: #475569;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --transition: all 0.3s ease;
    --border-radius: 16px;
    --card-size: 100px;
}

/* ===================================
   GLOBAL STYLES
   =================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--gray-800);
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* ===================================
   SCREEN MANAGEMENT
   =================================== */
.screen {
    display: none;
    min-height: calc(100vh - 60px);
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===================================
   BUTTONS
   =================================== */
.btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
}

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

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

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

.btn-secondary:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

/* ===================================
   START SCREEN
   =================================== */
.game-header {
    text-align: center;
    margin-bottom: 2rem;
}

.title {
    font-size: 3rem;
    color: var(--white);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1.3rem;
    color: rgba(255, 255, 255, 0.9);
}

.game-preview {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.preview-cards {
    display: flex;
    gap: 1rem;
}

.preview-card {
    width: 80px;
    height: 80px;
    background: var(--white);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    box-shadow: var(--shadow-lg);
    animation: float 3s ease-in-out infinite;
}

.preview-card:nth-child(2) {
    animation-delay: 0.3s;
}

.preview-card:nth-child(3) {
    animation-delay: 0.6s;
}

.preview-card:nth-child(4) {
    animation-delay: 0.9s;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-15px);
    }
}

.start-content {
    background: var(--white);
    padding: 2.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
}

.start-content h2 {
    color: var(--gray-800);
    margin-bottom: 1rem;
}

.instructions {
    list-style: none;
    margin-bottom: 2rem;
}

.instructions li {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--gray-100);
    border-radius: 8px;
    color: var(--gray-700);
}

.difficulty-selector {
    margin-bottom: 2rem;
}

.difficulty-selector h3 {
    margin-bottom: 1rem;
    color: var(--gray-800);
}

.difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.difficulty-btn {
    padding: 1.5rem;
    background: var(--gray-100);
    border: 3px solid transparent;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.difficulty-btn:hover {
    background: var(--gray-200);
    transform: translateY(-3px);
}

.difficulty-btn.active {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: var(--white);
    border-color: var(--primary-color);
}

.diff-icon {
    font-size: 2rem;
}

.diff-name {
    font-size: 1.2rem;
    font-weight: 600;
}

.diff-desc {
    font-size: 0.9rem;
    opacity: 0.8;
}

.start-content .btn {
    width: 100%;
    margin-top: 1rem;
}

/* ===================================
   GAME SCREEN
   =================================== */
.game-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-box {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    font-size: 2.5rem;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--gray-600);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-800);
}

/* ===================================
   GAME BOARD
   =================================== */
.game-board {
    display: grid;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
}

/* ===================================
   CARDS
   =================================== */
.card {
    aspect-ratio: 1;
    perspective: 1000px;
    cursor: pointer;
    min-height: 80px;
}

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

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

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    box-shadow: var(--shadow-md);
}

.card-front {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--white);
    font-weight: 700;
}

.card-back {
    background: var(--white);
    transform: rotateY(180deg);
}

.card:hover:not(.flipped):not(.matched) .card-inner {
    transform: scale(1.05);
}

.card.matched .card-inner {
    animation: matchSuccess 0.6s ease;
}

@keyframes matchSuccess {
    0%, 100% {
        transform: scale(1) rotateY(180deg);
    }
    50% {
        transform: scale(1.2) rotateY(180deg);
    }
}

.card.matched {
    pointer-events: none;
}

.card.matched .card-back {
    background: var(--gradient-success);
    color: var(--white);
}

/* ===================================
   GAME CONTROLS
   =================================== */
.game-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.game-controls .btn {
    flex: 1;
    min-width: 150px;
}

/* ===================================
   RESULTS SCREEN
   =================================== */
.results-content {
    background: var(--white);
    padding: 3rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    text-align: center;
}

.results-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

.results-title {
    font-size: 2.5rem;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}

.results-subtitle {
    font-size: 1.3rem;
    color: var(--gray-600);
    margin-bottom: 2rem;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.result-stat {
    padding: 1.5rem;
    background: var(--gray-100);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.result-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

.result-value {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.result-label {
    font-size: 0.9rem;
    color: var(--gray-600);
}

.performance-message {
    margin: 2rem 0;
    padding: 2rem;
    border-radius: var(--border-radius);
    border-left: 5px solid;
}

.performance-message.perfect {
    background: #f0fdf4;
    border-color: var(--success-color);
}

.performance-message.great {
    background: #eff6ff;
    border-color: var(--primary-color);
}

.performance-message.good {
    background: #fef3c7;
    border-color: var(--warning-color);
}

.performance-message h3 {
    margin-bottom: 0.5rem;
    color: var(--gray-800);
}

.performance-message p {
    color: var(--gray-700);
    line-height: 1.6;
}

.results-actions {
    display: flex;
    gap: 1rem;
    margin: 2rem 0;
    flex-wrap: wrap;
}

.results-actions .btn {
    flex: 1;
    min-width: 200px;
}

/* ===================================
   LEADERBOARD
   =================================== */
.leaderboard {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--gray-200);
}

.leaderboard h3 {
    margin-bottom: 1rem;
    color: var(--gray-800);
}

.leaderboard-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--gray-100);
    border-radius: 8px;
    gap: 1rem;
}

.rank {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.score-moves {
    font-weight: 600;
    color: var(--gray-800);
}

.score-time {
    color: var(--gray-600);
}

.no-scores {
    padding: 2rem;
    color: var(--gray-600);
    font-style: italic;
}

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

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: var(--white);
    padding: 3rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    text-align: center;
    max-width: 500px;
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.overlay-content h2 {
    font-size: 2rem;
    color: var(--gray-800);
    margin-bottom: 1rem;
}

.overlay-content p {
    color: var(--gray-600);
    margin-bottom: 2rem;
}

.overlay-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.overlay-buttons .btn {
    width: 100%;
}

/* ===================================
   FOOTER
   =================================== */
.footer {
    background: rgba(0, 0, 0, 0.3);
    color: var(--white);
    text-align: center;
    padding: 1.5rem;
    margin-top: auto;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */
@media screen and (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .title {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .start-content {
        padding: 1.5rem;
    }

    .difficulty-buttons {
        grid-template-columns: 1fr;
    }

    .game-stats {
        grid-template-columns: 1fr;
    }

    .game-board {
        padding: 1rem;
        gap: 0.5rem;
    }

    .card-front,
    .card-back {
        font-size: 2rem;
    }

    .results-content {
        padding: 2rem 1.5rem;
    }

    .results-title {
        font-size: 2rem;
    }

    .results-actions {
        flex-direction: column;
    }

    .overlay-content {
        margin: 1rem;
        padding: 2rem;
    }
}

@media screen and (max-width: 480px) {
    .title {
        font-size: 1.5rem;
    }

    .preview-cards {
        gap: 0.5rem;
    }

    .preview-card {
        width: 60px;
        height: 60px;
        font-size: 2rem;
    }

    .btn {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    .card-front,
    .card-back {
        font-size: 1.5rem;
    }

    .results-icon {
        font-size: 3.5rem;
    }

    .results-stats {
        grid-template-columns: 1fr;
    }
}

/* ===================================
   ACCESSIBILITY
   =================================== */
button:focus,
.btn:focus {
    outline: 3px solid var(--warning-color);
    outline-offset: 2px;
}

.card:focus {
    outline: 3px solid var(--white);
    outline-offset: 3px;
}


/* Back Button */
.back-button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #2d7a4f;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
    padding: 12px 24px;
    border-radius: 8px;
    background: rgba(45, 122, 79, 0.1);
    transition: all 0.3s ease;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
}

.back-button:hover {
    background: #2d7a4f;
    color: white;
    transform: translateX(-5px);
}


/* ===================================
   ENHANCED RESPONSIVE DESIGN
   =================================== */

/* Tablet */
@media (max-width: 1024px) {
    .game-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        max-width: 500px;
    }
    
    .card {
        height: 120px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .back-button {
        top: 10px;
        left: 10px;
        font-size: 1rem;
        padding: 10px 16px;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .game-stats {
        flex-direction: column;
        gap: 15px;
    }
    
    .stat-item {
        min-width: 200px;
    }
    
    .game-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        max-width: 400px;
        padding: 15px;
    }
    
    .card {
        height: 100px;
    }
    
    .card-icon {
        font-size: 2rem;
    }
    
    .difficulty-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .back-button span:last-child {
        display: none;
    }
    
    .back-button {
        padding: 8px 12px;
        top: 5px;
        left: 5px;
    }
    
    .back-button i {
        font-size: 1.5rem;
    }
    
    .container {
        padding: 15px;
    }
    
    .title {
        font-size: 1.5rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .game-stats {
        padding: 12px;
    }
    
    .stat-item {
        padding: 10px 15px;
        min-width: auto;
        width: 100%;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    .stat-value {
        font-size: 1.3rem;
    }
    
    .game-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        max-width: 320px;
        padding: 10px;
    }
    
    .card {
        height: 80px;
    }
    
    .card-icon {
        font-size: 1.5rem;
    }
    
    .game-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn {
        width: 100%;
        padding: 12px 20px;
        font-size: 14px;
    }
    
    .difficulty-btn {
        font-size: 14px;
        padding: 15px;
    }
}

/* Very small mobile */
@media (max-width: 360px) {
    .game-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 280px;
    }
    
    .card {
        height: 90px;
    }
}

/* Touch optimization */
@media (hover: none) and (pointer: coarse) {
    .card {
        cursor: default;
    }
    
    .btn,
    .difficulty-btn,
    .back-button {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .card:hover {
        transform: none;
    }
}

/* Landscape on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .game-grid {
        grid-template-columns: repeat(4, 1fr);
        max-width: 600px;
    }
    
    .card {
        height: 90px;
    }
}
