/* Zig-themed palette: the signature Zig orange (#f7a41d, the logo colour) as the
   dominant accent over warm-neutral darks. */
:root {
    --base: #1b1a17;
    --mantle: #151412;
    --crust: #100f0d;
    --surface0: #2a2825;
    --surface1: #3b3833;
    --text: #eae6df;
    --subtext: #b6b0a6;
    --overlay: #746f66;
    --accent: #f7a41d;
    --accent-dim: #e0982e;
    --green: #9bb556;
    --red: #e5534b;
    --yellow: #f5c542;
}

* {
    box-sizing: border-box;
}

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

body {
    display: flex;
    flex-direction: column;
    font-family: ui-monospace, "Cascadia Code", "JetBrains Mono", monospace;
    font-size: 14px;
    line-height: 1.5;
    background: var(--base);
    color: var(--text);
}

/* Force both colors so selected text stays legible -- the default highlight
   leaves the nav's accent text low-contrast on its own background. */
::selection {
    background: var(--surface1);
    color: var(--text);
}

nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem;
    height: 3rem;
    background: var(--crust);
    border-bottom: 1px solid var(--surface0);
    flex: 0 0 auto;
}

nav .brand {
    color: var(--accent);
    font-weight: 700;
    margin-right: 1rem;
}

nav button {
    appearance: none;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--subtext);
    font: inherit;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
}

nav button:hover {
    color: var(--text);
}

nav button.active {
    color: var(--accent-dim);
    border-bottom-color: var(--accent-dim);
}

nav select {
    appearance: none;
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--surface1);
    border-radius: 4px;
    color: var(--subtext);
    font: inherit;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
}

nav select:hover {
    color: var(--text);
    border-color: var(--overlay);
}

nav select option {
    background: var(--crust);
    color: var(--text);
}

main {
    flex: 1;
    min-height: 0;
    display: flex;
}

.view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.view[hidden] {
    display: none;
}

#repl-output {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

#repl-output .echo {
    color: var(--accent-dim);
}

#repl-form {
    display: flex;
    align-items: flex-start;
    border-top: 1px solid var(--surface0);
    background: var(--mantle);
}

#repl-form .prompt {
    padding: 0.7rem 0.5rem 0 1rem;
    color: var(--accent-dim);
}

/* Auto-grows with its content (height set from scrollHeight in app.js) up to a
   cap, then scrolls -- so multi-line input (a fn, a paste) stays visible. */
#repl-input {
    flex: 1;
    background: transparent;
    border: none;
    color: inherit;
    font: inherit;
    line-height: 1.5;
    padding: 0.7rem 1rem 0.7rem 0;
    outline: none;
    resize: none;
    overflow-y: auto;
    max-height: 12rem;
}

#explorer-view {
    flex-direction: row;
}

#editor {
    flex: 0 0 42%;
    min-width: 16rem;
    resize: none;
    background: var(--mantle);
    border: none;
    color: inherit;
    font: inherit;
    padding: 1rem;
    outline: none;
    tab-size: 4;
}

#panels {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Drag handle between the editor and the panels. Transparent grab strip; the
   visible divider is the border. (The section boundaries are dragged via their
   labelled headers -- see `.pane > h2` below.) */
.gutter {
    flex: none;
    background: transparent;
}

.gutter:hover {
    background: var(--surface1);
}

.gutter-col {
    width: 5px;
    cursor: col-resize;
    border-left: 1px solid var(--surface0);
}

/* Each section opens with its label sitting on a 1px rule -- `-- ZIR -------`
   -- using the same divider line as the nav and the editor split */
.pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Result sizes to its short content; the two big panes share the rest until a
   gutter pins one to a fixed height. */
#pane-result {
    flex: 0 0 auto;
}

#pane-ast,
#pane-zir {
    flex: 1 1 0;
}

.pane > h2 {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    padding: 0.7rem 1rem 0.4rem;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--subtext);
}

.pane > h2::before {
    content: "";
    width: 1.25rem;
    border-top: 1px solid var(--surface0);
}

.pane > h2::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--surface0);
}

/* Every section but the first has a section above it, so its labelled header
   doubles as the drag handle for that boundary. */
.pane:not(:first-child) > h2 {
    cursor: row-resize;
}

.pane:not(:first-child) > h2:hover {
    color: var(--text);
}

