/* =====================================================
   SCREW SORT PUZZLE - RESPONSIVE CSS
   Mobile-First Breakpoints
   ===================================================== */

/* ===== BASE (Mobile First - 320px+) ===== */
:root {
    --game-padding: 12px;
    --screw-size: 45px;
    --hole-width: 55px;
    --hole-height: 110px;
    --container-width: 65px;
    --container-height: 95px;
}

/* ===== SMALL PHONES (375px+) ===== */
@media (min-width: 375px) {
    :root {
        --game-padding: 16px;
        --screw-size: 50px;
        --hole-width: 60px;
        --hole-height: 120px;
        --container-width: 70px;
        --container-height: 100px;
    }
}

/* ===== LARGE PHONES (414px+) ===== */
@media (min-width: 414px) {
    :root {
        --screw-size: 55px;
        --hole-width: 65px;
        --hole-height: 130px;
        --container-width: 75px;
        --container-height: 105px;
    }

    .game-header {
        padding: var(--space-md) var(--space-lg);
    }

    .stat {
        padding: var(--space-sm) var(--space-md);
    }
}

/* ===== TABLETS (768px+) ===== */
@media (min-width: 768px) {
    :root {
        --game-padding: 24px;
        --screw-size: 60px;
        --hole-width: 70px;
        --hole-height: 140px;
        --container-width: 85px;
        --container-height: 120px;
    }

    body {
        font-size: 18px;
    }

    .game-container {
        max-width: 600px;
    }

    .game-header {
        border-radius: var(--radius-xl);
    }

    .btn {
        padding: var(--space-md) var(--space-xl);
    }

    .modal {
        max-width: 500px;
    }

    .auth-card {
        padding: var(--space-2xl) var(--space-2xl);
    }

    .menu-logo {
        max-width: 350px;
    }

    .menu-buttons {
        max-width: 350px;
    }

    .level-complete-content {
        max-width: 450px;
        padding: var(--space-2xl) var(--space-2xl);
    }

    .star {
        width: 60px;
        height: 60px;
        font-size: 50px;
    }
}

/* ===== DESKTOP (1024px+) ===== */
@media (min-width: 1024px) {
    :root {
        --screw-size: 65px;
        --hole-width: 75px;
        --hole-height: 150px;
        --container-width: 90px;
        --container-height: 130px;
    }

    .game-wrapper {
        display: flex;
        justify-content: center;
    }

    .game-container {
        max-width: 700px;
    }

    .toast-container {
        top: var(--space-xl);
        right: var(--space-xl);
    }

    .toast {
        max-width: 400px;
    }
}

/* ===== LANDSCAPE MODE ===== */
@media (orientation: landscape) and (max-height: 500px) {
    .game-wrapper {
        flex-direction: row;
    }

    .game-container {
        flex-direction: row;
        max-width: 100%;
        padding: var(--space-sm);
    }

    .game-header {
        flex-direction: column;
        width: auto;
        margin-bottom: 0;
        margin-right: var(--space-md);
    }

    .header-left,
    .header-center,
    .header-right {
        flex-direction: column;
        margin: var(--space-xs) 0;
    }

    .game-board {
        flex: 1;
        flex-direction: row;
        min-height: auto;
        padding: var(--space-sm);
    }

    .containers-area {
        flex-direction: column;
        padding: var(--space-sm);
    }

    .ad-banner--top {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
    }
}

/* ===== SAFE AREA (Notch/Home Indicator) ===== */
@supports (padding: max(0px)) {
    .game-wrapper {
        padding-top: max(var(--space-md), env(safe-area-inset-top));
        padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
        padding-left: max(var(--space-md), env(safe-area-inset-left));
        padding-right: max(var(--space-md), env(safe-area-inset-right));
    }

    .ad-banner--top {
        top: max(0px, env(safe-area-inset-top));
    }

    .modal-overlay {
        padding-top: max(var(--space-md), env(safe-area-inset-top));
        padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    .screw {
        min-width: 44px;
        min-height: 44px;
    }

    .btn {
        min-height: 48px;
    }

    .btn--icon {
        min-width: 48px;
        min-height: 48px;
    }

    .form-input {
        min-height: 48px;
        font-size: 16px;
        /* Prevents iOS zoom */
    }

    /* Disable hover effects on touch */
    .screw--selectable:hover {
        transform: none;
        filter: none;
    }

    .container:hover {
        transform: none;
    }

    .btn--primary:hover {
        transform: none;
    }
}

/* ===== HIGH DPI DISPLAYS ===== */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .screw-head {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ===== DARK MODE (System Preference) ===== */
@media (prefers-color-scheme: dark) {

    /* Already dark by default, but ensure consistency */
    :root {
        color-scheme: dark;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .game-wrapper {
        display: none;
    }
}

/* ===== TUTORIAL OVERLAY RESPONSIVE ===== */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-tutorial);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

.tutorial-spotlight {
    position: absolute;
    border-radius: var(--radius-lg);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
    animation: highlightPulse 1.5s infinite;
    pointer-events: none;
}

.tutorial-message {
    position: absolute;
    background: white;
    color: #1a1a1a;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    max-width: 280px;
    text-align: center;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
}

.tutorial-message::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 10px solid transparent;
}

.tutorial-message--top::after {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-bottom-color: white;
}

.tutorial-message--bottom::after {
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-top-color: white;
}

.tutorial-finger {
    position: absolute;
    width: 60px;
    height: 60px;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23fff"><path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2zm0 18c-4.4 0-8-3.6-8-8s3.6-8 8-8 8 3.6 8 8-3.6 8-8 8z"/><circle cx="12" cy="12" r="5"/></svg>') center/contain no-repeat;
    animation: fingerTap 1s infinite;
    pointer-events: none;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

.tutorial-arrow {
    position: absolute;
    width: 40px;
    height: 40px;
    animation: arrowBounce 0.8s infinite;
    pointer-events: none;
}

.tutorial-skip {
    position: absolute;
    bottom: var(--space-xl);
    right: var(--space-xl);
}

@media (max-width: 374px) {
    .tutorial-message {
        max-width: 240px;
        font-size: var(--text-sm);
        padding: var(--space-sm) var(--space-md);
    }

    .tutorial-finger {
        width: 50px;
        height: 50px;
    }
}