/* ============================================================
   AI TERMINAL — styles/ai-terminal.css
   Follows the existing tape-trigger / drawer aesthetic from index.html
   ============================================================ */

/* ── Mascot (pixel robot, floats above trigger) ──────────────── */

@keyframes mascotFloat {
    0%, 100% { transform: translateY(0px); }
    50%       { transform: translateY(-6px); }
}

@keyframes mascotGlowDark {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(255,255,255,0.5)); }
    50%       { filter: drop-shadow(0 0 12px rgba(255,255,255,0.9)); }
}

@keyframes mascotGlowLight {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(255,107,0,0.6)); }
    50%       { filter: drop-shadow(0 0 12px rgba(255,107,0,1)); }
}

@keyframes bubblePop {
    0%   { transform: scale(0.85) translateY(4px); opacity: 0; }
    60%  { transform: scale(1.06) translateY(0); opacity: 1; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes dotBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%            { transform: translateY(-3px); opacity: 1; }
}

.ai-mascot {
    position: fixed;
    bottom: 50px; /* sits above the 44px trigger with a small gap */
    right: 88px;  /* visually centered over the trigger label */
    z-index: 7999;
    background: none;
    border: none;
    box-shadow: none;
    cursor: pointer;
    padding: 4px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    animation: mascotFloat 3s ease-in-out infinite;
}

/* default: white robot for dark sections */
.ai-mascot-svg {
    display: block;
    animation: mascotGlowDark 2.5s ease-in-out infinite;
    transition: transform 0.2s ease, filter 0.4s ease;
}

/* on lime green hero: black robot (color set via JS class) */
.ai-mascot.on-light-bg .ai-mascot-svg {
    animation: mascotGlowLight 2.5s ease-in-out infinite;
}


.ai-mascot:hover .ai-mascot-svg {
    transform: scale(1.1);
}

/* on dark sections: bubble is white with dark text (default) */
/* on light (lime green) hero: bubble flips to dark */
.ai-mascot.on-light-bg .ai-mascot-bubble {
    background: #0A0A0A;
    color: #ffffff;
}
.ai-mascot.on-light-bg .ai-mascot-bubble::after {
    border-top-color: #0A0A0A;
}
.ai-mascot.on-light-bg .ai-mascot-bubble-dots span {
    background: #ffffff;
}

.ai-mascot-bubble {
    font-family: 'DM Mono', monospace;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: #0a0a0a;
    background: #ffffff;
    padding: 6px 12px;
    border-radius: 10px 10px 10px 2px; /* speech bubble tail bottom-left */
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    order: -1; /* sits above the robot */
    position: relative;
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
    animation: bubblePop 0.4s cubic-bezier(0.16, 1, 0.3, 1) 1s both;
}

/* triangle tail pointing down toward robot */
.ai-mascot-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 14px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #ffffff;
}

.ai-mascot-bubble-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.ai-mascot-bubble-dots span {
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #0a0a0a;
    animation: dotBounce 1.2s ease-in-out infinite;
}

.ai-mascot-bubble-dots span:nth-child(1) { animation-delay: 0s; }
.ai-mascot-bubble-dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-mascot-bubble-dots span:nth-child(3) { animation-delay: 0.3s; }

/* ── Trigger button (fixed bottom-right corner) ─────────────── */

@keyframes aiPulse {
    0%, 100% { box-shadow: 0 -4px 14px rgba(0,191,255,0.25), 0 0 0 1px rgba(0,191,255,0.15); }
    50%       { box-shadow: 0 -6px 22px rgba(0,191,255,0.45), 0 0 0 1px rgba(0,191,255,0.3); }
}

.ai-terminal-trigger {
    position: fixed;
    bottom: 0;
    right: 80px;
    z-index: 8000;

    height: 44px;
    padding: 0 18px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.25);
    border-bottom: none;
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;

    transition: height 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                background 0.3s,
                border-color 0.3s,
                box-shadow 0.3s;
    animation: aiPulse 3s infinite;
}

.ai-terminal-trigger:hover {
    height: 54px;
    background: rgba(0,0,0,0.72);
    border-color: rgba(0,191,255,0.6);
    box-shadow: 0 -8px 24px rgba(0,191,255,0.3);
    animation: none;
}

.ai-terminal-trigger-label {
    font-family: 'DM Mono', monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* ── Overlay ─────────────────────────────────────────────────── */

#ai-terminal-overlay {
    display: none; /* shown via JS */
    position: fixed;
    inset: 0;
    z-index: 9500;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: flex-end;
    justify-content: center;
    padding: 0;

    /* Slide up from bottom */
    transform: translateY(100%);
    transition: transform 0.55s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.3s ease;
    opacity: 0;
}

#ai-terminal-overlay.is-active {
    transform: translateY(0);
    opacity: 1;
}

