/* ═══════════════════════════════════════════════════════════════
   HTML IDE — stylesheet
   Ported from the Python IDE CSS with HTML-specific additions
   ═══════════════════════════════════════════════════════════════ */

* {
    box-sizing: border-box
}

#ide-root {
    font-family: system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    visibility: hidden;

    /* Popup/modal palette (Examples, Elements, Assets, Programs, Confirm,
       Shortcuts, Toast). Defaults match the original fixed dark look;
       overridden per editor theme below so popups follow whichever
       CodeMirror theme is selected instead of always being this one dark
       palette regardless of theme. */
    --popup-dialog-bg: #161b22;
    --popup-content-bg: #0d1117;
    --popup-header-bg: #1c2230;
    --popup-item-bg: #21262d;
    --popup-border: #30363d;
    --popup-text: #e8e8e8;
    --popup-text-secondary: #ccc;
    --popup-text-muted: #888;
    --popup-accent: #7c3aed;
    --popup-accent-rgb: 124 58 237
}

/* Light CodeMirror themes (Angus/default, Murgatroyd/eclipse) */
#ide-root[data-editor-theme="default"],
#ide-root[data-editor-theme="eclipse"] {
    --popup-dialog-bg: #ffffff;
    --popup-content-bg: #f6f8fa;
    --popup-header-bg: #eef1f4;
    --popup-item-bg: #eceff2;
    --popup-border: #d0d7de;
    --popup-text: #1f2328;
    --popup-text-secondary: #444c56;
    --popup-text-muted: #6e7781;
    --popup-accent: #7c3aed;
    --popup-accent-rgb: 124 58 237
}

/* Penny/material — dark blue-grey */
#ide-root[data-editor-theme="material"] {
    --popup-dialog-bg: #21303a;
    --popup-content-bg: #263238;
    --popup-header-bg: #263a44;
    --popup-item-bg: #2c3e46;
    --popup-border: #3a4c56;
    --popup-text: #eeffff;
    --popup-text-secondary: #b0bec5;
    --popup-text-muted: #78909c;
    --popup-accent: #80cbc4;
    --popup-accent-rgb: 128 203 196
}

/* Ricky/monokai — dark warm */
#ide-root[data-editor-theme="monokai"] {
    --popup-dialog-bg: #2f2b25;
    --popup-content-bg: #272822;
    --popup-header-bg: #34302a;
    --popup-item-bg: #3e3d32;
    --popup-border: #49483e;
    --popup-text: #f8f8f2;
    --popup-text-secondary: #cfcfc2;
    --popup-text-muted: #90908a;
    --popup-accent: #a6e22e;
    --popup-accent-rgb: 166 226 46
}

/* Vivica/dracula — dark purple */
#ide-root[data-editor-theme="dracula"] {
    --popup-dialog-bg: #21222c;
    --popup-content-bg: #282a36;
    --popup-header-bg: #262835;
    --popup-item-bg: #343746;
    --popup-border: #44475a;
    --popup-text: #f8f8f2;
    --popup-text-secondary: #c2c4d6;
    --popup-text-muted: #8892b0;
    --popup-accent: #bd93f9;
    --popup-accent-rgb: 189 147 249
}

/* ── Toolbar ──────────────────────────────────────────────────── */

#toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px
}

.toolbar-sep {
    width: 1px;
    height: 22px;
    background: var(--color-border-secondary, #555);
    margin: 0 2px
}

button.tb {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 2.2em;
    padding: 0 12px;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid #fff0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    color: #fff
}

button.tb:hover:not(:disabled) {
    filter: brightness(1.08)
}

button.tb:active:not(:disabled) {
    transform: scale(.97)
}

button.tb:disabled {
    background: #6b7280 !important;
    border-color: #6b7280 !important;
    color: #d1d5db !important;
    opacity: .6;
    cursor: not-allowed;
    transform: none
}

button.tb.primary {
    background: #15803d;
    border-color: #15803d
}

button.tb.primary:hover:not(:disabled) {
    background: #166534;
    border-color: #166534
}

button.tb.success {
    background: #2563eb;
    border-color: #2563eb
}

button.tb.success:hover:not(:disabled) {
    background: #1d4ed8;
    border-color: #1d4ed8
}

button.tb.danger {
    background: #b91c1c;
    border-color: #b91c1c
}

button.tb.danger:hover:not(:disabled) {
    background: #991b1b;
    border-color: #991b1b
}

button.tb:not(.primary):not(.danger):not(.success) {
    background: #2563eb;
    border-color: #2563eb
}

button.tb:not(.primary):not(.danger):not(.success):hover:not(:disabled) {
    background: #1d4ed8;
    border-color: #1d4ed8
}

button.tb.icon-only {
    width: 2.2em;
    justify-content: center;
    padding: 0
}

#dbSaveBtn {
    background: #7c3aed;
    border-color: #7c3aed
}

