
:root {
    --bg: #1e1e1e;
    --sidebar: #181818;
    --panel: #1e1e1e;
    --titlebar: #181818;
    --tab: #1f1f1f;
    --border: #2b2b2b;
    --text: #cccccc;
    --muted: #858585;
    --accent: #007acc;
    --green: #2ea043;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 13px;
}

/* Application header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 0 18px;
    background: var(--titlebar);
    border-bottom: 1px solid var(--border);
}

    header .brand {
        display: flex;
        align-items: center;
        gap: 10px;
        color: inherit;
        text-decoration: none;
    }

    header .brand-logo {
        display: block;
        height: 42px;
        width: auto;
    }

    header .version {
        padding: 1px 7px;
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--muted);
        font-size: 11px;
        line-height: 16px;
        white-space: nowrap;
    }

    header h1 {
        margin: 0;
        font-size: 14px;
        font-weight: 600;
        letter-spacing: .2px;
    }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
}

button {
    border: 1px solid #454545;
    border-radius: 4px;
    padding: 8px 14px;
    background: #303030;
    color: #e6e6e6;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s ease;
}

    button:hover:not(:disabled) {
        background: #414141;
    }

    button:focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }

    button:disabled {
        opacity: .5;
        cursor: not-allowed;
    }

#runButton {
    background: #238636;
    border-color: #238636;
    color: white;
    font-weight: 600;
}

#debugButton {
    background: #0e639c;
    border-color: #0e639c;
    color: white;
    font-weight: 600;
}

    #runButton:hover:not(:disabled) {
        background: #2ea043;
    }

#resetButton {
    background: #303030;
}

/* Execution status */
.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

#status {
    flex: 1;
    padding: 8px 18px;
    color: var(--muted);
    font-size: 12px;
}

.version-badge {
    margin-right: 18px;
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

/* Editor, terminal, debug console, and debug side panel */
.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr) minmax(260px, 320px);
    grid-template-rows: minmax(240px, 1fr) 260px;
    gap: 1px;
    background: var(--border);
    height: calc(100vh - 148px);
    min-height: 520px;
}

.editor-panel {
    grid-column: 1 / span 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.debug-side {
    grid-column: 3;
    grid-row: 1 / span 2;
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.debug-console-panel {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel {
    min-width: 0;
    overflow: hidden;
    background: var(--panel);
    border: 0;
    border-radius: 0;
}

.panel-title {
    display: flex;
    align-items: center;
    min-height: 37px;
    padding: 0 16px;
    background: var(--tab);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 400;
    color: #dddddd;
}

/* CodeMirror editor */
.CodeMirror {
    height: auto;
    flex: 1;
    min-height: 0;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: Consolas, "Cascadia Code", monospace;
    font-size: 14px;
    line-height: 1.65;
}

.CodeMirror-gutters {
    background: #1e1e1e;
    border-right: 0;
}

.CodeMirror-linenumber {
    color: #858585;
    padding: 0 12px 0 8px;
}

.CodeMirror-activeline-background {
    background: #262626;
}

.CodeMirror-cursor {
    border-left: 2px solid #aeafad;
}

/* Terminal output */
#output {
    margin: 0;
    padding: 16px;
    min-height: 360px;
    max-height: calc(100vh - 180px);
    overflow: auto;
    background: #181818;
    color: #d4d4d4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 13px/1.7 Consolas, "Cascadia Code", monospace;
}

/* Mobile layout */
@media (max-width: 800px) {
    header {
        padding: 12px 16px;
    }

    .toolbar {
        padding: 10px 16px;
    }

    #status {
        padding: 8px 16px;
    }

    .workspace {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: none;
        height: auto;
        min-height: 0;
    }

    .editor-panel,
    .debug-side,
    .terminal-panel,
    .debug-console-panel {
        grid-column: 1;
        grid-row: auto;
    }

    .CodeMirror {
        height: 45vh;
        min-height: 240px;
        flex: none;
    }

    #output {
        min-height: 180px;
        max-height: 35vh;
    }

    button {
        min-height: 40px;
    }
}

#themeSelect {
    background: #303030;
    color: #e6e6e6;
    border: 1px solid #454545;
    border-radius: 4px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    min-height: 36px;
}

    #themeSelect:hover {
        border-color: #007acc;
    }

    #themeSelect:focus-visible {
        outline: 2px solid #007acc;
        outline-offset: 2px;
    }

.toolbar label {
    color: #aaaaaa;
    font-size: 12px;
}

/* Highlight the active editor line */
.CodeMirror-activeline-background {
    background: rgba(128, 128, 128, 0.10);
}

