/**
 * Responsive Design for Kids Games
 * Mobile-first approach with breakpoints
 */

/* Tablet and up (768px and larger) */
@media (min-width: 768px) {
    :root {
        --font-size-large: 56px;
        --font-size-medium: 40px;
        --font-size-normal: 28px;
        --font-size-small: 20px;
        --space-lg: 32px;
        --space-xl: 40px;
    }

    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .hide-md {
        display: none !important;
    }
}

/* Desktop and up (1024px and larger) */
@media (min-width: 1024px) {
    .container {
        padding: 0 48px;
    }

    .grid {
        gap: 32px;
    }

    .hide-lg {
        display: none !important;
    }

    /* Larger buttons on desktop */
    button, .btn {
        font-size: 24px;
        padding: 16px 32px;
        min-height: 64px;
    }
}

/* Landscape mode adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    h1 {
        font-size: 32px;
        margin-bottom: 12px;
    }

    h2 {
        font-size: 24px;
    }

    button, .btn {
        padding: 8px 16px;
        min-height: 44px;
        font-size: 16px;
    }

    .card {
        padding: 12px;
    }

    /* Reduce vertical spacing */
    :root {
        --space-lg: 12px;
        --space-md: 8px;
    }
}

/* Very small devices (320px) */
@media (max-width: 320px) {
    :root {
        --font-size-large: 24px;
        --font-size-medium: 20px;
        --font-size-normal: 16px;
        --font-size-small: 14px;
    }

    h1 {
        font-size: 24px;
    }

    button, .btn {
        font-size: 14px;
        padding: 8px 12px;
        min-height: 44px;
    }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* Small phones (480px) */
@media (max-width: 480px) {
    :root {
        --font-size-large: 32px;
        --font-size-medium: 24px;
        --font-size-normal: 18px;
        --font-size-small: 16px;
        --space-lg: 16px;
        --space-md: 12px;
        --radius-lg: 16px;
    }

    body {
        padding: 0;
    }

    h1 {
        font-size: 32px;
        margin-bottom: 16px;
    }

    h2 {
        font-size: 24px;
    }

    .container {
        padding: 0 12px;
    }

    .game-container {
        padding: 12px;
    }

    .card {
        padding: 12px;
    }

    button, .btn {
        width: 100%;
        font-size: 16px;
        padding: 12px 16px;
        min-height: 44px;
    }

    /* Grid adjustments */
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid {
        gap: 12px;
    }

    /* Touch-friendly spacing */
    .flex {
        flex-direction: column;
        gap: 12px;
    }

    /* Hide desktop elements */
    .hide-mobile {
        display: none !important;
    }
}

/* Tablet (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .grid-4 {
        grid-template-columns: repeat(3, 1fr);
    }

    .hide-tablet {
        display: none !important;
    }
}

/* Portrait mode */
@media (orientation: portrait) {
    .card-landscape {
        flex-direction: column;
    }
}

/* Landscape mode */
@media (orientation: landscape) {
    .card-landscape {
        flex-direction: row;
    }

    body {
        max-height: 100vh;
        overflow-y: auto;
    }
}

/* High DPI screens (Retina) */
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    /* Finer details for high resolution */
    button, .btn {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .card {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

/* Low resolution / older devices */
@media (max-width: 240px) or (max-height: 400px) {
    .hide-small-screen {
        display: none !important;
    }
}

/* Print media */
@media print {
    body {
        background: white;
        margin: 0;
        padding: 0;
    }

    .no-print,
    button, .btn,
    .navigation {
        display: none !important;
    }

    .card {
        page-break-inside: avoid;
        box-shadow: none;
    }
}

/* Accessibility - Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    button:hover, .btn:hover {
        transform: none;
    }

    .card:hover {
        transform: none;
    }
}

/* Accessibility - High contrast mode */
@media (prefers-contrast: more) {
    :root {
        --text-dark: #000000;
        --text-light: #222222;
    }

    button, .btn {
        border: 2px solid currentColor;
        font-weight: 700;
    }

    .card {
        border: 2px solid var(--text-dark);
    }
}

/* Accessibility - Color scheme */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
        color: #ffffff;
    }

    .card {
        background: #2a2a2a;
    }

    input, textarea, select {
        background: #3a3a3a;
        color: #ffffff;
        border-color: #555555;
    }
}

/* Large displays (1920px and up) */
@media (min-width: 1920px) {
    :root {
        --font-size-large: 72px;
        --font-size-medium: 48px;
        --font-size-normal: 32px;
        --font-size-small: 24px;
    }

    .container {
        max-width: 1400px;
    }

    button, .btn {
        font-size: 28px;
        padding: 20px 40px;
        min-height: 72px;
    }
}

/* Very large displays (2560px and up) */
@media (min-width: 2560px) {
    :root {
        --font-size-large: 96px;
        --font-size-medium: 64px;
        --font-size-normal: 40px;
        --font-size-small: 32px;
    }

    button, .btn {
        font-size: 36px;
        padding: 24px 48px;
        min-height: 96px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    button, .btn {
        /* Ensure sufficient touch targets */
        min-height: 56px;
        min-width: 56px;
    }

    button:active, .btn:active {
        background: rgba(0, 0, 0, 0.1);
    }

    /* Disable hover effects on touch */
    button:hover, .btn:hover {
        transform: none;
    }
}

/* Pointer device with hover capability */
@media (hover: hover) and (pointer: fine) {
    button:hover, .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    }

    .card:hover {
        transform: translateY(-4px);
    }
}

/* Flexible columns for games */
.game-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

@media (max-width: 480px) {
    .game-grid {
        gap: 12px;
        grid-template-columns: 1fr;
    }
}

@media (min-width: 768px) {
    .game-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .game-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1400px) {
    .game-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Fullscreen support */
.fullscreen {
    width: 100vw;
    height: 100vh;
    max-width: 100%;
    overflow: hidden;
}

@media (max-width: 768px) {
    .fullscreen {
        height: 100dvh; /* Dynamic viewport height for mobile */
    }
}
