/* Mobile-specific styles */

/* Touch-friendly spacing */
@media (max-width: 768px) {
    #app {
        padding: 0.75rem;
    }

    header {
        padding: 0.75rem 0;
        margin-bottom: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    /* Fix main menu title - prevent wrapping and ensure centering */
    .game-title {
        font-size: 1.2rem !important;
        white-space: nowrap;
        text-align: center !important;
        width: 100%;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .game-subtitle {
        font-size: 0.5rem !important;
    }

    /* Show mobile controls hint */
    #controls-hint .desktop {
        display: none;
    }

    #controls-hint .mobile {
        display: block;
    }

    /* Larger touch targets */
    .primary-button {
        padding: 1rem 2rem;
        font-size: 1.125rem;
        min-height: 48px;
    }

    /* Optimize game info for mobile - prevent wrapping and better alignment */
    #game-info {
        gap: 0.5rem;
        padding: 0.75rem;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
    }

    .info-item .label {
        font-size: 0.5rem;
        white-space: nowrap;
    }

    .info-item span:last-child {
        font-size: 0.9rem;
    }

    /* Lives display sizing for challenge mode */
    #lives-display {
        font-size: 0.9rem !important;
    }

    /* Modal adjustments */
    .modal-content {
        padding: 1.5rem;
        max-width: 90%;
    }

    .modal-content h2 {
        font-size: 1.5rem;
    }

    .stats {
        gap: 0.75rem;
    }

    .stat {
        padding: 0.75rem;
        min-width: 80px;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    /* Submenu header mobile adjustments */
    .submenu-header {
        padding: 0.75rem 1rem;
    }

    .back-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.65rem;
    }

    .submenu-title {
        font-size: 0.8rem;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    #app {
        padding: 0.5rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    #game-info {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .info-item {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
    }

    .modal-content {
        padding: 1rem;
    }
}

/* Landscape mobile */
@media (max-height: 600px) and (orientation: landscape) {
    #app {
        padding: 0.5rem;
    }

    header {
        padding: 0.5rem 0;
        margin-bottom: 0.5rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .subtitle {
        display: none;
    }

    #game-container {
        gap: 0.5rem;
    }

    #game-info {
        padding: 0.5rem;
    }

    #controls-hint {
        margin-top: 0.5rem;
        font-size: 0.75rem;
    }

    #grid-container {
        --tile-size: 40px;
        --grid-gap: 2px;
        padding: 0.5rem;
    }
}

/* iOS smooth scrolling improvements */
@supports (-webkit-overflow-scrolling: touch) {
    #app {
        -webkit-overflow-scrolling: touch;
    }

    .menu-container {
        padding: 1rem;
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }

    /* Character selection and help screens */
    #character-selection-screen .menu-content,
    #help-screen .menu-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        min-height: 0;
        padding-top: 1rem;
    }

    /* Ensure back buttons stay visible */
    #character-selection-screen .menu-play-btn,
    #help-screen .menu-play-btn {
        flex-shrink: 0;
        margin-top: 1rem;
    }

    /* Character grid should scroll if needed */
    .char-selection-grid {
        flex: 1;
        overflow-y: auto;
    }

    /* Game info boxes in help screen */
    .game-info-box {
        flex-shrink: 0;
    }
}

/* Prevent zoom on input focus (iOS Safari) */
@media (max-width: 768px) {
    input,
    select,
    textarea,
    button:not(.hint-btn):not(.retry-btn):not(.switch-char-btn) {
        font-size: 16px !important;
    }

    /* Keep emoji buttons at their defined size */
    .hint-btn,
    .retry-btn,
    .switch-char-btn {
        font-size: 28px !important;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .tile,
    .player {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Dark mode support (if OS prefers dark) */
@media (prefers-color-scheme: dark) {
    /* Already dark by default, but we could add overrides here */
}

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

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}