/* ── Terminal panel ──────────────────────────────────────────── */

.ai-terminal-panel {
    position: relative;
    width: 100%;
    max-width: 900px;
    height: 78vh;
    min-height: 420px;
    max-height: 860px;
    background: #0d0d0d;
    border: 1px solid rgba(0,255,65,0.25);
    border-bottom: none;
    border-radius: 12px 12px 0 0;

    display: flex;
    flex-direction: column;
    overflow: hidden;

    box-shadow: 0 -12px 80px rgba(0,255,65,0.12), inset 0 1px 0 rgba(0,255,65,0.2);
}

/* ── Mac window controls ─────────────────────────────────────── */

.ai-terminal-controls {
    position: absolute;
    top: 22px;
    right: 28px;
    z-index: 10;
}

/* ── Terminal header ─────────────────────────────────────────── */

.ai-terminal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 32px 14px;
    font-family: 'DM Mono', monospace;
    background: rgba(0,255,65,0.03);
}

.ai-terminal-prompt {
    color: #00FF41;
    font-size: 1rem;
    font-weight: 700;
    text-shadow: 0 0 8px rgba(0,255,65,0.7);
}

.ai-terminal-title {
    color: #00FF41;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-shadow: 0 0 6px rgba(0,255,65,0.5);
}

.ai-terminal-version {
    color: rgba(0,255,65,0.45);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
}

.ai-terminal-status {
    margin-left: auto;
    margin-right: 80px; /* clear of mac controls */
    font-size: 0.75rem;
    letter-spacing: 0.18em;
    color: rgba(0,255,65,0.5);
    text-transform: uppercase;
}

.ai-terminal-header-blink {
    color: #00FF41;
    font-size: 0.85rem;
    animation: blink 1s step-end infinite;
    text-shadow: 0 0 6px rgba(0,255,65,0.6);
}

/* blink keyframe is already defined in index.html — fallback here in case */
@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

.ai-terminal-divider {
    flex-shrink: 0;
    height: 1px;
    background: linear-gradient(90deg, rgba(0,255,65,0.5) 0%, rgba(0,255,65,0.08) 100%);
    margin: 0;
}

/* ── Boot message ────────────────────────────────────────────── */

.ai-terminal-boot {
    flex-shrink: 0;
    padding: 18px 32px 0;
    font-family: 'DM Mono', monospace;
    font-size: 0.92rem;
    color: rgba(0,255,65,0.8);
    letter-spacing: 0.04em;
    line-height: 1.7;
}

.ai-boot-voice-hint {
    display: inline;
    background: rgba(0,255,65,0.1);
    border: 1px solid rgba(0,255,65,0.4);
    color: #00FF41;
    font-family: 'DM Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    vertical-align: middle;
}

.ai-boot-voice-hint:hover {
    background: rgba(0,255,65,0.18);
    border-color: rgba(0,255,65,0.7);
}

/* ── Message history ─────────────────────────────────────────── */

.ai-terminal-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 32px 0;
    scroll-behavior: smooth;

    /* Thin scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(0,255,65,0.25) transparent;
}

.ai-terminal-messages::-webkit-scrollbar {
    width: 4px;
}
.ai-terminal-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ai-terminal-messages::-webkit-scrollbar-thumb {
    background: rgba(0,255,65,0.25);
    border-radius: 2px;
}

/* ── Individual messages ─────────────────────────────────────── */

.ai-msg {
    display: block;
    font-family: 'DM Mono', monospace;
    font-size: 1rem;
    line-height: 1.8;
    margin-bottom: 24px;
    word-break: break-word;
}

.ai-msg--user {
    color: #00FF41;
    text-shadow: 0 0 6px rgba(0,255,65,0.5);
}

.ai-msg-prompt {
    color: #00FF41;
    font-weight: 700;
    opacity: 0.8;
}

.ai-msg--assistant {
    color: #e8e8e8;
    padding-left: 20px;
    border-left: 2px solid rgba(0,255,65,0.35);
    position: relative;
}

.ai-msg--error {
    color: rgba(255,90,82,0.85);
}

.ai-msg-link {
    color: #00FF41;
    text-decoration: underline;
    text-underline-offset: 3px;
    word-break: break-all;
}
.ai-msg-link:hover { color: #fff; }

/* Streaming blink cursor */
.ai-stream-cursor {
    color: #00FF41;
    animation: blink 0.7s step-end infinite;
    font-size: 0.88rem;
    margin-left: 2px;
}

/* Thinking dots animation */
.ai-thinking {
    color: rgba(0,255,65,0.5);
    font-size: 0.88rem;
}

.ai-thinking::after {
    content: '';
    animation: thinkingDots 1.2s steps(4, end) infinite;
}

@keyframes thinkingDots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}

/* ── Speak button ────────────────────────────────────────────── */

