/* Circuit Lab - palette: deep slate + phosphor + amber. Distinctive lab/oscilloscope vibe. */

:root {
    --bg: #0a0e14;
    --bg-soft: #0f141c;
    --bg-elev: #141a24;
    --line: #1e2632;
    --line-soft: #161d27;
    --text: #d7e0ee;
    --text-dim: #8693a8;
    --text-mute: #5b6678;
    --phos: #34d399;
    /* phosphor green */
    --phos-soft: #34d39922;
    --amber: #f6c177;
    --red: #f87171;
    --blue: #7aa2f7;
    --shadow: 0 4px 24px -8px rgba(0, 0, 0, .6);
    --font-mono: ui-monospace, "JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace;
    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    /* faint grid like oscilloscope reticle */
    background-image:
        linear-gradient(var(--line-soft) 1px, transparent 1px),
        linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
    background-size: 32px 32px, 32px 32px;
    background-position: -1px -1px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* TOP BAR */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(to bottom, #0d121a, #0a0e14);
    height: 52px;
    flex-shrink: 0;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--phos);
    font-weight: 600;
    letter-spacing: .02em;
}

.brand svg {
    color: var(--phos);
    filter: drop-shadow(0 0 6px var(--phos-soft));
}

.brand-name {
    font-size: 15px;
    color: var(--text);
}

.brand-tag {
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: .04em;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pill {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    color: var(--text-dim);
    white-space: nowrap;
}

.pill-warn {
    color: var(--amber);
    border-color: #f6c17744;
}

.pill-ok {
    color: var(--phos);
    border-color: var(--phos-soft);
}

.pill-err {
    color: var(--red);
    border-color: #f8717144;
}

/* BUTTONS */
.ghost-btn {
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: var(--font-mono);
    cursor: pointer;
    display: inline-flex;
    gap: 6px;
    align-items: center;
    transition: border-color .15s, background .15s, color .15s;
}

.ghost-btn:hover:not([disabled]) {
    border-color: var(--phos);
    color: var(--phos);
}

.ghost-btn[disabled] {
    opacity: .45;
    cursor: not-allowed;
}

.ghost-btn.small {
    padding: 4px 9px;
    font-size: 11px;
}

.primary-btn {
    background: var(--phos);
    color: #062014;
    border: none;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    letter-spacing: .02em;
}

.primary-btn:hover {
    filter: brightness(1.08);
}

.primary-btn[disabled] {
    opacity: .5;
    cursor: not-allowed;
}

/* LAYOUT */
.layout {
    flex: 1;
    display: grid;
    grid-template-columns: var(--col-chat, 400px) 6px 1fr;
    gap: 0;
    padding: 14px;
    min-height: 0;
}

@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 6px 1fr;
    }
}

.panel {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-elev);
}

.panel-header h2 {
    margin: 0;
    font-size: 12px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--text-dim);
    font-weight: 600;
}

.sim-actions {
    display: flex;
    gap: 6px;
}

/* CHAT */
.chat-panel {
    min-width: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-thumb {
    background: #1d2735;
    border-radius: 4px;
}

.msg {
    border-radius: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
}

.msg p {
    margin: 0 0 6px;
}

.msg p:last-child {
    margin-bottom: 0;
}

.msg-system {
    background: var(--bg-elev);
    color: var(--text-dim);
}

.msg-user {
    background: #131b27;
    border-color: #1f2a3a;
    align-self: flex-end;
    max-width: 92%;
}

.msg-user::before {
    content: "you";
    display: block;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
    letter-spacing: .14em;
    margin-bottom: 4px;
}

.msg-assistant {
    background: #0d141c;
    border-color: #1a2533;
    border-left: 2px solid var(--phos);
}

.msg-assistant::before {
    content: "llm";
    display: block;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--phos);
    letter-spacing: .14em;
    margin-bottom: 4px;
}

.msg-error {
    background: #1a0d10;
    border-color: #3a1f23;
    border-left: 2px solid var(--red);
    color: #f8b9b9;
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: pre-wrap;
}

.examples {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.example {
    background: transparent;
    border: 1px dashed #2a3548;
    color: var(--text-dim);
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font-mono);
    transition: border-color .15s, color .15s;
}

.example:hover {
    border-color: var(--phos);
    color: var(--phos);
}

