/* Canvas Area */
#editor-canvas { flex: 1; background: var(--bg-canvas); display: flex; flex-direction: column; position: relative; min-width: 0; }
#welcome-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: var(--start-page-bg, #1a1c1e);
    overflow-y: auto;
    overflow-x: hidden;
    padding: clamp(20px, 4vh, 40px) clamp(16px, 3vw, 32px);
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}
#welcome-screen::-webkit-scrollbar { width: 8px; }
#welcome-screen::-webkit-scrollbar-track { background: transparent; }
#welcome-screen::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
}
#welcome-screen::-webkit-scrollbar-thumb:hover { background: var(--accent); }
#welcome-screen.hidden { display: none; }

/* Start Mode — hide chrome around the canvas */
.start-mode #file-explorer { display: none; }
.start-mode #properties-sidebar { display: none; }
.start-mode #iframe-wrapper { display: none; }
.start-mode .top-bar-center { display: none; }
.start-mode .top-bar-right > *:not(#auth-container):not(.start-only-btn) { display: none; }

/* Start Screen */
#app.start-mode {
    --start-page-bg: #1a1c1e;
    --start-page-surface: #242729;
    --start-page-surface-hover: rgba(59, 130, 246, 0.05);
    --start-page-border: #333639;
    --start-page-border-strong: rgba(59, 130, 246, 0.5);
    --start-page-topbar-bg: rgba(26, 28, 30, 0.82);
    --start-page-topbar-border: #2a2d30;
    --start-page-title: #76A9FA;
    --start-page-subtitle:#e1e1e1;
    --start-page-text: #d1d5db;
    --start-page-muted: #9ca3af;
    --start-page-subtle: #6b7280;
    --start-page-accent: #3b82f6;
    --start-page-accent-strong: #2563eb;
    --start-page-button-secondary-bg: #2a2d30;
    --start-page-button-secondary-hover: #32363a;
    --start-page-button-secondary-border: #3f454b;
    --start-page-card-shadow: rgba(0, 0, 0, 0.28);
    --start-page-ai-shadow: rgba(15, 23, 42, 0.36);
}

html[data-theme="light"] #app.start-mode {
    --start-page-bg: #f5f7fb;
    --start-page-surface: #ffffff;
    --start-page-surface-hover: rgba(59, 130, 246, 0.08);
    --start-page-border: #d8e0ea;
    --start-page-border-strong: rgba(59, 130, 246, 0.42);
    --start-page-topbar-bg: rgba(245, 247, 251, 0.92);
    --start-page-topbar-border: #d7dee8;
    --start-page-title: #3b82f6;
    --start-page-subtitle: #76A9FA;
    --start-page-text: #334155;
    --start-page-muted: #64748b;
    --start-page-subtle: #64748b;
    --start-page-accent: #3b82f6;
    --start-page-accent-strong: #2563eb;
    --start-page-button-secondary-bg: #f8fafc;
    --start-page-button-secondary-hover: #eef2f7;
    --start-page-button-secondary-border: #d7dee8;
    --start-page-card-shadow: rgba(15, 23, 42, 0.08);
    --start-page-ai-shadow: rgba(37, 99, 235, 0.12);
}

#app.start-mode,
#app.start-mode button,
#app.start-mode input,
#app.start-mode select,
#app.start-mode textarea {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#app.start-mode,
#app.start-mode #main-content,
#app.start-mode #editor-canvas {
    background: var(--start-page-bg);
}

#app.start-mode #top-bar {
    position: relative;
    z-index: 30;
    background: var(--start-page-topbar-bg);
    border-bottom-color: var(--start-page-topbar-border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

#app.start-mode .logo {
    padding-left: 24px;
    padding-right: 24px;
}

.start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 48px;
    padding: 48px 8px 32px;
    max-width: 1320px;
    width: 100%;
    margin: auto;
}