.ai-speak-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
    background: none;
    border: none;
    font-size: 0.82rem;
    opacity: 0.4;
    cursor: pointer;
    padding: 2px 4px;
    vertical-align: middle;
    transition: opacity 0.2s, transform 0.2s;
    border-radius: 3px;
}

.ai-speak-btn:hover {
    opacity: 1;
    transform: scale(1.15);
}

.ai-speak-btn:disabled {
    cursor: default;
}

@keyframes speakPulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50%       { opacity: 1;   transform: scale(1.2); }
}

.ai-speak-btn.is-speaking {
    animation: speakPulse 0.8s ease-in-out infinite;
    opacity: 0.9;
}

/* ── Suggestion chips ────────────────────────────────────────── */

.ai-terminal-suggestions {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 18px 32px 14px;
    border-top: 1px solid rgba(0,255,65,0.1);
}

.ai-suggestion-chip {
    background: rgba(0,255,65,0.07);
    border: 1px solid rgba(0,255,65,0.35);
    color: rgba(0,255,65,0.9);
    font-family: 'DM Mono', monospace;
    font-size: 0.84rem;
    letter-spacing: 0.05em;
    padding: 9px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

.ai-suggestion-chip:hover {
    background: rgba(0,255,65,0.14);
    border-color: rgba(0,255,65,0.7);
    color: #00FF41;
    box-shadow: 0 0 12px rgba(0,255,65,0.15);
}

/* ── Voice UI (waveform + transcribing) ─────────────────────── */

.ai-voice-ui {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 28px 14px;
    border-top: 1px solid rgba(0,255,65,0.1);
    background: #050505;
}

.ai-voice-ui.is-visible {
    display: flex;
}

.ai-voice-ui-inner {
    width: 100%;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.ai-waveform {
    width: 100%;
    height: 48px;
    display: block;
}

/* Transcribing dots */
.ai-transcribing-dots {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 48px;
}

.ai-transcribing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #00FF41;
    box-shadow: 0 0 6px rgba(0,255,65,0.7);
    animation: transcribeBounce 1s ease-in-out infinite;
}

.ai-transcribing-dots span:nth-child(1) { animation-delay: 0s; }
.ai-transcribing-dots span:nth-child(2) { animation-delay: 0.1s; }
.ai-transcribing-dots span:nth-child(3) { animation-delay: 0.2s; }
.ai-transcribing-dots span:nth-child(4) { animation-delay: 0.3s; }
.ai-transcribing-dots span:nth-child(5) { animation-delay: 0.4s; }

@keyframes transcribeBounce {
    0%, 80%, 100% { transform: scaleY(1);   opacity: 0.4; }
    40%            { transform: scaleY(2.5); opacity: 1;   }
}

/* Thinking orb — pulsing rings */
.ai-thinking-orb {
    display: none;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 48px;
    height: 48px;
}

.ai-orb-core {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #00FF41;
    box-shadow: 0 0 10px rgba(0,255,65,0.9);
    position: absolute;
}

.ai-orb-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(0,255,65,0.5);
    animation: orbExpand 1.8s ease-out infinite;
}

.ai-orb-ring:nth-child(1) { width: 18px; height: 18px; animation-delay: 0s; }
.ai-orb-ring:nth-child(2) { width: 28px; height: 28px; animation-delay: 0.4s; }
.ai-orb-ring:nth-child(3) { width: 40px; height: 40px; animation-delay: 0.8s; }

@keyframes orbExpand {
    0%   { opacity: 0.8; transform: scale(0.6); }
    100% { opacity: 0;   transform: scale(1.4); }
}

/* Speaking bars — music equalizer style */
.ai-speaking-bars {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 48px;
}

.ai-speaking-bars span {
    width: 4px;
    border-radius: 2px;
    background: #00FF41;
    box-shadow: 0 0 6px rgba(0,255,65,0.6);
    animation: speakBar 0.8s ease-in-out infinite alternate;
}

.ai-speaking-bars span:nth-child(1)  { height: 10px; animation-delay: 0.0s; }
.ai-speaking-bars span:nth-child(2)  { height: 20px; animation-delay: 0.1s; }
.ai-speaking-bars span:nth-child(3)  { height: 32px; animation-delay: 0.2s; }
.ai-speaking-bars span:nth-child(4)  { height: 24px; animation-delay: 0.15s; }
.ai-speaking-bars span:nth-child(5)  { height: 40px; animation-delay: 0.05s; }
.ai-speaking-bars span:nth-child(6)  { height: 40px; animation-delay: 0.25s; }
.ai-speaking-bars span:nth-child(7)  { height: 24px; animation-delay: 0.1s; }
.ai-speaking-bars span:nth-child(8)  { height: 32px; animation-delay: 0.3s; }
.ai-speaking-bars span:nth-child(9)  { height: 20px; animation-delay: 0.05s; }
.ai-speaking-bars span:nth-child(10) { height: 10px; animation-delay: 0.2s; }

