/* Base styles and responsive design */
* {
    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;
    overflow-x: hidden;
    position: relative;
    padding-bottom: 80px; /* Space for footer */
}

/* Responsive height management for iframe vs full screen */
.game-container {
    width: 100%;
    height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

/* Detect iframe environment */
@media (max-height: 500px) {
    .game-container {
        height: 450px;
        padding: 5px;
    }
    
    .menu-card, .game-over-card {
        max-height: 400px;
        overflow-y: auto;
    }
    
    .game-header {
        padding: 8px 12px;
        font-size: 0.9em;
    }
    
    .card {
        width: 70px !important;
        height: 85px !important;
    }
    
    body {
        padding-bottom: 60px; /* Smaller footer space for small screens */
    }
    
    .footer {
        padding: 10px 0;
        font-size: 12px;
    }
}

/* Screen management */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Tooltip styles */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 300px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tooltip.show {
    opacity: 1;
}

.tooltip-content h3 {
    margin-bottom: 8px;
    color: #ffd700;
}

/* Footer styles */
.footer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 15px 0;
    text-align: center;
    font-size: 14px;
    z-index: 100;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer p {
    margin: 5px 0;
}

.footer a {
    color: #ffd700;
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer a:hover {
    color: #ffffff;
    text-decoration: underline;
}

/* Menu Screen Styles */
.menu-card {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 100%;
    text-align: center;
    animation: slideIn 0.5s ease-out;
}

.game-title {
    margin-bottom: 30px;
    cursor: help;
    transition: transform 0.2s ease;
}

.game-title:hover {
    transform: scale(1.02);
}

.game-title h1 {
    font-size: 2.2em;
    color: #333;
    margin-bottom: 8px;
}

.game-title p {
    color: #666;
    font-size: 1.1em;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 25px;
}

.difficulty-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 12px;
    padding: 16px 20px;
    color: white;
    font-weight: 600;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.difficulty-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.difficulty-btn.easy {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.3);
}

.difficulty-btn.medium {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.difficulty-btn.difficult {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.level {
    font-size: 1.2em;
    text-transform: capitalize;
}

.pairs {
    font-size: 0.9em;
    opacity: 0.9;
}

/* Score History */
.score-history {
    background: #f8fafc;
    border-radius: 12px;
    padding: 16px;
    margin-top: 20px;
}

.score-history h3 {
    color: #333;
    margin-bottom: 12px;
    font-size: 1.1em;
}

.score-list {
    max-height: 120px;
    overflow-y: auto;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.9em;
}

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

.score-details {
    display: flex;
    gap: 12px;
    color: #666;
}

.score-value {
    font-weight: 600;
    color: #f59e0b;
}

/* Game Screen Styles */
.game-header {
    background: white;
    border-radius: 12px;
    padding: 12px 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.menu-btn {
    background: #f1f5f9;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    color: #475569;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.menu-btn:hover {
    background: #e2e8f0;
    transform: translateX(-2px);
}

.difficulty-label {
    font-size: 1.1em;
    font-weight: 600;
    color: #333;
    text-transform: capitalize;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #475569;
}

.stat-icon {
    font-size: 1.1em;
}

.stat-value {
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

/* Game Board */
.game-board {
    display: grid;
    gap: 12px;
    justify-content: center;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 10px;
}

/* Card Styles - Fixed card flipping animation */
.card {
    width: 90px;
    height: 110px;
    perspective: 1000px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.card:hover {
    transform: scale(1.05);
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Fixed: Ensure proper card flipping behavior */
.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.card-back {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 2.5em;
    /* Fixed: Ensure back face is visible by default */
    transform: rotateY(0deg);
}

.card-front {
    background: white;
    /* Fixed: Ensure front face is rotated 180 degrees initially */
    transform: rotateY(180deg);
    border: 2px solid #e2e8f0;
    flex-direction: column;
    padding: 8px;
}

.card.matched .card-front {
    background: #dcfce7;
    border-color: #22c55e;
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

/* Fraction Display */
.fraction-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 6px;
}

.fraction-text {
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
}

.fraction-visual {
    display: grid;
    gap: 2px;
    max-width: 60px;
}

.fraction-part {
    width: 12px;
    height: 12px;
    border: 1px solid #666;
    border-radius: 2px;
}

.fraction-part.filled {
    background: #3b82f6;
}

.fraction-part.empty {
    background: white;
}

/* Game Over Screen */
.game-over-card {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 100%;
    text-align: center;
    animation: slideIn 0.5s ease-out;
}

.celebration {
    font-size: 4em;
    margin-bottom: 15px;
    animation: bounce 1s ease-in-out infinite alternate;
}

.game-over-card h2 {
    font-size: 2em;
    color: #333;
    margin-bottom: 8px;
}

.game-over-card p {
    color: #666;
    margin-bottom: 25px;
    font-size: 1.1em;
}

.final-stats {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 1.1em;
}

.stat-row:not(:last-child) {
    border-bottom: 1px solid #e2e8f0;
}

.score-row {
    border-top: 2px solid #e2e8f0;
    margin-top: 8px;
    padding-top: 12px;
    font-weight: 600;
}

.score-row span:last-child {
    font-size: 1.3em;
    color: #f59e0b;
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.play-again-btn {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    border: none;
    border-radius: 12px;
    padding: 14px 20px;
    color: white;
    font-weight: 600;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.4);
}

.back-menu-btn {
    background: #f1f5f9;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    color: #475569;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-menu-btn:hover {
    background: #e2e8f0;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(-10px);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .menu-card, .game-over-card {
        margin: 10px;
        padding: 20px;
    }
    
    .game-header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .header-left, .header-right {
        justify-content: center;
    }
    
    .card {
        width: 75px;
        height: 95px;
    }
    
    .difficulty-btn {
        padding: 14px 16px;
        font-size: 1em;
    }
}

@media (max-width: 480px) {
    .card {
        width: 65px;
        height: 80px;
    }
    
    .fraction-text {
        font-size: 1em;
    }
    
    .fraction-part {
        width: 10px;
        height: 10px;
    }
}