/* Mobile Responsive Styles for All Games */

/* Prevent zoom on double tap */
* {
    touch-action: manipulation;
}

/* Prevent text selection on mobile */
body {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
}

/* Allow selection on inputs and textareas */
input, textarea, [contenteditable] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Responsive containers */
.max-w-3xl, .max-w-4xl, .max-w-5xl {
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Mobile breakpoints */
@media (max-width: 768px) {
    /* Header adjustments */
    h1 {
        font-size: 2rem !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
    }
    
    /* Button adjustments */
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.875rem;
    }
    
    /* Stats panels */
    .glass-panel {
        padding: 0.75rem;
        min-width: 80px !important;
    }
    
    .glass-panel .text-2xl {
        font-size: 1.5rem !important;
    }
    
    /* Flex wrapping for controls */
    .flex-wrap {
        justify-content: center;
    }
    
    /* Canvas responsive */
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Game board responsive */
    .game-board {
        max-width: 100% !important;
    }
    
    /* Modal adjustments */
    #gameOverModal .glass-panel,
    #modeModal .glass-panel {
        max-width: 90% !important;
        margin: 1rem;
    }
}

@media (max-width: 640px) {
    /* Smaller screens */
    h1 {
        font-size: 1.75rem !important;
    }
    
    /* Stats in column on very small screens */
    .flex.gap-4 {
        gap: 0.5rem;
    }
    
    /* Buttons stack */
    .flex.gap-4.mb-6 {
        flex-direction: column;
        align-items: stretch;
    }
    
    .flex.gap-4.mb-6 .btn {
        width: 100%;
    }
    
    /* Controls full width */
    .flex.gap-2.mb-4 {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .flex.gap-2.mb-4 .glass-panel {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Select elements full width */
    select {
        width: 100%;
    }
}

/* Touch-specific adjustments */
@media (hover: none) and (pointer: coarse) {
    /* Make buttons bigger for touch */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Increase tap target size */
    button, a, [role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch */
    .btn:hover,
    .glass-panel:hover {
        transform: none !important;
    }
    
    /* Active state instead */
    .btn:active {
        transform: scale(0.95);
        opacity: 0.9;
    }
}

/* Landscape mode adjustments */
@media (max-width: 896px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    .pt-24 {
        padding-top: 4rem !important;
    }
    
    .pb-12 {
        padding-bottom: 2rem !important;
    }
    
    .mb-6 {
        margin-bottom: 1rem !important;
    }
    
    /* Make game area use more screen */
    h1 {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    p {
        font-size: 0.875rem;
    }
    
    /* Hide some descriptions in landscape */
    .text-\[var\(--text-secondary\)\] {
        display: none;
    }
}

/* Portrait mode adjustments */
@media (max-height: 700px) and (orientation: portrait) {
    /* Compact mode for short screens */
    .pt-24 {
        padding-top: 3rem !important;
    }
    
    .mb-6 {
        margin-bottom: 0.75rem !important;
    }
    
    h1 {
        font-size: 1.5rem !important;
    }
}

/* Game-specific mobile adjustments */

/* Snake - Touch controls hint */
.snake-touch-hint {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    z-index: 100;
    animation: fadeIn 0.3s ease-in;
}

/* Memory - Smaller cards on mobile */
@media (max-width: 640px) {
    .memory-card {
        font-size: 2rem !important;
    }
}

/* 2048 - Responsive grid */
@media (max-width: 640px) {
    .tile-container {
        font-size: 2rem !important;
    }
}

/* Block Blast - Drag hint */
.drag-hint {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(45, 212, 191, 0.9);
    color: white;
    padding: 1rem 2rem;
    border-radius: 1rem;
    font-weight: bold;
    z-index: 1000;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Safe area for notched devices (iPhone X, etc.) */
@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix iOS Safari bounce */
    body {
        position: fixed;
        overflow: hidden;
        width: 100%;
        height: 100vh;
    }
    
    .flex.flex-col.min-h-screen {
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Virtual controls styling (added by mobile-touch-handler.js) */
#mobile-controls {
    display: none;
}

@media (max-width: 768px) and (hover: none) {
    #mobile-controls {
        display: flex !important;
    }
}

/* Loading spinner for mobile */
.mobile-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border: 4px solid rgba(45, 212, 191, 0.2);
    border-top-color: rgba(45, 212, 191, 1);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 10000;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Accessibility - Larger tap targets */
@media (max-width: 768px) {
    a, button, [role="button"], input[type="button"], input[type="submit"] {
        padding: 0.75rem 1rem;
    }
}

/* Print styles */
@media print {
    #mobile-controls,
    .glass-panel,
    button,
    #game-header,
    footer {
        display: none !important;
    }
}
