:root {
    --bg-dark: #050505;
    --bg-panel: #0a0a0a;
    --primary: #00ff9d;
    --accent: #00b8ff;
    --danger: #ff0055;
    --text-main: #e0e0e0;
    --text-dim: #666;
    --border: #333;
    --glass: rgba(20, 20, 20, 0.8);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    overflow: hidden;
    font-family: 'Rajdhani', 'PingFang SC', sans-serif;
    background-image: 
        radial-gradient(circle at 50% 50%, #111 0%, #000 100%);
}

.app-container {
    width: 98vw;
    height: 96vh;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    position: relative;
}
/* Cyberpunk corner decorations */
.app-container::before {
    content: ''; position: absolute; top: -1px; left: -1px; width: 20px; height: 20px;
    border-top: 2px solid var(--primary); border-left: 2px solid var(--primary);
}
.app-container::after {
    content: ''; position: absolute; bottom: -1px; right: -1px; width: 20px; height: 20px;
    border-bottom: 2px solid var(--primary); border-right: 2px solid var(--primary);
}

header {
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    backdrop-filter: blur(5px);
}

.logo {
    font-family: 'Orbitron', sans-serif;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 3px;
    text-shadow: 0 0 10px rgba(0, 255, 157, 0.3);
}
.logo span { color: var(--primary); }

.status-indicator {
    font-size: 10px;
    color: var(--primary);
    display: flex;
    align-items: stretch;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.status-indicator::before {
    content: ''; display: block; width: 6px; height: 6px;
    background: var(--primary); border-radius: 50%;
    box-shadow: 0 0 8px var(--primary);
    animation: pulse 2s infinite;
}
@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }

main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Controls Panel (Left) */
.controls-panel {
    width: 360px;
    padding: 15px;
    border-right: 1px solid var(--border);
    background: rgba(10, 10, 10, 0.95);
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

.input-group label {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--accent);
    margin-bottom: 5px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.input-group textarea {
    width: 100%;
    height: 100px; /* Reduced height */
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border);
    color: #fff;
    padding: 10px;
    font-family: 'Rajdhani', 'PingFang SC', sans-serif;
    resize: none;
    font-size: 13px;
    transition: border 0.3s;
}
.input-group textarea:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 10px rgba(0,255,157,0.1);
}

.read-only-text {
    font-size: 11px;
    color: #888;
    background: rgba(0,0,0,0.5);
    padding: 8px;
    border: 1px solid var(--border);
    min-height: 35px;
    word-break: break-all;
    font-family: monospace;
}

.settings-row { display: flex; gap: 10px; }
.settings-row .input-group { flex: 1; }

select {
    width: 100%;
    background: #000; background-size: contain; background-position: center; background-repeat: no-repeat;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 6px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
}

/* Switches */
.toggle-group {
    display: flex;
    align-items: stretch;
    gap: 10px;
}
.switch {
    display: inline-block; width: 34px; height: 18px; position: relative;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #333; transition: .4s;
}
.slider.round { border-radius: 18px; }
.slider.round:before { border-radius: 50%; }
.slider:before {
    position: absolute; content: ""; height: 12px; width: 12px; left: 3px; bottom: 3px;
    background-color: white; transition: .4s;
}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(16px); }
.toggle-label { font-size: 12px; color: var(--text-dim); }

/* Buttons */
.cyber-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    border: none;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    color: #000;
    font-weight: 800;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
    text-transform: uppercase;
}
.cyber-btn:hover {
    background: #fff;
    box-shadow: 0 0 20px var(--primary);
    text-shadow: 0 0 5px rgba(0,0,0,0.5);
}
.cyber-btn:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
    box-shadow: none;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 2px 6px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.icon-btn:hover { background: var(--accent); color: #000; }

/* Viewport Panel (Right) */
.viewport-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0; /* Full bleed */
    background: #000; background-size: contain; background-position: center; background-repeat: no-repeat;
    position: relative;
}
/* Grid Background */
.viewport-panel::before {
    content: ""; opacity: 0.1; position: absolute; top:0; left:0; right:0; bottom:0;
    background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 40px 40px; pointer-events: none;
}

/* Main Preview Area */
.preview-container {
    flex: 1; /* Takes available space */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    padding: 0;
    overflow: hidden;
}

