/* =========================================
   CSS Variables — Temas dark / light
   ========================================= */
:root {
    --bg-primary:    #1e1e2e;
    --bg-secondary:  #181825;
    --bg-panel:      #24273a;
    --bg-header:     #1e2030;
    --bg-output:     #181825;
    --bg-line-nums:  #1e1e2e;
    --border:        #363a4f;
    --text-primary:  #cdd6f4;
    --text-secondary:#a6adc8;
    --text-muted:    #6c7086;
    --accent:        #89b4fa;
    --accent-hover:  #74c7ec;
    --run-bg:        #a6e3a1;
    --run-color:     #1e1e2e;
    --run-hover:     #94e2d5;
    --error-color:   #f38ba8;
    --warn-color:    #f9e2af;
    --log-color:     #a6e3a1;
    --result-color:  #cba6f7;
    --badge-bg:      #313244;
    --kbd-bg:        #313244;
    --shadow:        0 4px 24px rgba(0,0,0,0.4);
    --radius:        8px;
    --radius-sm:     4px;
    --font-mono:     'Fira Code', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    --font-ui:       'Segoe UI', system-ui, -apple-system, sans-serif;
    --transition:    0.2s ease;
}

[data-theme="light"] {
    --bg-primary:    #eff1f5;
    --bg-secondary:  #e6e9ef;
    --bg-panel:      #dce0e8;
    --bg-header:     #ccd0da;
    --bg-output:     #e6e9ef;
    --bg-line-nums:  #dce0e8;
    --border:        #bcc0cc;
    --text-primary:  #4c4f69;
    --text-secondary:#5c5f77;
    --text-muted:    #9ca0b0;
    --accent:        #1e66f5;
    --accent-hover:  #04a5e5;
    --run-bg:        #40a02b;
    --run-color:     #eff1f5;
    --run-hover:     #179299;
    --error-color:   #d20f39;
    --warn-color:    #df8e1d;
    --log-color:     #40a02b;
    --result-color:  #8839ef;
    --badge-bg:      #ccd0da;
    --kbd-bg:        #ccd0da;
    --shadow:        0 4px 24px rgba(0,0,0,0.1);
}

/* =========================================
   Reset & Base
   ========================================= */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: var(--font-ui);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: background-color var(--transition), color var(--transition);
}

/* =========================================
   App Layout
   ========================================= */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* =========================================
   Header
   ========================================= */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 52px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 1.4rem;
}

.title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.badge {
    background-color: var(--badge-bg);
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* =========================================
   Icon Buttons
   ========================================= */
.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 1rem;
    width: 34px;
    height: 34px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition), color var(--transition);
}

.icon-btn:hover {
    background-color: var(--badge-bg);
    color: var(--text-primary);
}

.icon-btn.small {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
}

/* =========================================
   Main — two panels side by side
   ========================================= */
.main {
    display: flex;
    flex: 1;
    gap: 0;
    overflow: hidden;
    padding: 16px;
    gap: 12px;
}

/* =========================================
   Panels
   ========================================= */
.panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    min-width: 0;
}

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

.panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.editor-info {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* =========================================
   Editor
   ========================================= */
.editor-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    background-color: var(--bg-secondary);
}

.line-numbers {
    padding: 12px 8px;
    background-color: var(--bg-line-nums);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    text-align: right;
    user-select: none;
    border-right: 1px solid var(--border);
    min-width: 40px;
    overflow: hidden;
    white-space: pre;
}

/* =========================================
   Editor — highlight overlay pattern
   ========================================= */
.editor-highlight-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden;
    background-color: var(--bg-secondary);
}

/* ── Highlight layer (behind) ── */
#highlight-layer {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    tab-size: 2;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: auto;
    background: transparent;
    border: none;
    pointer-events: none;
    /* Match textarea scrolling */
    overflow: hidden;
}

#highlight-layer code {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    tab-size: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: transparent !important;
    padding: 0 !important;
    /* Override hljs background */
}