#dbSaveBtn:hover:not(:disabled) {
    background: #6d28d9;
    border-color: #6d28d9
}

#programsBtn {
    background: #0e7490;
    border-color: #0e7490
}

#programsBtn:hover:not(:disabled) {
    background: #0c6175;
    border-color: #0c6175
}

select.tb {
    height: 2.2em;
    padding: 0 8px;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid #444;
    border-radius: 6px;
    background: #2a2a2a;
    color: #e8e8e8;
    cursor: pointer
}

.select-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center
}

.select-icon {
    /* !important: this page loads three separate FontAwesome installs
       simultaneously (Joomla's own bundled FA6 plus this site's FA7 kit),
       and at least two of them define a base `.fa-solid` rule with
       `display: ... !important` to force icon rendering regardless of
       page CSS. A plain `display: none` here loses to that every time
       (verified live), so this has to fight fire with fire. */
    display: none !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    color: #fff;
    font-size: 1rem
}

@media (max-width: 900px) {
    .select-wrapper select.tb {
        width: 2.2em;
        padding: 0;
        color: #fff0;
        text-indent: -9999px
    }

    .select-wrapper select.tb option {
        color: #e8e8e8;
        text-indent: 0
    }

    .select-icon {
        display: block !important;
        pointer-events: none
    }
}

/* ── Active program badge ─────────────────────────────────────── */

#activeProgramBadge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
    color: #a78bfa;
    background: rgb(124 58 237 / .15);
    border: 1px solid rgb(124 58 237 / .3);
    border-radius: 4px;
    padding: 1px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    margin-left: 6px
}

#activeProgramBadge.unsaved {
    color: #f59e0b;
    border-color: rgb(245 158 11 / .4);
    background: rgb(245 158 11 / .08)
}

#activeProgramBadge .badge-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0
}

#ragBadge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    line-height: 1;
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
    margin-left: 6px
}

.rag-badge-red { background: rgb(220 38 38 / .15); border: 1px solid rgb(220 38 38 / .4); color: #fca5a5 }
.rag-badge-amber { background: rgb(217 119 6 / .15); border: 1px solid rgb(217 119 6 / .4); color: #fbbf24 }
.rag-badge-green { background: rgb(22 163 74 / .15); border: 1px solid rgb(22 163 74 / .4); color: #86efac }

#resubmitBadge {
    display: inline-flex;
    align-items: center;
    line-height: 1;
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
    margin-left: 6px;
    background: rgb(220 38 38 / .12);
    border: 1px solid rgb(220 38 38 / .35);
    color: #fca5a5
}

#teacherEditedBanner {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12px;
    background: rgb(217 119 6 / .1);
    border-bottom: 1px solid rgb(217 119 6 / .3);
    color: #fbbf24
}

.program-feedback-pill {
    font-size: 10.5px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 9px;
    background: rgb(124 58 237 / .16);
    border: 1px solid rgb(124 58 237 / .4);
    color: #a78bfa;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 6px
}

.program-rag-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    vertical-align: middle;
    margin-left: 6px
}