/* Result Container */
#result-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
}

.image-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 150px;
    display: flex;
    justify-content: center;
    align-items: stretch;
    border: 1px solid var(--border);
    background: #050505;
}

#result-image {
    width: 100%;
    height: auto;
    
    object-fit: contain;
}

/* Meta Data - Compact */
.meta-data-row {
    width: 100%;
    max-width: 100%;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    background: rgba(20,20,20,0.8);
    border: 1px solid var(--border);
    backdrop-filter: blur(5px);
    font-size: 11px;
    font-family: 'Share Tech Mono', monospace;
    color: var(--text-dim);
}
.meta-group { display: flex; gap: 20px; align-items: stretch; }
.highlight { color: var(--primary); font-weight: 700; margin-left: 5px; }
.timings-group ul { display: flex; gap: 10px; list-style: none; }
.timings-group span:first-child { color: var(--accent); margin-right: 3px; }

/* Safe Zone Overlay */
.safe-zone-overlay {
    position: absolute; top: 0; bottom: 0;
    background: rgba(0, 255, 157, 0.05);
    border-left: 1px dashed var(--primary);
    border-right: 1px dashed var(--primary);
    pointer-events: none; 
}
.safe-zone-overlay::after {
    content: "SAFE ZONE";
    position: absolute; top: 5px; left: 5px;
    font-size: 10px; color: var(--primary); opacity: 0.7;
}

/* History Panel - Fixed Bottom */
.history-panel {
    height: 280px; overflow-y: auto;
    background: rgba(10,10,10,0.95);
    border-top: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    z-index: 10;
}
.history-label {
    font-size: 10px;
    color: var(--accent);
    margin-bottom: 8px;
    letter-spacing: 2px;
    text-transform: uppercase;
    font-weight: 700;
}

.gallery-strip {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 5px;
    align-content: flex-start;
}

.thumb-item {
    height: 60px;
    width: auto;
    aspect-ratio: 1920/462;
    border: 1px solid var(--border);
    background: #000;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
    position: relative;
    opacity: 0.5;
    transition: all 0.2s;
    flex-shrink: 0;
}
.thumb-item:hover, .thumb-item.active {
    opacity: 1;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 255, 157, 0.15);
}
.thumb-item.active::before {
    content: "ACTIVE";
    position: absolute; top: 2px; left: 2px;
    font-size: 8px; background: var(--primary); color: #000; padding: 1px 3px;
    z-index: 2;
}
.thumb-item img {
    width: 100%; height: 100%; object-fit: cover;
}
.thumb-info {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,0.8);
    color: var(--text-main);
    font-size: 9px;
    padding: 3px 5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* Loading & Placeholder State */
.placeholder-state {
    display: flex; flex-direction: column; justify-content: center; align-items: stretch;
    color: #333; height: 100%;
}
.placeholder-state p::after { content: "_"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

.loader {
    border: 2px solid #333; border-top: 2px solid var(--primary);
    border-radius: 50%; width: 30px; height: 30px;
    animation: spin 1s linear infinite; margin-bottom: 10px;
}
.loading-text { font-size: 12px; color: var(--primary); letter-spacing: 1px; }

.process-log {
    margin-top: 20px;
    width: 400px;
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    color: #888;
    background: rgba(0,0,0,0.5);
    padding: 10px;
    border: 1px solid #222;
}
.process-log div { margin-bottom: 2px; padding-left: 5px; border-left: 2px solid #333; }

.hidden { display: none !important; }

/* Prompt Steps Visualization */
.prompt-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.step-row {
    font-size: 11px;
    line-height: 1.4;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 2px;
}
.step-name {
    color: var(--primary);
    font-weight: bold;
    margin-right: 5px;
    min-width: 80px;
    display: inline-block;
}
.step-content {
    color: #ccc;
    word-break: break-all;
}

/* Prompt Steps Visualization */
.prompt-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.step-row {
    font-size: 11px;
    line-height: 1.4;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 2px;
}
.step-name {
    color: var(--primary);
    font-weight: bold;
    margin-right: 5px;
    min-width: 80px;
    display: inline-block;
}
.step-content {
    color: #ccc;
    word-break: break-all;
}

/* Loading Overlay Centering Fix */
#loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 200px;
}
