/**
 * Thinking Block - 像素樂高機器人 v4
 * 全 <rect> 方塊，零曲線 → 像素 / 樂高感
 * Version: 7.0.0
 */

/* ============================================================
   容器
   ============================================================ */
.thinking-block {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border-default);
    border-radius: 12px;
    margin: 12px 0;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 慶祝彈跳動畫 */
@keyframes celebrate-bounce {
    0% { transform: scale(1); }
    30% { transform: scale(1.03); }
    60% { transform: scale(0.98); }
    100% { transform: scale(1); }
}

.thinking-block.celebrate {
    animation: celebrate-bounce 0.5s ease-out;
}

/* ============================================================
   Header
   ============================================================ */
.thinking-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    user-select: none;
}

/* ============================================================
   像素機器人指示器
   ============================================================ */
.thinking-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.thinking-neural-net {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.neural-net-svg {
    width: 100%;
    height: 100%;
}

/* --- 身體 / 耳朵 / 腿 — 主體色 --- */
.px-body, .px-ear, .px-leg {
    fill: var(--color-accent);
    opacity: 0.45;
}

/* --- 天線 — 稍亮 --- */
.px-antenna {
    fill: var(--color-accent);
    opacity: 0.65;
    animation: px-antenna-pulse 2s ease-in-out infinite;
}

/* --- 眼睛 — 深色 --- */
.px-eye {
    fill: var(--color-text-primary);
    opacity: 0.7;
}

/* --- 動畫 1: 整體彈跳 --- */
.px-robot {
    animation: px-bounce 1.5s ease-in-out infinite;
}

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

/* --- 動畫 2: 眨眼 --- */
.px-eye-left {
    transform-origin: center;
    animation: px-blink 3.5s ease-in-out infinite;
}

.px-eye-right {
    transform-origin: center;
    animation: px-blink 3.5s ease-in-out 0.1s infinite;
}

@keyframes px-blink {
    0%, 42%, 48%, 100% { transform: scaleY(1); }
    45%                { transform: scaleY(0.1); }
}

/* --- 動畫 3: 天線脈衝 --- */
@keyframes px-antenna-pulse {
    0%, 100% { opacity: 0.45; }
    50%      { opacity: 0.85; }
}

/* ============================================================
   摘要文字
   ============================================================ */
.thinking-summary {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    margin-left: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* 兩層 shimmer（仿 Logo 光影掃過） */
    background:
        /* L1: 掃描光帶 — 亮白色，與底色有清晰對比 */
        linear-gradient(90deg,
            transparent 35%,
            rgba(255, 200, 150, 0.6) 42%,
            rgba(255, 240, 220, 0.9) 48%,
            #fff 50%,
            rgba(255, 240, 220, 0.9) 52%,
            rgba(255, 200, 150, 0.6) 58%,
            transparent 65%
        ),
        /* L2: 靜態底色 accent */
        linear-gradient(90deg,
            var(--color-accent) 0%,
            var(--color-accent) 100%
        );
    background-size: 500% 100%, 100% 100%;
    background-position: 120% center, 0% center;
    -webkit-background-clip: text, text;
    background-clip: text, text;
    -webkit-text-fill-color: transparent;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    animation: thinking-shimmer 4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes thinking-shimmer {
    0%   { background-position: 120% center, 0% center; }
    40%  { background-position: -20% center, 0% center; }
    100% { background-position: 120% center, 0% center; }
}

/* ============================================================
   完成狀態 — 全綠 + 停止動畫
   ============================================================ */
.thinking-block.completed .px-robot { animation: none; }

.thinking-block.completed .px-body,
.thinking-block.completed .px-ear,
.thinking-block.completed .px-leg {
    fill: var(--color-success);
    opacity: 0.6;
}

.thinking-block.completed .px-antenna {
    animation: none;
    fill: var(--color-success);
    opacity: 0.8;
}

.thinking-block.completed .px-eye {
    fill: var(--color-success);
    opacity: 0.9;
}

.thinking-block.completed .thinking-summary {
    background: none;
    -webkit-text-fill-color: var(--color-success);
    color: var(--color-success);
    animation: none;
}

/* ============================================================
   錯誤狀態 — 全紅 + 停止動畫
   ============================================================ */
.thinking-block.error .px-robot { animation: none; }

.thinking-block.error .px-body,
.thinking-block.error .px-ear,
.thinking-block.error .px-leg {
    fill: var(--color-danger);
    opacity: 0.4;
}

.thinking-block.error .px-antenna {
    animation: none;
    fill: var(--color-danger);
    opacity: 0.5;
}

.thinking-block.error .px-eye {
    fill: var(--color-danger);
    opacity: 0.6;
}

.thinking-block.error .thinking-summary {
    background: none;
    -webkit-text-fill-color: var(--color-danger);
    color: var(--color-danger);
    animation: none;
}

/* ============================================================
   顯示/隱藏動畫
   ============================================================ */
.thinking-block.showing {
    opacity: 1;
    transform: translateY(0);
}

.thinking-block.hiding {
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
}

/* ============================================================
   深色主題支援
   ============================================================ */
[data-theme="dark"] .thinking-block {
    background: var(--color-bg-tertiary);
    border-color: var(--color-border-default);
}

[data-theme="dark"] .thinking-block.completed .thinking-summary {
    -webkit-text-fill-color: var(--color-success);
    color: var(--color-success);
}

[data-theme="dark"] .thinking-block.error .thinking-summary {
    -webkit-text-fill-color: var(--color-danger);
    color: var(--color-danger);
}

/* ============================================================
   響應式設計
   ============================================================ */
@media (max-width: 768px) {
    .thinking-block {
        margin: 8px 0;
    }

    .thinking-header {
        padding: 10px 12px;
    }

    .thinking-summary {
        font-size: 13px;
        margin-left: 8px;
    }

    .thinking-neural-net {
        width: 36px;
        height: 36px;
    }
}

/* ============================================================
   無障礙：減少動態偏好
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .px-robot { animation: none !important; }
    .px-eye-left, .px-eye-right { animation: none !important; }
    .px-antenna { animation: none !important; opacity: 0.65; }
    .thinking-summary { animation: none !important; }
}
