/* Mobile-First Memory Game Styles — Dark Mode */

*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f0f1e;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #1e2a44;
    --accent-primary: #7b68ee;
    --accent-secondary: #9d8df1;
    --accent-danger: #ef4444;
    --accent-success: #10b981;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-bright: #ffffff;
    --border-dark: #2a2a3e;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);

    --card-size: 70px; /* fallback, overridden inline per grid */
    --card-gap: clamp(3px, 1.2vw, 8px);
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-tap-highlight-color: transparent;
    min-height: 100vh;
}

/* ===== HOME PAGE ===== */

.home-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 40px 20px;
    text-align: center;
}

.home-icon {
    width: 120px;
    height: 120px;
    margin: 0 auto 20px;
    display: block;
    filter: drop-shadow(0 0 20px rgba(123, 104, 238, 0.3));
}

.home-title h1 {
    font-size: clamp(1.6rem, 7vw, 3rem);
    color: var(--accent-primary);
    text-shadow: 0 0 30px rgba(123, 104, 238, 0.5);
    margin: 0 0 8px;
    white-space: nowrap;
}

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

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.difficulty-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    min-height: 72px;
    padding: 16px 20px;
    border: 2px solid var(--accent-primary);
    border-radius: 14px;
    background: var(--bg-secondary);
    color: var(--text-bright);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: var(--shadow-sm);
}

.difficulty-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-secondary);
}

.difficulty-btn:active {
    transform: scale(0.97);
    background: var(--accent-primary);
    box-shadow: 0 0 20px rgba(123, 104, 238, 0.4);
}

.difficulty-btn.easy {
    border-color: var(--accent-success);
}

.difficulty-btn.easy:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-success);
    filter: brightness(1.1);
}

.difficulty-btn.easy:active {
    background: var(--accent-success);
}

.difficulty-btn.hard {
    border-color: var(--accent-danger);
}

.difficulty-btn.hard:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-danger);
    filter: brightness(1.1);
}

.difficulty-btn.hard:active {
    background: var(--accent-danger);
}

.difficulty-title {
    font-size: 1.4rem;
    font-weight: 700;
}

.difficulty-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.difficulty-btn:active .difficulty-desc {
    color: rgba(255, 255, 255, 0.85);
}

/* ===== GAME PAGE ===== */

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    min-height: 100vh;
}

.game-title {
    width: 100%;
    max-width: 520px;
    text-align: center;
    margin-bottom: 14px;
}

.game-title h1 {
    margin: 0;
    font-size: 1.8rem;
    color: var(--accent-primary);
    text-shadow: 0 0 20px rgba(123, 104, 238, 0.4);
}

.stat {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-value {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-secondary);
    margin-top: 2px;
}

/* ===== CARD GRID ===== */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, var(--card-size));
    gap: var(--card-gap);
    width: 100%;
    max-width: 680px;
    justify-content: center;
}

/* ===== CARD FLIP ANIMATION (CSS-only 3D) ===== */

.memory-card {
    width: var(--card-size);
    height: var(--card-size);
    perspective: 600px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.memory-card.locked {
    cursor: default;
    pointer-events: none;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.4s cubic-bezier(0.4, 0.2, 0.2, 1);
    border-radius: 10px;
}

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

.card-back,
.card-front {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Back face — visible by default */
.card-back {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-dark);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s;
}

.memory-card:not(.locked):hover .card-back {
    border-color: var(--accent-primary);
}

.card-back-pattern {
    font-size: calc(var(--card-size) * 0.35);
    color: var(--accent-primary);
    opacity: 0.45;
}

/* Front face — shown after flip (pre-rotated 180deg so it reads correctly) */
.card-front {
    background: var(--bg-secondary);
    border: 2px solid var(--accent-primary);
    box-shadow: var(--shadow-sm);
    transform: rotateY(180deg);
}

.card-emoji {
    font-size: calc(var(--card-size) * 0.54);
    line-height: 1;
    color: initial;
}

/* Matched card — green glow */
.memory-card.matched .card-front {
    background: rgba(16, 185, 129, 0.12);
    border-color: var(--accent-success);
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.35);
}

/* ===== GAME FOOTER ===== */

.game-footer {
    margin-top: 18px;
    width: 100%;
    max-width: 520px;
}

.quit-btn {
    width: 100%;
    min-height: 48px;
    font-size: 1rem;
    border: 2px solid var(--border-dark);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.quit-btn:hover {
    border-color: var(--accent-danger);
    color: var(--accent-danger);
}

.quit-btn:active {
    background: var(--accent-danger);
    color: var(--text-bright);
}

/* ===== VICTORY OVERLAY ===== */

.victory-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 30, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.victory-modal {
    background: var(--bg-secondary);
    border: 3px solid var(--accent-success);
    border-radius: 16px;
    padding: 30px 36px;
    text-align: center;
    max-width: 90%;
    width: 380px;
    box-shadow: 0 0 60px rgba(16, 185, 129, 0.4);
    animation: scaleIn 0.3s ease-out;
}

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

.victory-modal h2 {
    color: var(--accent-success);
    margin: 0 0 24px;
    font-size: 1.8rem;
    text-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}

.victory-stats {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-dark);
}

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

.stat-item .stat-label {
    font-size: 1rem;
    text-transform: none;
    letter-spacing: 0;
}

.stat-item .stat-value {
    font-size: 1.15rem;
    color: var(--accent-success);
    margin-top: 0;
}

.score-item .score-value {
    font-size: 1.5rem;
    color: var(--accent-primary);
    text-shadow: 0 0 10px rgba(123, 104, 238, 0.4);
}

.new-game-btn {
    width: 100%;
    min-height: 52px;
    font-size: 1.1rem;
    font-weight: 700;
    border: 2px solid var(--accent-success);
    border-radius: 10px;
    background: var(--accent-success);
    color: var(--text-bright);
    cursor: pointer;
    transition: all 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.new-game-btn:hover {
    background: #059669;
    border-color: #059669;
    transform: scale(1.02);
}

.new-game-btn:active {
    transform: scale(0.98);
}

/* ===== NO-GAME STATE ===== */

.no-game {
    text-align: center;
    padding: 60px 20px;
}

.no-game p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.no-game button {
    min-height: 48px;
    padding: 10px 30px;
    font-size: 1rem;
    border: 2px solid var(--accent-primary);
    border-radius: 8px;
    background: var(--accent-primary);
    color: var(--text-bright);
    cursor: pointer;
    transition: all 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.no-game button:hover {
    background: var(--accent-secondary);
}

/* ===== FOOTER ===== */

.app-footer {
    text-align: center;
    padding: 12px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    opacity: 0.5;
}

/* ===== RESPONSIVE ===== */

@media (min-width: 768px) {
    .game-container {
        padding: 20px;
    }

    .difficulty-buttons {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
}