.msg code {
    font-family: var(--font-mono);
    background: #0a0f17;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11.5px;
    color: var(--phos);
}

.proj-summary {
    margin-top: 8px;
    border-top: 1px dashed #233044;
    padding-top: 8px;
    font-size: 11.5px;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

.proj-summary b {
    color: var(--phos);
    font-weight: 500;
}

.proj-actions {
    margin-top: 8px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.link-btn {
    background: none;
    border: none;
    color: var(--phos);
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    letter-spacing: .02em;
}
.link-btn:hover { text-decoration: underline; }

.file-chip {
    display: inline-block;
    background: #0a0f17;
    border: 1px solid #1d2735;
    color: var(--text-dim);
    padding: 1px 7px;
    margin: 2px 4px 0 0;
    border-radius: 3px;
    font-size: 10.5px;
}

/* typing cursor */
.cursor::after {
    content: "▍";
    color: var(--phos);
    animation: blink 1s steps(1) infinite;
    margin-left: 1px;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* COMPOSER */
.composer {
    border-top: 1px solid var(--line);
    padding: 10px 12px;
    background: var(--bg-elev);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composer textarea {
    resize: none;
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 6px;
    padding: 10px;
    font-family: var(--font-sans);
    font-size: 13px;
    outline: none;
    transition: border-color .15s;
}

.composer textarea:focus {
    border-color: var(--phos);
}

.composer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hint {
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 11px;
}

#send-btn {
    background: var(--phos);
    color: #062014;
    border: none;
    padding: 7px 14px;
    border-radius: 6px;
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    letter-spacing: .03em;
}

#send-btn:hover:not([disabled]) {
    filter: brightness(1.08);
}

#send-btn[disabled] {
    background: #1d2735;
    color: var(--text-mute);
    cursor: not-allowed;
}

/* SIM */
.sim-panel {
    min-width: 0;
}

.iframe-wrap {
    flex: 1;
    min-height: 240px;
    background: #000;
    border-bottom: 1px solid var(--line);
    position: relative;
}

#wokwi-embed {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.serial {
    height: var(--serial-h, 200px);
    display: flex;
    flex-direction: column;
    background: #060a10;
    flex-shrink: 0;
}

.serial-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--line);
    letter-spacing: .1em;
    text-transform: uppercase;
}

.serial-header .dot {
    width: 7px;
    height: 7px;
    background: var(--phos);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--phos);
}

.serial-header button {
    margin-left: auto;
}

.serial-out {
    flex: 1;
    margin: 0;
    padding: 10px 14px;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--phos);
    text-shadow: 0 0 5px rgba(52, 211, 153, .35);
    white-space: pre-wrap;
    word-break: break-all;
}

.serial-out::-webkit-scrollbar {
    width: 8px;
}

.serial-out::-webkit-scrollbar-thumb {
    background: #1d2735;
    border-radius: 4px;
}

/* MODAL */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 5, 10, .72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-card {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 10px;
    width: 100%;
    max-width: 480px;
    padding: 18px 20px 16px;
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .7);
    max-height: 90vh;
    overflow: auto;
}

.modal-card.wide {
    max-width: 900px;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.modal-head h3 {
    margin: 0;
    font-size: 13px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--phos);
    font-weight: 600;
}

.modal-sub {
    color: var(--text-dim);
    font-size: 12px;
    margin: 0 0 14px;
}

.modal-card label {
    display: block;
    margin: 10px 0;
}

.modal-card label>span {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: .08em;
    color: var(--text-dim);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.modal-card input[type=text],
.modal-card input[type=password] {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 11px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    outline: none;
}

.modal-card input:focus {
    border-color: var(--phos);
}

.presets summary {
    cursor: pointer;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: .08em;
    padding: 6px 0;
    text-transform: uppercase;
}

.preset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 6px;
}

.preset {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 5px;
    color: var(--text-dim);
    padding: 8px;
    text-align: left;
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: pointer;
}

.preset:hover {
    border-color: var(--phos);
    color: var(--phos);
}

@media (max-width: 540px) {
    .preset-grid {
        grid-template-columns: 1fr;
    }
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

/* ── files explorer ─ */
.files-head-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.primary-btn.small {
    padding: 5px 10px;
    font-size: 11px;
}

.files-count {
    margin-left: 6px;
    font-size: 11px;
    color: var(--text-mute);
    letter-spacing: .04em;
    font-weight: 400;
    text-transform: none;
}

.files-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 12px;
    margin-top: 10px;
    height: 64vh;
}

