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

/* ── EXPORT SIZE MODAL ────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(10, 4, 24, 0.75);
    backdrop-filter: blur(4px);
    align-items: center; justify-content: center;
}
.modal-overlay.visible { display: flex; }

.modal-box {
    background: linear-gradient(145deg, #2a1050, #1a0a2e);
    border: 1px solid rgba(255, 107, 0, 0.35);
    border-radius: 14px;
    padding: 28px 32px;
    min-width: 320px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    display: flex; flex-direction: column; gap: 20px;
}

.modal-title {
    font-size: 15px; font-weight: 700;
    color: var(--text-light);
    border-bottom: 1px solid rgba(255,107,0,0.2);
    padding-bottom: 12px;
}

.modal-sizes {
    display: flex; flex-direction: column; gap: 8px;
}

.size-btn {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,107,0,0.18);
    border-radius: 8px;
    color: var(--text-light);
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.size-btn:hover {
    background: rgba(255,107,0,0.18);
    border-color: var(--orange);
    transform: translateX(3px);
}
.size-btn:active { transform: translateX(0); }

.size-tag {
    font-size: 10px; font-weight: 700;
    background: linear-gradient(90deg, var(--orange), var(--orange-dark));
    color: #fff;
    padding: 2px 7px; border-radius: 4px;
    letter-spacing: 0.5px;
}

.modal-actions {
    display: flex; justify-content: flex-end; gap: 10px;
}

/* ── CONFIRM MODALS ───────────────────────────────────── */
.modal-box--confirm {
    min-width: 340px; max-width: 420px;
    align-items: center; text-align: center;
    gap: 16px;
}

.modal-confirm-icon {
    font-size: 42px;
    line-height: 1;
    filter: drop-shadow(0 0 12px rgba(255,107,0,0.5));
}

.modal-confirm-msg {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    padding: 0 8px;
}

.modal-box--confirm .modal-title {
    border-bottom: none;
    padding-bottom: 0;
    font-size: 16px;
}

.modal-box--confirm .modal-actions {
    justify-content: center;
    width: 100%;
}

.btn-danger {
    padding: 8px 20px;
    background: linear-gradient(135deg, #c0392b, #e74c3c);
    border: 1px solid rgba(231,76,60,0.5);
    border-radius: 7px;
    color: #fff;
    font-size: 12px; font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    letter-spacing: 0.3px;
}
.btn-danger:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-danger:active { transform: translateY(0); }

/* ── TOS MODAL ────────────────────────────────────────── */
.modal-box--tos {
    min-width: 520px; max-width: 720px;
    max-height: 80vh;
    display: flex; flex-direction: column;
    gap: 0;
}

.modal-tos-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-muted);
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

.modal-tos-body h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 12px 0;
}

.modal-tos-body h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 16px 0 6px 0;
}

.modal-tos-body p {
    margin: 0 0 8px 0;
}

.modal-tos-body strong {
    color: var(--text-main);
    font-weight: 600;
}

.modal-box--tos .modal-actions {
    padding-top: 14px;
    justify-content: center;
}

/* ── WORKSPACE TABS BAR ───────────────────────────────── */
.workspace-tabs-bar {
    display: flex; align-items: center;
    background: rgba(10, 4, 24, 0.6);
    border-bottom: 1px solid rgba(255,107,0,0.18);
    min-height: 34px;
    flex-shrink: 0;
    overflow: hidden;
}

.workspace-tabs {
    display: flex; align-items: stretch;
    overflow-x: auto; overflow-y: hidden;
    flex: 1; min-width: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,107,0,0.3) transparent;
}
.workspace-tabs::-webkit-scrollbar { height: 3px; }
.workspace-tabs::-webkit-scrollbar-thumb { background: rgba(255,107,0,0.3); border-radius: 2px; }

.ws-tab {
    display: flex; align-items: center; gap: 6px;
    padding: 0 10px 0 12px;
    min-width: 90px; max-width: 160px;
    height: 34px;
    font-size: 11px; font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none; border-right: 1px solid rgba(255,107,0,0.1);
    cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    position: relative;
}
.ws-tab:hover { background: rgba(255,107,0,0.08); color: var(--text-light); }
.ws-tab.active {
    background: rgba(255,107,0,0.15);
    color: var(--orange-light);
    border-bottom: 2px solid var(--orange);
}