.start-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    /* width: min(100%, 940px); */
}
.start-logo-icon { font-size: 40px; line-height: 1; }
.start-logo-name { display: block; width: min(100%, 450px); font-size: 26px; font-weight: 700; color: var(--text-main); letter-spacing: -0.5px; }
.start-logo-name svg { display: block; width: 100%; height: auto; }
.start-logo-name svg path { fill: var(--start-page-title); }
.start-logo-sub,
.start-logo-sub2 {
    max-width: 100%;
    text-align: center;
}
.start-logo-sub {
    max-width: 80vw;
    font-size: clamp(1rem, 4vw, 2rem);
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.04em;
    color: var(--start-page-subtitle);
}
.start-logo-sub2 {
    /* max-width: 880px; */
    font-size: clamp(0.7rem, 1.8vw, 1rem);
    line-height: 1.7;
    color: var(--start-page-muted);
}

.start-cards {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
}
.start-card {
    background: var(--start-page-surface);
    border: 1px solid var(--start-page-border);
    border-radius: 8px;
    padding: 28px 24px 24px;
    min-height: 268px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    transition:
        transform 0.18s ease,
        border-color 0.18s ease,
        background-color 0.18s ease,
        box-shadow 0.18s ease;
}
.start-card:hover {
    border-color: var(--start-page-accent);
    background: var(--start-page-surface-hover);
    transform: translateY(-2px);
    box-shadow: 0 16px 36px var(--start-page-card-shadow);
}
.start-card-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--start-page-accent);
    margin-bottom: 2px;
}
.start-card-icon svg {
    width: 32px;
    height: 32px;
}
.start-card h3 {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--start-page-title);
}
.start-card p {
    margin-bottom: 18px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.6;
    color: var(--start-page-muted);
    flex: 1;
}
.start-card .btn {
    width: 100%;
    margin-top: auto;
}
.start-card-button {
    min-height: 42px;
    /* border-radius: 12px; */
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    box-shadow: none;
}
.start-card-button-primary {
    background: var(--start-page-accent-strong);
    color: #fff;
    border: 1px solid transparent;
}
.start-card-button-primary:hover {
    background: var(--start-page-accent);
}
.start-card-button-secondary {
    background: var(--start-page-button-secondary-bg);
    border: 1px solid var(--start-page-button-secondary-border);
    color: var(--start-page-text);
}
.start-card-button-secondary:hover {
    background: var(--start-page-button-secondary-hover);
    border-color: var(--start-page-button-secondary-border);
}
.start-card-continue {
    border: 2px solid var(--start-page-border-strong);
    padding: 27px 23px 23px;
}
.start-card-continue:hover {
    border-color: var(--start-page-accent);
    box-shadow: 0 18px 38px var(--start-page-ai-shadow);
}
.start-card-continue .start-card-icon { color: var(--start-page-accent); }

@media (max-height: 900px), (max-width: 1100px) {
    #welcome-screen {
        align-items: flex-start;
    }

    .start-screen {
        gap: 34px;
        padding: 28px 8px 24px;
    }

    .start-logo {
        width: min(100%, 820px);
    }

    .start-cards {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 920px) {
    .start-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 700px), (max-height: 760px) {
    .start-screen {
        gap: 24px;
        padding: 18px 0 16px;
    }

    .start-logo {
        width: min(100%, 100%);
        gap: 10px;
    }

    .start-logo-sub,
    .start-logo-sub2 {
        width: 100%;
    }

    .start-cards {
        gap: 12px;
        grid-template-columns: minmax(0, 1fr);
    }

    .start-card {
        min-height: 0;
    }
}

#iframe-wrapper { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; position: relative; }
#iframe-wrapper.hidden { display: none; }

#iframe-wrapper:fullscreen,
#iframe-wrapper:-webkit-full-screen {
    width: 100%;
    height: 100%;
    background: var(--bg-canvas);
}

#iframe-wrapper:fullscreen #iframe-container-outer,
#iframe-wrapper:-webkit-full-screen #iframe-container-outer {
    padding: 0;
    background-image: none;
}

#iframe-wrapper:fullscreen #resizable-iframe-container,
#iframe-wrapper:-webkit-full-screen #resizable-iframe-container {
    width: 100% !important;
    max-width: none;
    height: 100%;
    box-shadow: none;
}

#iframe-wrapper:fullscreen .resize-handle,
#iframe-wrapper:-webkit-full-screen .resize-handle {
    display: none;
}