.program-rag-dot-red { background: #dc2626 }
.program-rag-dot-amber { background: #d97706 }
.program-rag-dot-green { background: #16a34a }

.program-resubmit-pill {
    font-size: 10.5px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 9px;
    background: rgb(220 38 38 / .16);
    border: 1px solid rgb(220 38 38 / .4);
    color: #fca5a5;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 6px
}

/* ── IDE layout ───────────────────────────────────────────────── */

#ide-layout {
    display: grid;
    grid-template-columns: 75% 6px calc(25% - 6px);
    min-height: 220px;
	height: calc(100vh - 100px);
    margin-top: 6px;
    z-index: 2;
    border-radius: 6px 6px 0 0;
    overflow: hidden
}

.outline-23 #ide-layout { height: calc(100vh - 300px) }
.outline-12 #ide-layout { height: calc(100vh - 200px) }
.outline-18 #ide-layout { height: calc(100vh - 100px) }

#splitter {
    background: var(--color-border-secondary, #444);
    cursor: col-resize;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center
}

#splitter:hover { background: #666 }

#swapBtn {
    position: relative;
    z-index: 5;
    width: 20px;
    height: 32px;
    padding: 0;
    font-size: 13px;
    background: #555;
    border: 1px solid #777;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    line-height: 1
}

#swapBtn i {
    transition: transform 0.3s ease
}

#swapBtn.vertical i {
    transform: rotate(90deg)
}

#swapBtn:hover {
    background: #7c3aed;
    border-color: #7c3aed
}

#heightSplitter {
    height: 8px;
    cursor: row-resize;
    background: var(--color-border-secondary, #444);
    border-radius: 0 0 4px 4px
}

#heightSplitter:hover {
    background: #666
}

#editor-wrapper,
#console-wrapper {
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column
}

@media (max-width: 700px) {
    #ide-layout {
        grid-template-columns: 1fr
    }

    #splitter {
        display: none
    }
}

/* ── Pane tabs ────────────────────────────────────────────────── */

.pane-tabs {
    display: flex;
    align-items: stretch;
    background: var(--color-background-secondary, #1a1a1a);
    border: .5px solid var(--color-border-secondary, #444);
    border-bottom: none;
    min-height: 26px
}

.pane-tab {
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--color-text-secondary, #888);
    padding: 4px 12px;
    cursor: pointer;
    border-bottom: 2px solid #fff0;
    transition: color 0.15s, border-color 0.15s;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 5px
}

.pane-tab:hover {
    color: #ccc
}

.pane-tab.active {
    color: #e8e8e8;
    border-bottom-color: #7c3aed
}

.pane-tab .tab-badge {
    font-size: 10px;
    background: #7c3aed;
    color: #fff;
    border-radius: 9px;
    padding: 0 5px;
    line-height: 16px
}

.pane-label-right {
    margin-left: auto;
    font-size: 11px;
    letter-spacing: .06em;
    color: var(--color-text-secondary, #888);
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 8px
}

.pane-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 20px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
    color: #fff;
    background: #2563eb;
    border: 1px solid #2563eb;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s
}

.pane-action-btn:hover { background: #1d4ed8; border-color: #1d4ed8 }
.pane-action-btn:active { transform: scale(.97) }

/* ── Sub-tabs: colour dots + dirty indicator ──────────────────── */

.tab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0
}

.tab-dot.html-dot  { background: #f38ba8 }
.tab-dot.css-dot   { background: #89dceb }
.tab-dot.js-dot    { background: #f9e2af }
.tab-dot.notes-dot { background: #a78bfa }

#tabNotes .tab-badge { background: #7c3aed }
#tabNotes.has-notes { color: #a78bfa }
#tabNotes.has-notes:not(.active) { border-bottom-color: rgb(124 58 237 / .4) }

.pane-tab .tab-dirty {
    display: none;
    font-size: 10px;
    color: #f59e0b;
    margin-left: 2px
}

.pane-tab.dirty .tab-dirty {
    display: inline
}

/* ── Editor pane ──────────────────────────────────────────────── */

#editor-pane {
    position: relative;
    display: flex;
    flex-direction: column;
    border: .5px solid var(--color-border-secondary, #444);
    overflow: hidden;
    flex: 1;
    min-height: 0
}

/* cm-panel: only the active sub-editor is visible */
.cm-panel {
    display: none;
    flex: 1;
    overflow: hidden;
    flex-direction: column
}

.cm-panel.active {
    display: flex
}

#notes-pane {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background: #0d1117
}

#notes-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #555;
    font-size: 13px;
    gap: 8px;
    text-align: center;
    padding: 20px
}

#notes-empty svg { opacity: .3 }

#notes-list { padding: 6px 0 }

.note-card {
    padding: 9px 12px;
    margin: 0 8px 8px;
    background: #161b22;
    border: 1px solid #1e2530;
    border-left: 3px solid #7c3aed;
    border-radius: 6px
}

.note-card-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap }
.note-card-author { font-size: 12px; font-weight: 600; color: #a78bfa }
.note-card-date { font-size: 11px; color: #666 }
.note-card-body {
    font-size: 13px;
    line-height: 1.55;
    margin-top: 5px;
    color: #e8e8e8;
    white-space: pre-wrap;
    word-break: break-word
}

.CodeMirror {
    width: 100%;
    height: 100%;
    font-size: 14px;
    font-family: Consolas, "Courier New", monospace;
    line-height: 1.2
}

.CodeMirror-lines {
    padding-bottom: 75px
}

.CodeMirror pre {
    line-height: 1.2;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere
}

/* ── Console / preview pane ───────────────────────────────────── */

#console-pane {
    display: flex;
    flex-direction: column;
    border: .5px solid var(--color-border-secondary, #444);
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: #fff
}

#preview-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #888;
    font-size: 14px;
    pointer-events: none;
    background: var(--color-background-secondary, #1a1a1a)
}

#preview-placeholder svg {
    opacity: .25
}

#preview-placeholder strong {
    color: #e8e8e8
}

/* ── Status bar ───────────────────────────────────────────────── */

#statusBar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--color-text-secondary, #888);
    padding: 4px 0
}

#statusControls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap
}

@media (max-width: 700px) {
    #statusBar { row-gap: 6px }

    #statusControls {
        width: 100%;
        margin-left: 0;
        justify-content: space-between
    }

    #statusControls > span { flex: 1 1 220px }

    #statusControls input[type="range"] {
        width: 100%;
        min-width: 80px
    }
}