.ws-tab-label {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ws-tab-close {
    display: flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; flex-shrink: 0;
    border-radius: 3px;
    font-size: 11px; line-height: 1;
    color: var(--text-dim);
    background: transparent; border: none; cursor: pointer;
    transition: background 0.12s, color 0.12s;
    padding: 0;
}
.ws-tab-close:hover { background: rgba(255,80,80,0.25); color: #ff6b6b; }

.ws-new-tab-btn {
    flex-shrink: 0;
    padding: 0 12px;
    height: 34px;
    font-size: 11px; font-weight: 700;
    color: var(--orange-light);
    background: transparent; border: none;
    border-left: 1px solid rgba(255,107,0,0.18);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.ws-new-tab-btn:hover { background: rgba(255,107,0,0.12); }

/* ── AI CLEAR CHAT BUTTON ─────────────────────────────── */
.ai-clear {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dim); font-size: 14px; padding: 2px 6px;
    border-radius: 4px; transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
}
.ai-clear:hover { background: rgba(255,80,80,0.2); color: #ff6b6b; }

:root {
    --orange:        #ff6b00;
    --orange-light:  #ff8c00;
    --orange-dark:   #cc5500;
    --purple:        #6a0dad;
    --purple-light:  #9b30d0;
    --purple-dark:   #450a7d;
    --bg-dark:       #1a0a2e;
    --bg-surface:    rgba(42, 16, 80, 0.45);
    --bg-editor:     rgba(255, 255, 255, 0.04);
    --text-main:     #ffffff;
    --text-light:    #f0e6ff;
    --text-muted:    #c4a8e8;
    --text-dim:      rgba(196, 168, 232, 0.5);
    --accent:        #ff8c00;
    --border:        rgba(255, 107, 0, 0.12);
    --border-light:  rgba(255, 255, 255, 0.06);
    --error-color:   #ff6b6b;
    --header-h:      52px;
    --status-h:      28px;
    --font-mono:     'Cascadia Code', 'Fira Code', 'Consolas', 'Courier New', monospace;
}

html, body {
    height: 100vh; height: 100dvh; width: 100vw; overflow: hidden;
    display: flex; flex-direction: column;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-dark);
    color: var(--text-light);
}

/* ── HEADER ───────────────────────────────────────────── */
.header {
    height: var(--header-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 12px;
    background: linear-gradient(90deg, var(--purple-dark) 0%, var(--purple) 50%, var(--orange-dark) 100%);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 8px;
}

.header-left {
    display: flex; align-items: center; gap: 10px; min-width: 0;
}

.app-icon-wrap {
    width: 44px; height: 44px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--orange), var(--orange-dark));
    border-radius: 8px;
}

.app-icon {
    width: 28px; height: 28px;
    display: block;
    object-fit: contain;
}

.brand {
    font-size: 14px; font-weight: 700; letter-spacing: 0.5px;
    color: #fff; text-decoration: none;
    display: flex; align-items: center; gap: 3px;
    white-space: nowrap;
}
.brand span { color: var(--orange-light); }
.brand small {
    font-weight: 400; font-size: 10px;
    color: rgba(255,255,255,0.5); letter-spacing: 1px;
    margin-left: 2px;
}

.lang-switcher {
    display: flex; gap: 3px; flex-shrink: 0;
}

.lang-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 4px;
    color: var(--text-light);
    padding: 2px 6px;
    font-size: 10px; font-weight: 600;
    text-decoration: none;
    transition: background 0.15s;
    white-space: nowrap; line-height: 1.5;
}
.lang-btn:hover { background: rgba(255,107,0,0.3); }
.lang-btn.lang-active {
    background: linear-gradient(90deg, var(--orange), var(--orange-dark));
    border-color: var(--orange);
    color: #fff;
}

.header-actions { display: flex; align-items: center; gap: 6px; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 14px; border-radius: 6px;
    font-size: 12px; font-weight: 600;
    cursor: pointer; border: none;
    transition: filter 0.15s, transform 0.1s;
    white-space: nowrap; line-height: 1.4;
}
.btn:hover  { filter: brightness(1.15); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(90deg, var(--orange), var(--orange-dark));
    color: #fff;
}
.btn-ghost {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-light);
}

