/* 
    MEMORY MATCH - Accessible Card Game Styles
    
    CHOICE: Using CSS variables for theming
    WHY: Easy to swap themes (high contrast, colorblind modes) without duplicating styles
    ACCESSIBILITY: All interactive elements have visible focus states
    
    TODO: Add reduced-motion media query support
*/

:root {
    /* Base colors - chosen for good contrast ratios */
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --card-back: #6366f1;
    --card-front: #ffffff;
    --focus-ring: #f59e0b;
    
    /* Spacing - consistent scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Animation */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
}

/* 
    CHOICE: High contrast theme as a class, not media query
    WHY: Users can toggle it manually, not forced by system settings
    ACCESSIBILITY: Meets WCAG AAA contrast requirements
*/
.high-contrast {
    --bg-primary: #000000;
    --bg-secondary: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --accent: #ffff00;
    --accent-hover: #ffff99;
    --success: #00ff00;
    --card-back: #333333;
    --card-front: #ffffff;
    --focus-ring: #00ffff;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--space-md);
}

/* 
    CHOICE: Using max-width container instead of full-width
    WHY: Better readability on large screens, cards don't get comically huge
*/
.container {
    max-width: 800px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: var(--space-lg);
}

h1 {
    font-size: 2.5rem;
    margin-bottom: var(--space-xs);
}

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

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: var(--space-xl);
    background: var(--bg-secondary);
    padding: var(--space-md);
    border-radius: 8px;
    margin-bottom: var(--space-md);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.stat {
    text-align: center;
}

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

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
}

/* Controls */
.controls {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
    margin-bottom: var(--space-lg);
}

/* 
    CHOICE: Large touch-friendly buttons (min 44x44px per WCAG)
    WHY: Works for motor impairments and mobile users
    ACCESSIBILITY: Focus ring is thick and high-contrast
*/
.btn {
    padding: var(--space-sm) var(--space-lg);
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 44px;
    min-width: 44px;
}

.btn:focus {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

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

.btn-secondary:hover {
    border-color: var(--text-primary);
}

/* Game Board */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

/* 
    CHOICE: Cards maintain aspect ratio
    WHY: Square cards look better and are easier to recognize
    RESPONSIVE: Adjusts grid columns on smaller screens
*/
.card {
    aspect-ratio: 1;
    perspective: 1000px;
    cursor: pointer;
    position: relative;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform var(--transition-normal);
    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: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card-back {
    background: var(--card-back);
    /* Pattern for card back - helps colorblind users distinguish from front */
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(255,255,255,0.1) 10px,
        rgba(255,255,255,0.1) 20px
    );
}

.card-front {
    background: var(--card-front);
    transform: rotateY(180deg);
    border: 2px solid var(--text-secondary);
}

/* Matched cards get a subtle success indicator */
.card.matched .card-front {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

/* 
    CHOICE: Focus visible only on keyboard navigation
    WHY: Mouse users don't need focus rings, but keyboard users do
    ACCESSIBILITY: Uses :focus-visible for smart focus indication
*/
.card:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 4px;
}

/* Screen reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    padding: var(--space-xl);
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    margin: var(--space-md);
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: var(--space-md);
}

.modal-content p {
    margin-bottom: var(--space-lg);
    font-size: 1.1rem;
}

footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: var(--space-xl);
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* 
    RESPONSIVE: Mobile-first adjustments
    CHOICE: Reduce to 2 columns on very small screens
    WHY: Cards stay large enough to tap accurately
    FIX: Actually changed from 4 to 2 columns (was a bug)
*/
@media (max-width: 480px) {
    .game-board {
        grid-template-columns: repeat(2, 1fr); /* FIX: Changed from 4 to 2 */
        gap: var(--space-sm);
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .stats-bar {
        flex-wrap: wrap;
        gap: var(--space-md);
    }
    
    .card-front {
        font-size: 2rem;
    }
}

/* 
    ACCESSIBILITY: Reduced motion preference
    CHOICE: Respect user's system preference
    WHY: Important for users with vestibular disorders
*/
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}