.canvas-toolbar { height: 36px; background: var(--bg-panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 10px; justify-content: flex-end; color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 14px; opacity: 0.7; }
.btn-icon:hover { opacity: 1; }
.btn-icon.active { opacity: 1; color: var(--accent); }
.btn-icon.active svg { fill: var(--accent); }
.separator { margin: 0 8px; opacity: 0.3; }

.pad-x-10 { padding-left: 10px; padding-right: 10px;}

#iframe-container-outer {
    flex: 1; display: flex; justify-content: center; align-items: center;
    padding: 0px 10px; background-image: radial-gradient(var(--sidebar-header-bg) 1px, transparent 1px);
    background-size: 20px 20px; overflow: hidden;
}

#resizable-iframe-container {
    width: 100%; height: 100%; position: relative; background: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); max-width: 100%; box-sizing: border-box;
}

#preview-iframe { width: 100%; height: 100%; border: none; background: white; display: block; }

.iframe-empty-state {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.98));
}

.iframe-empty-state.hidden {
    display: none;
}

.iframe-empty-state-card {
    max-width: 360px;
    padding: 18px 22px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
    text-align: center;
}

.iframe-empty-state-card p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
}

.resize-handle {
    position: absolute; top: 0; bottom: 0; width: 14px; height: 100%;
    background: transparent; border-left: 1px solid transparent; border-right: 1px solid transparent;
    cursor: col-resize; display: flex; align-items: center; justify-content: center; z-index: 50;
    transition: background 0.2s, border-color 0.2s;
}

.resize-handle:hover { background: rgba(0, 122, 204, 0.1); border-color: rgba(0, 122, 204, 0.3); }
.resize-handle::after {
    content: '||'; color: #888; font-size: 10px; letter-spacing: 1px; font-weight: bold;
    background: var(--bg-panel); padding: 4px 2px; border-radius: 2px; border: 1px solid var(--border);
}
.resize-handle:hover::after { color: white; background: var(--accent); border-color: var(--accent); }
.handle-left { left: -14px; }
.handle-right { right: -14px; }

#iframe-drag-overlay { position: absolute; inset: 0; z-index: 40; display: none; cursor: copy; }
#resizable-iframe-container.is-resizing #iframe-drag-overlay { display: block; cursor: col-resize; }
#iframe-drag-overlay.block-drag-active { display: block; }

/* Element move handle */
#element-move-handle {
    position: absolute;
    width: 22px;
    height: 22px;
    background: var(--accent);
    color: white;
    border-radius: 3px;
    cursor: grab;
    z-index: 45;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: opacity 0.15s;
}
#element-move-handle:hover { opacity: 0.85; }
#element-move-handle:active { cursor: grabbing; }
#element-move-handle.visible { display: flex; }

#element-tag-badge {
    position: absolute;
    display: none;
    z-index: 46;
}
#element-tag-badge.visible { display: block; }
#element-tag-trigger {
    height: 22px;
    min-width: 42px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    border-radius: 3px;
    font-size: 12px;
    line-height: 1;
    font-weight: 600;
    text-transform: lowercase;
    padding: 0 8px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#element-tag-trigger:hover { opacity: 0.9; }

#element-tag-menu {
    position: absolute;
    left: 0;
    bottom: calc(100% + 4px);
    min-width: 220px;
    max-width: min(340px, calc(100vw - 24px));
    max-height: 260px;
    overflow-y: auto;
    overflow-x: hidden;
    display: none;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
    padding: 6px;
}
#element-tag-badge.open #element-tag-menu { display: block; }
#element-tag-badge.drop-down #element-tag-menu {
    bottom: auto;
    top: calc(100% + 4px);
}
#element-tag-menu.floating {
    position: fixed;
    bottom: auto;
    z-index: 58;
}
#element-tag-menu::-webkit-scrollbar,
.element-tag-row-actions::-webkit-scrollbar {
    width: 8px;
    background: transparent;
}
#element-tag-menu::-webkit-scrollbar-track,
.element-tag-row-actions::-webkit-scrollbar-track {
    background: transparent;
}
#element-tag-menu::-webkit-scrollbar-thumb,
.element-tag-row-actions::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
}
#element-tag-menu::-webkit-scrollbar-thumb:hover,
.element-tag-row-actions::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}
#element-tag-menu,
.element-tag-row-actions {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.element-tag-menu-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
}