/* ── MAIN LAYOUT ──────────────────────────────────────── */
.app-main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── FILE EXPLORER ──────────────────────────────────── */
.panel-explorer {
    width: 210px; flex-shrink: 0;
    display: flex; flex-direction: column;
    border-right: 1px solid var(--border-light);
    background: rgba(0,0,0,0.18);
    overflow: hidden;
}
.explorer-header {
    padding: 5px 12px;
    font-size: 10px; font-weight: 600;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.explorer-tree {
    flex: 1; overflow-y: auto;
    padding: 4px 0;
}
.explorer-folder {
    padding: 2px 12px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: default;
    display: flex; align-items: center; gap: 4px;
}
.folder-icon { font-size: 11px; }
.file-item {
    padding: 2px 12px 2px 28px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex; align-items: center; gap: 5px;
    white-space: nowrap;
}
.file-item:hover { background: rgba(255,255,255,0.04); color: var(--text-light); }
.file-item.active { background: rgba(255,107,0,0.1); color: var(--text-light); }
.file-icon { font-size: 11px; flex-shrink: 0; }

/* ── TABBED EDITOR ──────────────────────────────────── */
.panel-editor {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.editor-tabs {
    display: flex; flex-shrink: 0;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--border-light);
    overflow-x: auto;
}
.tab {
    padding: 4px 14px;
    font-size: 11px;
    color: var(--text-dim);
    cursor: pointer;
    border-right: 1px solid var(--border-light);
    white-space: nowrap;
    user-select: none;
}
.tab:hover { color: var(--text-light); background: rgba(255,255,255,0.03); }
.tab.active {
    color: var(--text-light);
    background: rgba(255,255,255,0.06);
    border-bottom: 2px solid var(--orange);
}
.tab-err { color: var(--error-color); font-size: 10px; margin-left: 4px; }

.editor-textarea {
    flex: 1; min-height: 0;
    width: 100%; resize: none;
    background: var(--bg-editor);
    border: none; outline: none;
    color: var(--text-light);
    font-family: var(--font-mono);
    font-size: 12px; line-height: 1.55;
    padding: 8px 12px;
    tab-size: 2;
}
.editor-textarea:focus { background: rgba(255,255,255,0.055); }

.editor-error {
    display: none;
    padding: 2px 12px;
    font-size: 10px; line-height: 1.4;
    color: var(--error-color);
    background: rgba(255,107,107,0.08);
    border-top: 1px solid rgba(255,107,107,0.15);
    flex-shrink: 0; min-height: 0;
    max-height: 36px; overflow-y: auto;
}
.editor-error.has-errors { display: block; }

/* ── RIGHT COLUMN (preview + info) ───────────────────── */
.panel-preview {
    width: 672px; flex-shrink: 0;
    display: flex; flex-direction: column;
    align-items: center; overflow: hidden;
    padding: 16px; gap: 12px;
}

.canvas-wrap {
    flex-shrink: 0;
    width: 640px; height: 360px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    overflow: hidden;
    background: rgba(255,255,255,0.02);
    display: flex; align-items: center; justify-content: center;
}
.canvas-wrap canvas {
    display: block;
    width: 640px; height: 360px;
    image-rendering: auto;
}

.info-grid {
    width: 640px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    flex-shrink: 0;
}

.info-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 8px 12px;
    text-align: center;
    backdrop-filter: blur(2px);
}
.info-card .val {
    font-size: 14px; font-weight: 700;
    color: var(--orange-light);
    font-family: var(--font-mono);
}
.info-card .lbl {
    font-size: 9px; text-transform: uppercase;
    letter-spacing: 0.6px; color: var(--text-dim);
    margin-top: 1px;
}

/* ── STATUS BAR ──────────────────────────────────────── */
.status-bar {
    height: var(--status-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    background: rgba(0,0,0,0.35);
    border-top: 1px solid var(--border-light);
    font-size: 11px; color: var(--text-muted);
    flex-shrink: 0;
}
.status-bar .err-count {
    display: inline-flex; align-items: center; gap: 4px;
}
.status-bar .err-count.has-errors { color: var(--error-color); font-weight: 600; }
.status-bar .ok-indicator { color: #4caf92; }
.status-bar .file-indicator {
    font-size: 10px; color: var(--text-dim);
    font-family: var(--font-mono);
    margin: 0 auto;
}

/* ── TERMINAL ──────────────────────────────────────────── */
.terminal {
    flex-shrink: 0;
    max-height: 0;
    overflow: hidden;
    background: rgba(0,0,0,0.55);
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    transition: max-height 0.2s ease;
}
.terminal.visible { max-height: 140px; }

.terminal-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 12px;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.terminal-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
}
.terminal-info {
    font-size: 10px;
    color: var(--error-color);
    font-weight: 600;
    margin-left: auto;
}
.terminal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    line-height: 1;
}
.terminal-close:hover { color: var(--text-light); }

