/* General Reset and Body */
:root {
    /* Color Variables */
    --primary-color: #ff6347;
    --bg-primary: #121212;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #1f1f1f;
    --bg-section: #2c2c2c;
    --border-color: #3c3c3c;
    --text-primary: #e0e0e0;
    --text-muted: #666666;
    
    /* Font Variables */
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: Arial, sans-serif;
}

* {
    box-sizing: border-box; /* Ensure all elements include padding and border in their width */
}

html {
    height: 100%;
    height: 100dvh; /* Use dynamic viewport height when supported */
    overflow: hidden;
    -webkit-text-size-adjust: none; /* Prevent iOS text scaling */
    -ms-text-size-adjust: none;
    touch-action: manipulation; /* Prevent zoom on touch */
}

body {
    font-family: var(--font-sans);
    margin: 0;
    padding: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: row;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height when supported */
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Window Container */
.window {
    flex: 1;
    background-color: var(--bg-secondary);
    border-radius: 0;
    box-shadow: none;
    height: 100vh;
    overflow: hidden;
    border-right: 2px solid var(--bg-section);
}

/* Controls Container */
.controls-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(550px, 40vw); /* Responsive width with max 550px */
    max-width: 550px;
    min-width: 300px; /* Minimum width for usability */
    background-color: var(--bg-tertiary);
    padding: 20px;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height when supported */
    overflow-y: auto;
    box-sizing: border-box; /* Include padding in width calculation */
}

/* Window Header */
.window-header {
    background-color: var(--bg-tertiary);
    padding: 12px 20px;
    border-bottom: 1px solid var(--bg-section);
    font-weight: 500;
    color: var(--primary-color);
    font-size: 16px;
    letter-spacing: -0.01em;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.window-header span {
    flex-grow: 1;
    text-align: center;
}

/* Header Button Styles (Home and Reset Camera) */
.home-button,
.reset-camera-button {
    background: rgba(255, 99, 71, 0.1);
    color: var(--primary-color);
    border: 1px solid rgba(255, 99, 71, 0.3);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.home-button:hover,
.reset-camera-button:hover {
    background: rgba(255, 99, 71, 0.2);
    border-color: rgba(255, 99, 71, 0.5);
    transform: translateY(-1px);
}

.home-button:active,
.reset-camera-button:active {
    transform: translateY(0);
    background: rgba(255, 99, 71, 0.15);
}

/* Window Content */
.window-content {
    padding: 0;
    height: calc(100vh - 45px);
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
}

/* Input Section */
.input-section {
    padding: 16px 24px;
    background-color: var(--bg-section);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0; /* Allow flex shrinking */
    width: 100%;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-section label {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 500;
    color: var(--primary-color);
    white-space: nowrap;
}

.range-label {
    flex-shrink: 0;
    text-align: center;
}

.range-label span {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 500;
    color: var(--primary-color);
    background: transparent;
    padding: 0;
    border-radius: 0;
    white-space: nowrap;
}

.input-section input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 16px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-section input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 99, 71, 0.1);
}

.input-section input::placeholder {
    color: var(--text-muted);
}

/* Control Sections (Toggle and Slider) */
.toggle-section,
.slider-section {
    margin-top: 12px;
    background-color: var(--bg-section);
    border-radius: 8px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    text-align: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-sans);
    font-size: 16px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    margin: 0;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
    background-color: var(--bg-section);
    border: 2px solid var(--border-color);
    border-radius: 3px;
    appearance: none;
    -webkit-appearance: none;
    position: relative;
}

.checkbox-label input[type="checkbox"]:checked {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-label input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.checkbox-label input[type="checkbox"]:hover {
    border-color: var(--primary-color);
}

/* Camera menu spacing */
.reset-camera-button + .checkbox-label {
    margin-top: 12px;
}

.slider-section label {
    display: block;
    font-family: var(--font-sans);
    font-size: 16px;
    color: var(--primary-color);
    margin-bottom: 8px;
    font-weight: 500;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.slider-container input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 5px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.slider-container input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.slider-container span {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-primary);
    min-width: 30px;
    text-align: center;
}

/* Color Indicator */
.color-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.color-gradient {
    width: 100%;
    max-width: 300px;
    height: 30px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    /* Gradient will be set dynamically by JavaScript */
}

.color-label-left, .color-label-right {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-primary);
    min-width: 30px;
    text-align: center;
}

/* Quality Warning Text */
.quality-warning {
    font-family: var(--font-sans);
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 8px;
    font-style: italic;
}

/* Canvas */
#sphere-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* === Desktop Responsiveness === */

/* For screens smaller than 1200px (smaller desktops/laptops) */
@media (max-width: 1200px) {
    .controls-container {
        width: min(450px, 35vw);
        max-width: 450px;
        padding: 16px;
    }
}