/* ── Override hljs container background ── */
.hljs {
    background: transparent !important;
}

#code-editor {
    position: absolute;
    inset: 0;
    padding: 12px 14px;
    background: transparent;
    color: transparent;
    caret-color: var(--accent);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    tab-size: 2;
    overflow: auto;
    z-index: 1;
    /* Selection color so selected text is still visible */
    -webkit-text-fill-color: transparent;
}

#code-editor::placeholder {
    color: transparent;
    -webkit-text-fill-color: transparent;
}

/* Placeholder visible cuando el editor está vacío — lo ponemos en el pre */
.editor-highlight-wrapper:has(#code-editor:placeholder-shown) #highlight-layer::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
    white-space: pre;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
}

#code-editor::-webkit-scrollbar,
#highlight-layer::-webkit-scrollbar,
.output-content::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

#code-editor::-webkit-scrollbar-track,
#highlight-layer::-webkit-scrollbar-track,
.output-content::-webkit-scrollbar-track {
    background: transparent;
}

#code-editor::-webkit-scrollbar-thumb,
#highlight-layer::-webkit-scrollbar-thumb,
.output-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background-color: var(--bg-header);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.hint {
    font-size: 0.72rem;
    color: var(--text-muted);
}

kbd {
    background-color: var(--kbd-bg);
    color: var(--text-secondary);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.68rem;
    font-family: var(--font-mono);
    border: 1px solid var(--border);
}

/* =========================================
   Run Button
   ========================================= */
.run-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 18px;
    background-color: var(--run-bg);
    color: var(--run-color);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color var(--transition), transform 0.1s ease;
    letter-spacing: 0.02em;
}

.run-btn:hover {
    background-color: var(--run-hover);
}

.run-btn:active {
    transform: scale(0.97);
}

.run-btn.running {
    opacity: 0.7;
    cursor: not-allowed;
}

.run-icon {
    font-size: 0.75rem;
}

/* =========================================
   Output / Console
   ========================================= */
.output-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.exec-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.output-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    background-color: var(--bg-output);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
}

.output-placeholder {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Console entry lines */
.output-line {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid transparent;
    word-break: break-all;
    animation: fadeIn 0.15s ease;
}

.output-line:last-child {
    border-bottom: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(2px); }
    to   { opacity: 1; transform: translateY(0); }
}

.output-prefix {
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.75rem;
    opacity: 0.7;
}

.output-line.log    .output-prefix { color: var(--log-color); }
.output-line.error  .output-prefix { color: var(--error-color); }
.output-line.warn   .output-prefix { color: var(--warn-color); }
.output-line.result .output-prefix { color: var(--result-color); }
.output-line.info   .output-prefix { color: var(--accent); }

.output-line.log    .output-text { color: var(--log-color); }
.output-line.error  .output-text { color: var(--error-color); }
.output-line.warn   .output-text { color: var(--warn-color); }
.output-line.result .output-text { color: var(--result-color); }
.output-line.info   .output-text { color: var(--accent); }

.output-text {
    flex: 1;
    white-space: pre-wrap;
}

/* Execution divider */
.exec-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 8px 0;
}

/* =========================================
   Snippets Bar
   ========================================= */
.snippets-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background-color: var(--bg-header);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    overflow-x: auto;
}

.snippets-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    margin-right: 4px;
}