.terminal-body {
    flex: 1;
    padding: 5px 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    color: var(--error-color);
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 0;
}

/* status bar terminal toggle */
.terminal-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 3px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 1px 6px;
    line-height: 1.4;
    margin-left: auto;
}
.terminal-btn:hover {
    color: var(--text-light);
    background: rgba(255,255,255,0.1);
}

/* ── AI PANEL ──────────────────────────────────────────── */
.btn-ai {
    background: linear-gradient(90deg, var(--purple-light), var(--orange));
    color: #fff;
    border: none;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 14px; border-radius: 6px;
    font-size: 12px; font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s, transform 0.1s;
    white-space: nowrap; line-height: 1.4;
}
.btn-ai:hover  { filter: brightness(1.15); transform: translateY(-1px); }
.btn-ai:active { transform: translateY(0); }
.btn-ai:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ai-panel {
    flex-shrink: 0;
    max-height: 0;
    overflow: hidden;
    background: rgba(20, 8, 40, 0.95);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: max-height 0.2s ease;
}
.ai-panel.visible { max-height: 280px; }

.ai-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 12px;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.ai-label {
    font-size: 10px; font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    white-space: nowrap;
}
.ai-key-row {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    max-width: 320px;
}
.ai-key-input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-light);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 8px;
    outline: none;
    min-width: 0;
    -webkit-text-security: disc;
}
.ai-key-input:focus { border-color: var(--purple-light); }
.ai-key-input::placeholder { color: var(--text-dim); font-family: sans-serif; }

.ai-save-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 1px 6px;
    line-height: 1.4;
}
.ai-save-btn:hover { color: var(--text-light); background: rgba(255,255,255,0.12); }

.ai-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    line-height: 1;
}
.ai-close:hover { color: var(--text-light); }

.ai-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 8px 12px 6px;
    gap: 6px;
}

.ai-chat {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    padding: 4px 0;
}

.ai-msg {
    font-size: 11px;
    line-height: 1.5;
    padding: 4px 8px;
    border-radius: 4px;
    max-width: 95%;
    word-wrap: break-word;
}
.ai-msg.ai-system {
    color: var(--text-muted);
    font-style: italic;
    background: rgba(255,255,255,0.03);
}
.ai-msg.ai-error {
    color: var(--error-color);
    background: rgba(255,107,107,0.08);
    border-left: 2px solid var(--error-color);
}
.ai-msg.ai-user {
    color: var(--text-light);
    background: rgba(106, 13, 173, 0.2);
    border-left: 2px solid var(--purple-light);
    align-self: flex-end;
}
.ai-msg.ai-assistant {
    color: var(--text-light);
    background: rgba(255, 107, 0, 0.08);
    border-left: 2px solid var(--orange);
}
.ai-msg.ai-loading {
    color: var(--text-dim);
    font-style: italic;
    background: rgba(255,255,255,0.02);
}

.ai-msg summary {
    cursor: pointer;
    font-size: 10px;
    color: var(--text-dim);
    margin-bottom: 2px;
}
.ai-msg details pre {
    margin-top: 4px;
}

.ai-code {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-light);
    border-radius: 3px;
    padding: 4px 6px;
    font-family: var(--font-mono);
    font-size: 10px;
    line-height: 1.4;
    color: var(--text-light);
    max-height: 120px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 4px 0;
}

.ai-ai-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ai-ai-content .btn-apply {
    font-size: 10px;
    padding: 2px 10px;
    background: linear-gradient(90deg, var(--orange), var(--orange-dark));
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-weight: 600;
}
.ai-ai-content .btn-apply:hover { filter: brightness(1.15); }