/* Improve bracket visibility */
.CodeMirror-matchingbracket {
    outline: 1px solid #888888;
    border-radius: 2px;
}


/* Milestone 7.5 - Integrated Terminal */

.terminal-panel {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.terminal-title {
    justify-content: space-between;
    gap: 12px;
}

.terminal-language {
    color: #858585;
    font-size: 11px;
    font-weight: 400;
}

.terminal-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: #181818;
}

    .terminal-body .terminal-scroll {
        padding: 4px 16px 16px;
        font: 13px/1.7 Consolas, "Cascadia Code", monospace;
        color: #e6e6e6;
        white-space: normal; /* markup whitespace must not render; #output and .shell-line set their own */
        overflow-wrap: anywhere;
        cursor: text;
    }

    /* Program output and the typing line share one flow, so a prompt like "Name? " and the cursor sit on the same line. */
    .terminal-body #output {
        display: inline;
        min-height: 0;
        max-height: none;
        overflow: visible;
        background: transparent;
        margin: 0;
        padding: 0;
        border: 0;
        white-space: pre-wrap;
        overflow-wrap: anywhere;
        font: inherit;
    }

.shell-line {
    display: inline;
    white-space: pre;
}

    .shell-line[hidden] {
        display: none;
    }

.shell-prompt {
    color: #4ec9b0;
    font-weight: 600;
}

#terminalInput {
    width: 1ch;
    min-width: 1ch;
    max-width: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #e6e6e6;
    font: inherit;
    caret-color: #e6e6e6;
    outline: none;
    box-shadow: none;
}

    #terminalInput:disabled {
        opacity: 1;
        cursor: default;
    }

/* Files pane beside the editor */
.editor-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.files-pane {
    display: flex;
    flex-direction: column;
    flex: none;
    width: 190px;
    min-height: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
}

.files-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 30px;
    padding: 0 8px 0 12px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.04em;
}

.files-actions {
    display: inline-flex;
    gap: 2px;
}

    .files-actions .output-icon-btn {
        width: 24px;
        height: 24px;
        padding: 0;
        font-size: 15px;
        line-height: 1;
    }

.file-tree {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 0 8px;
    font: 13px/1.5 Consolas, "Cascadia Code", monospace;
}

    .file-tree summary {
        padding: 2px 8px 2px 12px;
        color: #cccccc;
        cursor: pointer;
        list-style-position: inside;
        white-space: nowrap;
    }

        .file-tree summary:hover,
        .file-tree .file-item:hover {
            background: rgba(255, 255, 255, 0.07);
        }

    .file-tree .file-children {
        padding-left: 12px;
    }

    .file-tree .file-item {
        display: block;
        width: 100%;
        min-height: 0;
        padding: 2px 8px 2px 28px;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: #cccccc;
        font: inherit;
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        cursor: pointer;
    }

        .file-tree .file-item.current {
            background: rgba(0, 122, 204, 0.3);
            color: #ffffff;
        }

.editor-body .CodeMirror {
    flex: 1;
    min-width: 0;
}

@media (max-width: 800px) {
    .editor-body {
        flex-direction: column;
    }

    .files-pane {
        width: auto;
        max-height: 140px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
}


/* Output panel toolbar */

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 36px;
}

.output-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.output-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 5px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: #a0a0a0;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

    .output-icon-btn:hover {
        background: rgba(255, 255, 255, 0.09);
        color: #ffffff;
    }

    .output-icon-btn:active {
        background: rgba(255, 255, 255, 0.15);
    }

    .output-icon-btn svg {
        width: 16px;
        height: 16px;
    }

/* Debug mode */

.breakpoint-marker {
    width: 10px;
    height: 10px;
    margin: 6px auto 0;
    border-radius: 50%;
    background: #e51400;
}

.debug-current-line {
    background: rgba(255, 196, 0, 0.18);
}

.debug-side section {
    border-bottom: 1px solid var(--border);
}

.debug-table-wrap,
#localsBody,
#breaksBody,
#debugOutput {
    max-height: 180px;
    overflow: auto;
}

.debug-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font: 12px Consolas, monospace;
}

.debug-table-wrap th,
.debug-table-wrap td {
    padding: 4px 8px;
    text-align: left;
    border-bottom: 1px solid #2b2b2b;
}

.debug-table-wrap tbody tr {
    cursor: pointer;
}

.debug-empty,
#localsBody {
    padding: 8px 12px;
    color: var(--muted);
    font: 12px Consolas, monospace;
}

.debug-var {
    padding: 2px 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.debug-var-name {
    color: #9cdcfe;
}

.debug-break-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    font: 12px Consolas, monospace;
}

.debug-remove {
    padding: 2px 6px;
    font-size: 11px;
}

