:root {
    --bg-color: #0c0c0c;
    --text-color: #cccccc;
    --prompt-color: #00ff00;
    --font-family: 'Fira Code', 'Noto Sans Mono CJK TC', 'WenQuanYi Micro Hei Mono', 'Droid Sans Fallback', 'Consolas', monospace;

    /* ANSI Colors */
    --ansi-black: #555555;
    --ansi-red: #cd0000;
    --ansi-green: #00cd00;
    --ansi-yellow: #cdcd00;
    --ansi-blue: #0000ee;
    --ansi-magenta: #cd00cd;
    --ansi-cyan: #00cdcd;
    --ansi-white: #e5e5e5;
    --ansi-bright-black: #7f7f7f;
    --ansi-bright-red: #ff0000;
    --ansi-bright-green: #00ff00;
    --ansi-bright-yellow: #ffff00;
    --ansi-bright-blue: #5c5cff;
    --ansi-bright-magenta: #ff00ff;
    --ansi-bright-cyan: #00ffff;
    --ansi-bright-white: #ffffff;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    overflow: hidden;
}

#terminal-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 10px;
    box-sizing: border-box;
}

#output-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: 60px;
    box-sizing: border-box;
    min-height: 0;
}

.output-pane {
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre;
    word-break: break-all;
    overflow-wrap: anywhere;
    font-size: 16px;
    line-height: 1.2;
    user-select: text;
    -webkit-user-select: text;
    font-family: 'Noto Sans Mono CJK TC', 'WenQuanYi Micro Hei Mono', 'NSimSun', 'MingLiU', monospace;
    letter-spacing: 0;
    word-spacing: 0;
    font-variant-ligatures: none;
    padding: 2px 0;
}

#output-scroll {
    flex: 1 1 auto;
    min-height: 0;
}

#output-divider {
    display: none;
    height: 2px;
    margin: 4px 0;
    background: linear-gradient(90deg, rgba(0, 255, 0, 0.1), rgba(0, 255, 0, 0.95), rgba(0, 255, 0, 0.1));
    box-shadow: 0 0 6px rgba(0, 255, 0, 0.35);
    pointer-events: none;
}

#output-live {
    display: none;
    flex: 0 0 28vh;
    max-height: 240px;
    min-height: 120px;
    padding-bottom: 10px;
    overflow: hidden;
}

#output-area.split-active #output-divider {
    display: block;
}

#output-area.split-active #output-live {
    display: block;
}

#input-area {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-color);
    padding: 10px;
    border-top: 1px solid #333;
}

#prompt {
    color: var(--prompt-color);
    margin-right: 10px;
}

#command-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 14px;
    outline: none;
}

/* ANSI Colors */
.bold {
    font-weight: bold;
}

.color-black {
    color: var(--ansi-black);
}

.color-red {
    color: var(--ansi-red);
}

.color-green {
    color: var(--ansi-green);
}

.color-yellow {
    color: var(--ansi-yellow);
}

.color-blue {
    color: var(--ansi-blue);
}

.color-magenta {
    color: var(--ansi-magenta);
}

.color-cyan {
    color: var(--ansi-cyan);
}

.color-white {
    color: var(--ansi-white);
}

.color-bright-black {
    color: var(--ansi-bright-black);
}

.color-bright-red {
    color: var(--ansi-bright-red);
}

.color-bright-green {
    color: var(--ansi-bright-green);
}

.color-bright-yellow {
    color: var(--ansi-bright-yellow);
}

.color-bright-blue {
    color: var(--ansi-bright-blue);
}

.color-bright-magenta {
    color: var(--ansi-bright-magenta);
}

.color-bright-cyan {
    color: var(--ansi-bright-cyan);
}

.color-bright-white {
    color: var(--ansi-bright-white);
}

#connect-button {
    background-color: #333;
    color: var(--prompt-color);
    border: 1px solid var(--prompt-color);
    padding: 5px 15px;
    font-family: var(--font-family);
    font-size: 14px;
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.2s;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: bold;
}

#connect-button:hover {
    background-color: var(--prompt-color);
    color: #000;
}

#connect-button:active {
    transform: translateY(2px);
}

::selection {
    background: #444;
    color: #fff;
}

#output-area ::selection {
    background: var(--prompt-color);
    color: #000;
}

#mobile-controls {
    display: block;
    position: fixed;
    bottom: 60px;
    right: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #333;
    touch-action: manipulation;
    opacity: 0.5;
    transition: opacity 0.2s;
}

#mobile-controls:hover,
#mobile-controls:focus-within {
    opacity: 1;
}

#copy-toast {
    position: fixed;
    left: 50%;
    bottom: 78px;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    border: 1px solid rgba(0, 255, 0, 0.6);
    padding: 6px 12px;
    border-radius: 14px;
    font-size: 12px;
    letter-spacing: 0.5px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 120;
}

#copy-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(-6px);
}

.dpad {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    max-width: 165px; /* Roughly 3 columns of 50px + gaps */
}

.dpad-btn {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
}

.dpad-btn.auto-btn {
    font-size: 16px;
    line-height: 1.1;
    word-break: break-all;
    padding: 2px;
}

#auto-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin-top: 5px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 5px;
}

#auto-controls::-webkit-scrollbar {
    width: 6px;
}

#auto-controls::-webkit-scrollbar-track {
    background: #111;
}

#auto-controls::-webkit-scrollbar-thumb {
    background: var(--prompt-color);
    border-radius: 3px;
}

.dpad-btn {
    background: #222;
    border: 1px solid var(--prompt-color);
    color: var(--prompt-color);
    font-family: var(--font-family);
    font-weight: bold;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
    background: var(--prompt-color);
    color: #000;
}

.dpad-btn.dynamic-btn {
    border-color: #00d2ff;
    color: #00d2ff;
}

.dpad-btn.dynamic-btn:active {
    background: #00d2ff;
    color: #000;
}


@media (max-width: 768px) {
    #auto-controls {
        display: none;
    }

    .output-pane {
        font-size: 12px;
        line-height: 1.1;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .output-pane::-webkit-scrollbar {
        height: 4px;
        /* Thin horizontal scrollbar for mobile */
    }

    #output-area {
        padding-bottom: 230px;
        /* Space for dpad + input */
    }

    #output-area.split-active #output-live {
        flex: 0 0 auto;
        height: calc(2.2em + 6px);
        min-height: 0;
        max-height: none;
    }

    #input-area {
        z-index: 100;
    }

    #command-input {
        font-size: 16px;
        /* Prevent iOS zoom on focus */
    }
}