.ai-controls {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.ai-target, .ai-model {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-light);
    font-size: 11px;
    padding: 3px 6px;
    outline: none;
    cursor: pointer;
}
.ai-target:focus, .ai-model:focus { border-color: var(--purple-light); }
.ai-target option, .ai-model option { background: #1a0a2e; color: var(--text-light); }

.ai-input-row {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.ai-prompt {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-light);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 4px 8px;
    outline: none;
    resize: vertical;
    min-height: 28px;
    max-height: 60px;
}
.ai-prompt:focus { border-color: var(--purple-light); }
.ai-prompt::placeholder { color: var(--text-dim); font-family: sans-serif; }

.ai-dot-pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--orange-light);
    animation: aiPulse 0.8s ease-in-out infinite alternate;
    margin-right: 4px;
    vertical-align: middle;
}
@keyframes aiPulse {
    0% { opacity: 0.3; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1.2); }
}

/* ── SCROLLBAR ────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ── EXPLORER TOGGLE (mobile) ──────────────────────────── */
.explorer-toggle {
    display: none;
    align-items: center; justify-content: center;
    width: 32px; height: 32px; flex-shrink: 0;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #fff;
    font-size: 18px; line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
}
.explorer-toggle:hover { background: rgba(255,107,0,0.3); }

.explorer-overlay {
    display: none;
}

/* ── RESPONSIVE / MOBILE ────────────────────────────────── */

/* Small desktop / tablet landscape */
@media (max-width: 1100px) {
    .panel-explorer {
        width: 180px;
    }
    .panel-preview {
        width: calc(100vw - 420px);
        min-width: 300px;
        padding: 12px;
    }
    .canvas-wrap {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
    }
    .canvas-wrap canvas {
        width: 100%;
        height: auto;
    }
    .info-grid {
        width: 100%;
    }
}

/* Tablet portrait */
@media (max-width: 820px) {
    .panel-explorer {
        width: 160px;
    }
    .panel-preview {
        width: 100%;
        padding: 10px;
    }
    .app-main {
        flex-wrap: wrap;
    }
    .panel-editor {
        min-width: 100%;
        order: -1;
    }
    .header {
        padding: 0 8px;
        gap: 4px;
    }
    .header-actions {
        gap: 3px;
    }
    .btn {
        padding: 4px 10px;
        font-size: 11px;
    }
    .btn-ai {
        padding: 4px 10px;
        font-size: 11px;
    }
    .brand small {
        display: none;
    }
    .info-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .modal-box {
        min-width: unset;
        width: 85%;
    }
    .modal-box--tos {
        min-width: unset;
        width: 85%;
    }
    .modal-box--confirm {
        min-width: unset;
        width: 85%;
    }
}

/* Mobile */
@media (max-width: 640px) {
    .explorer-toggle {
        display: flex;
    }

    .panel-explorer {
        position: fixed;
        top: var(--header-h);
        left: 0;
        width: 240px;
        height: calc(100vh - var(--header-h) - var(--status-h));
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        background: rgba(26, 10, 46, 0.98);
        backdrop-filter: blur(8px);
        border-right: 1px solid var(--border);
    }
    .panel-explorer.open {
        transform: translateX(0);
    }

    .panel-preview {
        width: 100%;
        padding: 8px;
        gap: 8px;
    }
    .canvas-wrap {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
    }
    .canvas-wrap canvas {
        width: 100%;
        height: auto;
    }
    .info-grid {
        width: 100%;
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }
    .info-card {
        padding: 4px 8px;
    }
    .info-card .val {
        font-size: 12px;
    }
    .info-card .lbl {
        font-size: 8px;
    }

    .header {
        height: auto;
        min-height: var(--header-h);
        flex-wrap: wrap;
        padding: 4px 6px;
        gap: 2px;
    }
    .header-actions .btn {
        padding: 3px 6px;
        font-size: 10px;
    }
    .btn-ai {
        padding: 3px 6px;
        font-size: 10px;
    }
    .brand {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        font-size: 13px;
        line-height: 1.3;
        gap: 0;
    }
    .brand small {
        display: inline;
        font-size: 10px;
    }
    .lang-btn {
        font-size: 9px;
        padding: 1px 4px;
    }
    .app-icon-wrap {
        width: 32px;
        height: 32px;
    }
    .app-icon {
        width: 20px;
        height: 20px;
    }

    .header-left {
        flex: 1;
        flex-wrap: wrap;
        gap: 1px 4px;
    }
    .header-left .lang-switcher {
        width: 100%;
        margin-left: 0;
    }
    .header-actions {
        gap: 2px;
    }

    .modal-box {
        min-width: unset;
        width: 92%;
        padding: 14px 16px;
    }
    .modal-box--tos {
        min-width: unset;
        width: 92%;
        max-height: 85vh;
    }
    .modal-box--confirm {
        min-width: unset;
        width: 85%;
    }
    .modal-sizes {
        gap: 6px;
    }
    .size-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .workspace-tabs-bar {
        min-height: 28px;
    }
    .ws-tab {
        height: 28px;
        font-size: 10px;
        min-width: 60px;
        max-width: 110px;
        padding: 0 6px;
    }
    .ws-new-tab-btn {
        height: 28px;
        font-size: 10px;
        padding: 0 8px;
    }

    .editor-textarea {
        font-size: 11px;
        padding: 6px 8px;
    }
    .editor-tabs {
        overflow-x: auto;
    }
    .tab {
        font-size: 10px;
        padding: 3px 8px;
    }

    .ai-panel.visible {
        max-height: 60vh;
    }
    .ai-key-row {
        max-width: 100%;
    }
    .ai-bar {
        flex-wrap: wrap;
        gap: 4px;
        padding: 3px 8px;
    }
    .ai-body {
        padding: 6px 8px 4px;
    }
    .ai-controls {
        flex-wrap: wrap;
    }
    .ai-input-row {
        gap: 4px;
    }
    .ai-prompt {
        font-size: 10px;
        min-height: 24px;
        max-height: 48px;
    }

    .terminal.visible {
        max-height: 100px;
    }
    .terminal-body {
        font-size: 10px;
        padding: 4px 8px;
    }
    .status-bar {
        padding: 0 8px;
        font-size: 10px;
    }
    .status-bar .file-indicator {
        font-size: 9px;
    }

    .explorer-overlay {
        position: fixed;
        inset: 0;
        z-index: 99;
        background: rgba(0,0,0,0.4);
    }
    .explorer-overlay.visible {
        display: block;
    }

    body.noscroll {
        overflow: hidden;
    }
}

