:root {
    --bg-deep: #020617;
    --bg-panel: #0f172a;
    --bg-input: #020617;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.4);
    --border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --header-h: 65px;
    --side-w: 70px;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --dd-accent: #6366f1;
    --dd-accent-2: #ec4899;
    --dd-cyan: #06b6d4;
}

* { box-sizing: border-box; font-family: 'Inter', sans-serif; outline: none; }

body, html { 
    margin: 0; padding: 0; height: 100%; width: 100%; 
    background: var(--bg-deep); color: var(--text-main); 
    overflow: hidden; overflow-y: auto; position: fixed;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.dd-logo { display: flex; align-items: center; gap: clamp(0.7rem, 1.8vw, 1rem); padding: 1rem; user-select: none; }
.dd-logo-icon { position: relative; width: clamp(30px, 8vw, 50px); height: clamp(30px, 8vw, 50px); flex-shrink: 0; }
.dd-logo-link { text-decoration: none; }
.dd-icon-container {
    position: relative; width: 100%; height: 100%;
    background: linear-gradient(135deg, #1a1f35 0%, #0f1424 100%);
    border-radius: 16px; border: 2px solid rgba(99, 102, 241, 0.3);
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.terminal-header { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; z-index: 2; }
.terminal-dot { width: 3px; height: 3px; border-radius: 50%; animation: pulse-dot 2s ease-in-out infinite; }
.terminal-dot:nth-child(1) { background: #ff5f56; animation-delay: 0s; }
.terminal-dot:nth-child(2) { background: #ffbd2e; animation-delay: 0.3s; }
.terminal-dot:nth-child(3) { background: #27c93f; animation-delay: 0.6s; }

@keyframes pulse-dot { 0%, 100% { opacity: 0.6; transform: scale(1); } 50% { opacity: 1; transform: scale(1.2); } }

.dd-code-symbol {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    font-size: clamp(14px, 3vw, 20px);
    background: linear-gradient(135deg, var(--dd-accent) 0%, var(--dd-accent-2) 50%, var(--dd-cyan) 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
    font-weight: 900; animation: glow-pulse 3s ease-in-out infinite;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.5));
}

@keyframes glow-pulse { 0%, 100% { filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.4)); } 50% { filter: drop-shadow(0 0 16px rgba(99, 102, 241, 0.8)); } }

.dd-binary-bg { position: absolute; inset: 0; overflow: hidden; opacity: 0.15; }
.dd-binary-col { position: absolute; top: -100%; font-family: 'JetBrains Mono', monospace; font-size: 8px; color: var(--dd-accent); white-space: nowrap; animation: fall linear infinite; }
.dd-binary-col:nth-child(1) { left: 15%; animation-duration: 4s; animation-delay: 0s; }
.dd-binary-col:nth-child(2) { left: 45%; animation-duration: 5s; animation-delay: 1s; }
.dd-binary-col:nth-child(3) { left: 75%; animation-duration: 4.5s; animation-delay: 2s; }
@keyframes fall { to { transform: translateY(200%); } }

.dd-corner { position: absolute; width: 12px; height: 12px; border: 2px solid var(--dd-accent-2); opacity: 0.6; }
.dd-corner.tl { top: 4px; left: 4px; border-right: none; border-bottom: none; }
.dd-corner.tr { top: 4px; right: 4px; border-left: none; border-bottom: none; }
.dd-corner.bl { bottom: 4px; left: 4px; border-right: none; border-top: none; }
.dd-corner.br { bottom: 4px; right: 4px; border-left: none; border-top: none; }

@media (max-width: 640px) {
    .dd-logo { gap: 0.5rem; }
    .dd-code-symbol { font-size: clamp(12px, 2.8vw, 20px); }
    .dd-corner { width: 5px; height: 5px; border: 1.5px solid var(--dd-accent-2); }
    .terminal-header { gap: 2px; top: 6.5px; left: 6.5px; }
    .terminal-dot { width: 2px; height: 2px; }
}

/* --- APP SHELL --- */
.app-shell { display: flex; height: 100vh; width: 100vw; flex-direction: row; }

/* --- SIDEBAR (RESPONSIVE) --- */
.sidebar {
    width: var(--side-w); background: #000; border-right: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: center; padding: 25px 0; 
    flex-shrink: 0; z-index: 100; transition: all 0.3s ease;
}
.logo {
    width: 42px; height: 42px; background: var(--accent); border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 35px; box-shadow: 0 0 20px var(--accent-glow); color: #fff;
}
.nav-group { display: flex; flex-direction: column; width: 100%; gap: 5px; }
.nav-item {
    color: var(--text-dim); font-size: 1.2rem; cursor: pointer; transition: 0.2s;
    padding: 18px 0; width: 100%; display: flex; justify-content: center; position: relative;
}
.nav-item:hover { color: #fff; }
.nav-item.active { color: var(--accent); background: rgba(99, 102, 241, 0.05); }
.nav-item.active::before {
    content: ''; position: absolute; left: 0; top: 20%; height: 60%; width: 3px;
    background: var(--accent); border-radius: 0 4px 4px 0; box-shadow: 0 0 10px var(--accent);
}

/* --- MAIN WORKBENCH --- */
.workbench { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }

.top-bar {
    height: var(--header-h); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 24px;
    justify-content: space-between; background: rgba(15, 23, 42, 0.7); 
    backdrop-filter: blur(15px); flex-shrink: 0;
}
.top-bar h1 { font-size: 0.85rem; letter-spacing: 1.5px; text-transform: uppercase; font-weight: 800; margin: 0; }

/* --- SPLIT ENGINE (BUG-FREE) --- */
.split-container { 
    display: grid; grid-template-columns: 1fr 4px 1fr; 
    flex-grow: 1; min-height: 0; background: var(--bg-deep); overflow: hidden;
}

.pane { 
    display: flex; flex-direction: column; min-width: 0; 
    background: var(--bg-panel); overflow: hidden; position: relative; 
}

.pane-header { 
    padding: 10px 18px; background: rgba(0,0,0,0.2); border-bottom: 1px solid var(--border); 
    font-size: 10px; font-weight: 900; color: var(--text-dim); letter-spacing: 1px;
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}

.editor-wrapper { 
    flex-grow: 1; position: relative; background: var(--bg-input); 
    width: 100%; overflow: hidden; /* Fix for horizontal scroll leak */
}
.cm-wrapper { height: 100%; width: 100% !important; overflow: auto !important; }

.resizer { background: #000; cursor: col-resize; transition: 0.2s; z-index: 10; display: flex; align-items: center; justify-content: center; }
.resizer:hover { background: var(--accent); }

/* --- UI COMPONENTS --- */
.btn-group { display: flex; gap: 8px; }
.btn { 
    background: var(--accent); color: white; border: none; padding: 10px 16px; 
    border-radius: 8px; font-weight: 700; cursor: pointer; display: flex; 
    align-items: center; gap: 8px; font-size: 0.75rem; transition: 0.2s;
}
.btn-secondary { background: rgba(255,255,255,0.05); color: var(--text-main); border: 1px solid var(--border); }
.btn:hover { opacity: 0.9; transform: translateY(-1px); }

/* FILE OVERLAY */
.upload-view { 
    position: absolute; inset: 0; display: flex; flex-direction: column; 
    align-items: center; justify-content: center; background: var(--bg-input); 
    z-index: 50; border: 2px dashed var(--border); margin: 15px; border-radius: 12px; 
    cursor: pointer; transition: 0.3s;
}
.upload-view:hover { border-color: var(--accent); background: rgba(99, 102, 241, 0.02); }
.upload-view.hidden { display: none; }

/* --- TOAST SYSTEM (RESPONSIVE) --- */
#toast-container {
    position: fixed; bottom: 30px; right: 30px;
    display: flex; flex-direction: column; gap: 10px; z-index: 9999;
}
.toast {
    padding: 14px 24px; border-radius: 12px; font-size: 0.85rem; font-weight: 700;
    display: flex; align-items: center; gap: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: toastSlideIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
    min-width: 280px;
}
.toast.success { background: var(--success-bg); color: var(--success-text); border: 1px solid #bbf7d0; }
.toast.error { background: var(--error-bg); color: var(--error-text); border: 1px solid #fecaca; }

@keyframes toastSlideIn { 
    from { opacity: 0; transform: translateX(100px); } 
    to { opacity: 1; transform: translateX(0); } 
}

.loader {
    position: fixed; inset: 0; background: rgba(2, 6, 23, 0.85); backdrop-filter: blur(8px);
    display: none; align-items: center; justify-content: center; z-index: 1000;
}
.loader.active { display: flex; }
.spinner { width: 30px; height: 30px; border: 3px solid rgba(99, 102, 241, 0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- MOBILE RESPONSIVENESS RE-ADDED --- */
@media (max-width: 768px) {
    .app-shell { flex-direction: column-reverse; }
    .sidebar { 
        width: 100%; height: 65px; flex-direction: row; padding: 0; 
        border-right: none; border-top: 1px solid var(--border); 
    }
    .logo { display: none; }
    .nav-group { flex-direction: row; align-items: center; justify-content: space-around; height: 100%; }
    .nav-item { width: auto; padding: 0 20px; }
    .nav-item.active::before {  display: none; }
    
    .split-container { grid-template-columns: 1fr !important; grid-template-rows: 1fr 4px 1fr; }
    .resizer { height: 4px; width: 100%; cursor: row-resize; }
    .resizer::after { content: ''; width: 40px; height: 2px; background: var(--border); }
    
    .top-bar h1 span { display: none; }
    .btn span { display: none; }
    
    #toast-container { right: 20px; left: 20px; bottom: 85px; align-items: center; }
    .toast { min-width: auto; width: 100%; justify-content: center; }
}