body { margin: 0; padding: 0; overflow: hidden; background-color: #1a1a1a; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

/* Layout */
#container { display: flex; height: 100vh; width: 100vw; }

/* Sidebar (Editor) */
#sidebar { 
    width: 400px; 
    background: #222; 
    color: #eee; 
    overflow-y: auto; 
    border-right: 2px solid #444; 
    display: flex; 
    flex-direction: column; 
    box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    z-index: 10;
}

.sidebar-header {
    padding: 20px;
    background: #111;
    border-bottom: 1px solid #444;
    position: sticky;
    top: 0;
    z-index: 20;
}
.sidebar-header h2 { margin: 0; color: #e63946; text-transform: uppercase; font-size: 1.2rem; }
.sidebar-header p { margin: 5px 0 0; color: #888; font-size: 0.8rem; }

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 15px;
    background: #111;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #333;
}
.toggle-label {
    font-size: 0.8rem;
    font-weight: bold;
    color: #aaa;
}
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #444;
  transition: .4s;
  border-radius: 20px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 14px; width: 14px;
  left: 3px; bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}
input:checked + .slider { background-color: #e63946; }
input:checked + .slider:before { transform: translateX(20px); }

/* Scene List Items */
.scene-item { 
    padding: 15px 20px; 
    border-bottom: 1px solid #333; 
    cursor: pointer; 
    transition: all 0.2s; 
    position: relative;
}
.scene-item:hover { background: #2a2a2a; }
.scene-item.active { 
    background: #333; 
    border-left: 5px solid #e63946; 
    padding-left: 15px; /* Adjust for border */
}

.scene-meta { 
    display: flex; 
    justify-content: space-between; 
    margin-bottom: 6px; 
    font-size: 0.75rem; 
    color: #888; 
    text-transform: uppercase; 
    letter-spacing: 1px;
}
.scene-script { 
    font-size: 1rem; 
    color: #fff; 
    margin-bottom: 10px; 
    line-height: 1.4; 
    font-family: 'Georgia', serif;
}
.scene-visual { 
    font-size: 0.85rem; 
    color: #aaa; 
    background: #151515; 
    padding: 8px 12px; 
    border-radius: 4px; 
    border: 1px solid #333;
}
.scene-visual strong { color: #e63946; }
.scene-type {
    background: #333;
    color: #e63946;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: bold;
    letter-spacing: 0.5px;
}

/* Back Button */
.back-btn {
    width: 100%;
    padding: 12px 20px;
    background: #1a1a1a;
    color: #aaa;
    border: none;
    border-bottom: 1px solid #333;
    cursor: pointer;
    font-size: 0.85rem;
    text-align: left;
    transition: background 0.2s;
}
.back-btn:hover { background: #2a2a2a; color: #fff; }

/* Export & Render Buttons */
.sidebar-actions {
    display: flex;
    gap: 8px;
    margin-top: 15px;
}

.export-btn, .render-btn {
    flex: 1;
    padding: 10px 12px;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s;
}

.export-btn {
    background: #2a5a8a;
}
.export-btn:hover { background: #3a6a9a; }

.render-btn {
    background: #2a8a5a;
}
.render-btn:hover { background: #3a9a6a; }
.render-btn:disabled { background: #444; cursor: wait; }

/* Feedback Badges */
.fb-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: bold;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-left: 4px;
}
.fb-pending { background: #333; color: #777; }
.fb-has-feedback { background: #5a3a10; color: #f0a030; }
.fb-approved { background: #1a3a1a; color: #4caf50; }

/* Scene item status borders */
.scene-item.scene-approved { border-left: 4px solid #4caf50; }
.scene-item.scene-has-feedback { border-left: 4px solid #f0a030; }

/* Feedback Panel */
.fb-panel {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #2a2a2a;
}
.fb-status { margin-bottom: 8px; }
.fb-textarea {
    width: 100%;
    min-height: 60px;
    max-height: 150px;
    padding: 8px 10px;
    background: #1a1a1a;
    color: #ddd;
    border: 1px solid #333;
    border-radius: 4px;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.8rem;
    line-height: 1.4;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
.fb-textarea:focus {
    outline: none;
    border-color: #e63946;
}
.fb-textarea::placeholder { color: #555; }
.fb-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.fb-btn {
    flex: 1;
    padding: 7px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    transition: background 0.2s;
}
.fb-btn-save {
    background: #3a3020;
    color: #f0a030;
}
.fb-btn-save:hover { background: #4a4030; }
.fb-btn-approve {
    background: #1a3a1a;
    color: #4caf50;
}
.fb-btn-approve:hover { background: #2a4a2a; }

.improve-btn {
    margin-top: 10px;
    padding: 8px 12px;
    background: #e63946;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    transition: background 0.2s;
    width: 100%;
}
.improve-btn:hover {
    background: #c32f3a;
}
.improve-btn.processing {
    background: #666;
    cursor: wait;
}

/* Preview Area — flex column so editor stacks below canvas */
#preview-area {
    flex-grow: 1;
    background: #111;
    display: flex;
    flex-direction: column;
    position: relative;
    background-image: radial-gradient(#222 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: hidden;
}

/* Canvas container — takes remaining space, centers the 16:9 canvas */
#canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 0;
}

canvas {
    display: block;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    border: 2px solid #333;
}

/* Timeline */
#timeline-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: rgba(0,0,0,0.7);
    padding: 10px 20px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    z-index: 110;
    opacity: 0;
    transition: opacity 0.3s;
}

#canvas-container:hover #timeline-container {
    opacity: 1;
}

#timelineSlider {
    flex-grow: 1;
    cursor: pointer;
    accent-color: #e63946;
}

#playPauseBtn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    margin-right: 15px;
    width: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
}
#playPauseBtn:hover {
    color: #e63946;
}

/* --- Collapsible Approved Scenes --- */

.scene-chevron {
    display: inline-block;
    width: 14px;
    font-size: 0.6rem;
    color: #666;
    transition: transform 0.2s;
    margin-right: 4px;
    flex-shrink: 0;
}

.scene-item.collapsed .scene-body {
    display: none;
}

.scene-item .scene-body {
    display: block;
}

.scene-item.collapsed .scene-meta {
    margin-bottom: 0;
}

.scene-item.collapsed {
    padding: 10px 20px;
}

/* --- Live Code Editor Panel --- */

#code-editor-panel {
    height: 300px;
    flex-shrink: 0;
    background: #14141a;
    border-top: 2px solid #e63946;
    display: flex;
    flex-direction: column;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #1a1a20;
    border-bottom: 1px solid #333;
    gap: 12px;
    flex-shrink: 0;
}

.editor-title {
    color: #aaa;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.editor-title strong {
    color: #e63946;
}

.editor-status {
    color: #4caf50;
    font-size: 0.7rem;
    white-space: nowrap;
    padding: 2px 8px;
    background: #111;
    border-radius: 3px;
    min-width: 80px;
    text-align: center;
}

.editor-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.editor-btn {
    padding: 5px 12px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    transition: background 0.2s;
}

.editor-btn-save {
    background: #1a3a1a;
    color: #4caf50;
}
.editor-btn-save:hover { background: #2a4a2a; }

.editor-btn-revert {
    background: #3a3020;
    color: #f0a030;
}
.editor-btn-revert:hover { background: #4a4030; }

.editor-btn-close {
    background: #3a1a1a;
    color: #e63946;
}
.editor-btn-close:hover { background: #4a2a2a; }

#codeEditorTextarea {
    flex: 1;
    width: 100%;
    padding: 12px 16px;
    background: #0d0d12;
    color: #d4d4d4;
    border: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    box-sizing: border-box;
    tab-size: 4;
}
#codeEditorTextarea:focus {
    outline: none;
}

/* Edit Code button */
.fb-btn-edit {
    background: #1a2a3a;
    color: #5ba0d0;
}
.fb-btn-edit:hover { background: #2a3a4a; }

/* Feedback Screenshots */
.fb-screenshot {
    margin-bottom: 8px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #333;
    cursor: pointer;
}
.fb-screenshot img {
    width: 100%;
    display: block;
    border-radius: 3px;
    transition: opacity 0.2s;
}
.fb-screenshot img:hover {
    opacity: 0.85;
}

/* Fullscreen screenshot overlay */
#screenshot-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    cursor: pointer;
}
#screenshot-overlay img {
    max-width: 90vw;
    max-height: 85vh;
    border: 2px solid #444;
    border-radius: 4px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}
.screenshot-hint {
    color: #666;
    font-size: 0.75rem;
    margin-top: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.fb-btn-regen {
    background: #3a2a0a;
    color: #d4880a;
}
.fb-btn-regen:hover { background: #4a3a1a; }

.fb-btn-fix {
    background: #1a2a3a;
    color: #5ba0d0;
}
.fb-btn-fix:hover { background: #2a3a4a; }

/* Chapter navigation bar */
.chapter-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: #111;
    border-bottom: 1px solid #444;
    position: sticky;
    top: 0;
    z-index: 20;
}
.chapter-nav-btn {
    padding: 8px 14px;
    background: #2a2a2a;
    color: #ccc;
    border: 1px solid #444;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
    transition: background 0.2s;
}
.chapter-nav-btn:hover:not(:disabled) { background: #3a3a3a; color: #fff; }
.chapter-nav-btn:disabled { opacity: 0.3; cursor: default; }
.chapter-nav-title {
    font-size: 1rem;
    font-weight: bold;
    color: #e63946;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
}
.chapter-nav-title:hover { color: #ff5a67; }

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    body { overflow: auto; }

    #container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    /* Canvas area — sticky at top, sized to fit 16:9 */
    #preview-area {
        width: 100%;
        height: auto;
        flex-grow: 0;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 100;
    }
    #canvas-container {
        /* just enough height for 16:9 + timeline */
        height: calc(56.25vw + 50px);
        min-height: 0;
    }

    /* Sidebar — sits below canvas, scrolls naturally */
    #sidebar {
        width: 100%;
        order: 2;
        height: auto;
        overflow-y: visible;
        border-right: none;
        border-top: 2px solid #444;
        box-shadow: none;
    }

    /* Hide render/build buttons on mobile */
    .desktop-only {
        display: none !important;
    }

    .sidebar-header {
        padding: 14px;
        position: static;
    }
    .sidebar-header h2 {
        font-size: 1rem;
    }

    .scene-item {
        padding: 18px 20px;
    }

    .fb-textarea {
        min-height: 80px;
        font-size: 16px; /* prevents iOS zoom on focus */
    }

    .fb-btn {
        padding: 12px;
        font-size: 0.85rem;
    }

    .export-btn, .render-btn {
        padding: 12px;
        font-size: 0.8rem;
    }

    .chapter-nav-btn {
        padding: 12px 16px;
        font-size: 0.85rem;
    }

    #timeline-container {
        opacity: 1;
    }
    #canvas-container:hover #timeline-container {
        opacity: 1;
    }
}