#statusDot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
    flex-shrink: 0;
    transition: background 0.2s
}

#statusDot.running {
    background: #56d364;
    animation: pulse 1s ease-in-out infinite
}

#statusDot.error { background: #ff7b72 }
#statusDot.ok    { background: #56d364 }

@keyframes pulse {
    0%, 100% { opacity: 1 }
    50%       { opacity: .4 }
}

#autosaveIndicator,
#dbSaveIndicator {
    font-size: 11px;
    opacity: 0;
    transition: opacity 0.4s;
    white-space: nowrap
}

#autosaveIndicator         { color: #56d364 }
#dbSaveIndicator           { color: #a78bfa }
#autosaveIndicator.visible,
#dbSaveIndicator.visible   { opacity: 1 }

#autosaveIndicator i,
#dbSaveIndicator i { margin-right: 4px }

/* ── Examples modal ───────────────────────────────────────────── */

#examplesModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgb(0 0 0 / .55);
    align-items: center;
    justify-content: center
}

#examplesDialog {
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 10px;
    width: min(700px, 95vw);
    height: min(85vh, 800px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#examplesHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--popup-header-bg, #1c2230);
    border-bottom: 1px solid var(--popup-border, #30363d)
}

#examplesTitle {
    font-size: 15px;
    font-weight: 600;
    color: var(--popup-text, #e8e8e8)
}

#examplesClose {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    color: var(--popup-text-muted, #888)
}

#examplesClose:hover { color: var(--popup-text, #e8e8e8) }

#shortcutsModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgb(0 0 0 / .55);
    align-items: center;
    justify-content: center
}

#shortcutsDialog {
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 10px;
    width: min(420px, 95vw);
    max-height: min(85vh, 600px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#shortcutsHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--popup-header-bg, #1c2230);
    border-bottom: 1px solid var(--popup-border, #30363d)
}

#shortcutsTitle {
    font-size: 15px;
    font-weight: 600;
    color: var(--popup-text, #e8e8e8)
}

#shortcutsClose {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    color: var(--popup-text-muted, #888)
}

