:root {
    --bg-app: #11111b;       /* Darkest */
    --bg-panel: #1e1e2e;     /* IDE background */
    --bg-header: #181825;
    --border: #313244;
    --text-main: #cdd6f4;
    --text-muted: #a6adc8;
    
    /* Brand Colors per AGENTS.md */
    --primary: #6C63FF;      /* Violet */
    --primary-hover: #5a52d5;
    --secondary: #A78BFA;    /* Lavender */
    --accent: #F472B6;       /* Pink */

    /* Syntax Highlighting Base */
    --syn-tag: #F472B6;      /* Pink */
    --syn-attr: #A78BFA;     /* Lavender */
    --syn-value: #a6e3a1;    /* Green */
    --syn-keyword: #6C63FF;  /* Violet */
    --syn-string: #f9e2af;   /* Yellow */
    --syn-comment: #6c7086;  /* Gray */

    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { background-color: var(--bg-app); color: var(--text-main); height: 100vh; overflow: hidden; display: flex; flex-direction: column; }

/* Custom Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb { background: #45475a; border-radius: 5px; border: 2px solid var(--bg-panel); }
::-webkit-scrollbar-thumb:hover { background: #585b70; }

/* Header */
.app-header {
    height: 50px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    flex-shrink: 0;
}

.logo { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; color: var(--text-main); }
.logo svg { color: var(--primary); }

.controls { display: flex; align-items: center; gap: 8px; }
.divider { width: 1px; height: 20px; background-color: var(--border); margin: 0 4px; }

/* Buttons */
.btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    display: flex; align-items: center; gap: 6px;
    transition: all 0.2s;
}
.btn:hover { color: var(--text-main); background: rgba(255,255,255,0.05); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); color: white; border-color: var(--primary-hover); }
.btn-icon { padding: 6px; }
.btn-small { padding: 4px; }

/* Layout */
.app-body { display: flex; flex: 1; height: calc(100vh - 50px); overflow: hidden; }