/* ── VERY SMALL PHONES (3–5", ≤480px) ───────────────────── */
@media (max-width: 480px) {
    .header {
        padding: 3px 4px;
        gap: 2px;
    }
    .header-left {
        flex: 1 1 100%;
        flex-wrap: wrap;
        gap: 2px;
        min-width: 0;
    }
    .app-icon-wrap {
        width: 26px;
        height: 26px;
    }
    .app-icon {
        width: 16px;
        height: 16px;
    }
    .brand {
        flex: 0 1 auto;
        flex-direction: row;
        font-size: 11px;
        gap: 2px;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .brand small {
        display: none;
    }
    .brand span {
        font-size: 11px;
    }
    .explorer-toggle {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
    .lang-switcher {
        gap: 2px;
    }
    .lang-btn {
        font-size: 8px;
        padding: 1px 3px;
        line-height: 1.3;
    }
    .header-actions {
        flex: 1 1 100%;
        justify-content: flex-end;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 3px;
        padding-bottom: 2px;
    }
    .header-actions::-webkit-scrollbar {
        display: none;
    }
    .header-actions .btn {
        flex-shrink: 0;
        padding: 2px 5px;
        font-size: 9px;
        gap: 3px;
    }
    .btn-ai {
        padding: 2px 5px;
        font-size: 9px;
    }

    /* AI Panel: ensure clear + close always visible */
    .ai-bar {
        flex-wrap: nowrap;
        gap: 3px;
        padding: 2px 4px;
        overflow: hidden;
    }
    .ai-label {
        font-size: 9px;
        flex-shrink: 0;
    }
    .ai-key-row {
        flex: 0 1 auto;
        max-width: 40%;
        min-width: 0;
    }
    .ai-key-input {
        font-size: 8px;
        padding: 1px 4px;
        min-width: 30px;
    }
    .ai-key-input::placeholder {
        font-size: 8px;
    }
    .ai-save-btn {
        font-size: 10px;
        padding: 0 3px;
    }
    .ai-clear, .ai-close {
        flex-shrink: 0;
        font-size: 11px;
        padding: 2px 4px;
    }
    .ai-panel.visible {
        max-height: 75vh;
    }
    .ai-body {
        padding: 4px 6px 3px;
        gap: 4px;
    }
    .ai-chat {
        gap: 4px;
    }
    .ai-msg {
        font-size: 10px;
        padding: 3px 6px;
    }
    .ai-controls {
        flex-wrap: nowrap;
        gap: 3px;
    }
    .ai-target, .ai-model {
        font-size: 9px;
        padding: 2px 4px;
    }
    .ai-input-row {
        gap: 3px;
    }
    .ai-prompt {
        font-size: 9px;
        min-height: 20px;
        max-height: 36px;
        padding: 2px 6px;
    }
    .ai-code {
        font-size: 9px;
        max-height: 80px;
    }

    /* Terminal */
    .terminal.visible {
        max-height: 80px;
    }
    .terminal-body {
        font-size: 9px;
        padding: 3px 6px;
    }
    .terminal-bar {
        padding: 2px 8px;
    }

    /* Buttons in action bar — prevent overflow */
    .btn-tos {
        display: none;
    }

    /* Workspace tabs */
    .workspace-tabs-bar {
        min-height: 24px;
    }
    .ws-tab {
        height: 24px;
        font-size: 9px;
        min-width: 50px;
        max-width: 90px;
        padding: 0 4px;
    }
    .ws-new-tab-btn {
        height: 24px;
        font-size: 9px;
        padding: 0 6px;
    }

    /* Editor */
    .editor-textarea {
        font-size: 10px;
        padding: 4px 6px;
    }
    .tab {
        font-size: 9px;
        padding: 2px 6px;
    }

    /* Status bar */
    .status-bar {
        padding: 0 6px;
        font-size: 9px;
        height: 24px;
    }
    .status-bar .file-indicator {
        font-size: 8px;
    }

    /* Canvas / preview */
    .panel-preview {
        padding: 4px;
        gap: 4px;
    }
    .info-card {
        padding: 3px 6px;
    }
    .info-card .val {
        font-size: 10px;
    }
    .info-card .lbl {
        font-size: 7px;
    }
    .info-grid {
        gap: 3px;
    }

    /* Mobile sidebar */
    .panel-explorer {
        width: 200px;
        top: 42px;
        height: calc(100vh - 42px - 24px);
    }
    .explorer-header {
        font-size: 9px;
        padding: 3px 8px;
    }
    .file-item {
        font-size: 10px;
        padding: 2px 8px 2px 24px;
    }
    .modal-box {
        padding: 10px 12px;
    }
    .modal-title {
        font-size: 12px;
    }
    .size-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
}

/* ── TINY SCREENS (≤360px, very compact) ───────────────── */
@media (max-width: 360px) {
    .header-left .lang-switcher {
        display: none;
    }
    .btn-ghost.btn-tos {
        display: none;
    }
    .btn-ghost:not(.btn-tos) {
        padding: 2px 4px;
        font-size: 8px;
    }
    .header-actions .btn {
        padding: 2px 4px;
        font-size: 8px;
    }
    .btn-ai {
        padding: 2px 4px;
        font-size: 8px;
    }
    .brand {
        font-size: 10px;
    }
    .brand span {
        font-size: 10px;
    }
    .app-icon-wrap {
        width: 22px;
        height: 22px;
    }
    .app-icon {
        width: 14px;
        height: 14px;
    }
    .explorer-toggle {
        width: 22px;
        height: 22px;
        font-size: 12px;
    }

    .ai-key-row {
        max-width: 35%;
    }
    .ai-key-input::placeholder {
        font-size: 7px;
    }
}

/* ── iPHONE SE / small phones (≤390px) ──────────────────── */
@media (max-width: 390px) {
    .header {
        flex-wrap: wrap;
        height: auto;
        padding: 4px 6px;
        gap: 2px;
    }
    .header-left {
        width: 100%;
        flex-wrap: wrap;
        gap: 2px;
    }
    .brand {
        font-size: 12px;
        flex-direction: row;
        overflow: visible;
        text-overflow: clip;
        white-space: nowrap;
        flex: 0 1 auto;
        min-width: 0;
    }
    .brand small {
        display: inline;
        font-size: 10px;
    }
    .header-left .lang-switcher {
        width: 100%;
        justify-content: center;
        padding: 2px 0;
        gap: 4px;
    }
    .lang-btn {
        font-size: 9px;
        padding: 2px 5px;
    }
    .header-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        overflow: visible;
        gap: 4px;
        padding: 2px 0;
    }
    .header-actions .btn {
        flex-shrink: 0;
        padding: 3px 8px;
        font-size: 10px;
    }
    .btn-ai {
        padding: 3px 8px;
        font-size: 10px;
    }
    .btn-tos {
        display: none;
    }
}
