* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    background: #1e1e1e;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.main-layout {
    display: flex;
    align-items: stretch;
    height: 100vh;
    width: 100vw;
    gap: 12px;
    padding: 12px;
}

/* ---- left: code panel ---- */

.code-panel {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.editor-stage {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
}

/* ---- console: bottom half of the code panel ---- */

.console-panel {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    overflow: hidden;
}

.console-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    padding: 6px 10px;
    border-bottom: 1px solid #2a2a2a;
    color: #ccc;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.console-header .importButton {
    padding: 4px 10px;
    font-size: 11px;
}

.console-output {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 10px;
    font-family: "Fira Code", Consolas, Menlo, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    color: #9cdcae;
}

.console-line {
    white-space: pre-wrap;
    word-break: break-word;
}

.console-line.console-error {
    color: #ff6b6b;
}

.console-line.console-stats {
    color: #6ab7ff;
}

/* ---- middle: run/import/project controls, as a sidebar ---- */

.controls-sidebar {
    flex: 0 0 118px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    background: #181818;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px;
    overflow-y: auto;
}

.sidebar-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-square-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    border: 1px solid #444;
    border-radius: 6px;
    background: transparent;
    color: #ccc;
    cursor: pointer;
    padding: 10px 0;
}

.sidebar-square-btn:hover {
    background: #2a2a2a;
    border-color: #6400d7;
}

.sidebar-square-btn.active {
    background: #6400d7;
    border-color: #6400d7;
    color: #fff;
}

.sidebar-square-btn.run {
    background: #6400d7;
    border: none;
    color: #fff;
}

.sidebar-square-btn.run:hover {
    background: #7c1eff;
}

.sidebar-square-btn.stop {
    background: #333;
    border: none;
    color: #eee;
}

.sidebar-square-btn.stop:hover {
    background: #b8332f;
}

.sidebar-square-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.codeEditor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    resize: none;
    background: #111;
    color: #d4d4d4;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 12px;
    font-family: "Fira Code", Consolas, Menlo, monospace;
    font-size: 14px;
    line-height: 1.5;
    tab-size: 4;
}

.codeEditor:focus {
    outline: none;
    border-color: #6400d7;
}

.blockly-div {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none;
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    overflow: hidden;
}

.editor-stage.mode-blocks .codeEditor,
.editor-stage.mode-blocks .CodeMirror {
    display: none;
}

.editor-stage.mode-blocks .blockly-div {
    display: block;
}

/* ---- CodeMirror (replaces the plain textarea in text mode) ---- */

.editor-stage .CodeMirror {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #111;
    color: #d4d4d4;
    border: 1px solid #333;
    border-radius: 6px;
    font-family: "Fira Code", Consolas, Menlo, monospace;
    font-size: 14px;
    line-height: 1.5;
}

.editor-stage .CodeMirror-focused {
    outline: none;
    border-color: #6400d7;
}

.editor-stage .CodeMirror-gutters {
    background: #111;
    border-right: 1px solid #2a2a2a;
}

.editor-stage .CodeMirror-linenumber {
    color: #555;
}

.editor-stage .CodeMirror-cursor {
    border-left: 1px solid #999;
}

.editor-stage .CodeMirror-matchingbracket {
    color: #fff !important;
    background: #6400d766;
    border-radius: 2px;
}

.editor-stage .CodeMirror-selected {
    background: #6400d74d;
}

.editor-stage .CodeMirror-activeline-background {
    background: #2a2a2a;
}

/* ---- autocomplete popup (show-hint) - restyled to match the dark/  ---- */
/* ---- purple editor theme instead of CodeMirror's default light box ---- */

.CodeMirror-hints {
    position: absolute;
    z-index: 20;
    overflow: hidden auto;
    max-height: 20em;
    min-width: 120px;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    font-family: "Fira Code", Consolas, Menlo, monospace;
    font-size: 13px;
}

.CodeMirror-hint {
    margin: 0;
    padding: 4px 12px;
    white-space: pre;
    color: #d4d4d4;
    cursor: pointer;
    border-radius: 0;
}

li.CodeMirror-hint-active {
    background: #6400d7;
    color: #fff;
}

/* ---- text / blocks mode toggle ---- */

.modeToggle {
    display: flex;
    width: 100%;
    border: 1px solid #444;
    border-radius: 6px;
    overflow: hidden;
}

.modeToggle button {
    flex: 1 1 50%;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: #ccc;
    cursor: pointer;
}

.modeToggle button + button {
    border-left: 1px solid #444;
}

.modeToggle button:hover {
    background: #2a2a2a;
}

.modeToggle button.active {
    background: #6400d7;
    color: #fff;
}