/* Sidebar */
.sidebar { width: 250px; background-color: var(--bg-header); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; transition: width 0.3s; }
.sidebar.hidden { width: 0; border-right: none; overflow: hidden; }
.sidebar-header { padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.story-list { list-style: none; overflow-y: auto; flex: 1; }
.story-item { padding: 10px 16px; font-size: 13px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.02); display: flex; justify-content: space-between; align-items: center; transition: background 0.2s; }
.story-item:hover { background: rgba(255,255,255,0.05); }
.story-item.active { background: rgba(108, 99, 255, 0.15); border-left: 3px solid var(--primary); padding-left: 13px; color: white;}
.story-item .delete-btn { opacity: 0; color: #f38ba8; background: none; border: none; cursor: pointer; padding: 4px; border-radius: 4px; }
.story-item:hover .delete-btn { opacity: 1; }
.story-item .delete-btn:hover { background: rgba(243, 139, 168, 0.2); }

/* Workspace */
.workspace { display: flex; flex: 1; overflow: hidden; }
.pane { display: flex; flex-direction: column; height: 100%; min-width: 100px; }
.editors-pane { background-color: var(--bg-panel); }
.preview-pane { background-color: var(--bg-app); }

/* Resizers */
.resizer { background-color: var(--border); position: relative; z-index: 10; transition: background-color 0.2s; }
.resizer:hover, .resizer.dragging { background-color: var(--primary); }
.resizer.vertical { width: 6px; cursor: col-resize; margin: 0 -3px; }
.resizer.horizontal { height: 6px; cursor: row-resize; margin: -3px 0; }

/* Editors */
.editor-container { display: flex; flex-direction: column; flex: 1; min-height: 50px; overflow: hidden; position: relative; }
.editor-header { padding: 4px 12px; background: rgba(0,0,0,0.2); font-size: 11px; font-weight: 600; color: var(--text-muted); display: flex; align-items: center; flex-shrink: 0; border-bottom: 1px solid rgba(0,0,0,0.3); }
.lang-label { display: inline-block; padding: 2px 6px; border-radius: 4px; }
.lang-label.html { color: #f38ba8; }
.lang-label.css { color: #89b4fa; }
.lang-label.js { color: #f9e2af; }

/* Textarea / Highlight overlay hack */
.editor-wrapper { position: relative; flex: 1; overflow: hidden; background: var(--bg-panel); font-family: 'Fira Code', monospace; font-size: 13px; line-height: 1.5; }
.editor-wrapper textarea, .editor-wrapper pre {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    margin: 0; padding: 12px; border: none; overflow: auto;
    font-family: inherit; font-size: inherit; line-height: inherit;
    white-space: pre; word-wrap: normal;
}
.editor-wrapper textarea {
    color: transparent; /* Text is drawn by <pre> behind it */
    background: transparent;
    caret-color: var(--text-main);
    z-index: 2;
    resize: none;
    outline: none;
}
.editor-wrapper pre {
    z-index: 1;
    pointer-events: none;
    color: var(--text-main);
}
.editor-wrapper textarea::selection { background: rgba(108, 99, 255, 0.4); color: transparent; }

/* Preview Pane */
.preview-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; background-color: var(--bg-header); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.device-toggles, .bg-toggles { display: flex; gap: 6px; background: rgba(0,0,0,0.2); padding: 4px; border-radius: 6px; }
.device-btn { background: none; border: none; color: var(--text-muted); width: 28px; height: 28px; border-radius: 4px; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: all 0.2s; }
.device-btn:hover { color: var(--text-main); background: rgba(255,255,255,0.05); }
.device-btn.active { color: white; background: var(--primary); }

.bg-btn { width: 20px; height: 20px; border-radius: 4px; cursor: pointer; transition: transform 0.2s; }
.bg-btn:hover { transform: scale(1.1); }
.bg-btn.active { outline: 2px solid var(--primary); outline-offset: 2px; }
.bg-btn.checkered {
    background-color: #fff;
    background-image: 
        linear-gradient(45deg, #ccc 25%, transparent 25%), 
        linear-gradient(-45deg, #ccc 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #ccc 75%), 
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
    border: 1px solid #aaa;
}

.preview-stage { flex: 1; display: flex; justify-content: center; align-items: center; padding: 20px; overflow: auto; background-color: var(--bg-app); transition: background-color 0.3s; position: relative;}
.iframe-container { height: 100%; max-height: 100%; border-radius: 8px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.3); transition: width 0.3s ease; position: relative; border: 1px solid var(--border); background: #fff; display: flex; flex-direction: column;}
#preview-iframe { width: 100%; height: 100%; border: none; background: transparent; flex: 1;}

body.fullscreen .app-header, body.fullscreen .sidebar, body.fullscreen .editors-pane, body.fullscreen .resizer, body.fullscreen .preview-toolbar, body.fullscreen .console-panel { display: none !important; }
body.fullscreen .preview-pane { width: 100% !important; }
body.fullscreen .preview-stage { padding: 0; }
body.fullscreen .iframe-container { width: 100% !important; height: 100%; border-radius: 0; border: none; }

/* Console */
.console-panel { background-color: #181825; border-top: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.console-panel.collapsed .console-logs { display: none; }
.console-panel.collapsed .chevron { transform: rotate(180deg); }
.console-header { padding: 6px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); cursor: pointer; display: flex; justify-content: space-between; align-items: center; user-select: none; }
.console-header:hover { background: rgba(255,255,255,0.02); }
.badge { background: var(--primary); color: white; padding: 2px 6px; border-radius: 10px; font-size: 10px; margin-left: 6px; }
.flex-gap { display: flex; align-items: center; gap: 8px; }
.chevron { transition: transform 0.2s; }
.console-logs { height: 150px; overflow-y: auto; padding: 8px 16px; font-family: 'Fira Code', monospace; font-size: 12px; line-height: 1.5; background: #11111b; }
.log-entry { margin-bottom: 4px; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.05); word-wrap: break-word;}
.log-error { color: #f38ba8; }
.log-warn { color: #f9e2af; }

/* Modals */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); display: flex; justify-content: center; align-items: center; z-index: 100; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal { background: var(--bg-panel); padding: 24px; border-radius: 12px; min-width: 300px; border: 1px solid var(--border); box-shadow: 0 20px 40px rgba(0,0,0,0.4); transform: translateY(20px); transition: transform 0.2s; }
.modal-overlay.active .modal { transform: translateY(0); }
.modal h3 { margin-bottom: 16px; font-size: 18px; }
.modal input { width: 100%; background: #11111b; border: 1px solid var(--border); color: var(--text-main); padding: 10px; border-radius: 6px; margin-bottom: 20px; font-family: inherit; outline: none; }
.modal input:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; }

/* Tokens */
.token.tag { color: var(--syn-tag); }
.token.attr { color: var(--syn-attr); }
.token.string { color: var(--syn-string); }
.token.keyword { color: var(--syn-keyword); }
.token.value { color: var(--syn-value); }
.token.comment { color: var(--syn-comment); font-style: italic; }
