:root {
    --header-bg: #eee;
    --main-bg: #fff;
    --editor-bg: #ddd;
    --terminal-bg: #bdbdbd;
    --title: #3c424b;
    --text-color: #000;
    --link-color: #444;
    --link-color-dnl: #696969;
}

html.dark {
    --header-bg: #111;
    --main-bg: #121212;
    --editor-bg: #1f1f1f;
    --terminal-bg: #000000;
    --title: #94a3b8;
    --text-color: #ddd;
    --link-color: #bbb;
    --link-color-dnl: #969696;
}

html, body {
    height: 100%;
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    overscroll-behavior: none;
    overflow: hidden;
    background: var(--main-bg);
}

header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1em 1em;
    background: var(--header-bg);
    color: var(--text-color);
    z-index: 100000;
    border-bottom: 1px solid var(--link-color);
    backdrop-filter: blur(5px);
    border-bottom-left-radius: 0.3em;
    border-bottom-right-radius: 0.3em;
}

.logo-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
}

.logo-img {
    width: 28px;
    height: 28px;
}

.logo-text {
    font-size: 1.2em;
    font-weight: bold;
}

.menu-controls { display: flex; align-items: center; gap: 1em; }

.doc-button {
    align-items: center;
    color: var(--text-color);
    width: 28px;
    height: 28px;
}

.github-button {
    align-items: center;
    color: var(--text-color);
    width: 22px;
    height: 24px;
}

.lang-select {
    margin-right: 40px;
    background: var(--main-bg);
    color: var(--text-color);
    border: 1px solid var(--link-color);
    padding: 0 0.4em;
    border-radius: 0.3em;
    font-size: 0.9em;
    height: 22px;
    appearance: none;
    cursor: pointer;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.menu-controls button,
.menu-controls .play-button,
.menu-controls .github-button,
.menu-controls .doc-button,
.menu-controls .theme-switch,
.menu-controls .lang-select {
    transition: background-color 0.5s ease, color 0.5s ease, border-color 0.5s ease, box-shadow 0.3s ease, filter 0.3s ease, outline-color 0.3s ease;
}

.menu-controls button:hover,
.menu-controls .play-button:hover,
.menu-controls .github-button:hover,
.menu-controls .doc-button:hover,
.menu-controls .theme-switch:hover,
.menu-controls .lang-select:hover {
    filter: brightness(1.1)
        drop-shadow(0 0 8px currentColor);
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: background-color 0.4s;
    border-radius: 30px;
    line-height: 1.4;
}

.slider::before {
    content: "☀";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    border-radius: 50%;
    transition: transform 0.4s, color 0.4s, background-color 0.4s, content 0.4s;
}

.theme-switch input:checked + .slider {
    background-color: #333;
}

.theme-switch input:checked + .slider::before {
    transform: translateX(18px);
    content: "☾";
    color: white;
    background-color: black;
}

#app {
    box-sizing: border-box;
    margin-top: 4.5em;
    display: flex;
    gap: 12px;
    padding : 16px;
    height: calc(100vh - 4.5em);
    overflow: hidden;
}

#left, #right {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(2,6,23,0.6);
}

#left {
    max-width: 60%;
}

.pane-title {
    box-sizing: border-box;
    min-height: 54px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(105, 99, 99, 0.18);
    padding: 10px 14px;
    color: var(--title);
    font-weight: 600;
    border-bottom: 1px solid rgba(105, 99, 99, 0.4);
}

.pane-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    margin: 0;
    cursor: pointer;
    color: var(--title);
    width: 34px;
    height: 34px;
    padding: 4px;
    border-radius: 6px;
    box-sizing: border-box;
    transition:
        background-color 160ms ease,
        transform 160ms ease,
        box-shadow 160ms ease,
        filter 160ms ease,
        border-color 160ms ease,
        color 160ms ease;
}

.icon-btn:hover,
.icon-btn:focus {
    background-color: rgba(0,0,0,0.06);
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 6px 18px rgba(2,6,23,0.15);
    filter: brightness(1.03);
    border-color: rgba(0,0,0,0.08);
    outline: none;
}

.icon-btn svg {
    width: 18px;
    height: 18px;
    display: block;
    vector-effect: non-scaling-stroke;
    overflow: visible;
}

.icon-btn:focus {
    filter: brightness(1.1)
            drop-shadow(0 0 8px currentColor);
}

.pane-file-input {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

#editor, #terminal {
    overflow: auto;
}

#editor {
    flex: 1;
    resize: none;
    padding: 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", monospace;
    font-size: 13px;
    color: var(--text-color);
    background: var(--editor-bg);
    border: 0;
    outline: 0;
    line-height: 1.45;
}

.controls {
    padding: 10px 14px;
    background: rgba(0,0,0,0.04);
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls button {
    background: #22c55e;
    border: 0;
    color: #03120a;
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

.controls #stopBtn {
    background: #ef4444;
    color: white;
    margin-left: auto;
}

#stopBtn { order: 2; flex: 0 0 auto; }
#status  { order: 1; flex: 1 1 auto; text-align: center; }
#runBtn  { order: 0; flex: 0 0 auto; }

#status {
    color: var(--editor-placeholder-color, #888);
}

#left .controls button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

#right {
    background: var(--terminal-bg);
    color: var(--text-color);
    min-width: 350px;
}

#terminal {
    flex: 1;
    padding: 16px;
    overflow: auto;
    font-family: ui-monospace, Menlo, Monaco, monospace;
    font-size: 13px;
    position: relative;
}

