:root {
    /* Reference Theme Palette (Slate/Dark Mode Accents) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    /* Lighter secondary */
    --bg-tertiary: #e2e8f0;

    --text-primary: #0f172a;
    /* Slate 900 */
    --text-secondary: #64748b;
    /* Slate 500 */

    --accent: #0f172a;
    /* Dark Slate (Almost Black) matching reference */
    --accent-hover: #1e293b;
    /* Slightly lighter on hover */

    --border: #e2e8f0;
    /* Slate 200 */
    --radius: 0.5rem;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    height: 60px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background-color: var(--bg-primary);
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo span {
    color: var(--accent);
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Sidebar */
aside {
    width: 310px;
    /* Increased by ~10% from 280px */
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border);
    padding: 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Scrollbar styling for sidebar to keep it subtle */
aside::-webkit-scrollbar {
    width: 6px;
}

aside::-webkit-scrollbar-track {
    background: transparent;
}

aside::-webkit-scrollbar-thumb {
    background: #e4e4e7;
    border-radius: 3px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    /* Tighter controls */
    border-bottom: 1px solid var(--bg-secondary);
    padding-bottom: 0.75rem;
}

.control-group:last-child {
    border-bottom: none;
}

.control-group h3 {
    font-size: 0.7rem;
    /* 11px */
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    /* Very tight label-input gap */
}

label {
    font-size: 0.75rem;
    /* 12px */
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sub-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 0.1rem;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    /* Lint Fix */
    width: 100%;
    background: transparent;
    cursor: pointer;
    margin: 0.25rem 0;
    /* Reduced margin */
    display: block;
    /* Ensure block */
}

input[type="range"]:focus {
    outline: none;
}

/* WebPy Track */
input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #e4e4e7;
    border-radius: 2px;
}

/* WebKit Thumb */
input[type="range"]::-webkit-slider-thumb {
    height: 14px;
    /* Smaller thumb */
    width: 14px;
    border-radius: 50%;
    background: var(--accent);
    /* Dark Accent Thumb */
    border: 2px solid white;
    /* White ring for contrast */
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -5px;
    /* (4 - 14) / 2 */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s, border-color 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Firefox styles omitted for brevity, fallback ok */

select,
input[type="text"],
input[type="number"] {
    background-color: #fff;
    /* White background for inputs */
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.35rem 0.5rem;
    /* Compact padding */
    border-radius: 6px;
    /* Slightly squarer */
    outline: none;
    font-size: 0.8rem;
    /* Smaller font */
    width: 100%;
    transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus,
input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

button {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 0.75rem;
    /* Compact */
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

button.secondary {
    background-color: #fff;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

button.secondary:hover {
    background-color: var(--bg-secondary);
    border-color: #d4d4d8;
}

button.small-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Segmented Control - Reference Style */
.segmented-control {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px;
    display: flex;
    gap: 4px;
}

.segmented-control .toggle-btn {
    flex: 1;
    background-color: var(--bg-tertiary);
    /* Inactive background */
    color: var(--text-secondary);
    border: none;
    padding: 0.35rem;
    /* Taller */
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    cursor: pointer;
    transition: all 0.2s;
}

.segmented-control .toggle-btn:hover {
    background-color: #cbd5e1;
    color: var(--text-primary);
}

.segmented-control .toggle-btn.active {
    background-color: var(--accent);
    /* Dark Active */
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-weight: 600;
}

/* Color Input Row */
.color-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background-color: #fff;
}

input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    /* Lint Fix */
    border: none;
    width: 32px;
    /* reduced */
    height: 24px;
    /* reduced */
    cursor: pointer;
    background: none;
    padding: 0;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}

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

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Reset Button in Color Row */
.color-input-row .icon-btn {
    border: none;
    background: transparent;
    padding: 0.25rem;
    min-width: 32px;
    height: 32px;
    color: var(--text-secondary);
}

.color-input-row .icon-btn:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.05);
}

#bg-color-text {
    border: none;
    background: transparent;
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    width: 100%;
    padding: 0;
    text-transform: uppercase;
}

#bg-color-text:focus {
    color: var(--text-primary);
    outline: none;
}

/* Row Inputs (Width / Height) */
.row-inputs {
    display: flex;
    gap: 0.5rem;
    /* Reduced from 0.75rem */
}

