:root {
    --bg-color: #050505;
    --term-color: #33ff33; /* Default green terminal */
    --ui-bg: rgba(0, 0, 0, 0.9);
    --ui-border: #333;
    --font-stack: 'Fira Code', 'Courier New', Courier, monospace;
    --accent-color: #33ff33;
    --danger-color: #ff4444;
}

/* Light Theme Variables */
body.light-mode {
    --bg-color: #f0f0f0;
    --term-color: #000000;
    --ui-bg: rgba(255, 255, 255, 0.95);
    --ui-border: #ccc;
    --accent-color: #0066ff;
    --danger-color: #ff0000;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--term-color);
    font-family: var(--font-stack);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, color 0.3s;
}

/* CRT Overlay Effects */
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 0, 0, 0.25) 50%
    ), linear-gradient(
        90deg,
        rgba(255, 0, 0, 0.06),
        rgba(0, 255, 0, 0.02),
        rgba(0, 0, 255, 0.06)
    );
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    z-index: 10;
}

body.light-mode .crt-overlay { opacity: 0.15; }

.scanline {
    width: 100%;
    height: 100px;
    z-index: 10;
    background: linear-gradient(0deg, rgba(0,0,0,0) 0%, rgba(33, 255, 33, 0.04) 50%, rgba(0,0,0,0) 100%);
    opacity: 0.1;
    position: absolute;
    bottom: 100%;
    animation: scanline 10s linear infinite;
    pointer-events: none;
}

body.light-mode .scanline {
    background: linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(0, 0, 0, 0.05) 50%, rgba(255,255,255,0) 100%);
}

@keyframes scanline {
    0% { bottom: 100%; }
    100% { bottom: -100px; }
}

/* Controls UI */
.controls {
    position: absolute;
    top: 20px;
    left: 20px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    padding: 20px;
    border-radius: 8px;
    z-index: 20;
    backdrop-filter: blur(5px);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
    max-width: 300px;
    transition: opacity 0.3s, background 0.3s, border-color 0.3s;
}

.controls:hover { opacity: 1; }

.controls h1 {
    margin-top: 0;
    font-size: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 0 5px var(--term-color);
    margin-bottom: 20px;
}

body.light-mode .controls h1 { text-shadow: none; }

.control-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-size: 0.8rem;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
}

.btn-row {
    display: flex;
    gap: 10px;
}

.btn-row button { flex: 1; }

input[type="file"] { display: none; }

.file-upload-btn {
    border: 1px solid var(--term-color);
    padding: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(0, 255, 0, 0.1);
}

body.light-mode .file-upload-btn { background: rgba(0, 0, 0, 0.05); }
.file-upload-btn:hover {
    background: var(--term-color);
    color: var(--bg-color);
}

button {
    background: transparent;
    border: 1px solid var(--term-color);
    color: var(--term-color);
    padding: 8px;
    font-family: var(--font-stack);
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
}

button:hover:not(:disabled) {
    background: var(--term-color);
    color: var(--bg-color);
    box-shadow: 0 0 10px var(--term-color);
}

body.light-mode button:hover:not(:disabled) {
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #555;
    color: #555;
}

body.light-mode button:disabled {
    border-color: #999;
    color: #999;
}

select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--term-color);
    color: var(--term-color);
    padding: 5px;
    font-family: var(--font-stack);
    font-size: 0.8rem;
    width: 100%;
    cursor: pointer;
    outline: none;
    margin-top: 5px;
}

select option {
    background: var(--bg-color);
    color: var(--term-color);
}

body.light-mode select {
    background: rgba(255, 255, 255, 0.5);
    border-color: #999;
    color: #000;
}

body.light-mode select option {
    background: #fff;
    color: #000;
}

input[type="range"] {
    width: 100%;
    background: transparent;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 15px;
    width: 15px;
    background: var(--term-color);
    cursor: pointer;
    margin-top: -5px;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 5px;
    background: #333;
}

body.light-mode input[type="range"]::-webkit-slider-runnable-track { background: #ccc; }

/* Layout */
.main-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    padding-left: 0; /* Remove padding to center canvas on screen */
    box-sizing: border-box;
}