.element-tag-tree-node {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.element-tag-tree-children {
    margin-left: 8px;
    padding-left: 10px;
    border-left: 1px solid rgba(0, 122, 204, 0.18);
}
.element-tag-tree-children.collapsed {
    display: none;
}

.element-tag-menu-item {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text-primary, var(--text-main));
    text-align: left;
    border-radius: 4px;
    cursor: pointer;
    padding: 6px 8px;
    font-size: 12px;
    text-transform: lowercase;
}
.element-tag-menu-item:hover {
    background: rgba(0, 122, 204, 0.14);
}

.element-tag-tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: none;
}

.element-tag-tree-branch {
    width: 12px;
    flex-shrink: 0;
    color: var(--text-secondary, var(--text-muted));
    font-size: 9px;
    text-align: center;
    cursor: pointer;
    user-select: none;
}

.element-tag-tree-content {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: 5px;
    overflow: hidden;
}

.element-tag-tree-item .dom-tree-tag {
    flex-shrink: 0;
}

.element-tag-tree-item .dom-tree-meta {
    margin-left: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.element-tag-tree-row:hover .element-tag-tree-branch,
.element-tag-menu-row.actions-open .element-tag-tree-branch {
    color: var(--text-primary, var(--text-main));
}

.element-tag-tree-row.is-selected .element-tag-menu-item {
    background: rgba(0, 122, 204, 0.36);
    box-shadow: inset 2px 0 0 var(--accent);
}

.element-tag-tree-row.is-selected .element-tag-menu-item:hover {
    background: rgba(0, 122, 204, 0.42);
}

.element-tag-tree-row.is-selected .dom-tree-tag {
    color: #fff;
    font-weight: 700;
}

.element-tag-tree-row.is-selected .dom-tree-meta {
    color: #e6eef8;
}

.element-tag-tree-row.is-selected .element-tag-tree-branch,
.element-tag-tree-row.is-selected .element-tag-menu-tools-btn {
    color: var(--text-primary, var(--text-main));
}

.element-tag-menu-tools-btn {
    width: 22px;
    height: 24px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary, var(--text-muted));
    cursor: pointer;
    line-height: 1;
    font-size: 14px;
    padding: 0;
}
.element-tag-menu-tools-btn:hover,
.element-tag-menu-row.actions-open .element-tag-menu-tools-btn {
    background: rgba(0, 122, 204, 0.16);
    color: var(--text-primary, var(--text-main));
}

.element-tag-row-actions {
    position: absolute;
    top: 0;
    left: calc(100% + 4px);
    min-width: 210px;
    width: 220px;
    max-width: 260px;
    box-sizing: border-box;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-panel);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
    overflow-y: auto;
    display: none;
    z-index: 10;
}
.element-tag-row-actions.floating {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 60;
}
.element-tag-menu-row.actions-open .element-tag-row-actions {
    display: block;
}
.element-tag-menu-row.open-up .element-tag-row-actions:not(.floating) {
    top: auto;
    bottom: 0;
}
.element-tag-menu-row.open-left .element-tag-row-actions:not(.floating) {
    left: auto;
    right: calc(100% + 4px);
}

.element-tag-action-item {
    width: 100%;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-primary, var(--text-main));
    font-size: 12px;
    text-align: left;
    padding: 6px 8px;
    cursor: pointer;
}
.element-tag-action-item:hover {
    background: rgba(0, 122, 204, 0.16);
}
.element-tag-action-item-has-flyout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.element-tag-action-item-has-flyout.active {
    background: rgba(0, 122, 204, 0.16);
}
.element-tag-action-caret {
    font-size: 10px;
    line-height: 1;
}
.element-tag-action-item-danger {
    color: #e5534b;
}
.element-tag-action-item-danger:hover {
    background: rgba(229, 83, 75, 0.14);
    color: #ff8f88;
}
.element-tag-action-item.disabled,
.element-tag-action-item:disabled {
    color: var(--text-muted);
    opacity: 0.55;
    pointer-events: none;
}

.element-tag-action-separator {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.element-tag-menu-empty {
    color: var(--text-secondary, var(--text-muted));
    font-size: 12px;
    padding: 6px 8px;
}
