/* =============================================
   DRIVEFOCUS - MOBILE RESPONSIVE FIX v32
   Place AFTER styles.css in your HTML
   Only activates on phones (768px and smaller)
============================================== */

@media screen and (max-width: 768px) {
    
    /* ===========================================
       HOME SCREEN - Fixed layout
    =========================================== */
    
    #screen-home {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        padding-top: 100px;
        padding-bottom: 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        gap: 12px;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    .brand-header {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        transform: none;
        padding: 10px 14px;
        gap: 8px;
        z-index: 200;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
    }
    
    .brand-logo {
        width: 22px;
        height: 22px;
    }
    
    .brand-name {
        font-size: 12px;
        letter-spacing: 1px;
    }
    
    .user-info {
        width: auto;
        justify-content: center;
        gap: 8px;
        margin-top: 0;
        margin-left: 8px;
    }
    
    .user-credits-display {
        padding: 5px 10px;
        font-size: 11px;
    }
    
    .user-avatar {
        padding: 5px 10px;
        font-size: 10px;
    }
    
    .rev-cluster {
        width: 150px;
        height: 150px;
        margin-top: 10px;
        margin-bottom: 10px;
        flex-shrink: 0;
    }
    
    .rev-outer {
        border-width: 1px;
    }
    
    .rev-inner {
        inset: 12px;
    }
    
    .rev-ticks {
        inset: 14px;
    }
    
    .rev-tick {
        height: 8px;
        width: 1.5px;
        top: 6px;
    }
    
    .rev-tick.major {
        height: 12px;
        width: 2px;
    }
    
    .rev-value {
        font-size: 28px;
    }
    
    .rev-label {
        font-size: 8px;
        margin-top: 2px;
    }
    
    .rev-display {
        bottom: 25px;
    }
    
    .rev-needle {
        height: 50px;
        width: 3px;
    }
    
    .rev-center {
        width: 14px;
        height: 14px;
    }
    
    .home-tagline {
        font-size: 9px;
        letter-spacing: 2px;
        margin-bottom: 10px;
    }
    
    .home-stats {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        padding: 12px 15px;
        gap: 12px;
        margin-bottom: 5px;
        width: auto;
        max-width: 95%;
    }
    
    .home-stat {
        min-width: 55px;
        flex: 1;
    }
    
    .home-stat-icon {
        font-size: 16px;
        margin-bottom: 2px;
    }
    
    .home-stat-value {
        font-size: 14px;
    }
    
    .home-stat-label {
        font-size: 7px;
    }
    
    .stats-week-label {
        font-size: 9px;
        margin-bottom: 0;
    }
    
    .btn-enter {
        padding: 14px 35px;
        font-size: 12px;
        margin-top: 100px;
        margin-bottom: 12px;
    }
    
    .legal-links {
        font-size: 9px;
        margin-top: 8px;
        margin-bottom: 40px;
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
    
    /* ===========================================
       NAVIGATION
    =========================================== */
    
    .top-nav {
        position: fixed;
        height: 50px;
        padding: 8px 10px;
        gap: 8px;
        background: linear-gradient(to bottom, rgba(10, 10, 10, 0.95), rgba(10, 10, 10, 0.7), transparent);
    }
    
    .nav-tabs {
        gap: 5px;
    }
    
    .nav-tab {
        padding: 8px 14px;
        font-size: 10px;
        letter-spacing: 0.5px;
        background: transparent;
    }
    
    .nav-tab.active {
        background: rgba(255, 255, 255, 0.1);
    }
    
    .nav-arrow {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    
    /* ===========================================
       BACK BUTTON - Routes page
    =========================================== */
    
    .back-btn {
        position: fixed;
        top: 75px !important;
        left: 10px;
        padding: 8px 12px;
        font-size: 11px;
        z-index: 150;
    }
    
    /* ===========================================
       CARD SELECTOR
    =========================================== */
    
    .card-selector {
        position: absolute;
        bottom: 70px;
        left: 0;
        right: 0;
        transform: none;
        padding: 15px 20px 10px 20px;
        gap: 12px;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        scroll-padding-left: 20px;
    }
    
    .select-card {
        width: 150px;
        height: 210px;
        min-width: 150px;
        flex-shrink: 0;
    }
    
    .select-card.active {
        width: 170px;
        height: 240px;
        min-width: 170px;
    }
    
    .select-card:first-child {
        margin-left: 0;
    }
    
    .select-card-title {
        font-size: 13px;
    }
    
    .select-card.active .select-card-title {
        font-size: 15px;
    }
    
    .select-card-subtitle {
        font-size: 9px;
    }
    
    .select-card-content {
        padding: 12px;
    }
    
    .card-flag {
        width: 26px;
        height: 26px;
        font-size: 14px;
        top: 10px;
        right: 10px;
    }
    
    .route-reward {
        font-size: 10px;
        padding: 4px 8px;
        top: 10px;
        left: 10px;
    }
    
    .route-meta {
        font-size: 9px;
        gap: 8px;
        margin-top: 6px;
    }
    
    /* ===========================================
       DRIVE SCREEN - Split bottom layout
       
       LEFT SIDE:
       - Volume/Settings buttons (top)
       - Speed/Time/Miles panel (bottom)
       
       RIGHT SIDE:
       - Start Focus button (top)
       - Ambient sounds (bottom)
    =========================================== */
    
    .drive-route-info {
        top: 10px;
        left: 10px;
        padding: 10px 12px;
        gap: 8px;
        max-width: 170px;
    }
    
    .route-icon {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
    
    .route-text h3 {
        font-size: 12px;
    }
    
    .route-text p {
        font-size: 9px;
    }
    
    .drive-status {
        top: 10px;
        right: 10px;
        bottom: auto;
        gap: 8px;
    }
    
    .status-badge {
        padding: 8px 12px;
        gap: 6px;
    }
    
    .status-dot {
        width: 6px;
        height: 6px;
    }
    
    .status-text {
        font-size: 9px;
    }
    
    .speed-limit {
        width: 36px;
        height: 36px;
        font-size: 16px;
        border-width: 4px;
    }
    
    /* LEFT BOTTOM: Speed panel */
    .speed-panel {
        position: absolute;
        left: 10px;
        right: auto;
        bottom: 15px;
        padding: 10px 12px;
        gap: 10px;
        max-width: 48%;
    }
    
    .speed-value {
        font-size: 28px;
    }
    
    .speed-unit {
        font-size: 8px;
    }
    
    .stat-value {
        font-size: 14px;
    }
    
    .stat-label {
        font-size: 6px;
    }
    
    .stat-divider {
        height: 22px;
    }
    
    /* LEFT TOP: Volume/Settings buttons - above speed panel */
    .control-panel {
        position: absolute;
        left: 10px;
        bottom: 95px;
        right: auto;
        gap: 8px;
        flex-direction: row;
    }
    
    .control-btn {
        width: 40px;
        height: 40px;
    }
    
    .control-btn svg {
        width: 16px;
        height: 16px;
    }
    
    /* Pause button - show next to settings */
    .btn-pause {
        display: flex !important;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .btn-pause.visible {
        display: flex !important;
    }
    
    /* RIGHT BOTTOM: Ambient sounds */
    .ambient-selector {
        position: absolute;
        bottom: 15px;
        right: 10px;
        left: auto;
        transform: none;
        flex-direction: column;
        align-items: center;
        gap: 5px;
    }
    
    .ambient-label {
        display: none;
    }
    
    .ambient-buttons {
        padding: 8px 12px;
        gap: 8px;
    }
    
    .ambient-btn {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }
    
    /* Volume control - larger touch targets for mobile */
    .ambient-volume-control {
        padding: 12px 16px;
        border-radius: 25px;
        margin-top: 8px;
        pointer-events: auto !important;
    }
    
    .ambient-volume-slider {
        width: 120px;
        height: 8px;
        -webkit-appearance: none;
        appearance: none;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 4px;
        cursor: pointer;
        pointer-events: auto !important;
    }
    
    .ambient-volume-slider::-webkit-slider-runnable-track {
        height: 8px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 4px;
    }
    
    .ambient-volume-slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 32px;
        height: 32px;
        background: #e91e63;
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(233, 30, 99, 0.5);
        margin-top: -12px;
        pointer-events: auto !important;
    }
    
    .ambient-volume-slider::-moz-range-thumb {
        width: 32px;
        height: 32px;
        background: #e91e63;
        border: none;
        border-radius: 50%;
        cursor: pointer;
    }
    
    .ambient-volume-slider::-moz-range-track {
        height: 8px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 4px;
    }
    
    /* RIGHT TOP: Start Focus / End Session button - above ambient */
    .btn-drive {
        position: fixed !important;
        bottom: 95px !important;
        right: 10px !important;
        left: auto !important;
        transform: none !important;
        padding: 12px 20px;
        font-size: 11px;
        z-index: 110;
        transition: bottom 0.3s ease !important;
    }
    
    /* Move END SESSION button UP when volume slider is visible */
    .btn-drive.volume-active {
        bottom: 140px !important;
    }
    
    .focus-goal-bar {
        top: 68px;
        left: 10px;
        width: 170px;
        height: 22px;
        transform: none;
    }
    
    .goal-text {
        font-size: 9px;
    }
    
    #screen-drive .back-btn {
        top: 98px !important;
        left: 10px;
    }
    
    .car-avatar {
        width: 55px;
        left: calc(50% - 27px);
        top: 45%;
    }
    
    /* ===========================================
       MODALS
    =========================================== */
    
    .modal-panel,
    .settings-panel,
    .car-shop-content,
    .credit-shop-content,
    .session-summary-content,
    .pause-warning-content {
        width: 95%;
        max-width: 360px;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .auth-container {
        width: 95%;
        max-width: 360px;
        padding: 25px 20px;
    }
    
    .auth-logo span {
        font-size: 20px;
    }
    
    .goal-options {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .goal-option {
        padding: 12px 8px;
        font-size: 13px;
    }
    
    .car-shop-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 15px;
    }
    
    .credit-packages {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

/* ===========================================
   SAFE AREA SUPPORT (iPhone X and newer)
=========================================== */
@supports (padding: env(safe-area-inset-top)) {
    @media screen and (max-width: 768px) {
        .brand-header {
            top: calc(10px + env(safe-area-inset-top));
        }
        
        #screen-home {
            padding-top: calc(100px + env(safe-area-inset-top));
        }
        
        .top-nav {
            padding-top: calc(8px + env(safe-area-inset-top));
            height: calc(50px + env(safe-area-inset-top));
        }
        
        .back-btn {
            top: calc(75px + env(safe-area-inset-top)) !important;
        }
        
        #screen-drive .back-btn {
            top: calc(98px + env(safe-area-inset-top)) !important;
        }
        
        .card-selector {
            bottom: calc(70px + env(safe-area-inset-bottom));
            padding-top: 20px;
        }
        
        .speed-panel {
            bottom: calc(15px + env(safe-area-inset-bottom));
        }
        
        .control-panel {
            bottom: calc(95px + env(safe-area-inset-bottom));
        }
        
        .ambient-selector {
            bottom: calc(15px + env(safe-area-inset-bottom));
        }
        
        .btn-drive {
            bottom: calc(95px + env(safe-area-inset-bottom)) !important;
        }
        
        .btn-drive.volume-active {
            bottom: calc(140px + env(safe-area-inset-bottom)) !important;
        }
    }
}

/* ===========================================
   LANDSCAPE MODE (phone horizontal)
=========================================== */
@media screen and (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    
    .drive-route-info {
        top: 8px;
        left: 8px;
        padding: 8px 10px;
        max-width: 150px;
    }
    
    .route-icon {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }
    
    .route-text h3 {
        font-size: 11px;
    }
    
    .route-text p {
        font-size: 8px;
    }
    
    .focus-goal-bar {
        top: 55px;
        left: 8px;
        width: 150px;
        height: 18px;
    }
    
    .goal-text {
        font-size: 8px;
    }
    
    /* Landscape: Exit button top right */
    #screen-drive .back-btn {
        top: 8px !important;
        left: auto !important;
        right: 180px !important;
        padding: 6px 10px;
        font-size: 10px;
    }
    
    .drive-status {
        top: 8px;
        right: 8px;
        bottom: auto;
    }
    
    .speed-limit {
        width: 30px;
        height: 30px;
        font-size: 14px;
        border-width: 3px;
    }
    
    .status-badge {
        padding: 6px 10px;
    }
    
    .status-text {
        font-size: 8px;
    }
    
    .speed-panel {
        left: 8px;
        bottom: 8px;
        padding: 8px 10px;
    }
    
    .speed-value {
        font-size: 24px;
    }
    
    .control-panel {
        left: 8px;
        bottom: 70px;
    }
    
    .control-btn {
        width: 34px;
        height: 34px;
    }
    
    .ambient-selector {
        bottom: 8px;
        right: 8px;
    }
    
    .ambient-btn {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
    
    .btn-drive {
        bottom: 70px !important;
        right: 8px !important;
        padding: 10px 16px;
        font-size: 10px;
    }
    
    .btn-drive.volume-active {
        bottom: 110px !important;
    }
    
    .car-avatar {
        width: 45px;
        top: 50%;
    }
}


@media screen and (max-width: 768px) {
    .ambient-volume-control {
        display: none !important;
    }
    
    .btn-drive.volume-active {
        bottom: 95px !important;
    }
}