@keyframes speakBar {
    from { transform: scaleY(0.3); opacity: 0.5; }
    to   { transform: scaleY(1.0); opacity: 1.0; }
}

.ai-voice-ui-label {
    font-family: 'DM Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.1em;
    color: rgba(0,255,65,0.5);
    text-align: center;
}

.ai-voice-cancel {
    background: transparent;
    border: 1px solid rgba(255,90,82,0.3);
    color: rgba(255,90,82,0.6);
    font-family: 'DM Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    padding: 4px 12px;
    border-radius: 3px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.ai-voice-cancel:hover {
    border-color: rgba(255,90,82,0.7);
    color: rgba(255,90,82,0.9);
}

/* ── Voice mode toggle (in header) ──────────────────────────── */

.ai-voice-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 14px;
    background: rgba(0,255,65,0.06);
    border: 1px solid rgba(0,255,65,0.35);
    color: rgba(0,255,65,0.75);
    font-family: 'DM Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    padding: 5px 11px;
    border-radius: 3px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.ai-voice-mode-btn:hover {
    border-color: rgba(0,255,65,0.7);
    color: #00FF41;
    background: rgba(0,255,65,0.1);
}

.ai-voice-mode-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(0,255,65,0.35);
    flex-shrink: 0;
    transition: background 0.2s, box-shadow 0.2s;
}

.ai-voice-mode-btn.is-active {
    border-color: rgba(0,255,65,0.7);
    color: #00FF41;
    background: rgba(0,255,65,0.06);
}

.ai-voice-mode-btn.is-active .ai-voice-mode-dot {
    background: #00FF41;
    box-shadow: 0 0 6px rgba(0,255,65,0.8);
    animation: speakPulse 1s ease-in-out infinite;
}

/* ── Mic button ──────────────────────────────────────────────── */

.ai-mic-btn {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid rgba(0,255,65,0.25);
    color: rgba(0,255,65,0.6);
    width: 38px;
    height: 38px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
}

.ai-mic-btn:hover:not(:disabled) {
    background: rgba(0,255,65,0.08);
    border-color: rgba(0,255,65,0.5);
    color: #00FF41;
}

.ai-mic-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0,255,65,0.5); }
    50%       { box-shadow: 0 0 0 5px rgba(0,255,65,0); }
}

.ai-mic-btn.is-listening {
    background: rgba(0,255,65,0.15);
    border-color: #00FF41;
    color: #00FF41;
    animation: micPulse 1s ease-out infinite;
}

.ai-mic-icon {
    pointer-events: none;
}

/* ── Input row ───────────────────────────────────────────────── */

.ai-terminal-input-row {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px 18px;
    border-top: 2px solid rgba(0,255,65,0.2);
    background: rgba(0,255,65,0.04);
    margin: 0 12px 12px;
    border-radius: 6px;
    border: 1px solid rgba(0,255,65,0.25);
}

.ai-input-dollar {
    font-family: 'DM Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: #00FF41;
    text-shadow: 0 0 8px rgba(0,255,65,0.7);
    flex-shrink: 0;
}

.ai-terminal-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: 'DM Mono', monospace;
    font-size: 1rem;
    color: #ffffff;
    caret-color: #00FF41;
    letter-spacing: 0.03em;
}

.ai-terminal-input::placeholder {
    color: rgba(255,255,255,0.35);
}

.ai-terminal-input:disabled {
    opacity: 0.4;
}

.ai-send-btn {
    flex-shrink: 0;
    background: rgba(0,255,65,0.15);
    border: 1px solid rgba(0,255,65,0.5);
    color: #00FF41;
    font-family: 'DM Mono', monospace;
    font-size: 1rem;
    width: 38px;
    height: 38px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.ai-send-btn:hover:not(:disabled) {
    background: rgba(0,255,65,0.28);
    border-color: #00FF41;
    transform: scale(1.08);
    box-shadow: 0 0 14px rgba(0,255,65,0.3);
}

.ai-send-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

/* ── Mobile ──────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .ai-terminal-trigger {
        display: none; /* replaced by mobile bottom bar button */
    }

    .ai-mascot {
        display: none;
    }

    .ai-terminal-panel {
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }

    #ai-terminal-overlay {
        align-items: flex-start;
    }

    .ai-terminal-input {
        font-size: 16px; /* prevent iOS zoom */
    }

    .ai-terminal-header {
        padding: 18px 20px 10px;
    }

    .ai-terminal-messages,
    .ai-terminal-boot {
        padding-left: 20px;
        padding-right: 20px;
    }

    .ai-terminal-suggestions {
        padding: 12px 20px;
    }

    .ai-terminal-input-row {
        margin: 0 8px 8px;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .ai-terminal-divider {
        margin: 0;
    }
}
