/* --- Modern Theming using CSS Variables --- */

/* 1. Global Box-Sizing & Font Reset */
html {
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*,
*:before,
*:after {
    box-sizing: inherit;
    --transition-speed: 0.2s;
}

/* 2. CSS Variables for Theming */
:root {
    /* Light Theme Palette - Professional & Clean */
    --bg-main: #f3f4f6;
    --bg-surface: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --accent-primary: #2563eb;
    /* Primary is Blue */
    --accent-primary-hover: #1d4ed8;
    --accent-green: #19b461;
    /* Secondary is Green */
    --accent-green-hover: #169c53;
    --accent-danger: #dc2626;
    --accent-danger-hover: #b91c1c;
    --accent-neutral: #e5e7eb;
    --accent-neutral-hover: #d1d5db;
    --glow-primary: color-mix(in srgb, var(--accent-primary) 35%, transparent);
    --glow-green: color-mix(in srgb, var(--accent-green) 35%, transparent);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    /* Custom property for p5.js to read */
    --canvas-bg-p5: #ffffff;
    --canvas-border-p5: #d1d5db;
}

body.dark-mode {
    /* Dark Theme Palette - Based on Reference Image */
    --bg-main: #111317;
    --bg-surface: #1C1F24;
    --text-primary: #e6e6e6;
    --text-secondary: #9a9a9a;
    --border-color: #363A42;
    --accent-primary: #0ea5e9;
    /* Primary is Blue */
    --accent-primary-hover: #38bdf8;
    --accent-green: #00f5a0;
    /* Secondary is Green */
    --accent-green-hover: #00d68e;
    --accent-danger: #e84855;
    --accent-danger-hover: #e32d3a;
    --accent-neutral: #363A42;
    --accent-neutral-hover: #484d57;
    --glow-primary: color-mix(in srgb, var(--accent-primary) 25%, transparent);
    --glow-green: color-mix(in srgb, var(--accent-green) 25%, transparent);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    /* Custom property for p5.js to read */
    --canvas-bg-p5: #000000;
    --canvas-border-p5: #4b5563;
}

/* 3. Global Resets & Body Styling */
body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    padding: 1rem;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

#main-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100vw;
    max-height: calc(100vh - 2rem);
}

#canvas-container {
    border: 2px dashed var(--canvas-border-p5);
    border-radius: 0.75rem;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: var(--canvas-bg-p5);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    transition: all var(--transition-speed) ease;
}

/* NEW: Style for when a file is being dragged over the canvas */
#canvas-container.dragging-over {
    border-color: var(--accent-primary);
    border-style: solid;
}


canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.control-panel {
    background-color: var(--bg-surface);
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-speed) ease;
}

.controls-group {
    display: flex;
    position: relative;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

/* === A-B LOOP: THUMB STYLE === */
#ab-start-slider,
#ab-end-slider {
    -webkit-appearance: none;
    appearance: none;
    background: red;
    /* hide track */
    height: 0px;

    position: absolute;
    width: 100%;
    pointer-events: none;
    padding: 0 2px;
}

#ab-start-slider::-webkit-slider-thumb,
#ab-end-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 50%;
    border: 2px solid teal;
    background: transparent;
    cursor: pointer;
    pointer-events: all;
}


#ab-start-slider::-moz-range-thumb,
#ab-end-slider::-moz-range-thumb {
    border-radius: 50%;
    border: 2px solid teal;
    background: transparent;
    cursor: pointer;
    pointer-events: all;
}

input[type="range"]:focus-visible {
    -webkit-appearance: none;
    appearance: none;
    box-shadow: 0 0 0 2px var(--text-primary);
}

#ab-start-slider:focus-visible {
    box-shadow: 0 0 0 1px rgba(0, 255, 0, 0.6);

}

#ab-end-slider:focus-visible {
    box-shadow: 0 0 0 1px rgba(0, 170, 255, 0.8);
}

#ab-range-readout {
    opacity: 0.75;
    font-size: 0.6em;
    height: 0;
    margin-top: -10px
}