/* For screens smaller than 1000px (tablets in landscape) */
@media (max-width: 1000px) {
    .controls-container {
        width: min(400px, 40vw);
        max-width: 400px;
        padding: 14px;
    }
}

/* === Mobile Responsiveness === */

/* For screens smaller than 768px (tablet or mobile) */
@media (max-width: 768px) {
    body {
        flex-direction: column;
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height when supported */
        max-height: 100vh;
        max-height: 100dvh;
        overflow: hidden;
    }
    
    .window {
        flex: 1;
        min-height: 0; /* Allow flex shrinking */
        margin: 0;
        border-radius: 0;
        border-right: none;
        border-bottom: 2px solid var(--bg-section);
        display: flex;
        flex-direction: column;
    }
    
    .window-header {
        padding: 10px 16px;
        font-size: 14px;
        text-align: center;
        flex-shrink: 0; /* Prevent header from shrinking */
    }
    
    .home-button,
    .reset-camera-button {
        font-size: 12px;
        padding: 5px 10px;
    }
    
    .window-content {
        flex: 1;
        min-height: 0; /* Allow flex shrinking */
        height: auto;
    }
    
    .controls-container {
        width: 100%;
        max-width: none;
        min-width: auto;
        height: auto;
        max-height: 45vh;
        max-height: 45dvh;
        padding: 12px;
        gap: 12px;
        overflow-y: auto;
        overflow-x: hidden; /* Prevent horizontal overflow */
        flex-shrink: 0; /* Prevent controls from shrinking too much */
        box-sizing: border-box;
    }
    
    .input-section {
        padding: 12px 16px;
        gap: 10px;
    }
    
    .input-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .input-section label {
        font-size: 18px;
        min-width: fit-content;
    }
    
    .input-section input {
        flex: 1;
        min-width: 200px;
        font-size: 16px;
        padding: 12px 14px;
    }
    
    .range-label {
        text-align: center;
        margin-top: 4px;
    }
    
    .range-label span {
        font-size: 16px;
    }
    
    .toggle-section, .slider-section {
        padding: 12px 16px;
    }
    
    .checkbox-label {
        font-size: 18px;
        gap: 10px;
    }
    
    .checkbox-label input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }
    
    .checkbox-label input[type="checkbox"]:checked::after {
        font-size: 13px;
    }
    
    .slider-section label {
        font-size: 18px;
        margin-bottom: 12px;
    }
    
    .slider-container {
        gap: 16px;
    }
    
    .slider-container input[type="range"] {
        height: 8px;
    }
    
    .slider-container input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    .slider-container input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
    
    .slider-container span {
        font-size: 16px;
        min-width: 40px;
    }
    
    .color-indicator {
        gap: 12px;
        margin-top: 16px;
    }
    
    .color-gradient {
        width: 100%;
        max-width: 250px;
        height: 32px;
    }
    
    .color-label-left, .color-label-right {
        font-size: 16px;
        min-width: 35px;
    }
    
    .quality-warning {
        font-size: 11px;
        margin-top: 10px;
    }
}

/* For screens smaller than 480px (small phones) */
@media (max-width: 480px) {
    .window-header {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .home-button,
    .reset-camera-button {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    .controls-container {
        max-height: 50vh;
        max-height: 50dvh;
        padding: 10px;
        gap: 10px;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .input-section {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .input-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .input-section label {
        font-size: 16px;
        text-align: center;
    }
    
    .input-section input {
        min-width: auto;
        font-size: 16px;
        padding: 12px;
    }
    
    .range-label span {
        font-size: 14px;
    }
    
    .checkbox-label {
        font-size: 16px;
    }
    
    .slider-section label {
        font-size: 16px;
    }
    
    .slider-container {
        gap: 12px;
    }
    
    .color-gradient {
        width: 100%;
        max-width: 200px;
        height: 28px;
    }
    
    .color-label-left, .color-label-right {
        font-size: 14px;
        min-width: 30px;
    }
    
    .quality-warning {
        font-size: 10px;
        margin-top: 8px;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .window-header {
        padding: 6px 8px;
        font-size: 12px;
    }
    
    .home-button,
    .reset-camera-button {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    .controls-container {
        max-height: 55vh;
        max-height: 55dvh;
        padding: 8px;
        gap: 8px;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .input-section {
        padding: 8px 10px;
    }
    
    .color-gradient {
        width: 100%;
        max-width: 150px;
        height: 24px;
    }
}

/* Landscape orientation on mobile devices */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        height: 100vh;
        height: 100dvh;
    }
    
    .controls-container {
        max-height: 60vh;
        max-height: 60dvh;
        overflow-x: hidden;
        box-sizing: border-box;
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    .slider-container input[type="range"]::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }
    
    .slider-container input[type="range"]::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }
    
    .checkbox-label input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }
    
    .checkbox-label input[type="checkbox"]:checked::after {
        font-size: 15px;
    }
}