.editor-wrap {
    display: flex;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: var(--editor-bg);
}

.gutter {
    box-sizing: border-box;
    padding: 14px 8px;
    text-align: right;
    user-select: none;
    font-family: ui-monospace, Menlo, Monaco, monospace;
    font-size: 13px;
    line-height: 1.45;
    border-right: 1px solid rgba(0,0,0,0.06);
    color: var(--link-color);
    background: rgba(0,0,0,0.03);
    width: 54px;
    overflow: hidden;
}

.gutter-line {
    height: calc(1.45 * 13px);
    padding: 0 4px;
    box-sizing: border-box;
}

.editor-wrap textarea#editor {
    flex: 1;
    box-sizing: border-box;
    border: 0;
    outline: none;
    padding: 14px;
    resize: none;
    font-family: ui-monospace, Menlo, Monaco, "Roboto Mono", monospace;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-color);
    background: transparent;
    white-space: pre;
    word-wrap: normal;
    overflow-x: auto;
    overflow-y: auto;
    min-height: 0;
}

.editor-wrap textarea#editor::-webkit-scrollbar { width: 8px; }
.editor-wrap textarea#editor::-webkit-scrollbar-thumb {
    background-color: var(--link-color);
    border-radius: 4px;
}

.terminal-output {
    font-family: ui-monospace, Menlo, Monaco, monospace;
    font-size: 13px;
    white-space: normal;
}

.terminal-line {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 0 0 2px 0;
    min-width: max-content;
}

.terminal-line .line-num {
    width: 34px;
    text-align: right;
    padding-right: 6px;
    box-sizing: border-box;
    user-select: none;
    color: var(--link-color);
    font-family: ui-monospace, Menlo, Monaco, monospace;
    font-size: 13px;
    line-height: 1.45;
}

.terminal-line .line-content {
    line-height: 1.45;
    flex: 0 0 auto;
    white-space: pre;
    word-wrap: normal;
}

.terminal-output .line-num::after { content: " "; }

#input-line {
    display: block;
    vertical-align: baseline;
    line-height: 1.45;
    margin: 0;
    padding: 0;
    white-space: pre;
}

#cmd-prefix {
    color: var(--title);
}

#cmd-line {
    display: inline-block;
    outline: none;
    line-height: inherit;
    font-family: ui-monospace, Menlo, Monaco, monospace;
    font-size: 13px;
    vertical-align: baseline;
    white-space: pre;
    caret-color: transparent;
    -webkit-user-modify: read-write-plaintext-only;
    padding: 0;
    margin: 0;
    min-width: 0;
}

#block-caret {
    display: none;
    position: absolute;
    pointer-events: none;
    line-height: 1.2;
    font-family: ui-monospace, Menlo, Monaco, monospace;
    font-size: 13px;
    transform: translateY(0);
    animation: blink 1s steps(1, start) infinite;
    will-change: left, top, opacity;
}

#terminal[aria-disabled="true"] #block-caret {
    display: none !important;
}
.hidden {
    display: none;
}

@keyframes blink {
    0%   { opacity: 1; }
    50%  { opacity: 0; }
    100% { opacity: 1; }
}

#editor::-webkit-scrollbar,
#terminal::-webkit-scrollbar {
    width: 8px;
}
#editor::-webkit-scrollbar-track,
#terminal::-webkit-scrollbar-track {
    background: var(--main-bg);
    transition: background 0.5s ease;
}
#editor::-webkit-scrollbar-thumb,
#terminal::-webkit-scrollbar-thumb {
    background-color: var(--link-color);
    border-radius: 4px;
    transition: background-color 0.5s ease;
}
#editor::-webkit-scrollbar-thumb:hover,
#terminal::-webkit-scrollbar-thumb:hover {
    background-color: var(--link-color-dnl);
}

@media (max-width: 700px) {
    #app {
        flex-direction: column;
        gap: 10px;
        padding: 12px;
        margin-top: 6.5em;
        height: calc(100vh - 6.5em);
        overflow: hidden;
    }

    #left, #right {
        width: 100%;
        max-width: none;
        min-width: 0;
        border-radius: 10px;
        flex: 1 1 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .editor-wrap {
        display: flex;
        flex-direction: row;
        flex: 1 1 0;
        min-height: 0;
        height: auto;
        overflow: hidden;
    }

    .editor-wrap textarea#editor {
        flex: 1 1 0;
        min-height: 0;
        height: auto;
        overflow: auto;
    }

    .controls {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        box-sizing: border-box;
        padding: 10px 14px;
        gap: 8px;
    }

    #right {
        background: var(--terminal-bg);
        color: var(--text-color);
        overflow: auto;
    }

    #terminal {
        flex: 1 1 0;
        min-height: 0;
        overflow: auto;
    }

    .pane-title { min-height: 48px; }

    header {
        flex-direction: column;
        align-items: center !important;
        padding: 1em 0 !important;
    }

    .logo-wrapper {
        margin: 0 auto 0.5em auto;
    }

    .controls {
        justify-content: center;
        margin: 0 auto;
    }

    .lang-select {
        margin-right: 0 !important;
    }

    #menuToggle {
        position: fixed;
        bottom: 1rem;
        left: 1rem;
        top: auto;
    }

    main, .container {
        margin-top: 36px;
        margin-left: 0 !important;
    }

    table {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        display: block;
    }

    pre {
        overflow-x: auto;
        max-width: 100vw;
        box-sizing: border-box;
        word-wrap: normal;
        -webkit-overflow-scrolling: touch;
    }

    code {
        display: block;
    }
}
