/* Additional custom styles */
body {
    touch-action: none;
    height: 100vh;
    overflow: hidden;
}

/* Main Layout Container - Default (Landscape/Wide) */
#mainContent {
    flex-direction: row;
    gap: 0.5rem;
}

/* Joystick Columns */
.left-joystick-column,
.right-joystick-column {
    flex: 0 0 100px;
    min-width: 100px;
}

/* Center Column */
.center-column {
    flex: 1;
    min-width: 0;
}

/* Vertical Joystick */
.joystick-vertical {
    width: 80px;
    height: 100%;
    max-height: 400px;
    background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    border-radius: 40px;
    position: relative;
    box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5);
    border: 4px solid #374151;
    touch-action: none;
}

.joystick-handle {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.6);
    border: 3px solid #60a5fa;
    transition: box-shadow 0.2s;
    touch-action: none;
}

.joystick-handle:active,
.joystick-handle.dragging {
    cursor: grabbing;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.8);
}

/* Speedometer Styles */
.speedometers-section {
    flex: 0 0 auto;
}

.speedometers-section .flex {
    flex-wrap: wrap;
}

.speedometers-section h3 {
    white-space: nowrap;
}

/* Controls Section */
.controls-section {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
}

.joystick-wrapper {
    max-height: 280px;
    aspect-ratio: 1/1;
    width: auto;
    height: 100%;
    max-width: 280px;
    margin: 0 auto;
    position: relative;
}

.btn-control {
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 60px;
}

.btn-control.active {
    transform: scale(0.95);
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.5);
}

.btn-control:active {
    transform: scale(0.95);
}

.joystick-container {
    width: 100%;
    height: 100%;
    max-width: 280px;
    max-height: 280px;
    aspect-ratio: 1/1;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
    border-radius: 50%;
    position: relative;
    box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5);
    border: 4px solid #374151;
    touch-action: none;
    aspect-ratio: 1/1;
}

.joystick {
    width: 30%;
    height: 30%;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.6);
    border: 3px solid #60a5fa;
    transition: box-shadow 0.2s;
    touch-action: none;
}

.joystick:active {
    cursor: grabbing;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.8);
}

.joystick.dragging {
    cursor: grabbing;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.8);
}

/* Prevent text selection during drag */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Blink animation for indicators */
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.btn-control.blinking {
    animation: blink 1s ease-in-out infinite;
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .btn-control {
        min-height: 55px;
        padding: 0.4rem;
    }
}

/* Portrait Mode - 3 rows layout */
@media (orientation: portrait), (max-width: 640px) {
    body {
        overflow: hidden;
    }
    
    #mainContent {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto minmax(0, 1fr) auto;
        gap: 0.5rem;
        padding: 0.5rem;
    }
    
    /* Row 1: Speedometers span both columns */
    .speedometers-section {
        grid-column: 1 / -1;
        grid-row: 1;
        padding: 0.5rem !important;
    }
    
    /* Row 2: Left joystick (column 1) */
    .left-joystick-column {
        grid-column: 1;
        grid-row: 2;
        padding: 0.5rem !important;
    }
    
    /* Row 2: Right joystick (column 2) */
    .right-joystick-column {
        grid-column: 2;
        grid-row: 2;
        padding: 0.5rem !important;
    }
    
    /* Row 3: Center column with buttons spans both columns */
    .center-column {
        grid-column: 1 / -1;
        grid-row: 3;
    }
    
    /* Adjust joystick size for portrait */
    .joystick-vertical {
        width: 70px;
        height: 100%;
        min-height: 200px;
        max-height: 100%;
    }
    
    .joystick-handle {
        width: 56px;
        height: 56px;
    }
    
    /* Smaller speedometers in portrait */
    .speedometers-section .relative {
        width: 4rem !important;
        height: 4rem !important;
    }
    
    .speedometers-section svg {
        width: 100% !important;
        height: 100% !important;
    }
    
    .speedometers-section h3 {
        font-size: 0.65rem;
    }
    
    .speedometers-section #leftSpeedValue,
    .speedometers-section #rightSpeedValue {
        font-size: 0.875rem !important;
    }
    
    .speedometers-section .text-xs {
        font-size: 0.625rem;
    }
    
    /* Compact header */
    header {
        padding: 0.5rem 1rem;
    }
    
    header h1 {
        font-size: 1.25rem;
    }
}

/* Landscape Mode - 3 columns layout */
@media (orientation: landscape) and (min-width: 641px) {
    header {
        padding: 0.5rem 1rem;
    }
    
    header h1 {
        font-size: 1.25rem;
    }
    
    #mainContent {
        flex-direction: row !important;
        display: flex !important;
    }
    
    /* Column 1: Left Joystick */
    .left-joystick-column {
        flex: 0 0 100px;
        min-width: 100px;
    }
    
    /* Column 2: Center (Speedometers + Buttons) */
    .center-column {
        flex: 1;
        min-width: 0;
    }
    
    /* Column 3: Right Joystick */
    .right-joystick-column {
        flex: 0 0 100px;
        min-width: 100px;
    }
    
    /* Full height joysticks in landscape */
    .joystick-vertical {
        max-height: 100%;
        height: 100%;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: #1f2937;
    border-radius: 1rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    border: 1px solid #374151;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #374151;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.setting-item {
    margin-bottom: 2rem;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: #60a5fa;
    margin-bottom: 0.5rem;
}

.setting-description {
    font-size: 0.875rem;
    color: #9ca3af;
    margin-bottom: 1rem;
}

.setting-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.setting-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: #111827;
    border: 2px solid #374151;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    color: #d1d5db;
    width: 100%;
    text-align: left;
}

.setting-option:hover {
    border-color: #4b5563;
    background: #1f2937;
}

.setting-option.active {
    border-color: #3b82f6;
    background: #1e3a8a;
    color: #ffffff;
}

.setting-option svg {
    flex-shrink: 0;
}
