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

:root {
    color-scheme: dark;
    --bg: #000000;
    --panel: #0d0d0d;
    --panel-2: #151515;
    --text: #ffffff;
    --text-dim: #b8b8b8;
    --border: #3a3a3a;
    --focus: #f0f0f0;
    --danger: #ff6b6b;
    --window-gap: 12px;
    --toolbar-height: 52px;
    --titlebar-height: 44px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    overflow: hidden;
}

body {
    font-family: "JetBrains Mono", "Consolas", "Menlo", "Liberation Mono", monospace;
    color: var(--text);
}

.app {
    position: relative;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at top, #141414 0%, var(--bg) 48%);
}

.intro {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(24px, 3.4vw, 46px);
    white-space: nowrap;
    letter-spacing: 0.07em;
    text-shadow: 0 0 14px #ffffff4a;
    transition:
        top 850ms cubic-bezier(0.21, 0.79, 0.24, 0.99),
        transform 850ms cubic-bezier(0.21, 0.79, 0.24, 0.99),
        font-size 850ms cubic-bezier(0.21, 0.79, 0.24, 0.99),
        text-shadow 850ms ease;
    will-change: transform, top, font-size;
    backface-visibility: hidden;
    z-index: 20;
}

.intro.docking {
    top: 18px;
    transform: translate(-50%, 0);
    font-size: clamp(20px, 2.2vw, 32px);
    text-shadow: 0 0 12px #ffffff2e;
    z-index: 50;
}

.intro.compact {
    gap: 0;
}

.intro.compact .cursor {
    visibility: hidden;
    animation: none;
}

.intro-prefix {
    display: inline-block;
    max-width: 180px;
    margin-right: 0;
    color: var(--text-dim);
    transition:
        opacity 180ms ease,
        max-width 220ms ease,
        margin-right 220ms ease,
        transform 220ms ease;
}

.intro.name-only .intro-prefix {
    opacity: 0;
    max-width: 0;
    margin-right: -6px;
    transform: translateX(-6px);
}

.cursor {
    display: inline-block;
    animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
    to {
        visibility: hidden;
    }
}

.toolbar {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 40;
}

.new-terminal-btn {
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    font: inherit;
    cursor: pointer;
    transition: border-color 150ms ease, transform 120ms ease;
}

.new-terminal-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.new-terminal-btn:not(:disabled):hover {
    border-color: var(--focus);
    background: #1c1c1c;
}

.new-terminal-btn:not(:disabled):active {
    transform: translateY(1px);
}

.desktop {
    position: absolute;
    inset: 0;
    padding-top: 56px;
}

.terminal-window {
    position: absolute;
    min-width: 380px;
    min-height: 260px;
    width: 750px;
    height: 500px;
    background: linear-gradient(180deg, #161616 0%, #0a0a0a 100%);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 20px 45px #0000009e;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: window-reveal 340ms cubic-bezier(0.18, 0.9, 0.3, 1) both;
}

.terminal-window.active {
    border-color: var(--focus);
    box-shadow: 0 22px 52px #000000cc, 0 0 0 1px #ffffff55;
}

@keyframes window-reveal {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.terminal-titlebar {
    height: 38px;
    background: #151515;
    border-bottom: 1px solid #202020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px 0 14px;
    cursor: move;
    user-select: none;
}

.terminal-title {
    color: #f3f3f3;
    font-size: 13px;
}

.window-close-btn {
    border: 1px solid #2f2f2f;
    background: transparent;
    color: #d1d1d1;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
}

.window-close-btn:hover {
    color: #ffffff;
    border-color: var(--danger);
}

.terminal-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.terminal-output {
    margin: 0;
    padding: 14px;
    flex: 1;
    min-height: 0;
    overflow: auto;
    color: #dfdfdf;
    font-size: 14px;
    line-height: 1.42;
    white-space: pre-wrap;
}

.output-line {
    margin: 0;
    word-break: break-word;
}

.output-line.empty-line {
    min-height: 1.42em;
}

.output-line + .output-line {
    margin-top: 2px;
}

.output-line.user-command {
    color: #ffffff;
}

.output-line.backend-response {
    color: #cccccc;
}

.output-line.system-message {
    color: #a9a9a9;
}

.output-line.error-message {
    color: #ff9a9a;
}

.output-line strong {
    font-weight: 700;
    color: #ffffff;
}

.output-line.system-message strong {
    color: #e8e8e8;
}

.output-line.error-message strong {
    color: #ffd4d4;
}

.output-line.user-command strong {
    color: #ffffff;
}

.markdown-window {
    width: 820px;
    height: 560px;
}

.message-window {
    width: 640px;
    height: 520px;
    min-width: 360px;
    min-height: 320px;
}

.message-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 14px 0 0;
    background: #0c0c0c;
}

.message-pretty-content {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 16px;
    -webkit-overflow-scrolling: touch;
}

.message-chat-form {
    flex-shrink: 0;
    margin-top: auto;
}

.message-chat-error {
    flex-shrink: 0;
    margin: 0;
    padding: 6px 16px 0;
    color: #ff9a9a;
    font-size: 13px;
    line-height: 1.35;
}

.message-chat-error[hidden] {
    display: none;
}

.message-pretty-header {
    margin: 0 0 6px;
    color: #a9a9a9;
    font-size: 14px;
    line-height: 1.4;
}

.message-pretty-line {
    margin: 0;
    color: #dfdfdf;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-pretty-header strong,
.message-pretty-line strong {
    font-weight: 700;
    color: #ffffff;
}

.audio-window {
    width: 620px;
    height: 290px;
    min-width: 380px;
    min-height: 190px;
}

.audio-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 14px;
    background: transparent;
}

.audio-render {
    margin: 0;
    flex: 1;
    min-height: 0;
    overflow: auto;
    white-space: pre;
    color: #dfdfdf;
    font-size: 14px;
    line-height: 1.42;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
}

.markdown-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 22px 24px;
    background: #0c0c0c;
}