#watchForm,
.debug-controls,
.debug-command-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    align-items: center;
}

#watchInput,
#debugCommand {
    flex: 1;
    min-width: 0;
    border: 1px solid #454545;
    border-radius: 4px;
    padding: 6px 8px;
    background: #252526;
    color: #e6e6e6;
    font: 12px Consolas, monospace;
}

.debug-controls button,
#watchForm button {
    padding: 4px 8px;
    font-size: 12px;
}

#debugOutput {
    flex: 1;
    margin: 0;
    padding: 8px 12px;
    background: #181818;
    color: #d4d4d4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 12px/1.5 Consolas, monospace;
}

.debug-prompt {
    color: #4ec9b0;
    font: 600 12px Consolas, monospace;
}

#graphicsPanel {
    padding: 12px 18px 20px;
    background: #181818;
    border-top: 1px solid var(--border);
}

#graphicsPanel h2 {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 600;
}

#figures {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

#figures .file-preview {
    margin: 0;
    flex-basis: 100%;
}

#figures .file-preview figcaption {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
}

#figures img,
#figures svg {
    max-width: 100%;
    height: auto;
    background: #fff;
    border: 1px solid #2b2b2b;
}

@media (max-width: 800px) {
    .editor-panel,
    .debug-side,
    .terminal-panel,
    .debug-console-panel {
        grid-column: 1;
        grid-row: auto;
    }
}

/* Breakpoint gutter: its own column to the left of the line numbers */
.CodeMirror-gutter.breakpoints {
    width: 18px;
}

.CodeMirror-gutter-elt .breakpoint-marker {
    width: 10px;
    height: 10px;
    margin: 6px 4px 0;
    cursor: pointer;
}

/* Desktop: the app fills the viewport exactly; panels scroll inside themselves.
   Narrow screens keep normal page scrolling (see the max-width: 800px rules). */
@media (min-width: 801px) {
    html, body {
        height: 100%;
        overflow: hidden;
    }

    body {
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }

    body > * {
        flex: none;
    }

    body > .workspace {
        flex: 1 1 0;
        height: auto;
        min-height: 0;
    }

    body > #graphicsPanel {
        max-height: 35dvh;
        overflow: auto;
    }
}

/* Image viewer (image-viewer.js) */
.zv {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: calc(100% - var(--zv-ml, 0px));
    margin: 0 0 12px var(--zv-ml, 0px);
    border: 1px solid var(--border);
    background: var(--panel);
}

.zv[hidden] {
    display: none;
}

.zv-tabs {
    display: flex;
    overflow-x: auto;
    background: var(--tab);
    border-bottom: 1px solid var(--border);
}

.zv-tab {
    flex: none;
    max-width: 200px;
    padding: 6px 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 0;
    border-right: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}

    .zv-tab:hover {
        color: #ffffff;
    }

    .zv-tab.active {
        background: var(--panel);
        color: #ffffff;
        box-shadow: inset 0 -2px 0 var(--accent);
    }

.zv-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
}

.zv-btn {
    width: auto;
    min-width: 28px;
    padding: 0 8px;
    font-size: 13px;
    line-height: 1;
}

.zv-zoom {
    min-width: 48px;
    color: var(--muted);
    text-align: center;
}

.zv-spacer {
    flex: 1;
}

.zv-close:hover {
    background: #c42b1c;
    color: #ffffff;
}

.zv-frame {
    position: relative;
    min-height: 0;
}

.zv-stage {
    position: relative;
    height: min(360px, 60dvh);
    overflow: hidden;
    background: #111111;
    cursor: grab;
    touch-action: none;
    outline: none;
}

    .zv-stage:focus-visible {
        outline: 1px solid var(--accent);
        outline-offset: -1px;
    }

    .zv-stage.zv-dragging {
        cursor: grabbing;
    }

    .zv-stage img {
        position: absolute;
        top: 0;
        left: 0;
        max-width: none;
        max-height: none;
        transform-origin: 0 0;
        background: #ffffff;
        user-select: none;
        -webkit-user-drag: none;
    }

    .zv-stage img[hidden] {
        display: none;
    }

.zv-handle {
    position: absolute;
    z-index: 3;
    touch-action: none;
}

/* Edges: a thin strip with a small grip in the middle that lights up on hover. */
.zv-handle-n, .zv-handle-s { left: 14px; right: 14px; height: 8px; cursor: ns-resize; }
.zv-handle-e, .zv-handle-w { top: 14px; bottom: 14px; width: 8px; cursor: ew-resize; }
.zv-handle-n { top: -4px; }
.zv-handle-s { bottom: -4px; }
.zv-handle-e { right: -4px; }
.zv-handle-w { left: -4px; }