.row-inputs .col {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Preview Area */
.preview-area {
    flex: 1;
    background-color: #f9fafb;
    /* Light Background */
    background-image:
        radial-gradient(circle at 1px 1px, #d4d4d8 1px, transparent 0);
    /* Gray dots */
    background-size: 24px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2rem;
    overflow: hidden;
}

/* Collapsible */
.collapsible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Push chevron to right */
    width: 100%;
    cursor: pointer;
    padding: 0.5rem 0;
    user-select: none;
}

.collapsible-header:hover label {
    color: var(--text-primary);
}

.collapsible-header .chevron-icon {
    transition: transform 0.2s;
    color: var(--text-secondary);
}

.collapsible-header.active .chevron-icon {
    transform: rotate(180deg);
}

.collapsible-content {
    margin-top: 0.25rem;
    padding-left: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    /* Gap between inputs and reset button */
}

.collapsible-content.hidden {
    display: none;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    cursor: grab;
    /* Indicate draggable */
}

canvas:active {
    cursor: grabbing;
}

.file-drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    overflow: hidden;
    /* Ensure content stays in */
}

/* Filename Text Truncation */
.file-drop-zone .file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    margin: 0;
    max-width: 100%;
}

.file-drop-zone:hover {
    border-color: var(--accent);
}

/* Duplicate styles removed */

/* Utility */
.hidden {
    display: none !important;
}

/* Timeline Slider (Horizontal) */
.timeline-slider.horizontal {
    position: relative;
    height: 24px;
    display: flex;
    align-items: center;
    cursor: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 4V12M4 8H12' stroke='black' stroke-width='1'/%3E%3C/svg%3E") 8 8, crosshair;
    margin: 0.5rem 0;
    width: 100%;
}

.timeline-slider.horizontal .timeline-track {
    position: absolute;
    width: 100%;
    height: 4px;
    background-color: #e5e7eb;
    border-radius: 2px;
}

.timeline-slider.horizontal .timeline-progress {
    position: absolute;
    height: 4px;
    background-color: var(--accent);
    border-radius: 2px;
    width: 0%;
    /* Dynamic */
    pointer-events: none;
}

/* Removed generic timeline-thumb as per request */

.timeline-slider.horizontal .timeline-stop {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    z-index: 10;
    transition: transform 0.1s, background-color 0.2s;
}

.timeline-stop.fixed {
    background-color: var(--text-secondary);
    opacity: 0.5;
    pointer-events: none;
    width: 8px;
    cursor: grab;
    z-index: 5;
}

/* Fix Human Settings Height Jump */
#interval-settings,
#custom-stops-settings {
    min-height: 6rem;
    /* Increased from 4.5rem to match Fixed% height */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Custom Select Styles */
.custom-select-wrapper {
    position: relative;
    width: 100%;
    user-select: none;
    font-family: var(--font-sans);
}

.custom-select-header {
    background-color: #fff;
    border: 1px solid var(--border);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-primary);
    transition: all 0.2s;
}

.custom-select-header .selected-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
    /* Gap from chevron */
}

.custom-select-header:hover {
    border-color: #cbd5e1;
}

.custom-select-header.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.1);
}

.custom-select-header .chevron {
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.custom-select-header.active .chevron {
    transform: rotate(180deg);
}

.custom-select-list {
    position: fixed;
    /* Fixed to viewport to avoid clipping */
    /* top/left/width set by JS */
    background-color: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 99999;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
}

.custom-select-option {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.1s;
}

.custom-select-option:hover {
    background-color: var(--bg-secondary);
}

.custom-select-option.selected {
    background-color: var(--accent);
    color: white;
}

/* Scrollbar for list */
.custom-select-list::-webkit-scrollbar {
    width: 6px;
}

.custom-select-list::-webkit-scrollbar-thumb {
    background-color: #e2e8f0;
    border-radius: 3px;
}

.timeline-stop.custom {
    background-color: var(--accent);
    cursor: grab;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.timeline-stop.custom:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.1);
}

.timeline-stop.custom:hover {
    transform: translate(-50%, -50%) scale(1.2);
}

/* Fixed Stops (Start/End) */
.timeline-slider.horizontal .timeline-stop.fixed {
    background-color: var(--border);
    border-color: var(--text-secondary);
    cursor: not-allowed;
    z-index: 1;
}

.timeline-slider.horizontal .timeline-stop.fixed:hover {
    transform: translate(-50%, -50%);
    /* No scale */
    border-color: var(--text-secondary);
}

/* Track Hover Effect */
.timeline-slider.horizontal:hover {
    cursor: copy;
    /* Plus icon cursor */
}

/* File Upload Button (Mock Input) */
/* File Upload Button (Mock Input) */
.file-upload-btn {
    flex: 1;
    min-width: 0;
    /* Critical for ellipsis in flex child */
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: border-color 0.2s;
}

.file-upload-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.file-upload-btn span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 0.5rem;
    flex: 1;
    /* Take available space */
    min-width: 0;
    /* Allow shrinking */
}