.pane:not(:first-child) > h2:hover::before,
.pane:not(:first-child) > h2:hover::after {
    border-color: var(--overlay);
}

.pane > pre {
    margin: 0;
    padding: 0.4rem 1rem 0.8rem;
    min-height: 0;
    overflow: auto;
    white-space: pre;
}

#pane-result > h2 {
    color: var(--green);
}

#pane-result > pre {
    font-size: 15px;
    white-space: pre-wrap;
    word-break: break-word;
}

.nodes {
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.6rem 1rem;
}

.node {
    display: flex;
    gap: 0.6rem;
    align-items: baseline;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    cursor: default;
}

.node .tag {
    color: var(--accent);
    font-size: 11px;
    min-width: 8rem;
}

.node .frag {
    color: var(--text);
    white-space: pre;
}

.tree-node {
    display: flex;
    flex-direction: column;
}

.tree-node > .node {
    align-self: flex-start;
}

.tree-children {
    display: flex;
    flex-direction: column;
    margin-left: 0.8rem;
    padding-left: 0.4rem;
    border-left: 1px solid var(--surface0);
}

.node.active {
    background: var(--accent-dim);
}

.node.active .tag,
.node.active .frag {
    color: var(--crust);
}

.node.linked {
    background: var(--surface0);
}

#environment-view {
    flex-direction: row;
}

#file-tree {
    flex: 0 0 14rem;
    min-width: 9rem;
    display: flex;
    flex-direction: column;
    background: var(--mantle);
    border-right: 1px solid var(--surface0);
}

.tree-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--subtext);
    border-bottom: 1px solid var(--surface0);
}

.tree-header button {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--subtext);
    font: inherit;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.3rem;
}

.tree-header button:hover {
    color: var(--accent);
}

#file-list {
    list-style: none;
    margin: 0;
    padding: 0.25rem 0;
    overflow-y: auto;
}

.tree-sub {
    list-style: none;
    margin: 0 0 0 0.7rem;
    padding-left: 0.6rem;
    border-left: 1px solid var(--surface0);
}

.tree-sub > li {
    position: relative;
}

.tree-sub > li::before {
    content: "";
    position: absolute;
    left: -0.6rem;
    top: 0.85em;
    width: 0.5rem;
    border-top: 1px solid var(--surface0);
}

.tree-sub > li:last-child::after {
    content: "";
    position: absolute;
    left: -0.7rem;
    top: calc(0.85em + 1px);
    bottom: 0;
    width: 2px;
    background: var(--mantle);
}

summary.dir-name {
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    color: var(--subtext);
    white-space: nowrap;
    user-select: none;
}

summary.dir-name:hover {
    color: var(--text);
}

summary.dir-name::marker {
    color: var(--overlay);
}

.tree-file {
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-file:hover {
    background: var(--surface0);
}

.tree-file.active {
    background: var(--surface1);
    color: var(--accent);
}

.context-menu {
    position: fixed;
    z-index: 10;
    min-width: 9rem;
    padding: 0.25rem;
    display: flex;
    flex-direction: column;
    background: var(--surface0);
    border: 1px solid var(--surface1);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.context-menu[hidden] {
    display: none;
}

.context-menu button {
    appearance: none;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text);
    font: inherit;
    text-align: left;
    padding: 0.35rem 0.6rem;
    cursor: pointer;
}

.context-menu button:hover {
    background: var(--surface1);
    color: var(--accent);
}

#env-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

#env-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--mantle);
    border-bottom: 1px solid var(--surface0);
}

#env-active {
    margin-right: auto;
    color: var(--subtext);
    font-size: 13px;
}

#env-toolbar button {
    appearance: none;
    background: var(--surface0);
    border: 1px solid var(--surface1);
    border-radius: 4px;
    color: var(--text);
    font: inherit;
    padding: 0.2rem 0.7rem;
    cursor: pointer;
}

#env-toolbar button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

#env-editor {
    flex: 1 1 60%;
    resize: none;
    background: var(--mantle);
    border: none;
    color: inherit;
    font: inherit;
    padding: 1rem;
    outline: none;
    tab-size: 4;
}

#env-output {
    flex: 0 1 40%;
    margin: 0;
    padding: 0.75rem 1rem;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--crust);
    border-top: 1px solid var(--surface0);
}

@media (max-width: 720px) {
    #explorer-view {
        flex-direction: column;
    }

    #editor {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--surface0);
    }
}