.zv-handle-n::after, .zv-handle-s::after, .zv-handle-e::after, .zv-handle-w::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 2px;
    background: var(--muted);
    opacity: 0.35;
    transform: translate(-50%, -50%);
    transition: opacity 0.15s, background 0.15s;
}

.zv-handle-n::after, .zv-handle-s::after { width: 32px; height: 3px; }
.zv-handle-e::after, .zv-handle-w::after { width: 3px; height: 32px; }

/* Corners: a small square that shows an L-shaped mark. */
.zv-handle-ne, .zv-handle-nw, .zv-handle-se, .zv-handle-sw { width: 16px; height: 16px; z-index: 4; }
.zv-handle-nw { top: -4px; left: -4px; cursor: nwse-resize; }
.zv-handle-ne { top: -4px; right: -4px; cursor: nesw-resize; }
.zv-handle-sw { bottom: -4px; left: -4px; cursor: nesw-resize; }
.zv-handle-se { bottom: -4px; right: -4px; cursor: nwse-resize; }

.zv-handle-ne::after, .zv-handle-nw::after, .zv-handle-se::after, .zv-handle-sw::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    border: 0 solid var(--muted);
    opacity: 0.45;
    transition: opacity 0.15s, border-color 0.15s;
}

.zv-handle-nw::after { top: 4px; left: 4px; border-width: 2px 0 0 2px; }
.zv-handle-ne::after { top: 4px; right: 4px; border-width: 2px 2px 0 0; }
.zv-handle-sw::after { bottom: 4px; left: 4px; border-width: 0 0 2px 2px; }
.zv-handle-se::after { bottom: 4px; right: 4px; border-width: 0 2px 2px 0; }

.zv-handle:hover::after {
    opacity: 1;
    background: var(--accent);
    border-color: var(--accent);
}

.zv-handle-ne:hover::after, .zv-handle-nw:hover::after,
.zv-handle-se:hover::after, .zv-handle-sw:hover::after {
    background: transparent;
}

/* While dragging a handle: no text selection, no stray pointer targets. */
body.zv-resizing {
    user-select: none;
    -webkit-user-select: none;
}

body.zv-resizing .CodeMirror {
    pointer-events: none;
}

@media (pointer: coarse) {
    .zv-handle-n, .zv-handle-s { height: 22px; }
    .zv-handle-e, .zv-handle-w { width: 22px; }
    .zv-handle-ne, .zv-handle-nw, .zv-handle-se, .zv-handle-sw { width: 30px; height: 30px; }
    .zv-btn { min-width: 36px; height: 36px; }
}

/* Maximized: fills the browser window. Escape or the restore button goes back. */
.zv.zv-max {
    position: fixed;
    margin: 0 !important;
    inset: 0;
    z-index: 1000;
    width: 100% !important;
    max-width: none;
    margin: 0;
    border: 0;
    background: var(--bg);
}

    .zv.zv-max .zv-frame {
        flex: 1 1 auto;
    }

    .zv.zv-max .zv-stage {
        height: 100% !important;
    }

    .zv.zv-max .zv-handle {
        display: none;
    }

/* Desktop: give the Graphics panel room while an image is open so the whole viewer is reachable. */
@media (min-width: 801px) {
    body > #graphicsPanel:has(.zv:not([hidden])) {
        max-height: 92dvh;
    }
}

/* Files panel: drag and drop highlight */
.file-tree.drop-target,
.file-tree summary.drop-target {
    outline: 1px dashed #4a9eff;
    outline-offset: -1px;
    background: rgba(74, 158, 255, 0.15);
}

/* Files panel: per-file "..." menu */
.file-row {
    display: flex;
    align-items: center;
}

    .file-row .file-item {
        flex: 1 1 auto;
        min-width: 0;
    }

.file-menu-btn {
    flex: none;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
}

    .file-row:hover .file-menu-btn,
    .file-menu-btn:focus-visible,
    .file-menu-btn[aria-expanded] {
        opacity: 1;
    }

    .file-menu-btn:hover {
        background: rgba(255, 255, 255, 0.12);
        color: #ffffff;
    }

@media (pointer: coarse) {
    .file-menu-btn {
        opacity: 1;
        width: 30px;
        height: 30px;
    }
}