/* Icon Buttons */
.icon-btn {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    height: 100%;
    min-width: 36px;
    flex-shrink: 0;
    /* Prevent shrinking */
}

.icon-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

.icon-btn.danger:hover {
    border-color: #ef4444;
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.05);
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    margin-top: -0.25rem;
}

/* Export Overlay */
#export-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    /* Light glassmorphism */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(8px);
    transition: opacity 0.3s ease;
}

.export-content {
    background: #ffffff;
    padding: 2.5rem 3rem;
    border-radius: 12px;
    /* Hardcoded nice radius */
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        0 20px 25px -5px rgba(0, 0, 0, 0.1);
    /* Shadow-xl equivalent */
    text-align: center;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    min-width: 280px;
    transform: translateY(0);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.export-content h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: -0.025em;
}

/* Spinner Animation */
.spinner {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.dot {
    width: 12px;
    height: 12px;
    background-color: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Disabled State */
aside.disabled {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(100%);
    transition: all 0.3s ease;
}

/* Danger Button for Cancel */
.danger-btn {
    background-color: #fff;
    color: #ef4444;
    border: 1px solid #fee2e2;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.danger-btn:hover {
    background-color: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.danger-btn:active {
    transform: translateY(1px);
}

/* Ensure preview area is relative for absolute overlay */
.preview-area {
    position: relative;
}

/* =========================================
   Responsive Design (Mobile & Tablet)
   ========================================= */

@media (max-width: 900px) {
    body {
        height: 100vh;
        overflow: hidden;
        /* Disable page scrolling, we scroll sidebar only */
    }

    main {
        flex-direction: column-reverse;
        /* Controls bottom, Preview top */
        height: 100%;
        overflow: hidden;
    }

    /* Sidebar becomes bottom controls, scrollable */
    aside {
        width: 100%;
        flex: 1;
        /* Take remaining space */
        min-height: 0;
        /* Allow shrinking */
        border-right: none;
        border-top: 1px solid var(--border);
        overflow-y: auto;
        /* Scroll within sidebar */
        padding-bottom: 2rem;
        /* Extra padding for bottom */
    }

    /* Preview Area sits fixed at top */
    .preview-area {
        height: 45vh;
        /* Fixed height */
        flex: 0 0 45vh;
        /* Don't grow or shrink */
        min-height: 300px;
        width: 100%;
        padding: 1rem;
        z-index: 10;
        /* Ensure above if needed */
        background-color: #f9fafb;
    }

    /* Adjust controls for touch targets */
    .control-group h3 {
        margin-top: 0.5rem;
    }

    /* --- Touch Optimization --- */
    button,
    select,
    input[type="text"],
    input[type="number"],
    .file-upload-btn,
    .custom-select-header {
        padding: 0.75rem 1rem;
        /* Larger touch area */
        font-size: 0.95rem;
        /* Readable text */
        min-height: 44px;
        /* Apple Human Interface Guidelines */
    }

    /* Segmented Control Buttons */
    .segmented-control .toggle-btn {
        padding: 0.6rem;
        font-size: 0.9rem;
    }

    /* Sliders (Range Inputs) */
    input[type="range"] {
        height: 6px;
        /* Thicker track */
        margin: 0.75rem 0;
    }

    input[type="range"]::-webkit-slider-thumb {
        height: 24px;
        /* Big thumb */
        width: 24px;
        margin-top: -9px;
        /* Center on 6px track: (6 - 24) / 2 */
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    }

    /* Collapsible Headers */
    .collapsible-header {
        padding: 0.75rem 0;
    }

    /* Spacing between inputs */
    .input-wrapper {
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    /* Color picker row */
    .color-input-row {
        padding: 0.4rem;
        height: 44px;
    }

    input[type="color"] {
        height: 32px;
        width: 40px;
    }

    /* --- Timeline Slider Touch Optimization --- */
    .timeline-slider.horizontal {
        height: 48px;
        /* Much taller hit area */
        cursor: pointer;
    }

    .timeline-slider.horizontal .timeline-track {
        height: 12px;
        /* Thicker track */
        border-radius: 6px;
    }

    .timeline-slider.horizontal .timeline-stop {
        width: 24px;
        /* Larger dots */
        height: 24px;
        border-width: 3px;
    }

    /* Adjust fixed stops to match new size (visually smaller but accessible) */
    .timeline-stop.fixed {
        width: 16px;
        height: 16px;
    }
}

@media (max-width: 600px) {
    .preview-area {
        height: 50vh;
        min-height: 300px;
        padding: 0.5rem;
    }

    .header {
        padding: 0 1rem;
    }

    /* Stack row inputs vertically on very small screens if needed */
    /* currently .row-inputs are flex row, let's keep them unless too squished */
}