/* styles.css */
/* Visual styling, layout (desktop + mobile + vertical mode), controls, preview, and scopes */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #1a1d22;
    color: #d8d9db;
    font-family: 'Arial', sans-serif;
    padding: 10px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#controls {
    background-color: #25282f;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.control-row:last-child {
    margin-bottom: 0;
}

#controls label {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 5px;
}

#controls select,
#controls input[type="file"],
#controls input[type="checkbox"] {
    background-color: #32363f;
    border: 1px solid #4a4f5a;
    color: #d8d9db;
    padding: 6px;
    border-radius: 4px;
    font-size: 12px;
}

#controls button {
    background-color: #4b5e85;
    color: #d8d9db;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

#controls button:hover {
    background-color: #5f75a8;
}

#averageColorDisplay {
    display: inline-block;
    padding: 4px 8px;
    background-color: #32363f;
    border-radius: 4px;
    font-size: 12px;
    color: #d8d9db;
}

#selectionSizeDisplay {
    display: inline-block;
    padding: 4px 8px;
    background-color: #32363f;
    border-radius: 4px;
    font-size: 12px;
    color: #d8d9db;
}

#container {
    display: flex;
    flex-direction: row;
    gap: 20px;
    flex-grow: 1;
    overflow-y: auto;
}

#preview {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

#mediaCanvas {
    background-color: #2a2e36;
    border: 1px solid #3c414b;
    border-radius: 4px;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 1;
    touch-action: none;
}

#scopes {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-content: flex-start;
}

.scope {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    flex: 0 0 calc(33.33% - 6.67px);
    max-width: none;
}

.scope label {
    font-size: 12px;
    color: #a0a3a8;
    text-align: center;
}

#selectedAreaCanvas,
#vectorscopeCanvas,
#lumaWaveformCanvas,
#rgbHistogramCanvas,
#rgbWaveformCanvas,
#rgbWaveformOverlayCanvas {
    background-color: #21242a;
    border: 1px solid #3c414b;
    border-radius: 4px;
    width: 100%;
    aspect-ratio: 1;
}

/* Mobile layout: Single column */
@media (max-width: 800px) {
    #container {
        flex-direction: column;
        gap: 10px;
    }

    #preview,
    #scopes {
        width: 100%;
    }

    .scope {
        flex: 0 0 100%;
        max-width: 100%;
    }

    #mediaCanvas,
    #vectorscopeCanvas,
    #lumaWaveformCanvas,
    #rgbHistogramCanvas,
    #rgbWaveformCanvas,
    #rgbWaveformOverlayCanvas,
    #selectedAreaCanvas {
        max-width: 100%;
    }

    /* Larger, touch-friendly controls for mobile */
    #controls {
        padding: 12px;
    }

    .control-row {
        gap: 12px;
    }

    #controls label {
        font-size: 16px;
        gap: 8px;
    }

    #controls select,
    #controls input[type="file"] {
        padding: 8px 10px;
        font-size: 16px;
        min-width: 120px; /* Easier to tap */
    }

    #controls input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }

    #controls button {
        padding: 8px 12px;
        font-size: 16px;
        min-width: 80px; /* Touch-friendly size */
    }

    #averageColorDisplay,
    #selectionSizeDisplay {
        padding: 6px 10px;
        font-size: 14px;
    }

    .scope label {
        font-size: 14px;
    }
}

/* Tiny screens (override to avoid too small fonts) */
@media (max-width: 480px) {
    #controls {
        padding: 10px;
    }

    .control-row {
        gap: 10px;
    }

    #controls label,
    #controls select,
    #controls button {
        font-size: 14px; /* Increased from 10px for better readability */
    }

    #controls input[type="checkbox"] {
        width: 18px;
        height: 18px;
    }

    #controls button {
        padding: 6px 10px;
    }
}

/* Vertical layout for mobile/vertical users */
.vertical-layout body {
    padding: 0;
}

.vertical-layout #container {
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    height: calc(100vh - 60px);
    margin-top: 60px;
    overflow: hidden;
}

.vertical-layout #preview {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.vertical-layout #preview canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.vertical-layout #scopes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.vertical-layout .scope {
    flex: 0 0 auto;
    opacity: 0.5;
    pointer-events: auto;
    margin: 0;
    width: 120px;
}

.vertical-layout .scope.selected-area {
    opacity: 1;
}

.vertical-layout #scopes .scope:nth-child(-n+3) {
    position: absolute;
    left: 5px;
}

.vertical-layout #scopes .scope:nth-child(1),
.vertical-layout #scopes .scope:nth-child(2),
.vertical-layout #scopes .scope:nth-child(3) {
    top: 50%;
    transform: translateY(-50%);
}

.vertical-layout #scopes .scope:nth-child(1) { top: calc(50% - 340px); }
.vertical-layout #scopes .scope:nth-child(2) { top: calc(50% - 120px); }
.vertical-layout #scopes .scope:nth-child(3) { top: calc(50% + 100px); }

.vertical-layout #scopes .scope:nth-child(n+4):nth-child(-n+6) {
    position: absolute;
    right: 5px;
}

.vertical-layout #scopes .scope:nth-child(4),
.vertical-layout #scopes .scope:nth-child(5),
.vertical-layout #scopes .scope:nth-child(6) {
    top: 50%;
    transform: translateY(-50%);
}

.vertical-layout #scopes .scope:nth-child(4) { top: calc(50% - 340px); }
.vertical-layout #scopes .scope:nth-child(5) { top: calc(50% - 120px); }
.vertical-layout #scopes .scope:nth-child(6) { top: calc(50% + 100px); }

.vertical-layout #controls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 3;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px; /* Slightly increased for nicer feel */
    box-sizing: border-box;
}

.vertical-layout #controls label,
.vertical-layout #controls select,
.vertical-layout #controls button {
    font-size: 16px; /* Increased from 14px for better mobile readability */
}

.vertical-layout #controls input[type="checkbox"] {
    width: 20px;
    height: 20px;
}

.vertical-layout #controls button {
    padding: 8px 12px; /* Larger padding for touch */
}

.vertical-layout .scope label {
    font-size: 16px; /* Increased for consistency */
}

.vertical-layout #vectorscopeCanvas,
.vertical-layout #lumaWaveformCanvas,
.vertical-layout #rgbHistogramCanvas,
.vertical-layout #rgbWaveformCanvas,
.vertical-layout #rgbWaveformOverlayCanvas,
.vertical-layout #selectedAreaCanvas {
    width: 120px;
    height: 120px;
}