/* --- Styles for Top Controls --- */
#top-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.left-controls {
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.grid-layout-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.centered-controls {
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.zoom-control {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.zoom-control label {
    font-weight: 500;
}

.zoom-control .slider {
    width: 150px;
}

.zoom-control span {
    width: 4rem;
    text-align: center;
    font-family: monospace;
}


/* --- General Control Styles --- */
.btn {
    background-color: var(--accent-primary);
    color: white;
    border: 1px solid transparent;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all var(--transition-speed) ease-in-out;
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
}

body.dark-mode .btn {
    color: #000;
}

.btn:hover {
    background-color: var(--accent-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 0 15px 1px var(--glow-primary);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    background-color: var(--accent-neutral) !important;
    color: var(--text-secondary) !important;
    cursor: not-allowed;
    opacity: 0.6;
    transform: none !important;
    box-shadow: none !important;
    border-color: transparent !important;
}

.btn.icon-btn {
    padding: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--accent-neutral);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn.icon-btn:hover {
    background-color: var(--accent-neutral-hover);
    box-shadow: none;
}

.btn.icon-btn svg {
    width: 1.25rem;
    height: 1.25rem;
}

.btn.icon-btn.active {
    background-color: var(--accent-green);
    color: white;
    border-color: transparent;
}

body.dark-mode .btn.icon-btn.active {
    color: #000;
}

.btn.icon-btn.active:hover {
    background-color: var(--accent-green-hover);
    box-shadow: 0 0 15px 1px var(--glow-green);
}

#speed-btn,
#theme-toggle-btn {
    background-color: var(--accent-green);
    color: white;
    border-color: transparent;
}

body.dark-mode #speed-btn,
body.dark-mode #theme-toggle-btn {
    background-color: var(--accent-green);
    color: #000;
}

#speed-btn:hover,
#theme-toggle-btn:hover {
    background-color: var(--accent-green-hover);
    box-shadow: 0 0 15px 1px var(--glow-green);
}


.btn.btn-danger {
    background-color: var(--accent-danger);
    color: white;
    border-color: transparent;
}

body.dark-mode .btn.btn-danger {
    color: #000;
}

.btn.btn-danger:hover {
    background-color: var(--accent-danger-hover);
    color: white;
    border-color: transparent;
    box-shadow: 0 0 15px 1px color-mix(in srgb, var(--accent-danger) 30%, transparent);
}


.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 5px;
    background: var(--accent-neutral);
    outline: none;
    opacity: 0.8;
    transition: opacity .2s;
}

.slider:hover {
    opacity: 1;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 3px solid var(--bg-surface);
    transition: all var(--transition-speed) ease;
}

.slider::-moz-range-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 3px solid var(--bg-surface);
    transition: all var(--transition-speed) ease;
}

.slider:hover::-webkit-slider-thumb {
    box-shadow: 0 0 10px 0px var(--glow-primary);
}

.slider:hover::-moz-range-thumb {
    box-shadow: 0 0 10px 0px var(--glow-primary);
}

.layout-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.layout-controls label {
    font-weight: 500;
    color: var(--text-secondary);
}

.layout-controls input {
    width: 50px;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.4rem;
    text-align: center;
    color: var(--text-primary);
    transition: all var(--transition-speed) ease;
}

.layout-controls input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 8px 0px var(--glow-primary);
}

/* --- Sub-Seekbar Styles --- */
#sub-seekbar-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
}

.framerate-control-wrapper {
    justify-self: start;
}

.time-display-container {
    justify-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.right-controls-wrapper {
    justify-self: end;
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

#timecode {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.125rem;
    color: var(--text-secondary);
    text-align: center;
}

#frame-counter {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    opacity: 0.7;
    text-align: center;
}

/* --- Playback Speed Control Styles --- */
.speed-control-wrapper {
    position: relative;
    /* Container for the absolute positioned menu */
    display: flex;
    align-items: center;
}

.speed-menu {
    display: none;
    /* Hidden by default */
    position: absolute;
    bottom: calc(100% + 0.5rem);
    /* Position above the button with a small gap */
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.75rem;
    box-shadow: var(--shadow-md);
    z-index: 10;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 180px;
    /* Give it a fixed width */
}

.speed-menu.visible {
    display: flex;
    /* Show the menu */
}

.speed-menu label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.speed-menu .slider {
    width: 100%;
}

#speed-display {
    font-family: monospace;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--bg-main);
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border-color);
    min-width: 4rem;
    /* Ensure consistent width */
    text-align: center;
}

/* --- Styles for View Modes --- */

#view-mode-btn {
    margin-right: 1rem;
    /* Add spacing between view mode and zoom */
}

/* Default state (Grid View) */
#clear-all-btn,
.grid-layout-controls {
    display: none;
}

/* Split View Active State */
body.split-view-active .grid-layout-controls,
body.split-view-active #clear-grid-btn {
    display: none;
}

body.split-view-active #clear-all-btn {
    display: flex;
}

/* Grid View Active State (Default) */
body:not(.split-view-active) .grid-layout-controls,
body:not(.split-view-active) #clear-grid-btn {
    display: flex;
}