.memory-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-x: auto;
    overflow-y: auto;
}

.memory-content {
    flex: 1;
    padding: 1rem;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.memory-content h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    margin-bottom: 0.5rem;
    color: var(--text-color);
    text-align: center;
}

.subtitle {
    text-align: center;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 1rem;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    padding: 0 1rem;
}

.game-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    padding: 0 0.5rem;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.difficulty-selector label {
    color: var(--text-color);
    font-weight: 500;
    font-size: clamp(0.85rem, 2.5vw, 1rem);
}

.difficulty-selector select {
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    padding: 0.5rem;
    max-width: 100%;
}

.game-btn {
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--editor-bg);
    color: var(--text-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: clamp(0.85rem, 2.5vw, 1rem);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    font-family: 'Space Mono', monospace;
    white-space: nowrap;
}

.game-btn:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.game-btn i {
    font-size: clamp(1rem, 3vw, 1.2rem);
}

.game-info {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    padding: 0 0.5rem;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem 0.75rem;
    background-color: var(--editor-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.75rem, 2.5vw, 0.95rem);
    white-space: nowrap;
}

.info-item i {
    font-size: clamp(1rem, 3vw, 1.3rem);
    color: var(--accent-color);
}

.board-wrapper {
    display: flex;
    justify-content: center;
    padding: 0.5rem;
    margin-bottom: 1rem;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.memory-board {
    display: grid;
    gap: clamp(0.5rem, 2vw, 1rem);
    padding: 1rem;
    max-width: 100%;
}

.memory-board.easy {
    grid-template-columns: repeat(4, 1fr);
}

.memory-board.medium {
    grid-template-columns: repeat(4, 1fr);
}

.memory-board.hard {
    grid-template-columns: repeat(6, 1fr);
}

.card {
    width: var(--card-size, 100px);
    height: var(--card-size, 100px);
    position: relative;
    cursor: pointer;
    perspective: 1000px;
    transition: transform 0.2s ease;
}

.card:hover:not(.flipped):not(.matched) {
    transform: scale(1.05);
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.card.flipped .card-inner,
.card.matched .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(2rem, 5vw, 3rem);
    border: 2px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-front {
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--sidebar-bg) 100%);
    color: white;
}

.card-front::before {
    content: '?';
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: bold;
    opacity: 0.8;
}

.card-back {
    background-color: var(--editor-bg);
    transform: rotateY(180deg);
}

.card.matched {
    animation: matchPulse 0.6s ease;
}

.card.matched .card-back {
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--sidebar-bg) 100%);
    color: white;
    border-color: var(--accent-color);
}

@keyframes matchPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.card.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

.game-instructions {
    max-width: 600px;
    margin: 1rem auto;
    padding: 1rem;
    background-color: var(--editor-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.game-instructions h3 {
    color: var(--text-color);
    margin-bottom: 0.75rem;
    font-size: clamp(1.1rem, 3vw, 1.3rem);
}

.game-instructions ul {
    list-style: none;
    padding: 0;
}

.game-instructions li {
    color: var(--text-color);
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: clamp(0.85rem, 2.5vw, 1rem);
}

.game-instructions li:last-child {
    border-bottom: none;
}

.game-instructions strong {
    color: var(--accent-color);
}

.message-box {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--editor-bg);
    border: 2px solid var(--accent-color);
    border-radius: 12px;
    padding: 1.5rem 2rem;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    text-align: center;
    min-width: 280px;
    max-width: 90vw;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.message-box.hidden {
    display: none;
}

.message-box h2 {
    color: var(--text-color);
    margin-bottom: 0.75rem;
    font-size: clamp(1.3rem, 4vw, 2rem);
}

.message-box p {
    color: var(--text-color);
    margin-bottom: 1rem;
    font-size: clamp(0.95rem, 3vw, 1.1rem);
}

.message-box button {
    padding: 0.75rem 1.5rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    font-family: 'Space Mono', monospace;
    transition: all 0.3s ease;
}

.message-box button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Responsive Design */
@media (max-width: 1024px) {
    :root {
        --card-size: 90px;
    }
}

@media (max-width: 768px) {
    :root {
        --card-size: 75px;
    }
    
    .memory-content {
        padding: 0.5rem;
    }

    .game-controls {
        gap: 0.5rem;
    }

    .game-info {
        gap: 0.4rem;
    }

    .info-item {
        padding: 0.4rem 0.6rem;
    }

    .game-btn {
        padding: 0.5rem 0.75rem;
    }

    .board-wrapper {
        padding: 0.25rem;
    }

    .memory-board {
        gap: 0.5rem;
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    :root {
        --card-size: 65px;
    }

    .memory-content {
        padding: 0.25rem;
    }

    .subtitle {
        margin-bottom: 0.5rem;
    }

    .game-controls,
    .game-info {
        gap: 0.3rem;
        margin-bottom: 0.5rem;
    }

    .info-item {
        padding: 0.3rem 0.5rem;
        gap: 0.2rem;
    }

    .game-btn {
        padding: 0.4rem 0.6rem;
        gap: 0.3rem;
    }

    .game-instructions {
        padding: 0.75rem;
        margin: 0.5rem;
    }

    .message-box {
        padding: 1rem 1.5rem;
        min-width: 260px;
    }

    .memory-board {
        gap: 0.4rem;
        padding: 0.25rem;
    }
}

@media (max-width: 360px) {
    :root {
        --card-size: 55px;
    }

    .difficulty-selector {
        flex-direction: column;
        gap: 0.3rem;
    }

    .info-item span {
        font-size: 0.7rem;
    }

    .memory-board {
        gap: 0.3rem;
    }
}

/* Touch feedback */
.card:active {
    opacity: 0.8;
}

/* Prevent text selection */
.memory-board,
.card {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Landscape mode adjustments for mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .memory-content h1 {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }
    
    .subtitle {
        font-size: 0.85rem;
        margin-bottom: 0.5rem;
    }
    
    .game-controls,
    .game-info {
        margin-bottom: 0.5rem;
    }
    
    .game-instructions {
        display: none;
    }
}