.markdown-content {
    width: min(100%, 68ch);
    margin-block: auto;
    color: #e8e8e8;
    font-size: 15px;
    line-height: 1.65;
    text-align: left;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    color: #ffffff;
    margin: 1.2em 0 0.5em;
    line-height: 1.25;
}

.markdown-content h1 {
    font-size: 1.75rem;
    margin-top: 0;
}

.markdown-content h2 {
    font-size: 1.35rem;
    border-bottom: 1px solid #2a2a2a;
    padding-bottom: 0.35em;
}

.markdown-content h3 {
    font-size: 1.1rem;
}

.markdown-content p {
    margin: 0.75em 0;
}

.markdown-content ul,
.markdown-content ol {
    margin: 0.75em 0;
    padding-left: 1.4em;
}

.markdown-content li {
    margin: 0.35em 0;
}

.markdown-content a {
    color: #ffffff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.markdown-content code {
    font-family: inherit;
    background: #1a1a1a;
    border: 1px solid #333333;
    border-radius: 4px;
    padding: 0.1em 0.35em;
    font-size: 0.92em;
}

.markdown-content pre {
    background: #111111;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 1em 0;
}

.markdown-content pre code {
    border: none;
    padding: 0;
    background: transparent;
}

.markdown-content blockquote {
    margin: 1em 0;
    padding-left: 1em;
    border-left: 3px solid #666666;
    color: #bdbdbd;
}

.markdown-content hr {
    border: none;
    border-top: 1px solid #2a2a2a;
    margin: 1.5em 0;
}

.terminal-input-form {
    border-top: 1px solid #1e1e1e;
    padding: 10px 12px;
    background: #090909;
}

.terminal-input-label {
    display: flex;
    align-items: center;
    gap: 10px;
}

.terminal-prompt {
    color: #f4f4f4;
    font-weight: 600;
}

.terminal-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: #ffffff;
    font: inherit;
    font-size: 14px;
}

.resize-handle {
    position: absolute;
    z-index: 5;
}

.resize-east,
.resize-west {
    top: 10px;
    bottom: 10px;
    width: 8px;
}

.resize-east {
    right: 0;
    cursor: ew-resize;
}

.resize-west {
    left: 0;
    cursor: ew-resize;
}

.resize-north,
.resize-south {
    left: 10px;
    right: 10px;
    height: 8px;
}

.resize-north {
    top: 0;
    cursor: ns-resize;
}

.resize-south {
    bottom: 0;
    cursor: ns-resize;
}

.resize-southeast,
.resize-southwest,
.resize-northeast,
.resize-northwest {
    width: 12px;
    height: 12px;
}

.resize-southeast {
    right: 0;
    bottom: 0;
    cursor: nwse-resize;
}

.resize-southwest {
    left: 0;
    bottom: 0;
    cursor: nesw-resize;
}

.resize-northeast {
    right: 0;
    top: 0;
    cursor: nesw-resize;
}

.resize-northwest {
    left: 0;
    top: 0;
    cursor: nwse-resize;
}

@media (max-width: 768px) {
    .app {
        touch-action: manipulation;
    }

    .intro {
        max-width: calc(100vw - 24px);
        white-space: normal;
        text-align: center;
        flex-wrap: wrap;
        justify-content: center;
    }

    .intro.docking {
        top: calc(12px + var(--safe-top));
        font-size: clamp(16px, 5vw, 22px);
        z-index: 30;
    }

    .toolbar {
        top: auto;
        bottom: calc(12px + var(--safe-bottom));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        z-index: 40;
    }

    .new-terminal-btn {
        padding: 10px 16px;
        min-height: 44px;
    }

    .desktop {
        padding-top: 0;
        padding-bottom: calc(56px + var(--safe-bottom));
    }

    .terminal-window,
    .markdown-window,
    .message-window,
    .audio-window {
        width: calc(100vw - var(--window-gap) * 2);
        max-width: none;
        min-width: 0;
        height: calc(100dvh - var(--toolbar-height) - var(--safe-top) - var(--safe-bottom) - var(--window-gap));
        min-height: 200px;
        left: var(--window-gap);
        top: calc(var(--toolbar-height) + var(--safe-top));
        border-radius: 10px;
    }

    .resize-handle {
        display: none;
    }

    .terminal-titlebar {
        height: var(--titlebar-height);
        touch-action: none;
    }

    .window-close-btn {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }

    .terminal-output {
        padding: 10px;
        font-size: 13px;
        -webkit-overflow-scrolling: touch;
    }

    .audio-body {
        padding: 10px;
    }

    .audio-render {
        font-size: 13px;
        -webkit-overflow-scrolling: touch;
    }

    .markdown-body {
        padding: 14px 12px 18px;
        -webkit-overflow-scrolling: touch;
    }

    .markdown-content {
        font-size: 14px;
    }

    .message-pretty-content {
        padding: 0 12px;
    }

    .terminal-input-form {
        padding: 8px 10px;
    }

    .terminal-input {
        font-size: 16px;
    }
}