#shortcutsClose:hover { color: var(--popup-text, #e8e8e8) }

#shortcutsList {
    width: 100%;
    border-collapse: collapse;
    overflow-y: auto
}

#shortcutsList td {
    padding: 10px 18px;
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    color: var(--popup-text, #e8e8e8);
    font-size: 13px
}

#shortcutsList td:first-child { white-space: nowrap; width: 1% }

#shortcutsList kbd {
    background: var(--popup-item-bg, #21262d);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: inherit;
    font-size: 12px
}

#examplesList {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--popup-content-bg, #0d1117)
}

/* category header row */
.ex-category-header {
    padding: 8px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--popup-text-muted, #888);
    background: var(--popup-dialog-bg, #161b22);
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none
}

.ex-category-header:hover { background: var(--popup-header-bg, #1c2230) }

.ex-category-arrow {
    transition: transform .2s;
    font-size: 10px;
    color: #555
}

/* individual example row */
.ex-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--popup-text, #e8e8e8);
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    transition: background 0.12s
}

.ex-item-header:hover { background: var(--popup-dialog-bg, #161b22) }

.ex-item-arrow {
    transition: transform .2s;
    font-size: 10px;
    color: #555
}

/* code preview block (hidden until item opened) */
.ex-item-code {
    display: none;
    flex-direction: column;
    border-bottom: 1px solid var(--popup-item-bg, #21262d)
}

.ex-item-code.open { display: flex }

/* mini tab bar inside code preview */
.ex-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 10px;
    background: var(--popup-header-bg, #1c2230);
    border-bottom: 1px solid var(--popup-item-bg, #21262d)
}

.ex-tab-btn {
    padding: 2px 10px;
    border-radius: 4px;
    border: none;
    background: var(--popup-item-bg, #21262d);
    color: var(--popup-text-muted, #888);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s
}

.ex-tab-btn.active {
    background: var(--popup-accent, #7c3aed);
    color: #fff
}

.ex-tab-btn:not(.active):hover {
    background: #2d333b;
    color: var(--popup-text-secondary, #ccc)
}

/* code preview pre */
.ex-pre {
    margin: 0;
    padding: 10px 14px;
    font-size: 12px;
    font-family: Consolas, "Courier New", monospace;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--popup-content-bg, #0d1117);
    color: var(--popup-text, #e8e8e8)
}

/* action buttons row */
.ex-copy-row {
    display: flex;
    justify-content: flex-end;
    padding: 6px 10px 8px;
    gap: 6px;
    background: var(--popup-content-bg, #0d1117)
}

.ex-copy-btn {
    padding: 3px 10px;
    border-radius: 5px;
    border: 1px solid var(--popup-border, #30363d);
    background: var(--popup-item-bg, #21262d);
    color: var(--popup-text-secondary, #ccc);
    cursor: pointer;
    font-size: 12px;
    transition: background 0.12s
}

.ex-copy-btn:hover { background: #2d333b }

.ex-copy-btn.copied {
    background: var(--popup-accent, #7c3aed);
    border-color: var(--popup-accent, #7c3aed);
    color: #fff
}

.ex-load-btn {
    padding: 3px 10px;
    border-radius: 5px;
    border: none;
    background: #15803d;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.12s
}

.ex-load-btn:hover { background: #166534 }

/* ── Elements modal ───────────────────────────────────────────── */

#elementsModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgb(0 0 0 / .55);
    align-items: center;
    justify-content: center
}

#elementsDialog {
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 10px;
    width: min(480px, 95vw);
    height: min(80vh, 700px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#elementsHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--popup-header-bg, #1c2230);
    border-bottom: 1px solid var(--popup-border, #30363d);
    flex-shrink: 0
}

#elementsTitle {
    font-size: 15px;
    font-weight: 600;
    color: var(--popup-text, #e8e8e8)
}

#elementsClose {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    color: var(--popup-text-muted, #888)
}

#elementsClose:hover { color: var(--popup-text, #e8e8e8) }

#elementsHint {
    padding: 8px 18px;
    font-size: 11px;
    color: var(--popup-text-muted, #888);
    background: var(--popup-content-bg, #0d1117);
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    flex-shrink: 0
}

#elementsList {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--popup-content-bg, #0d1117)
}

.el-category-header {
    padding: 8px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--popup-text-muted, #888);
    background: var(--popup-dialog-bg, #161b22);
    border-bottom: 1px solid var(--popup-item-bg, #21262d)
}

.el-item-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--popup-text, #e8e8e8);
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    transition: background 0.12s
}

.el-item-row:hover { background: var(--popup-header-bg, #1c2230) }

.el-item-row.copied { background: #14301f }

.el-item-icon {
    width: 18px;
    text-align: center;
    color: var(--popup-accent, #7c3aed);
    flex-shrink: 0
}

.el-item-code {
    margin-left: auto;
    font-family: Consolas, "Courier New", monospace;
    font-size: 11px;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 45%
}

/* ── Assets modal ─────────────────────────────────────────────── */

#assetsModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgb(0 0 0 / .55);
    align-items: center;
    justify-content: center
}

#assetsDialog {
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 10px;
    width: min(700px, 95vw);
    height: min(85vh, 800px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#assetsHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--popup-header-bg, #1c2230);
    border-bottom: 1px solid var(--popup-border, #30363d);
    flex-shrink: 0
}

#assetsTitle {
    font-size: 15px;
    font-weight: 600;
    color: var(--popup-text, #e8e8e8)
}

#assetsClose {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    color: var(--popup-text-muted, #888)
}

#assetsClose:hover { color: var(--popup-text, #e8e8e8) }

#assetsHint {
    padding: 8px 18px;
    font-size: 11px;
    color: var(--popup-text-muted, #888);
    background: var(--popup-content-bg, #0d1117);
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    flex-shrink: 0
}

#assetsGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
    background: var(--popup-content-bg, #0d1117);
    align-content: start
}

.asset-category-header {
    grid-column: 1 / -1;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--popup-text-muted, #888);
    padding: 10px 2px 6px;
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    margin-bottom: 2px
}

.asset-category-header:first-child { padding-top: 2px }

#assetsEmpty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
    padding: 24px
}

.asset-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 8px;
    padding: 8px 6px 6px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    user-select: none
}

.asset-card:hover {
    border-color: var(--popup-accent, #7c3aed);
    background: var(--popup-header-bg, #1c2230)
}

.asset-card.copied {
    border-color: #15803d;
    background: #14301f
}

.asset-card.img-error {
    border-color: #dc2626;
    background: #2d1414
}

.asset-card img,
.asset-card video {
    width: 100%;
    height: 70px;
    object-fit: contain;
    border-radius: 5px;
    display: block;
    background: var(--popup-content-bg, #0d1117)
}

.asset-card-video-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgb(0 0 0 / .65);
    color: #fff;
    font-size: 10px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center
}

.asset-card-label {
    font-size: 10px;
    color: var(--popup-text, #e8e8e8);
    text-align: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

/* ── Programs modal ───────────────────────────────────────────── */

#programsModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgb(0 0 0 / .6);
    align-items: center;
    justify-content: center
}

#programsDialog {
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 10px;
    width: min(640px, 95vw);
    max-height: min(85vh, 700px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#programsHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--popup-header-bg, #1c2230);
    border-bottom: 1px solid var(--popup-border, #30363d)
}

#programsTitle {
    font-size: 15px;
    font-weight: 600;
    color: var(--popup-text, #e8e8e8)
}

#programsClose {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    color: var(--popup-text-muted, #888)
}

#programsClose:hover { color: var(--popup-text, #e8e8e8) }

#programsNewRow {
    display: flex;
    gap: 8px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--popup-item-bg, #21262d);
    background: var(--popup-content-bg, #0d1117)
}

#programsNewName {
    flex: 1;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 6px;
    color: var(--popup-text, #e8e8e8);
    outline: none
}

#programsNewName:focus { border-color: var(--popup-accent, #7c3aed) }

#programsSaveNewBtn {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    background: var(--popup-accent, #7c3aed);
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    white-space: nowrap
}

#programsSaveNewBtn:hover { background: #6d28d9 }

#programsSearchRow {
    display: flex;
    gap: 8px;
    padding: 8px 18px;
    background: var(--popup-content-bg, #0d1117);
    border-bottom: 1px solid var(--popup-item-bg, #21262d)
}

#programsSort {
    flex: 0 0 auto;
    padding: 5px 8px;
    font-size: 12px;
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 6px;
    color: var(--popup-text, #e8e8e8);
    outline: none
}

#programsSort:focus { border-color: var(--popup-accent, #7c3aed) }

#programsSearch {
    flex: 1 1 auto;
    min-width: 0;
    padding: 5px 10px;
    font-size: 12px;
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 5px;
    color: var(--popup-text, #e8e8e8);
    outline: none
}

#programsSearch:focus { border-color: var(--popup-accent, #7c3aed) }

#programsList {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0
}

#programsEmpty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    color: #555;
    font-size: 13px
}

.program-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--popup-header-bg, #1c2230);
    transition: background 0.12s
}

.program-item:hover { background: var(--popup-header-bg, #1c2230) }

.program-item.active-prog {
    background: rgb(var(--popup-accent-rgb, 124 58 237) / .08);
    border-left: 3px solid var(--popup-accent, #7c3aed);
    padding-left: 15px
}

.program-item-info { flex: 1; min-width: 0 }

.program-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--popup-text, #e8e8e8);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

.program-item-meta {
    font-size: 11px;
    color: #555;
    margin-top: 2px
}

.program-item-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0
}

.prog-btn {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 4px;
    border: 1px solid var(--popup-border, #30363d);
    background: var(--popup-item-bg, #21262d);
    color: var(--popup-text-secondary, #ccc);
    cursor: pointer;
    transition: background 0.12s
}

.prog-btn:hover { background: #2d333b }

.prog-btn.load {
    background: #1a3a5c;
    border-color: #2563eb;
    color: #79c0ff
}

.prog-btn.load:hover { background: #1e4a7a }

.prog-btn.del {
    background: #2a1a1a;
    border-color: #7f1d1d;
    color: #fca5a5
}

.prog-btn.del:hover { background: #3d1f1f }

/* ── Confirm modal ────────────────────────────────────────────── */

#confirmModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgb(0 0 0 / .65);
    align-items: center;
    justify-content: center
}

#confirmDialog {
    background: var(--popup-dialog-bg, #161b22);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 10px;
    width: min(400px, 92vw);
    padding: 24px 24px 20px;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#confirmMsg {
    font-size: 14px;
    color: var(--popup-text, #e8e8e8);
    margin-bottom: 20px;
    line-height: 1.5
}

#confirmActions {
    display: flex;
    gap: 10px;
    justify-content: flex-end
}

.confirm-btn {
    padding: 6px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    cursor: pointer
}

.confirm-btn.ok {
    background: #b91c1c;
    color: #fff
}

.confirm-btn.ok:hover { background: #991b1b }

.confirm-btn.cancel {
    background: var(--popup-item-bg, #21262d);
    color: var(--popup-text-secondary, #ccc);
    border: 1px solid var(--popup-border, #30363d)
}

.confirm-btn.cancel:hover { background: #2d333b }

/* ── Toast ────────────────────────────────────────────────────── */

#ideToast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: var(--popup-header-bg, #1c2230);
    border: 1px solid var(--popup-border, #30363d);
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 13px;
    color: var(--popup-text, #e8e8e8);
    box-shadow: 0 4px 16px rgb(0 0 0 / .4);
    opacity: 0;
    pointer-events: none;
    z-index: 11000;
    transition: opacity 0.2s, transform 0.2s;
    white-space: nowrap
}

#ideToast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0)
}

#ideToast.toast-ok    { border-color: #15803d; color: #56d364 }
#ideToast.toast-error { border-color: #7f1d1d; color: #fca5a5 }
#ideToast.toast-info  { border-color: #2563eb; color: #79c0ff }

/* ── Misc ─────────────────────────────────────────────────────── */

.tb i {
    width: 1em;
    text-align: center;
    flex-shrink: 0
}

.tb.locked {
    opacity: .45;
    cursor: not-allowed;
    filter: grayscale(.6)
}

@media (max-width: 900px) {
    #toolbar { gap: 4px }

    .toolbar-sep { display: none }

    button.tb .btn-text { display: none }

    button.tb {
        padding: 0;
        width: 2.2em;
        justify-content: center
    }

    .pane-action-btn span { display: none }

    .pane-action-btn {
        width: 20px;
        padding: 0;
        justify-content: center
    }

    button.tb.has-text-only {
        width: auto;
        padding: 0 12px
    }
}

/* ── Mascot ───────────────────────────────────────────────────── */

#editorMascot {
    position: absolute;
    left: 10px;
    bottom: -40px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    z-index: 50;
    transition: bottom .35s ease, opacity .25s ease;
    pointer-events: none
}

#editorMascotImg {
    width: 90px;
    height: auto;
    display: block
}

#editorMascotBubble {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .25s ease, transform .25s ease;
    background: rgb(255 255 255 / .97);
    color: #222;
    border-radius: 16px;
    padding: 10px 14px;
    max-width: min(450px, calc(100% - 110px));
    box-shadow: 0 2px 8px rgb(0 0 0 / .2);
    align-self: flex-start;
    line-height: 1.4;
    font-size: 13px
}

#editorMascot.active {
    bottom: 0
}

#editorMascot.active #editorMascotBubble {
    opacity: 1;
    transform: translateY(0)
}

@media (max-width: 900px) {
    #editorMascotImg { width: 60px }
    #editorMascot    { bottom: -30px }
}

@media (max-width: 600px) {
    #editorMascotImg { width: 40px }
    #editorMascot    { bottom: -20px }

    #editorMascotBubble {
        font-size: .9rem;
        border-radius: 8px;
        padding: 5px 10px
    }
}

/* ── Page tab bar ─────────────────────────────────────────────── */

#code-tabs-bar {
    display: flex;
    align-items: stretch;
    background: var(--color-background-secondary, #1a1a1a);
    border: .5px solid var(--color-border-secondary, #444);
    border-bottom: none;
    min-height: 30px;
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0
}

#code-tabs-bar::-webkit-scrollbar { display: none }

#page-tabs {
    display: flex;
    align-items: stretch;
    flex-shrink: 0
}

.page-tab {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 11px;
    letter-spacing: .04em;
    color: var(--color-text-secondary, #888);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    border-right: 1px solid var(--color-border-secondary, #333);
    white-space: nowrap;
    user-select: none;
    transition: color 0.15s, background 0.15s
}

.page-tab:hover { color: #ccc; background: rgba(255,255,255,.04) }

.page-tab.active {
    color: #e8e8e8;
    border-bottom-color: #f38ba8;
    background: rgba(255,255,255,.03)
}

.page-tab-name { pointer-events: none }

.page-tab-del,
.page-tab-rename {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #666;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    pointer-events: all;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s
}

.page-tab-del:hover { background: rgba(243,56,56,.25); color: #fca5a5 }
.page-tab-rename:hover { background: rgba(124,58,237,.25); color: #c4b5fd }

#ide-root .page-tab-rename-input {
    font-size: 11px;
    background: #0d1117 !important;
    border: 1px solid #7c3aed;
    border-radius: 3px;
    color: #e8e8e8 !important;
    padding: 1px 5px;
    width: auto;
    min-width: 70px;
    max-width: 220px;
    outline: none
}

.add-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    padding: 0;
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 13px;
    flex-shrink: 0;
    transition: color 0.12s
}

.add-page-btn:hover { color: #a78bfa }

.tab-bar-sep {
    width: 1px;
    background: var(--color-border-secondary, #444);
    margin: 4px 3px;
    flex-shrink: 0
}

.shared-tab {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-text-secondary, #888);
    padding: 4px 11px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    transition: color 0.15s
}

.shared-tab:hover { color: #ccc }
.shared-tab.active { color: #e8e8e8; border-bottom-color: #7c3aed }