.file-menu {
    position: fixed;
    z-index: 1100;
    min-width: 130px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #252526;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.file-menu-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

    .file-menu-item:hover,
    .file-menu-item:focus-visible {
        background: rgba(255, 255, 255, 0.1);
        outline: none;
    }

    .file-menu-item.danger:hover,
    .file-menu-item.danger:focus-visible {
        background: #c42b1c;
        color: #ffffff;
    }

/* Library browser */
.library-wrap { position: relative; display: inline-block; }
.library-panel { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: min(440px, 92vw); max-height: 70vh; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--panel, #1e1e1e); color: inherit; border: 1px solid var(--border, #444); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); }
.library-panel[hidden] { display: none; }
.lib-head { display: flex; justify-content: space-between; align-items: center; }
.lib-close { background: none; border: 0; color: inherit; cursor: pointer; font-size: 16px; padding: 2px 6px; }
.lib-search { width: 100%; box-sizing: border-box; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border, #444); background: rgba(127, 127, 127, 0.12); color: inherit; font: inherit; }
.lib-note { font-size: 0.85em; opacity: 0.8; padding: 6px 8px; border-left: 3px solid #d29922; background: rgba(210, 153, 34, 0.1); border-radius: 3px; }
.lib-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-chip { cursor: pointer; border: 1px solid #3794ff; background: rgba(55, 148, 255, 0.15); color: inherit; border-radius: 999px; padding: 2px 10px; font: inherit; font-size: 0.85em; }
.lib-list { overflow-y: auto; min-height: 80px; display: flex; flex-direction: column; gap: 2px; }
.lib-category { margin-top: 6px; font-size: 0.75em; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.65; }
.lib-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 1px solid rgba(127, 127, 127, 0.15); }
.lib-info { flex: 1; min-width: 0; }
.lib-name { font-weight: 600; }
.lib-desc { font-size: 0.85em; opacity: 0.75; }
.lib-status { font-size: 0.8em; color: #d29922; }
.lib-missing .lib-name { opacity: 0.7; }
.lib-action { min-width: 72px; cursor: pointer; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border, #555); background: transparent; color: inherit; font: inherit; }
.lib-action.lib-on { border-color: #3794ff; background: rgba(55, 148, 255, 0.2); }
.lib-action:disabled { cursor: not-allowed; opacity: 0.4; }
.lib-empty, .lib-foot { font-size: 0.85em; opacity: 0.7; padding: 6px 2px; }
.lib-import { display: inline-block; margin-top: 3px; padding: 1px 6px; border-radius: 4px; background: rgba(127, 127, 127, 0.18); font-size: 0.8em; }
.lib-facts { margin-top: 2px; font-size: 0.78em; opacity: 0.6; }
.lib-compat { margin-top: 2px; font-size: 0.8em; opacity: 0.85; }
.lib-example { margin-top: 3px; font-size: 0.8em; }
.lib-example summary { cursor: pointer; opacity: 0.8; }
.lib-example pre { margin: 3px 0 0; padding: 6px 8px; overflow-x: auto; background: rgba(127, 127, 127, 0.15); border-radius: 4px; }
.lib-builtin { font-size: 0.78em; opacity: 0.7; white-space: nowrap; padding: 2px 6px; border: 1px solid rgba(127, 127, 127, 0.4); border-radius: 10px; }
.lib-request { display: flex; gap: 8px; margin-top: 8px; }
.lib-request-name { flex: 1; min-width: 0; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border, #444); background: rgba(127, 127, 127, 0.12); color: inherit; font: inherit; }
.lib-request-result { margin-top: 4px; font-size: 0.85em; color: #3fb950; }

/* ---- Time limit control ---- */
.limit-wrap { display: inline-flex; align-items: center; gap: 6px; }
.limit-wrap input[type="number"] { width: 74px; }
.limit-wrap input[hidden] { display: none; }

/* ---- Live graphics window (tkinter / graphics.py) ---- */
.gfxwin { margin: 0 0 14px; max-width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #252526; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); overflow: hidden; }
.gfxwin[hidden] { display: none; }
.gfxbar { display: flex; align-items: center; gap: 10px; padding: 7px 10px; background: linear-gradient(#303031, #2a2a2b); border-bottom: 1px solid #1a1a1a; user-select: none; }
.gfxdots { display: inline-flex; gap: 6px; }
.gfxdots i { width: 11px; height: 11px; border-radius: 50%; background: #5a5a5c; }
.gfxwin[data-state="live"] .gfxdots i:nth-child(1) { background: #ff5f57; }
.gfxwin[data-state="live"] .gfxdots i:nth-child(2) { background: #febc2e; }
.gfxwin[data-state="live"] .gfxdots i:nth-child(3) { background: #28c840; }
.gfxtitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; text-align: center; color: #d4d4d4; }
.gfxstat { font: 11px Consolas, monospace; color: var(--muted); }
.gfxwin[data-state="live"] .gfxstat { color: #4ec9b0; }
.gfxwin[data-state="live"] .gfxstat::before { content: "\25CF  "; animation: gfxpulse 1.4s ease-in-out infinite; }
@keyframes gfxpulse { 50% { opacity: 0.3; } }
.gfxclose { background: none; border: 0; color: #aaa; font-size: 18px; line-height: 1; padding: 0 4px; cursor: pointer; border-radius: 4px; }
.gfxclose:hover { color: #fff; background: #c42b1c; }
.gfxstage { position: relative; display: flex; justify-content: center; padding: 14px; background: repeating-conic-gradient(#2d2d2e 0% 25%, #292929 0% 50%) 0 0 / 20px 20px; }
.gfxstage canvas { display: block; max-width: 100%; background: #fff; border-radius: 3px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5); outline: none; cursor: crosshair; image-rendering: auto; }
.gfxstage canvas:focus-visible { box-shadow: 0 0 0 2px var(--accent), 0 2px 12px rgba(0, 0, 0, 0.5); }
.gfxwin:not([data-state="live"]) canvas { cursor: default; }
.gfxveil { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(24, 24, 24, 0.72); color: #ddd; font-size: 15px; backdrop-filter: blur(2px); }
.gfxveil[hidden] { display: none; }
.gfxhint { padding: 5px 12px 7px; font-size: 11px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .gfxwin[data-state="live"] .gfxstat::before { animation: none; } }

/* ---- window buttons (red close, yellow minimize, green enlarge) and the ? tooltip ---- */
.gfxdots { display: inline-flex; gap: 6px; }
.gfxdots button { width: 12px; height: 12px; padding: 0; border: 0; border-radius: 50%; cursor: pointer; }
.gfxd-close { background: #ff5f57; } .gfxd-min { background: #febc2e; } .gfxd-max { background: #28c840; }
.gfxdots button:hover { filter: brightness(1.2); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25); }
.gfxwin.min .gfxstage, .gfxwin.min .gfxhint { display: none; }
.help-tip { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border: 1px solid #888; border-radius: 50%; font-size: 11px; color: #bbb; cursor: help; user-select: none; }
.help-tip:hover, .help-tip:focus { color: #fff; border-color: #fff; outline: none; }
.help-tip::after { content: attr(data-tip); position: absolute; z-index: 40; top: 24px; left: -10px; width: 260px; padding: 8px 10px; background: #252526; color: #ddd; border: 1px solid #555; border-radius: 6px; font-size: 12px; line-height: 1.4; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.12s; }
.help-tip:hover::after, .help-tip:focus::after { opacity: 1; }

/* ---- file tabs of multi-file examples ---- */
.file-tabs { display: flex; gap: 2px; padding: 4px 8px 0; background: var(--titlebar); border-bottom: 1px solid var(--border); overflow-x: auto; }
.file-tabs[hidden] { display: none; }
.file-tabs button { background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; padding: 5px 12px; font: 12px Consolas, monospace; cursor: pointer; }
.file-tabs button:hover { color: var(--text); }
.file-tabs button.active { color: #fff; border-bottom-color: var(--accent); background: rgba(255, 255, 255, 0.05); }

/* ---- Milestone 18: header links, View menu, examples gallery ---- */
.header-nav { display: flex; align-items: center; gap: 4px; }
.nav-link, .nav-btn { padding: 6px 12px; border: 0; border-radius: 4px; background: transparent; color: var(--text); font: 13px "Segoe UI", Arial, sans-serif; text-decoration: none; cursor: pointer; }
.nav-link:hover, .nav-btn:hover:not(:disabled), .nav-btn[aria-expanded="true"] { background: #2d2d2d; color: #fff; }
.view-wrap { position: relative; }
.view-menu { position: absolute; z-index: 60; top: 36px; right: 0; width: 250px; padding: 6px; background: #252526; border: 1px solid #454545; border-radius: 8px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55); }
.view-menu[hidden] { display: none; }
.view-menu label { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 5px; cursor: pointer; }
.view-menu label:hover { background: #2f3136; }
.view-menu input { accent-color: var(--accent); width: 15px; height: 15px; }
.view-reset { display: block; width: calc(100% - 8px); margin: 4px; padding: 6px; background: transparent; border-color: #3c3c3c; color: var(--muted); font-size: 12px; }
body.hide-explorer .files-pane { display: none; }
body.hide-callstack .debug-side { display: none; }
body.hide-console .debug-console-panel { display: none; }
@media (min-width: 801px) {
    body.hide-callstack .workspace { grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr); }
    body.hide-console .terminal-panel { grid-column: 1 / span 2; }
}
@media (max-width: 800px) { .header-nav { gap: 0; } .nav-link, .nav-btn { padding: 6px 8px; } }

.examples-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--accent); border-color: #1a8ad4; color: #fff; }
.examples-btn:hover:not(:disabled) { background: #1a8ad4; }
.examples-count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: rgba(0, 0, 0, 0.28); font-size: 11px; line-height: 18px; text-align: center; }
.examples-count:empty { display: none; }
body.exg-open { overflow: hidden; }
.exg-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 3vh 3vw; background: rgba(8, 9, 12, 0.72); backdrop-filter: blur(3px); }
.exg-overlay[hidden] { display: none; }
.exg-box { display: flex; flex-direction: column; width: min(1180px, 100%); height: min(780px, 100%); background: #1b1c20; border: 1px solid #3a3d45; border-radius: 14px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65); overflow: hidden; }
.exg-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px 10px; }
.exg-heading { margin: 0; font-size: 19px; font-weight: 600; color: #fff; }
.exg-search { flex: 1; max-width: 460px; margin-left: auto; padding: 9px 14px; background: #121316; border: 1px solid #3a3d45; border-radius: 20px; color: #eee; font: 14px "Segoe UI", Arial, sans-serif; }
.exg-search:focus { outline: 2px solid var(--accent); border-color: transparent; }
.exg-close { width: 34px; height: 34px; padding: 0; border-radius: 50%; background: transparent; border-color: transparent; font-size: 22px; line-height: 1; color: var(--muted); }
.exg-close:hover { background: #2d2f36 !important; color: #fff; }
.exg-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid #2b2d33; }
.exg-tab { padding: 9px 16px; background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); font-size: 14px; }
.exg-tab:hover:not(:disabled) { background: transparent; color: #fff; }
.exg-tab.on { color: #fff; border-bottom-color: var(--accent); }
.exg-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px 4px; }
.exg-chip { padding: 4px 12px; border-radius: 14px; background: #24262c; border-color: #33363e; color: #b9bcc4; font-size: 12px; }
.exg-chip.on { background: #0b5a91; border-color: #1a8ad4; color: #fff; }
.exg-scroll { flex: 1; overflow-y: auto; padding: 6px 20px 22px; }
.exg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.exg-group { grid-column: 1 / -1; margin: 14px 0 0; font-size: 12px; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; color: #7f8591; }
.exg-card { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 14px; text-align: left; background: #22242a; border: 1px solid #333640; border-radius: 10px; color: #d6d8dd; transition: transform 0.12s, border-color 0.12s, background 0.12s; }
.exg-card:hover:not(:disabled) { background: #272a31; border-color: var(--accent); transform: translateY(-2px); }
.exg-card.is-multi { border-color: #3d5a80; background: linear-gradient(160deg, #22262f, #1f2a3a); }
.exg-title { font-size: 14px; font-weight: 600; color: #fff; }
.exg-desc { font-size: 12px; line-height: 1.45; color: #a3a8b3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.exg-code { margin: 0; padding: 8px 10px; background: #14151a; border-radius: 6px; font: 11px/1.45 Consolas, monospace; color: #9cdcfe; white-space: pre; overflow: hidden; }
.exg-files { display: flex; flex-wrap: wrap; gap: 5px; }
.exg-file { padding: 2px 8px; background: #14151a; border: 1px solid #2f4764; border-radius: 4px; font: 11px Consolas, monospace; color: #9cdcfe; }
.exg-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.exg-tag { padding: 1px 8px; border-radius: 10px; font-size: 11px; background: #2d3038; color: #aab0bb; }
.exg-tag.multi { background: #1d4f82; color: #d8ecff; }
.exg-tag.gfx { background: #5a2c78; color: #f0dcff; }
.exg-tag.input { background: #6b4a12; color: #ffe8bd; }
.exg-empty { padding: 40px; text-align: center; color: var(--muted); }
@media (max-width: 800px) { .exg-overlay { padding: 0; } .exg-box { height: 100%; border-radius: 0; } .exg-head { flex-wrap: wrap; } .exg-search { max-width: none; flex-basis: 100%; order: 3; margin: 0; } }

/* ---- gallery previews: a picture of the running example instead of its code ---- */
.exg-visual { display: block; height: 132px; margin: -4px -4px 2px; border-radius: 8px; overflow: hidden; background: #14151a; }
.exg-visual.is-img { display: flex; align-items: center; justify-content: center; background: #0d0e12; }
.exg-visual img { display: block; width: 100%; height: 100%; object-fit: contain; }
.exg-visual.is-term { padding: 0; }
.exg-termbar { display: flex; gap: 5px; padding: 6px 8px; background: #23252c; }
.exg-termbar i { width: 8px; height: 8px; border-radius: 50%; }
.exg-termtext { display: block; padding: 7px 10px; font: 11px/1.4 Consolas, monospace; color: #b8e0b0; white-space: pre; overflow: hidden; }
.exg-visual.is-plain { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1d2a44, #2b1d44); }
.exg-glyph { font: 700 30px Consolas, monospace; color: rgba(255, 255, 255, 0.35); letter-spacing: 1px; }

/* ---- resizable panels ---- */
.gfx-grip { position: absolute; right: 4px; bottom: 4px; width: 16px; height: 16px; cursor: nwse-resize; border-radius: 3px; background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.55) 50%, rgba(255, 255, 255, 0.55) 58%, transparent 58%, transparent 72%, rgba(255, 255, 255, 0.55) 72%, rgba(255, 255, 255, 0.55) 80%, transparent 80%); opacity: 0.7; touch-action: none; }
.gfx-grip:hover, .gfx-grip:focus-visible { opacity: 1; outline: none; }
.split { position: absolute; z-index: 6; background: transparent; touch-action: none; transition: background 0.12s; }
.split:hover, .split.drag, .split:focus-visible { background: var(--accent); outline: none; }
.split-v { width: 6px; cursor: col-resize; }
.split-h { height: 6px; cursor: row-resize; }
.split[hidden] { display: none; }
body.resizing { user-select: none; }
body.resizing * { cursor: inherit !important; }
#graphicsPanel { position: relative; }
.gfx-split { position: absolute; left: 0; right: 0; top: -3px; height: 6px; z-index: 6; cursor: row-resize; background: transparent; touch-action: none; }
.gfx-split:hover, .gfx-split.drag, .gfx-split:focus-visible { background: var(--accent); outline: none; }
@media (min-width: 801px) {
    .workspace { position: relative; grid-template-columns: var(--c1, minmax(0, 1fr)) minmax(160px, 1fr) var(--aside, minmax(260px, 320px)); grid-template-rows: minmax(140px, 1fr) var(--row2, 260px); }
    body.hide-callstack .workspace { grid-template-columns: var(--c1, minmax(0, 1fr)) minmax(160px, 1fr); }
}
@media (max-width: 800px) { .split, .gfx-split { display: none !important; } }

.file-menu-sep { height: 1px; margin: 4px 2px; background: var(--border); }
.file-menu-item:disabled { opacity: 0.4; cursor: default; }
.file-menu-item:disabled:hover { background: transparent; }

/* Files panel: multi-selection, selection box, keyboard focus */
.files-pane:focus { outline: none; }
.file-tree { user-select: none; }
.file-tree .file-item.selected,
.file-tree summary.selected {
    background: rgba(0, 122, 204, 0.28);
    box-shadow: inset 2px 0 0 #4a9eff;
}
.file-tree .file-item.current.selected { background: rgba(0, 122, 204, 0.45); }
.select-box {
    position: fixed;
    z-index: 50;
    pointer-events: none;
    border: 1px solid #4a9eff;
    background: rgba(74, 158, 255, 0.18);
}

/* ---- Pop-out windows (popout.js) ---- */
.graphics-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 0 0 10px; }
.graphics-head h2 { margin: 0; }
.popout-bar { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.popout-btn, .popout-placeholder button, .popout-head button { padding: 3px 10px; background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 4px; font: 12px "Segoe UI", Arial, sans-serif; cursor: pointer; }
.popout-btn:hover, .popout-placeholder button:hover, .popout-head button:hover { background: #2d2d2d; color: #fff; }
.popout-btn[hidden] { display: none; }
.popout-placeholder { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 0 0 12px; border: 1px dashed var(--border); border-radius: 6px; color: var(--muted); font-size: 12px; }
.popout-body { margin: 0; background: #181818; color: var(--text); font: 13px "Segoe UI", Arial, sans-serif; }
.popout-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--titlebar); font-weight: 600; }
.popout-content { padding: 14px; }
.popout-content > #imageViewer, .popout-content > #gfxWindow { width: 100%; }
.popout-content .zv { height: calc(100vh - 90px); }

/* ---- View > Terminal ---- */
body.hide-terminal .terminal-panel { display: none; }
@media (min-width: 801px) {
    body.hide-terminal .debug-console-panel { grid-column: 1 / span 2; }
    body.hide-terminal.hide-console .workspace { grid-template-rows: minmax(140px, 1fr); }
}

/* ---- Toast: a short message that fades by itself ---- */
.toast { position: fixed; z-index: 90; left: 50%; bottom: 18px; transform: translate(-50%, 12px); max-width: min(92vw, 640px); padding: 10px 16px; background: #252526; color: #ddd; border: 1px solid #454545; border-left: 3px solid var(--accent); border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