.snippet-btn {
    padding: 4px 12px;
    background-color: var(--badge-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color var(--transition), border-color var(--transition);
    font-family: var(--font-ui);
}

.snippet-btn:hover {
    background-color: var(--border);
    border-color: var(--accent);
}

/* =========================================
   Toast
   ========================================= */
.toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: var(--bg-header);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 18px;
    border-radius: 999px;
    font-size: 0.8rem;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* =========================================
   Scrollbar for snippets bar
   ========================================= */
.snippets-bar::-webkit-scrollbar {
    height: 3px;
}

.snippets-bar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* =========================================
   Mobile toolbar (tab switcher) — hidden on desktop
   ========================================= */
.mobile-tabs {
    display: none;
}

.mobile-run-fab {
    display: none;
}

.mobile-keys {
    display: none;
}

/* =========================================
   Responsive — tablet  (≤ 768px)
   ========================================= */
@media (max-width: 768px) {
    .header {
        padding: 0 12px;
        height: 48px;
    }

    .badge {
        display: none;
    }

    .main {
        padding: 10px;
        gap: 10px;
    }
}

/* =========================================
   Responsive — mobile  (≤ 600px)
   Full tab-based layout: editor OR console,
   never both cramped at the same time.
   ========================================= */
@media (max-width: 600px) {

    /* ── App becomes a true full-screen shell ── */
    .app {
        height: 100dvh; /* dynamic viewport height — handles mobile browser chrome */
    }

    /* ── Compact header ── */
    .header {
        padding: 0 10px;
        height: 44px;
    }

    .logo {
        font-size: 1.1rem;
    }

    .title {
        font-size: 0.95rem;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    /* ── Tab bar replaces side-by-side panels ── */
    .mobile-tabs {
        display: flex;
        background-color: var(--bg-header);
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
    }

    .mobile-tab {
        flex: 1;
        padding: 10px 0;
        background: transparent;
        border: none;
        border-bottom: 2px solid transparent;
        color: var(--text-muted);
        font-size: 0.8rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        cursor: pointer;
        transition: color var(--transition), border-color var(--transition);
        font-family: var(--font-ui);
    }

    .mobile-tab.active {
        color: var(--accent);
        border-bottom-color: var(--accent);
    }

    /* ── Main: full area, no padding or gap ── */
    .main {
        padding: 0;
        gap: 0;
        flex-direction: column;
        overflow: hidden;
    }

    /* ── Each panel takes the full area; hidden by default ── */
    .panel {
        flex: 1;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        display: none; /* JS will toggle .panel--active */
    }

    .panel.panel--active {
        display: flex;
    }

    /* ── Editor footer: hide hint text, keep button ── */
    .hint {
        display: none;
    }

    .editor-footer {
        justify-content: flex-end;
        padding: 6px 10px;
    }

    /* ── Bigger run button on mobile ── */
    .run-btn {
        padding: 9px 22px;
        font-size: 0.9rem;
    }

    /* ── Editor font slightly smaller for small screens ── */
    #code-editor,
    #highlight-layer {
        font-size: 0.8rem;
        padding: 10px;
    }

    .line-numbers {
        font-size: 0.75rem;
        padding: 10px 6px;
        min-width: 32px;
    }

    /* ── Output text ── */
    .output-content {
        font-size: 0.8rem;
        padding: 10px;
    }

    /* ── Snippets bar: scrollable, smaller pills ── */
    .snippets-bar {
        padding: 6px 10px;
        gap: 5px;
    }

    .snippets-label {
        display: none; /* save horizontal space */
    }

    .snippet-btn {
        padding: 5px 10px;
        font-size: 0.72rem;
    }

    /* ── Mobile symbol keyboard ── */
    .mobile-keys {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        padding: 6px 10px;
        background-color: var(--bg-header);
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }

    .mobile-key {
        flex: 0 0 auto;
        min-width: 36px;
        height: 34px;
        padding: 0 8px;
        background-color: var(--badge-bg);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        color: var(--text-primary);
        font-family: var(--font-mono);
        font-size: 0.85rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background-color var(--transition);
        /* Prevent double-tap zoom */
        touch-action: manipulation;
    }

    .mobile-key:active {
        background-color: var(--accent);
        color: var(--run-color);
    }

    /* ── FAB run button ── */
    .mobile-run-fab {
        display: none; /* shown only when editor tab is active — JS handles it */
    }

    /* ── Toast position adjustment ── */
    .toast {
        bottom: 80px;
        font-size: 0.75rem;
        padding: 6px 14px;
    }
}
