:root {
    --overlay-border-color: #3498db;
    --primary-color: #3498db;
    --secondary-color: #2980b9;
    --background-color: #f5f5f5;
    --container-bg: white;
    --border-color: #ccc;
    --text-color: #333;
    --disabled-color: #95a5a6;
    --success-color: #2ecc71;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background-color: var(--background-color);
    color: var(--text-color);
    -webkit-tap-highlight-color: transparent;
    /* Removes tap highlight color on mobile */
}

.container {
    background-color: var(--container-bg);
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 20px;
}

h1 {
    text-align: center;
}

.upload-container {
    border: 2px dashed var(--border-color);
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
    border-radius: 8px;
    background-color: #f9f9f9;
}

/* New flex layout for main content */
.main-content {
    display: flex;
    flex-direction: column;
    /* Start with column for mobile */
    gap: 15px;
    margin: 20px 0;
}

/* Recording controls positioning between video and settings on mobile */
.recording-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
    order: 2;
    /* Put controls after video but before settings */
}

/* Download button is separate and below recording controls */
.download-control {
    width: 100%;
    display: flex;
    justify-content: center;
    order: 3;
    /* Put download after recording controls */
    margin-bottom: 10px;
}

/* Status and progress positioning */
.progress {
    order: 4;
    height: 10px;
    background-color: #ecf0f1;
    border-radius: 4px;
    margin: 10px 0;
    overflow: hidden;
    display: none;
}

#status {
    order: 5;
    text-align: center;
    color: #7f8c8d;
    margin: 5px 0 15px;
    font-style: italic;
}

/* Adjust settings panel width */
.settings {
    flex: 1;
    /* Take full width on mobile */
    background-color: #f9f9f9;
    border-radius: 8px;
    padding: 15px;
    order: 6;
    /* Put settings last on mobile */
}

/* Video container takes remaining width */
.video-container {
    flex: 1;
    position: relative;
    width: 100%;
    min-height: 300px;
    height: 100%;
    margin: 0 auto;
    overflow: hidden;
    background-color: #eee;
    border-radius: 8px;
    order: 1;
    /* Put video first on mobile */
}

.video-container .upload-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #f0f0f0;
    border-radius: 8px;
    border: 2px dashed var(--border-color);
    z-index: 5;
}

#mainVideo {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    border-radius: 8px;
    background-color: #000;
    margin: 0 auto;
    /* Center the video */
}

/* Overlay container positioned exactly over the video */
.overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

#overlayVideo {
    position: absolute;
    border-radius: 12px;
    display: none;
    object-fit: cover;
}

/* Preview overlay now positioned over the video */
.preview-overlay {
    position: absolute;
    background-color: rgba(221, 221, 221, 0.7);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #777;
    pointer-events: none;
    z-index: 10;
    overflow: hidden;
    /* Add overflow hidden for cropping */
}

/* Mobile-friendly buttons - smaller and in one line */
.recording-controls button {
    flex: 1;
    padding: 10px 12px;
    font-size: 14px;
    min-height: 44px;
    /* Touch-friendly size */
    border-radius: 6px;
    margin: 0;
    max-width: 120px;
}

.download-control button {
    width: 100%;
    padding: 10px 15px;
    font-size: 14px;
    min-height: 44px;
    border-radius: 6px;
    max-width: 250px;
}

button:hover {
    background-color: var(--secondary-color);
}

button:disabled {
    background-color: var(--disabled-color);
    cursor: not-allowed;
}

.progress-bar {
    height: 100%;
    background-color: var(--success-color);
    width: 0%;
    transition: width 0.3s;
}

.settings h3 {
    margin-top: 0;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.setting-group {
    margin-bottom: 15px;
}

.setting-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

/* Mobile-friendly setting rows */
.setting-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.setting-row.mobile-slider {
    margin-bottom: 20px;
}

/* Container for slider and its value */
.slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Fix for the value span to prevent wrapping */
.setting-row span {
    min-width: 30px;
    text-align: right;
    white-space: nowrap;
}

/* Mobile-friendly sliders */
input[type="range"] {
    flex: 1;
    min-width: 100px;
    -webkit-appearance: none;
    appearance: none;
    height: 30px;
    /* Taller for better touch target */
    background: transparent;
    /* Remove default styling */
    margin: 0;
    padding: 0;
    touch-action: none;
    /* Prevents scroll/zoom while touching slider */
    cursor: pointer;
}

/* Track for mobile sliders */
input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 10px;
    background: #ddd;
    border-radius: 5px;
}

input[type="range"]::-moz-range-track {
    width: 100%;
    height: 10px;
    background: #ddd;
    border-radius: 5px;
}

/* Thumb for mobile sliders */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-color);
    margin-top: -7px;
    /* Center thumb on track */
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-color);
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Focus styles for sliders */
input[type="range"]:focus {
    outline: none;
}

input[type="range"]:focus::-webkit-slider-thumb {
    background: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
}

input[type="range"]:focus::-moz-range-thumb {
    background: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
}

input[type="color"] {
    height: 40px;
    width: 60px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

input[type="number"] {
    width: 60px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 16px;
    /* Prevents iOS zoom on focus */
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    align-self: flex-start;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.toggle-slider {
    background-color: var(--primary-color);
}

input:checked+.toggle-slider:before {
    transform: translateX(26px);
}

.setting-select {
    padding: 10px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: white;
    width: 100%;
    max-width: 100%;
    font-size: 16px;
    /* Prevents iOS zoom on focus */
    height: 44px;
    /* Touch-friendly height */
}

footer {
    text-align: center;
    margin-top: 30px;
    color: #7f8c8d;
    font-size: 14px;
}

.message {
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 15px;
    display: none;
}

.error {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

.info {
    background-color: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
}

/* Fix for desktop layout with buttons below content */
/* Improved desktop layout with controls properly positioned */
/* Improved desktop layout with controls properly positioned */
@media (min-width: 769px) {

    /* Set up a grid with 2 columns and multiple rows */
    .main-content {
        display: grid;
        grid-template-columns: 300px 1fr;
        grid-template-rows: auto auto auto auto;
        gap: 20px;
        align-items: start;
    }

    /* Settings in first column, spanning all rows */
    .settings {
        grid-column: 1;
        grid-row: 1;
        order: unset;
    }

    /* Video container in second column, first row */
    .video-container {
        grid-column: 2;
        grid-row: 1;
        order: unset;
        background-color: transparent;
    }

    /* Recording controls in second column, second row */
    .recording-controls {
        grid-column: 2;
        grid-row: 2;
        order: unset;
        display: flex;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
    }

    /* Download button in second column, third row */
    .download-control {
        grid-column: 2;
        grid-row: 3;
        order: unset;
        margin-top: 5px;
    }

    /* Progress bar in second column, fourth row */
    .progress {
        grid-column: 2;
        grid-row: 4;
        order: unset;
        margin-top: 5px;
    }

    /* Status below everything else on the right */
    #status {
        grid-column: 2;
        grid-row: 5;
        order: unset;
        margin-top: 5px;
    }
}