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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f1a;
    color: #e0e0e0;
    line-height: 1.6;
    min-height: 100vh;
}

main {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
}

.back-link {
    display: inline-block;
    color: #4ecca3;
    text-decoration: none;
    margin-bottom: 0.5rem;
}

.back-link:hover {
    text-decoration: underline;
}

h1 {
    text-align: center;
    color: #4ecca3;
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    position: relative;
}

.score-board {
    display: flex;
    gap: 1.5rem;
    font-size: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.score-board strong {
    color: #4ecca3;
}

.difficulty-selector {
    display: flex;
    gap: 0.5rem;
}

.diff-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    background: #1a1a2e;
    color: #e0e0e0;
    border: 2px solid #4ecca3;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.diff-btn:hover {
    background: #2a2a3e;
}

.diff-btn.active {
    background: #4ecca3;
    color: #0f0f1a;
}

.game-board {
    display: grid;
    gap: 8px;
    padding: 8px;
    background: #1a1a2e;
    border: 2px solid #4ecca3;
    border-radius: 8px;
}

.game-board.size-4 {
    grid-template-columns: repeat(4, 1fr);
    max-width: 360px;
}

.game-board.size-6 {
    grid-template-columns: repeat(6, 1fr);
    max-width: 480px;
}

.card {
    aspect-ratio: 1;
    width: 100%;
    min-width: 50px;
    max-width: 80px;
    perspective: 1000px;
    cursor: pointer;
}

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

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

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

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-back {
    background: linear-gradient(135deg, #4ecca3 0%, #3db892 100%);
    font-size: 1.5rem;
}

.card-back::after {
    content: '?';
    color: #0f0f1a;
    font-weight: bold;
}

.card-front {
    background: #2a2a3e;
    transform: rotateY(180deg);
    font-size: 2rem;
}

.card.matched .card-front {
    background: #1a3a2e;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 26, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay p {
    font-size: 1.5rem;
    color: #4ecca3;
}

.overlay p:first-child {
    font-size: 2rem;
}

.overlay button {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    background: #4ecca3;
    color: #0f0f1a;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

.overlay button:hover {
    background: #3db892;
}

.overlay .share-btn {
    background: #2a9d8f;
    margin-top: 0.5rem;
}

.overlay .share-btn:hover {
    background: #248c7f;
}

.instructions {
    font-size: 0.9rem;
    color: #888;
    text-align: center;
}

.content {
    padding-top: 1rem;
    border-top: 1px solid #2a2a3e;
}

.content h2 {
    color: #4ecca3;
    font-size: 1.25rem;
    margin: 1.5rem 0 0.75rem;
}

.content h2:first-child {
    margin-top: 1rem;
}

.content p {
    margin-bottom: 0.75rem;
}

.content ul {
    margin: 0.5rem 0 1rem 1.5rem;
}

.content li {
    margin-bottom: 0.5rem;
}

@media (min-width: 600px) {
    main {
        padding: 2rem;
    }

    h1 {
        font-size: 2rem;
    }

    .instructions {
        font-size: 1rem;
    }

    .card {
        min-width: 60px;
    }

    .card-front {
        font-size: 2.5rem;
    }
}

@media (max-width: 400px) {
    .game-board {
        gap: 4px;
        padding: 4px;
    }

    .card {
        min-width: 40px;
    }

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

    .score-board {
        gap: 1rem;
        font-size: 0.9rem;
    }
}