.runningButton,
.stopButton {
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.runningButton {
    background: #6400d7;
    color: #fff;
}

.runningButton:hover {
    background: #7c1eff;
}

.stopButton {
    background: #333;
    color: #eee;
}

.stopButton:hover {
    background: #b8332f;
}

.stopButton:disabled,
.runningButton:disabled {
    opacity: 0.4;
    cursor: default;
}

.importButton {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid #444;
    border-radius: 6px;
    background: transparent;
    color: #ccc;
    cursor: pointer;
}

.importButton:hover {
    background: #2a2a2a;
    border-color: #6400d7;
}

.import-log {
    font-size: 12px;
    color: #777;
    white-space: normal;
    word-break: break-word;
}

.run-status {
    font-size: 13px;
    color: #888;
    text-align: center;
}

.run-status.is-running {
    color: #4caf50;
}

/* ---- right: graph panel, boxed to a normal aspect ratio instead of ---- */
/* ---- filling the whole viewport                                    ---- */

.graph-panel {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    width: min(52vw, 960px);
    height: 100%;
    gap: 12px;
}

.graph {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    flex: 0 0 auto;
    background: black;
    border: 1px solid #333;
    border-radius: 6px;
    overflow: hidden;
}

.graph canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ---- objects panel (below the game) ---- */

.objects-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #181818;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px;
    overflow: hidden;
}

.objects-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    color: #ccc;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.objects-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.add-object-btn {
    width: 24px;
    height: 24px;
    line-height: 1;
    border: none;
    border-radius: 5px;
    background: #6400d7;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.add-object-btn.small {
    background: transparent;
    border: 1px solid #444;
    font-size: 12px;
}

.add-object-btn.small:hover {
    background: #2a2a2a;
    border-color: #6400d7;
}

.add-object-btn:hover {
    background: #7c1eff;
}

#objects-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#objects-breadcrumb .crumb-back {
    cursor: pointer;
    color: #bb8dff;
    font-weight: 700;
}

#objects-breadcrumb .crumb-back:hover {
    color: #fff;
}

.objects-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
}

.object-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 76px;
    cursor: pointer;
    user-select: none;
}

.object-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    background: #111 repeating-linear-gradient(
        45deg,
        #161616,
        #161616 8px,
        #111 8px,
        #111 16px
    );
    border: 1px solid #333;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: border-color 0.1s ease;
}

.object-card:hover .object-thumb {
    border-color: #555;
}

.object-card.active .object-thumb {
    border-color: #6400d7;
    box-shadow: 0 0 0 1px #6400d7;
}

.object-card-main .object-thumb {
    background-image: none !important;
}

.object-icon {
    font-size: 24px;
    line-height: 1;
    opacity: 0.85;
    transition: opacity 0.1s ease;
}

.object-card-main .object-icon {
    font-size: 22px;
}

.object-card-main .object-name {
    font-weight: 600;
}

/* Default placeholder icon hides itself once a real sprite image has
   been set - the .has-sprite class (added in render()) switches the
   thumb over to showing background-image instead. */
.object-thumb.has-sprite .object-icon {
    opacity: 0;
    pointer-events: none;
}

/* ---- hover overlay: settings / image / delete ---- */

.object-thumb-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.62);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
}

.object-card:hover .object-thumb-overlay,
.object-card:focus-within .object-thumb-overlay {
    opacity: 1;
    pointer-events: auto;
}

.obj-action-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 5px;
    color: #eee;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.obj-action-btn:hover {
    background: #6400d7;
}

.obj-action-btn.obj-delete-btn:hover {
    background: #b8332f;
}

.object-name {
    max-width: 76px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    color: #ccc;
    font-size: 12px;
}

.object-card.active .object-name {
    color: #fff;
}

.object-name-input {
    width: 68px;
    background: #0d0d0d;
    border: 1px solid #6400d7;
    border-radius: 4px;
    outline: none;
    color: #eee;
    font-size: 12px;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    padding: 1px 4px;
}

.sidebar,
.log {
    display: none;
}

/* ---- folders & standalone images in the objects panel ----        */
/* Purely organizational - folders and images never affect generated */
/* code. They reuse .object-card/.object-thumb for a consistent grid. */

.folder-card .object-thumb {
    background: #201a2b repeating-linear-gradient(
        45deg,
        #241d30,
        #241d30 8px,
        #201a2b 8px,
        #201a2b 16px
    );
}

.folder-card .object-icon {
    font-size: 28px;
}

.image-card .object-thumb {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.folder-card.drop-target-hover .object-thumb {
    border-color: #6400d7;
    box-shadow: 0 0 0 2px #6400d7;
}

#objects-breadcrumb .drop-target-hover {
    background: #6400d74d;
    border-radius: 4px;
    outline: 1px dashed #bb8dff;
}

.object-card[draggable="true"] {
    cursor: grab;
}

.object-card[draggable="true"]:active {
    cursor: grabbing;
}