/* ─── Variables ─────────────────────────────────────────── */
:root {
    --bg:        #0d1117;
    --bg-panel:  #161b22;
    --bg-input:  #0d1117;
    --border:    #30363d;
    --border-dim:#21262d;
    --text:      #c9d1d9;
    --text-dim:  #8b949e;
    --accent:    #00d4a8;
    --accent2:   #58a6ff;
    --user-c:    #79c0ff;
    --font:      'JetBrains Mono', 'Fira Mono', 'Consolas', monospace;
}

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

html, body {
    height: 100%;
    background: #000;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ─── Terminal window ────────────────────────────────────── */
.terminal-window {
    max-width: 1000px;
    margin: 0 auto;
    height: 100vh;
    background: var(--bg);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Title bar ──────────────────────────────────────────── */
.title-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    user-select: none;
}

.title-bar-dots { display: flex; gap: 6px; }

.title-bar-dots span { width: 12px; height: 12px; border-radius: 50%; }
.title-bar-dots span:nth-child(1) { background: #ff5f57; }
.title-bar-dots span:nth-child(2) { background: #febc2e; }
.title-bar-dots span:nth-child(3) { background: #28c840; }

.title-bar-text {
    color: var(--text-dim);
    font-size: 0.8rem;
    flex: 1;
    text-align: center;
}

/* ─── Header / MOTD ──────────────────────────────────────── */
.term-header {
    padding: 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* Toggle row */
.header-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 1.5rem;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.header-toggle:hover {
    background: rgba(0,212,168,0.04);
}

.term-header.collapsed .header-toggle {
    border-bottom-color: transparent;
}

.toggle-btn {
    color: var(--accent);
    font-size: 0.82rem;
    flex-shrink: 0;
    transition: color 0.15s;
}

.header-toggle:hover .toggle-btn { color: var(--text); }

.header-summary {
    color: var(--text-dim);
    font-size: 0.82rem;
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.25s ease, max-width 0.3s ease;
    pointer-events: none;
}

.term-header.collapsed .header-summary {
    opacity: 1;
    max-width: 600px;
}

/* Collapsible content */
.header-content {
    overflow: hidden;
    max-height: 600px;
    opacity: 1;
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.35s ease;
    padding: 0.75rem 1.5rem 1rem;
}

.term-header.collapsed .header-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.ascii-banner {
    font-size: 0.62rem;
    line-height: 1.3;
    color: var(--accent);
    white-space: pre;
    overflow-x: auto;
    margin-bottom: 1.25rem;
}

.sys-info { margin-bottom: 1rem; }

.info-line { display: flex; line-height: 1.8; }
.info-line .label { color: var(--accent); width: 4ch; flex-shrink: 0; }
.info-line .sep   { color: var(--text-dim); margin: 0 0.5rem; }
.info-line .value { color: var(--text); }

.divider { border-top: 1px solid var(--border-dim); margin: 0.75rem 0; }

.motd { color: var(--text-dim); font-size: 0.82rem; }

/* ─── Quick commands ─────────────────────────────────────── */
.quick-commands {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.section-label {
    color: var(--text-dim);
    font-size: 0.78rem;
    margin-bottom: 0.5rem;
}

.cmd-list { display: flex; flex-direction: column; gap: 2px; }

.cmd-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.85rem;
    text-align: left;
    padding: 0.2rem 0.25rem;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    width: 100%;
}

.cmd-btn:hover { color: var(--accent); background: rgba(0,212,168,0.05); }

.cmd-idx { color: var(--accent); margin-right: 0.5rem; }

/* ─── Session output ─────────────────────────────────────── */
.term-body {
    flex: 1;
    min-height: 0;          /* critical: prevents flex child from overflowing */
    overflow-y: auto;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

.term-body::-webkit-scrollbar { width: 4px; }
.term-body::-webkit-scrollbar-track { background: var(--bg); }
.term-body::-webkit-scrollbar-thumb { background: var(--border); }

.output-block { display: flex; flex-direction: column; gap: 0.2rem; }

.prompt-user { color: var(--accent2); font-weight: 700; }
.prompt-sys  { color: var(--accent);  font-weight: 700; }

.output-line {
    font-size: 0.875rem;
    line-height: 1.7;
    word-break: break-word;
}

.output-line .sep { color: var(--text-dim); }

.user-output .output-line   { color: var(--user-c); }
.assistant-output .output-line { color: var(--text); }
.loading-block .output-line { color: var(--text-dim); }

/* inline formatting inside responses */
.output-block strong { color: var(--accent); font-weight: 500; }
.output-block em     { color: var(--text-dim); font-style: italic; }
.output-block code {
    background: var(--bg-panel);
    border: 1px solid var(--border-dim);
    padding: 0 3px;
    font-family: var(--font);
    font-size: 0.82em;
    color: var(--accent);
}

.output-block ul, .output-block ol {
    margin: 0.25rem 0 0.25rem 1.5rem;
}

.output-block li {
    line-height: 1.7;
    font-size: 0.875rem;
    color: var(--text);
    list-style: none;
}

.output-block li::before {
    content: '─ ';
    color: var(--accent);
}

.output-block h3 {
    color: var(--accent);
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0.5rem 0 0.15rem;
    border-bottom: 1px solid var(--border-dim);
    padding-bottom: 0.15rem;
}

/* blinking cursor */
.cursor {
    display: inline-block;
    width: 8px;
    height: 0.9em;
    background: var(--accent);
    vertical-align: text-bottom;
    animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* loading spinner */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    vertical-align: middle;
    margin-left: 6px;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Input row ──────────────────────────────────────────── */
@keyframes input-glow {
    0%, 100% { box-shadow: 0 0 6px 1px rgba(0, 212, 168, 0.20), 0 0 14px 2px rgba(0, 212, 168, 0.10); }
    50%       { box-shadow: 0 0 10px 2px rgba(0, 212, 168, 0.45), 0 0 24px 4px rgba(0, 212, 168, 0.22); }
}

.term-input-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    margin: 6px 8px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: var(--bg-input);
    animation: input-glow 2.8s ease-in-out infinite;
}

.input-prompt {
    color: var(--accent2);
    font-weight: 700;
    font-size: 0.875rem;
    white-space: nowrap;
    padding-top: 2px;
    flex-shrink: 0;
}

#userInput {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.875rem;
    resize: none;
    line-height: 1.5;
    caret-color: var(--accent);
    max-height: 120px;
}

#userInput::placeholder { color: var(--text-dim); opacity: 0.5; }

#sendButton {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 1rem;
    padding: 2px 8px;
    cursor: pointer;
    font-family: var(--font);
    transition: color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

#sendButton:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
#sendButton:disabled { opacity: 0.3; cursor: not-allowed; }

/* ─── Footer ─────────────────────────────────────────────── */
.term-footer {
    border-top: 1px solid var(--border);
    padding: 0.6rem 1.5rem;
    background: var(--bg-panel);
}

.footer-cols {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.footer-cols .label { color: var(--accent); }
.footer-cols a { color: var(--accent2); text-decoration: none; }
.footer-cols a:hover { text-decoration: underline; }

/* ─── Access Gate ────────────────────────────────────────── */
@keyframes gate-glow {
    0%, 100% { box-shadow: 0 0 8px 2px rgba(0, 212, 168, 0.25), 0 0 24px 4px rgba(0, 212, 168, 0.10); }
    50%       { box-shadow: 0 0 14px 4px rgba(0, 212, 168, 0.50), 0 0 40px 8px rgba(0, 212, 168, 0.20); }
}

.gate-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    font-family: var(--font);
}

.gate-overlay.hidden { display: none; }

.gate-box {
    width: min(680px, 92vw);
    background: var(--bg);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 2rem 2.5rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    animation: gate-glow 2.8s ease-in-out infinite;
}

.gate-ascii {
    font-size: 0.5rem;
    line-height: 1.3;
    color: var(--accent);
    white-space: pre;
    overflow: hidden;
    text-align: left;
}

.gate-label {
    color: var(--text-dim);
    font-size: 0.8rem;
}

.gate-input-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.gate-prompt {
    color: var(--accent2);
    font-weight: 700;
    font-size: 0.875rem;
    white-space: nowrap;
    flex-shrink: 0;
}

#codeInput {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    outline: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 1.1rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    caret-color: var(--accent);
    padding: 4px 2px;
    max-width: 140px;
}

#codeInput::placeholder {
    color: var(--text-dim);
    opacity: 0.4;
    letter-spacing: 0.15em;
}

#codeSubmit {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 1rem;
    padding: 2px 10px;
    cursor: pointer;
    font-family: var(--font);
    transition: color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

#codeSubmit:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
#codeSubmit:disabled { opacity: 0.3; cursor: not-allowed; }

.gate-error {
    color: #ff5f57;
    font-size: 0.8rem;
    min-height: 1.1em;
}

.gate-hint {
    color: var(--text-dim);
    font-size: 0.72rem;
    opacity: 0.6;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
    .terminal-window { height: 100svh; border-left: none; border-right: none; }
    .ascii-banner    { font-size: 0.42rem; }
    .title-bar-text  { display: none; }
    .gate-ascii      { font-size: 0.38rem; }
    .gate-box        { padding: 1.5rem 1.25rem 1.25rem; }
}


