@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── tokens ── */
:root {
    --bg:      #111;
    --panel:   #1c1c1c;
    --inset:   #141414;
    --border:  #2a2a2a;
    --border-2:#222;

    --accent:  #e8a44a;   /* amber — used only on Run */

    --t1: #e4e4e4;   /* primary text */
    --t2: #888;      /* secondary */
    --t3: #444;      /* muted / section labels */

    --green:  #5a9f6e;
    --blue:   #4e85b8;
    --yellow: #b89a4e;
    --red:    #b85555;
    --purple: #8e6bb0;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--t1);
    font-size: 13px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── header ── */
.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 46px;
    padding: 0 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.home-link {
    text-decoration: none;
    color: inherit;
}

.app-header h1 {
    font-size: 14px;
    font-weight: 600;
    color: var(--t1);
    letter-spacing: -0.2px;
}

.app-header p {
    font-size: 12px;
    color: var(--t2);
    border-left: 1px solid var(--border);
    padding-left: 16px;
    margin-left: 4px;
}

/* ── layout ── */
.app-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    flex: 1;
    min-height: 0;
}

.editor-panel,
.runtime-panel {
    background: var(--panel);
    padding: 16px;
    overflow-y: auto;
}

.editor-panel {
    display: flex;
    flex-direction: column;
}

/* ── panel headings ── */
.panel-header { margin-bottom: 12px; }

.panel-header h2 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--t2);
}

.editor-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 200px;
}

/* ── textarea ── */
#code-editor {
    width: 100%;
    height: 100%;
    min-height: 300px;
    resize: none;
    padding: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.65;
    background: var(--inset);
    color: var(--t1);
    border: 1px solid var(--border);
    border-radius: 3px;
    outline: none;
    caret-color: var(--accent);
    transition: border-color 0.15s;
    white-space: pre;
    overflow: auto;
}
#code-editor:focus { border-color: #3a3a3a; }

/* ── highlighter overlay ── */
#code-highlighter {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.65;
    background: var(--inset);
    color: var(--t1);
    border: 1px solid var(--border);
    border-radius: 3px;
    pointer-events: none;
    overflow: hidden;
    margin: 0;
}
#code-highlighter.hidden { display: none; }

#code-highlighter div {
    min-height: 1.65em;
    white-space: pre;
}

.highlight-line {
    background-color: rgba(232, 164, 74, 0.25);
    border-radius: 2px;
}

/* ── controls ── */
.editor-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    align-items: center;
}

/* ── narrator box ── */
.narrator-box {
    background: var(--inset);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 12px;
    font-size: 13px;
    color: var(--accent);
    min-height: 44px;
    line-height: 1.5;
    font-family: 'JetBrains Mono', monospace;
}

.editor-controls button {
    padding: 5px 13px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    border-radius: 3px;
    border: 1px solid var(--border);
    background: #222;
    color: var(--t2);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.editor-controls button:hover {
    background: #2a2a2a;
    color: var(--t1);
}

#run-btn {
    background: var(--accent);
    color: #111;
    border-color: var(--accent);
    font-weight: 600;
}
#run-btn:hover { background: #d4943c; border-color: #d4943c; color: #111; }

.editor-controls select {
    padding: 5px 10px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    background: #222;
    color: var(--t2);
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    outline: none;
}
.editor-controls select option { background: #222; color: var(--t1); }

/* ── error ── */
.error-message {
    margin-top: 8px;
    padding: 6px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: #c47070;
    background: rgba(180,80,80,0.07);
    border-left: 2px solid #774040;
    display: none;
}
.error-message:not(:empty) { display: block; }

/* ── runtime panel ── */
.runtime-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-title {
    font-size: 11px;
    font-weight: 500;
    color: var(--t2);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 5px;
}

.runtime-container {
    min-height: 34px;
    background: var(--inset);
    border: 1px solid var(--border-2);
    border-radius: 3px;
    padding: 5px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.runtime-container div {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    padding: 3px 6px;
    border-radius: 2px;
    animation: fadein 0.12s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--t2);
    background: #1e1e1e;
    border: 1px solid #282828;
}

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* per-section item colors — subtle, muted */
#call-stack div    { color: #6c9bbf; border-color: #1e2a36; background: #131d26; }
#web-apis div      { color: #b8973a; border-color: #302614; background: #201900; }
#promises div      { color: #8b6aaa; border-color: #281e36; background: #1a1224; }
#microtask-queue div { color: #5a9970; border-color: #1a2e20; background: #0d1f12; }
#task-queue div    { color: #7a8a9a; border-color: #222a30; background: #131920; }
#event-loop div    { color: #c4826e; border-color: #38211b; background: #261612; }

/* ── bottom panel ── */
.bottom-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    border-top: 1px solid var(--border);
}

.explanation-panel, .console-panel {
    background: var(--panel);
    padding: 14px 16px;
}
.explanation-panel .panel-header,
.console-panel .panel-header { margin-bottom: 8px; }

#console-output {
    min-height: 80px;
    padding: 10px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.7;
    background: var(--inset);
    color: #6a9f6a;
    border: 1px solid var(--border-2);
    border-radius: 3px;
    overflow-x: auto;
    white-space: pre-wrap;
}

/* ── scrollbars ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2e2e2e; border-radius: 2px; }

@media (max-width: 860px) {
    .app-container, .bottom-panel { grid-template-columns: 1fr; }
}

/* ── footer ── */
footer {
    padding: 10px 32px;
    font-size: 12px;
    color: var(--t2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--panel);
    border-top: 1px solid var(--border);
}

footer a { color: var(--t2); text-decoration: none; }
footer a:hover { color: var(--t1); }