/* ASCII Output - Canvas */
.ascii-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    width: 100%;
    padding: 20px;
    padding-bottom: 220px; /* Space for floating editor */
    box-sizing: border-box;
}

#displayCanvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    filter: contrast(1.1) brightness(1.2) drop-shadow(0 0 4px rgba(51, 255, 51, 0.3));
}

body.light-mode #displayCanvas {
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    filter: none;
}

.mono-mode #displayCanvas {
    filter: contrast(1.2) sepia(1) hue-rotate(80deg) saturate(3);
}

body.light-mode.mono-mode #displayCanvas { filter: contrast(1.2); }

/* Video Editor Panel - Floating Centered */
.editor-panel {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 900px;
    height: 180px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    display: flex;
    flex-direction: column;
    z-index: 30;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    border-radius: 12px;
    overflow: hidden;
}

/* Toolbar */
.editor-toolbar {
    height: 40px;
    border-bottom: 1px solid var(--ui-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    font-size: 0.8rem;
    text-transform: uppercase;
    background: rgba(0,0,0,0.05);
}

.toolbar-left, .toolbar-center, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.toolbar-center {
    flex: 1;
    justify-content: center;
    border-left: 1px solid var(--ui-border);
    border-right: 1px solid var(--ui-border);
    margin: 0 15px;
    padding: 0 15px;
}

.duration-control {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 200px;
}

.tool-btn {
    border: 1px solid var(--ui-border);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.tool-btn.danger {
    color: var(--danger-color);
    border-color: var(--danger-color);
}
.tool-btn.danger:hover {
    background: var(--danger-color);
    color: white;
}

/* Track Area */
.timeline-track-area {
    flex: 1;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 15px;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: center;
    align-items: center;
}

body.light-mode .timeline-track-area { background: rgba(0,0,0,0.02); }

.timeline-track {
    display: flex;
    gap: 0; /* Removing gap because transition block will provide spacing */
    height: 100px;
    min-width: 0; 
    position: relative;
}

.track-clip {
    height: 100%;
    background: #222;
    border: 1px solid #444;
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.1s;
    user-select: none;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

body.light-mode .track-clip {
    background: #fff;
    border-color: #ddd;
}

.track-clip.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color) inset;
    background: rgba(51, 255, 51, 0.1);
}

body.light-mode .track-clip.selected {
    background: rgba(0, 102, 255, 0.1);
}

.clip-thumb {
    height: 100%;
    width: 100%;
    object-fit: cover;
    opacity: 0.5;
    pointer-events: none;
}

.track-clip.selected .clip-thumb { opacity: 0.8; }

.clip-label {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 0.7rem;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 2px 4px;
    border-radius: 3px;
    pointer-events: none;
}

/* Transition Block in Timeline */
.transition-block {
    height: 100%;
    background: repeating-linear-gradient(
      45deg,
      transparent,
      transparent 5px,
      rgba(255, 255, 255, 0.05) 5px,
      rgba(255, 255, 255, 0.05) 10px
    );
    border-top: 1px dashed var(--ui-border);
    border-bottom: 1px dashed var(--ui-border);
    flex-shrink: 0;
    position: relative;
    opacity: 0.5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.transition-block:after {
    content: '↔';
    font-size: 10px;
    color: var(--ui-border);
}

body.light-mode .transition-block {
    background: repeating-linear-gradient(
      45deg,
      transparent,
      transparent 5px,
      rgba(0, 0, 0, 0.05) 5px,
      rgba(0, 0, 0, 0.05) 10px
    );
}

/* Scrubber Overlay */
.scrubber-overlay {
    position: absolute;
    top: 0;
    left: 15px;
    right: 15px;
    height: 100%;
    pointer-events: none;
    display: flex;
    justify-content: center;
}

#timelineScrubber {
    pointer-events: auto;
    position: absolute;
    bottom: 0;
    width: 100%;
    margin: 0;
    opacity: 0.5;
}

#timelineScrubber::-webkit-slider-thumb {
    height: 100%;
    margin-top: -5px;
}
