/* ╔════════════════════════════════════════════════════════════╗
   ║     SCRIPTING STUDIO PRO v5.0 — Master Stylesheet          ║
   ╚════════════════════════════════════════════════════════════╝ */

:root {
    --bg:         #060a17;
    --panel:      #0b1122;
    --panel-2:    #0f172a;
    --border:     rgba(148, 163, 184, 0.16);
    --c1:         #38bdf8;
    --c2:         #a855f7;
    --c3:         #f472b6;
    --green:      #10b981;
    --text:       #f1f5f9;
    --muted:      #8b97b4;
    --header-h:   54px;
}

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

body, button, input, select, textarea {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

/* ── TOP HEADER (ZERO OVERLAP) ────────────────────────────────── */
.top-header {
    height: var(--header-h);
    background: rgba(8, 13, 28, 0.96);
    border-bottom: 1px solid var(--border);
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
    z-index: 30;
}

.hdr-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.back-btn-inline {
    background: rgba(30, 41, 59, 0.85);
    color: #f8fafc;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 9px;
    padding: 6px 11px;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}
.back-btn-inline:hover { background: #2563eb; border-color: #60a5fa; }

.brand-title {
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.8px;
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    background: linear-gradient(90deg, var(--c1), var(--c2), var(--c3));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.brand-title i { color: var(--c1); -webkit-text-fill-color: var(--c1); }

.ver-pill {
    font-size: 0.58rem;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 5px;
    background: linear-gradient(135deg, #06b6d4, #8b5cf6);
    color: #fff;
    -webkit-text-fill-color: #fff;
    letter-spacing: 0.6px;
}

/* AI Code-to-3D Bar */
.ai-bar {
    flex: 1;
    max-width: 420px;
    min-width: 180px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 20px;
    padding: 3px 4px 3px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.ai-bar:focus-within {
    border-color: var(--c1);
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.28);
}
.ai-bar input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: #f8fafc;
    font-size: 0.76rem;
}
.ai-bar input::placeholder { color: #64748b; }
.ai-go {
    background: linear-gradient(135deg, #06b6d4, #8b5cf6);
    border: none;
    color: #fff;
    border-radius: 16px;
    padding: 4px 11px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}
.ai-go:hover { filter: brightness(1.12); }

.hdr-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.stat-pill {
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.28);
    color: #7dd3fc;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 14px;
    white-space: nowrap;
}

.collab-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 14px;
    white-space: nowrap;
}
.collab-dot { width: 7px; height: 7px; border-radius: 50%; background: #64748b; }
.collab-pill.connected { border-color: #10b981; color: #6ee7b7; background: rgba(16, 185, 129, 0.14); }
.collab-pill.connected .collab-dot { background: #10b981; box-shadow: 0 0 8px #10b981; }

.hdr-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 10px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 0.74rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.18s;
    white-space: nowrap;
}
.hdr-btn:hover { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.28); }
.hdr-btn.ar-cta { background: linear-gradient(135deg, #06b6d4, #8b5cf6); border-color: transparent; color: #fff; }
.hdr-btn.export-cta { background: linear-gradient(135deg, #10b981, #06b6d4); border-color: transparent; color: #03151a; }

/* ── MAIN WORKSPACE ───────────────────────────────────────────── */
.workspace {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── LEFT EDITOR PANEL ────────────────────────────────────────── */
.editor-panel {
    width: 500px;
    min-width: 390px;
    max-width: 52vw;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.panel-header {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: rgba(15, 23, 42, 0.7);
}
.panel-title {
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--c1);
    display: flex;
    align-items: center;
    gap: 7px;
}
.panel-hdr-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: #cbd5e1;
    padding: 4px 8px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.icon-btn:hover { color: #fff; border-color: var(--c1); }
.icon-btn.active { background: rgba(56, 189, 248, 0.2); border-color: var(--c1); color: var(--c1); }

/* Code Editor with Synced Highlight & Line Numbers */
.editor-wrap {
    flex: 1;
    min-height: 180px;
    display: flex;
    position: relative;
    overflow: hidden;
    background: #070c1a;
}

.line-numbers {
    width: 40px;
    padding: 12px 6px 12px 4px;
    background: rgba(10, 15, 32, 0.9);
    border-right: 1px solid rgba(148, 163, 184, 0.1);
    color: #475569;
    font-family: 'Fira Code', monospace;
    font-size: 12.5px;
    line-height: 1.55;
    white-space: pre;
    text-align: right;
    overflow: hidden;
    user-select: none;
    flex-shrink: 0;
}

.code-layer-box {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.code-textarea, .code-highlight {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 12px 14px;
    font-family: 'Fira Code', monospace;
    font-size: 12.5px;
    line-height: 1.55;
    white-space: pre;
    word-wrap: normal;
    tab-size: 2;
    border: none;
    outline: none;
    margin: 0;
}

.code-highlight {
    pointer-events: none;
    overflow: hidden;
    color: #e2e8f0;
    z-index: 1;
}

.code-textarea {
    background: transparent;
    color: transparent;
    caret-color: #38bdf8;
    resize: none;
    overflow: auto;
    z-index: 2;
}
.code-textarea::selection { background: rgba(56, 189, 248, 0.28); }

/* Fast O(N) Syntax Highlight Tokens */
.tok-kw  { color: #c084fc; font-weight: 600; }
.tok-api { color: #38bdf8; font-weight: 600; }
.tok-str { color: #34d399; }
.tok-num { color: #fbbf24; }
.tok-cmt { color: #64748b; font-style: italic; }

/* Action Bar (ZERO CLIPPING — Compact Wrap-Safe Flex!) */
.actions-bar {
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.85);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.act-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: #e2e8f0;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.74rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.18s;
    white-space: nowrap;
}
.act-btn:hover { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.26); }
.act-btn.primary {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.35);
}
.act-btn.primary:hover { filter: brightness(1.12); }

/* ── BOTTOM DRAWER (Console, History, Toolbox, Projects) ──────── */
.bottom-drawer {
    height: 232px;
    min-height: 170px;
    display: flex;
    flex-direction: column;
    background: #080d1c;
    flex-shrink: 0;
}

.drawer-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    background: rgba(15, 23, 42, 0.85);
    border-bottom: 1px solid var(--border);
}
.dtab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.dtab-btn:hover { color: #e2e8f0; }
.dtab-btn.active {
    background: rgba(56, 189, 248, 0.16);
    border-color: rgba(56, 189, 248, 0.4);
    color: var(--c1);
}

.drawer-pane {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}
.drawer-pane.active { display: flex; }

/* Console Logs + REPL */
.console-logs {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
    font-family: 'Fira Code', monospace;
    font-size: 11.5px;
    line-height: 1.45;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.log-line { color: #cbd5e1; word-break: break-word; }
.log-line.ok { color: #34d399; }
.log-line.err { color: #f87171; }
.log-line.repl { color: #38bdf8; }

.repl-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-top: 1px solid var(--border);
    background: rgba(10, 15, 32, 0.9);
}
.repl-bar input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #f8fafc;
    font-family: 'Fira Code', monospace;
    font-size: 11.5px;
}

/* Toolbox / History / Projects Lists */
.drawer-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.toolbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}
.tb-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 9px;
    cursor: pointer;
    text-align: left;
    color: #e2e8f0;
    transition: all 0.16s;
}
.tb-card:hover { background: rgba(56, 189, 248, 0.12); border-color: var(--c1); }
.tb-card strong { display: block; font-size: 0.72rem; color: var(--c1); margin-bottom: 2px; }
.tb-card span { display: block; font-size: 0.64rem; color: var(--muted); }

.proj-bar {
    display: flex;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}
.proj-bar input {
    flex: 1;
    min-width: 0;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    color: #fff;
    font-size: 0.74rem;
    outline: none;
}
.proj-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 8px;
    font-size: 0.74rem;
}

/* ── RIGHT 3D VIEWPORT ────────────────────────────────────────── */
.viewport-panel {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #0b1122;
}
#viewport-3d {
    width: 100%;
    height: 100%;
}
#html-preview-frame {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    z-index: 8;
}

/* Floating Right Inspector (Scrollable — NEVER collides with bottom bar!) */
.viewport-hud {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 248px;
    max-height: calc(100% - 84px);
    overflow-y: auto;
    z-index: 12;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hud-card {
    background: rgba(10, 16, 34, 0.86);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.42);
}
.hud-card h4 {
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--c1);
}
.hud-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.74rem;
    color: #cbd5e1;
}
.hud-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--c1); cursor: pointer; }
.hud-row input[type="color"] { width: 32px; height: 22px; border: none; background: none; cursor: pointer; }
.hud-select {
    width: 100%;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border);
    color: #f8fafc;
    border-radius: 7px;
    padding: 5px 8px;
    font-size: 0.74rem;
    outline: none;
}

/* Bottom Viewport Export Dock */
.export-dock {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 9px;
    background: rgba(10, 16, 34, 0.88);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
    max-width: calc(100% - 24px);
    flex-wrap: nowrap;
    justify-content: center;
}
.dock-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: #e2e8f0;
    padding: 6px 9px;
    border-radius: 9px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.18s;
    white-space: nowrap;
}
.dock-btn:hover { background: rgba(56, 189, 248, 0.18); border-color: var(--c1); color: #fff; }
.dock-btn.ar { background: linear-gradient(135deg, #06b6d4, #8b5cf6); border-color: transparent; color: #fff; }
.dock-btn.rec.recording { background: rgba(239, 68, 68, 0.3); border-color: #ef4444; color: #fff; animation: pulseRed 1s infinite; }
@keyframes pulseRed { 0%,100% { box-shadow: 0 0 6px rgba(239,68,68,0.5); } 50% { box-shadow: 0 0 18px rgba(239,68,68,0.95); } }

/* ── MODALS (Gallery, Export Suite, Draw 3D Sketcher, HTML Fullscreen) ── */
.modal-bg {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(4, 8, 20, 0.8);
    backdrop-filter: blur(10px);
    align-items: center;
    justify-content: center;
    padding: 18px;
}
.modal-bg.open { display: flex; }

.modal-card {
    width: 100%;
    max-width: 780px;
    max-height: 90vh;
    overflow-y: auto;
    background: rgba(11, 17, 36, 0.97);
    border: 1px solid rgba(56, 189, 248, 0.34);
    border-radius: 18px;
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.72);
}
.modal-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}
.modal-hdr h3 { font-size: 1rem; font-weight: 800; display: flex; align-items: center; gap: 8px; color: #fff; }
.modal-x {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border);
    color: #cbd5e1;
    width: 30px; height: 30px;
    border-radius: 8px;
    cursor: pointer;
}
.modal-x:hover { background: rgba(239, 68, 68, 0.25); color: #fff; }

.tpl-cats { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl-cat-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 0.74rem;
    font-weight: 700;
    cursor: pointer;
}
.tpl-cat-btn.active, .tpl-cat-btn:hover { background: var(--c1); color: #04131c; border-color: var(--c1); }

.tpl-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.tpl-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    text-align: left;
    color: #f8fafc;
    display: flex;
    align-items: flex-start;
    gap: 11px;
    transition: all 0.18s;
}
.tpl-card:hover { background: rgba(56, 189, 248, 0.12); border-color: var(--c1); transform: translateY(-1px); }
.tpl-icon { font-size: 1.45rem; line-height: 1; flex-shrink: 0; }
.tpl-card h4 { font-size: 0.84rem; font-weight: 800; margin-bottom: 3px; }
.tpl-card p { font-size: 0.7rem; color: var(--muted); line-height: 1.35; }

.exp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.exp-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 11px;
    text-align: left;
    color: #f8fafc;
    transition: all 0.18s;
}
.exp-card:hover { background: rgba(56, 189, 248, 0.12); border-color: var(--c1); }
.exp-card.featured { background: linear-gradient(135deg, rgba(6, 182, 212, 0.15), rgba(139, 92, 246, 0.16)); border-color: rgba(139, 92, 246, 0.55); }
.exp-ic { width: 36px; height: 36px; border-radius: 9px; background: rgba(255, 255, 255, 0.08); display: flex; align-items: center; justify-content: center; font-size: 1rem; color: var(--c1); flex-shrink: 0; }
.exp-card h4 { font-size: 0.82rem; font-weight: 800; margin-bottom: 2px; }
.exp-card p { font-size: 0.68rem; color: var(--muted); }

/* Toast */
#toast {
    position: fixed;
    bottom: 76px;
    left: 50%;
    transform: translateX(-50%) translateY(14px);
    background: rgba(10, 18, 40, 0.95);
    border: 1px solid var(--c1);
    color: var(--c1);
    padding: 8px 18px;
    border-radius: 22px;
    font-size: 0.78rem;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: all 0.28s ease;
    z-index: 1200;
    white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(56, 189, 248, 0.35); border-radius: 4px; }