.files-tree {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: auto;
    padding: 6px 4px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.files-tree::-webkit-scrollbar { width: 8px; }
.files-tree::-webkit-scrollbar-thumb { background: #1d2735; border-radius: 4px; }

.tree-node {
    user-select: none;
}

.tree-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px 3px 4px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-dim);
    white-space: nowrap;
}
.tree-row:hover { color: var(--text); background: #131b27; }
.tree-row.active {
    background: var(--phos-soft);
    color: var(--phos);
}
.tree-row.folder { color: var(--text); }
.tree-row .caret {
    display: inline-block;
    width: 10px;
    text-align: center;
    color: var(--text-mute);
    transition: transform .12s;
}
.tree-row.collapsed .caret { transform: rotate(-90deg); }
.tree-row .icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--text-mute);
}
.tree-row.folder .icon { color: var(--amber); }
.tree-row .name { overflow: hidden; text-overflow: ellipsis; }
.tree-children {
    margin-left: 12px;
    border-left: 1px dashed #1d2735;
    padding-left: 4px;
}
.tree-children.hidden { display: none; }

.files-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.files-pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
}

.files-active-path {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--phos);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.files-view {
    margin: 0;
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 0 0 6px 6px;
    padding: 12px;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    white-space: pre;
    min-height: 0;
}

@media (max-width: 720px) {
    .files-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    .files-tree { max-height: 200px; }
    .files-view { height: 40vh; }
}
/* multi-session picker in chat panel header */
.session-bar {
    display: flex;
    align-items: center;
    gap: 6px;
}
.session-select {
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 3px 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    max-width: 180px;
}
.session-select:focus {
    outline: 1px solid var(--phos);
    border-color: var(--phos);
}

/* searchable session combobox */
.session-combo {
    position: relative;
}
.session-input {
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 3px 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    width: 180px;
}
.session-input:focus {
    outline: 1px solid var(--phos);
    border-color: var(--phos);
}
.session-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 220px;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: var(--shadow);
    z-index: 30;
}
.session-list.hidden {
    display: none;
}
.session-item {
    padding: 5px 8px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    border-bottom: 1px solid var(--line-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-item:last-child {
    border-bottom: none;
}
.session-item.active {
    color: var(--phos);
}
.session-item.focused,
.session-item:hover {
    background: var(--phos-soft);
}
.session-item .session-meta {
    color: var(--text-mute);
    font-size: 10px;
    margin-left: 6px;
}
.session-empty {
    padding: 8px;
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 12px;
    font-style: italic;
}

.ver-divider {
    width: 1px;
    align-self: stretch;
    background: var(--line);
    margin: 0 2px;
}
.ver-label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-mute);
    min-width: 38px;
    text-align: center;
}
.ver-label.dirty {
    color: var(--amber);
}

/* Drag-to-resize splitters between chat/sim and between iframe/serial. */
.splitter {
    background: transparent;
    position: relative;
    z-index: 5;
    flex-shrink: 0;
}
.splitter::before {
    content: '';
    position: absolute;
    background: var(--line);
    transition: background .15s;
}
.splitter:hover::before,
.splitter.dragging::before {
    background: var(--phos);
}
.splitter-h {
    cursor: col-resize;
    width: 6px;
}
.splitter-h::before {
    top: 18px;
    bottom: 18px;
    left: 2px;
    right: 2px;
    border-radius: 2px;
}
.splitter-v {
    cursor: row-resize;
    height: 6px;
}
.splitter-v::before {
    left: 24px;
    right: 24px;
    top: 2px;
    bottom: 2px;
    border-radius: 2px;
}
body.is-resizing,
body.is-resizing * {
    user-select: none;
    pointer-events: none;
}
body.is-resizing .splitter {
    pointer-events: auto;
}
/* While dragging, mask the iframe so pointer events don't get swallowed by Wokwi. */
body.is-resizing .iframe-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
}

@media (max-width: 960px) {
    .splitter-h {
        width: auto;
        height: 6px;
        cursor: row-resize;
    }
    .splitter-h::before {
        top: 2px;
        bottom: 2px;
        left: 24px;
        right: 24px;
    }
}
