.tui {
    width: calc(100vw - 1rem); /* 1rem inset keeps the scaled border off-screen */
    max-width: 1500px;
    border: 1px solid var(--border);
    background: var(--panel);
    display: flex;
    flex-direction: column;
    height: 98vh;
}

.tui-header {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.tui-header .title {
    font-weight: bold;
}

.tui-header .status {
    font-weight: bold;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.tui-header .status:hover {
    text-decoration: underline;
}

.tui-header-actions {
    display: flex;
    align-items: center;
    gap: 0.6em;
}

/* Header controls (lang switcher + CRT toggle) share a compact status-bar
   "chip" look: subtle accent border, dim when idle, accent-lit when active. */
.tui-header .lang,
.crt-toggle {
    font-size: 0.75em;
    font-weight: normal;
    letter-spacing: 0.05em;
    border: 1px solid rgba(var(--accent-rgb), 0.25);
    border-radius: 3px;
}

/* lang switcher — a two-segment control (EN | RU) */
.tui-header .lang {
    margin-left: 1em;
    display: inline-flex;
    overflow: hidden;
}

.tui-header .lang a {
    padding: 0.15em 0.55em;
    color: var(--muted);
    text-decoration: none;
    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.tui-header .lang a + a {
    border-left: 1px solid rgba(var(--accent-rgb), 0.25);
}

.tui-header .lang a:hover {
    background: rgba(var(--accent-rgb), 0.1);
    color: var(--fg);
}

.tui-header .lang .active {
    background: rgba(var(--accent-rgb), 0.18);
    color: var(--accent);
}

/* CRT toggle — a chip with an LED dot that lights up when effects are on. */
.crt-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    padding: 0.15em 0.55em;
    background: none;
    color: var(--muted);
    font-family: inherit;
    cursor: pointer;
    text-transform: uppercase;
    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.crt-toggle::before {
    content: "";
    width: 0.5em;
    height: 0.5em;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.45;
    transition:
        background 0.15s ease,
        box-shadow 0.15s ease,
        opacity 0.15s ease;
}

.crt-toggle:hover {
    background: rgba(var(--accent-rgb), 0.1);
    color: var(--fg);
}

.crt-toggle[aria-pressed="true"] {
    color: var(--accent);
    border-color: rgba(var(--accent-rgb), 0.55);
}

.crt-toggle[aria-pressed="true"]::before {
    background: var(--accent);
    opacity: 1;
    box-shadow: 0 0 5px rgba(var(--accent-rgb), 0.9);
}

.crt-toggle:focus-visible {
    outline: 1px solid var(--accent);
    outline-offset: 2px;
}

.tui-body {
    min-height: 0;
    flex: 1;
    display: flex;
    min-height: 0; /* REQUIRED for scroll to work */
}

.tui-menu {
    border-right: 1px solid var(--border);
    padding: 0.5rem 0;
    width: 165px;
    flex-shrink: 0;
    overflow: hidden;
}

.tui-menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tui-menu li {
    padding: 0.5rem 1rem;
    cursor: pointer;
    color: var(--fg);
    text-transform: uppercase;
    position: relative;
    padding-left: 1.5em; /* space for arrow */
}

.tui-menu li.active {
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent);
}

.tui-menu li::before {
    content: " ";
    position: absolute;
    left: 0;
}

.tui-menu li.active::before {
    content: "▶";
}

.tui-menu li:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tui-content {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    /* CRT-tinted scrollbar so it doesn't break the terminal illusion (Firefox) */
    scrollbar-width: auto;
    scrollbar-color: rgba(var(--accent-rgb), 0.7) rgba(var(--accent-rgb), 0.1);
}

/* WebKit/Blink scrollbar */
.tui-content::-webkit-scrollbar {
    width: 14px;
}

.tui-content::-webkit-scrollbar-track {
    background: rgba(var(--accent-rgb), 0.08);
    border-left: 1px solid rgba(var(--accent-rgb), 0.2);
}

.tui-content::-webkit-scrollbar-thumb {
    background: rgba(var(--accent-rgb), 0.55);
    border: 2px solid var(--panel); /* inset look */
    border-radius: 7px;
    box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.4); /* CRT glow */
}

.tui-content::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--accent-rgb), 0.85);
}

.tui-content pre {
    margin: 0;
    white-space: pre-wrap;
}

.tui-footer {
    padding: 0.4rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--muted);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (max-width: 700px) {
    body {
        font-size: 16px;
    }

    .tui {
        /*margin: auto;*/
        height: calc(100dvh - 1rem);
        transform: none;
        border-radius: 0;
    }

    .tui-body {
        flex-direction: column;
    }

    .tui-menu {
        width: 100%;
        overflow-x: auto;
    }

    .tui-menu ul {
        display: flex;
        justify-content: space-around;
    }

    .tui-menu li.active::before {
        content: "";
    }

    .footer-help {
        display: none;
    }
}

.footer-help {
    opacity: 0.6;
    font-size: 0.6rem;
}

.footer-prompt {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.footer-prompt input {
    flex: 1;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    outline: none;
}
