/* ========================================
   Q北對話系統樣式
   忍豆風雲 / 遊戲助手定位
   固定懸浮、左下角、緊密跟隨
   ======================================== */

/* ========================================
   桌面版 (Desktop >= 768px)
   ======================================== */

/* 對話容器 - 固定左下角 */
.qbei-dialog-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 50;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    pointer-events: none;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.qbei-dialog-container.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Q北立繪 - 桌面版 200px */
.qbei-avatar {
    width: 200px;
    height: 200px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.qbei-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}

/* 對話氣泡 - 桌面版 260px，左側覆蓋貓咪 */
.qbei-bubble {
    position: relative;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    padding: 16px 20px;
    padding-right: 32px; /* 給關閉按鈕留空間 */
    width: 260px;
    margin-left: -20px; /* 覆蓋貓咪右側 */
    box-shadow: 
        0 4px 20px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    cursor: pointer;
    transition: transform 0.2s ease;
    z-index: 2;
}

.qbei-bubble:hover {
    transform: scale(1.02);
}

/* 氣泡尖角 - 指向貓咪嘴巴（左下方向） */
.qbei-bubble::before {
    content: '';
    position: absolute;
    left: -12px;
    bottom: 40px; /* 調高對準嘴巴 */
    width: 0;
    height: 0;
    border: 12px solid transparent;
    border-right-color: #e2e8f0;
    border-left: 0;
}

.qbei-bubble::after {
    content: '';
    position: absolute;
    left: -9px;
    bottom: 42px; /* 調高對準嘴巴 */
    width: 0;
    height: 0;
    border: 10px solid transparent;
    border-right-color: #ffffff;
    border-left: 0;
}

/* 關閉按鈕 - 右上角 */
.qbei-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    background: #94a3b8;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    opacity: 0.7;
}

.qbei-close:hover {
    transform: scale(1.1);
    background: #ef4444;
    opacity: 1;
}

/* 對話文字 */
.qbei-text {
    font-size: 1rem;
    line-height: 1.6;
    color: #1e293b;
    min-height: 1.6em;
}

/* 逐字顯示的游標 */
.qbei-text.typing::after {
    content: '▌';
    animation: blink 0.5s infinite;
    color: #64748b;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 點擊提示 */
.qbei-hint {
    font-size: 0.75rem;
    color: #94a3b8;
    text-align: right;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.qbei-bubble:not(.typing) .qbei-hint {
    opacity: 1;
}

/* ========================================
   角色圖片映射 - Q北
   ======================================== */

.qbei-avatar[data-character="qbei"] img {
    content: url('/images/qbei/qbei-ninja-explain.png');
}

.qbei-avatar[data-character="qbei"][data-expression="explain"] img,
.qbei-avatar[data-character="qbei"][data-expression="smile"] img,
.qbei-avatar[data-character="qbei"][data-expression="curious"] img,
.qbei-avatar[data-character="qbei"][data-expression="default"] img {
    content: url('/images/qbei/qbei-ninja-explain.png');
}

.qbei-avatar[data-character="qbei"][data-expression="welcome"] img,
.qbei-avatar[data-character="qbei"][data-expression="excited"] img,
.qbei-avatar[data-character="qbei"][data-expression="happy"] img {
    content: url('/images/qbei/qbei-ninja-welcome.png');
}

.qbei-avatar[data-character="qbei"][data-expression="sales"] img,
.qbei-avatar[data-character="qbei"][data-expression="smug"] img,
.qbei-avatar[data-character="qbei"][data-expression="sneaky"] img {
    content: url('/images/qbei/qbei-ninja-sales.png');
}

.qbei-avatar[data-character="qbei"][data-expression="sad"] img,
.qbei-avatar[data-character="qbei"][data-expression="plead"] img,
.qbei-avatar[data-character="qbei"][data-expression="beg"] img {
    content: url('/images/qbei/qbei-ninja-sad.png');
}

.qbei-avatar[data-character="qbei"][data-expression="fail"] img,
.qbei-avatar[data-character="qbei"][data-expression="disappointed"] img,
.qbei-avatar[data-character="qbei"][data-expression="facepalm"] img,
.qbei-avatar[data-character="qbei"][data-expression="wrong"] img {
    content: url('/images/qbei/qbei-ninja-fail.png');
}

/* ========================================
   角色圖片映射 - 朵朵
   ======================================== */

.qbei-avatar[data-character="duoduo"] img {
    content: url('/images/duoduo/duoduo-miko-idle.png');
}

.qbei-avatar[data-character="duoduo"][data-expression="idle"] img,
.qbei-avatar[data-character="duoduo"][data-expression="default"] img {
    content: url('/images/duoduo/duoduo-miko-idle.png');
}

.qbei-avatar[data-character="duoduo"][data-expression="cast"] img,
.qbei-avatar[data-character="duoduo"][data-expression="magic"] img {
    content: url('/images/duoduo/duoduo-miko-cast.png');
}

.qbei-avatar[data-character="duoduo"][data-expression="cheer"] img,
.qbei-avatar[data-character="duoduo"][data-expression="excited"] img,
.qbei-avatar[data-character="duoduo"][data-expression="happy"] img {
    content: url('/images/duoduo/duoduo-miko-cheer.png');
}

.qbei-avatar[data-character="duoduo"][data-expression="sorry"] img,
.qbei-avatar[data-character="duoduo"][data-expression="limit"] img {
    content: url('/images/duoduo/duoduo-miko-sorry.png');
}

.qbei-avatar[data-character="duoduo"][data-expression="sleep"] img,
.qbei-avatar[data-character="duoduo"][data-expression="sleepy"] img,
.qbei-avatar[data-character="duoduo"][data-expression="cute"] img {
    content: url('/images/duoduo/duoduo-miko-sleep.png');
}

/* ========================================
   行動按鈕（可選）
   ======================================== */

.qbei-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.qbei-action-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.qbei-action-btn.primary {
    background: linear-gradient(135deg, #eab308 0%, #ca8a04 100%);
    color: white;
}

.qbei-action-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.4);
}

.qbei-action-btn.secondary {
    background: #f1f5f9;
    color: #475569;
}

.qbei-action-btn.secondary:hover {
    background: #e2e8f0;
}

/* ========================================
   角落待命模式（不打擾）
   ======================================== */

.qbei-idle {
    position: fixed;
    bottom: 0;
    left: 20px;
    z-index: 49;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.qbei-idle:hover {
    transform: scale(1.05) translateY(-5px);
}

.qbei-idle .qbei-avatar {
    width: 120px;
    height: 120px;
}

/* Hover 時的小氣泡 */
.qbei-idle-hint {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    margin-bottom: 8px;
}

.qbei-idle-hint::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1e293b;
}

.qbei-idle:hover .qbei-idle-hint {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

/* ========================================
   深色模式支援
   ======================================== */

[data-theme="dark"] .qbei-bubble {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-color: #334155;
}

[data-theme="dark"] .qbei-bubble::before {
    border-right-color: #334155;
}

[data-theme="dark"] .qbei-bubble::after {
    border-right-color: #1e293b;
}

[data-theme="dark"] .qbei-text {
    color: #e2e8f0;
}

[data-theme="dark"] .qbei-hint {
    color: #64748b;
}

[data-theme="dark"] .qbei-action-btn.secondary {
    background: #334155;
    color: #e2e8f0;
}

[data-theme="dark"] .qbei-action-btn.secondary:hover {
    background: #475569;
}

/* ========================================
   動畫效果
   ======================================== */

/* Q北 入場動畫 */
@keyframes qbei-bounce-in {
    0% {
        transform: scale(0) translateY(50px);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) translateY(-10px);
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.qbei-dialog-container.bounce-in {
    animation: qbei-bounce-in 0.5s ease forwards;
}

/* Q北 閒置時的小動作 */
@keyframes qbei-idle-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.qbei-idle .qbei-avatar {
    animation: qbei-idle-bob 2s ease-in-out infinite;
}

/* ========================================
   手機版 (Mobile < 768px)
   對話框在上方，貓咪在下方
   ======================================== */

@media (max-width: 767px) {
    /* 容器改為上下排列 */
    .qbei-dialog-container {
        bottom: 10px;
        left: 10px;
        flex-direction: column-reverse; /* 對話框在上，貓咪在下 */
        align-items: flex-start;
    }
    
    /* 貓咪縮小到 90px */
    .qbei-avatar {
        width: 90px;
        height: 90px;
    }
    
    /* 對話框調整 */
    .qbei-bubble {
        width: 200px;
        max-width: 70vw;
        margin-left: 0;
        margin-bottom: -10px; /* 覆蓋貓咪頭頂 */
        padding: 12px 16px;
        padding-right: 28px;
    }
    
    /* 氣泡尖角改為指向下方貓咪頭頂 */
    .qbei-bubble::before {
        left: 20px;
        bottom: -12px;
        top: auto;
        border: 12px solid transparent;
        border-top-color: #e2e8f0;
        border-bottom: 0;
        border-left-color: transparent;
        border-right-color: transparent;
    }
    
    .qbei-bubble::after {
        left: 22px;
        bottom: -8px;
        top: auto;
        border: 10px solid transparent;
        border-top-color: #ffffff;
        border-bottom: 0;
        border-left-color: transparent;
        border-right-color: transparent;
    }
    
    /* 文字縮小 */
    .qbei-text {
        font-size: 0.875rem;
        line-height: 1.5;
    }
    
    .qbei-hint {
        font-size: 0.7rem;
    }
    
    /* 關閉按鈕調整 */
    .qbei-close {
        width: 18px;
        height: 18px;
        font-size: 10px;
        top: 6px;
        right: 6px;
    }
    
    /* 待命模式 */
    .qbei-idle {
        left: 10px;
        bottom: 0;
    }
    
    .qbei-idle .qbei-avatar {
        width: 80px;
        height: 80px;
    }
}

/* 深色模式手機版尖角 */
@media (max-width: 767px) {
    [data-theme="dark"] .qbei-bubble::before {
        border-top-color: #334155;
        border-right-color: transparent;
    }
    
    [data-theme="dark"] .qbei-bubble::after {
        border-top-color: #1e293b;
        border-right-color: transparent;
    }
}

/* ========================================
   Placeholder（備用）
   ======================================== */

.qbei-avatar-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    border: 3px solid #eab308;
    box-shadow: 
        0 0 20px rgba(234, 179, 8, 0.3),
        inset 0 -10px 20px rgba(0, 0, 0, 0.3);
}

.qbei-avatar[data-character] .qbei-avatar-placeholder {
    display: none;
}

/* ========================================
   右下角輕量引導（不擋路版）
   ======================================== */

/* ========================================
   手機版：全屏對話模式
   ======================================== */

/* 引導容器 - 手機版全屏 */
.qbei-guide {
    position: fixed;
    z-index: 9999;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.qbei-guide.active {
    opacity: 1;
    pointer-events: auto;
}

/* 內容佈局 - 手機版垂直置中 */
.qbei-guide-inner {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    max-width: 320px;
}

/* 氣泡框 - 手機版 */
.qbei-guide-bubble {
    position: relative;
    background: #fdfbf7;
    border-radius: 16px;
    padding: 1.25rem 1.5rem;
    padding-right: 2rem;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    order: 1;
}

/* 氣泡尾巴 - 手機版指向下方的貓咪 */
.qbei-guide-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 16px;
    height: 16px;
    background: #fdfbf7;
}

/* 關閉按鈕 */
.qbei-guide-close {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: transparent;
    color: #78716c;
    border: none;
    border-radius: 50%;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.qbei-guide-close:hover {
    color: #451a03;
    transform: scale(1.1);
}

/* 文字內容 */
.qbei-guide-text {
    font-family: 'Yuji Syuku', serif;
    font-size: 1rem;
    color: #451a03;
    line-height: 1.6;
    font-weight: 500;
}

.qbei-guide-text .highlight {
    color: #b91c1c;
    font-weight: 700;
}

/* 按鈕區 */
.qbei-guide-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.qbei-guide-actions:empty {
    display: none;
}

.qbei-guide-btn {
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 6px;
    font-family: 'Yuji Syuku', serif;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.qbei-guide-btn.primary {
    background: linear-gradient(135deg, #991b1b 0%, #7f1d1d 100%);
    color: #fef3c7;
    box-shadow: 0 2px 6px rgba(127, 29, 29, 0.3);
}

.qbei-guide-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(127, 29, 29, 0.4);
}

.qbei-guide-btn.secondary {
    background: #f5f5f4;
    color: #57534e;
    border: 1px solid #d6d3d1;
}

.qbei-guide-btn.secondary:hover {
    background: #fafaf9;
    border-color: #a8a29e;
}

/* 點擊繼續提示 */
.qbei-guide-hint {
    font-size: 0.85rem;
    color: #78716c;
    text-align: center;
    margin-top: 0.5rem;
    margin-bottom: 0;
    opacity: 0;
    animation: hint-fade 1.5s ease-in-out infinite 1s;
}

@keyframes hint-fade {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* 有按鈕時隱藏提示 */
.qbei-guide-actions:not(:empty) + .qbei-guide-hint {
    display: none;
}

/* Q北圖片 - 手機版巨大化 */
.qbei-guide-avatar {
    width: 240px;
    height: 240px;
    flex-shrink: 0;
    order: 2;
    margin-top: -0.5rem;
    cursor: pointer;
    transition: transform 0.3s ease;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.4));
}

.qbei-guide-avatar:hover {
    transform: translateY(-8px);
}

.qbei-guide-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ========================================
   桌面版：右下角固定
   ======================================== */

/* ========================================
   電腦版：左下角輕量模式
   ======================================== */
@media (min-width: 768px) {
    .qbei-guide {
        /* 取消全屏，改為左下角 */
        inset: auto;
        background: transparent;
        backdrop-filter: none;
        padding: 0;
        left: 2rem;
        right: auto;
        bottom: 0;
        width: auto;
        justify-content: flex-end;
        align-items: flex-start;
        transition: all 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
        transform: translateY(150%);
    }
    
    .qbei-guide.active {
        transform: translateY(0);
    }
    
    .qbei-guide-inner {
        flex-direction: column;
        align-items: flex-start;
        max-width: none;
    }
    
    .qbei-guide-bubble {
        max-width: 260px;
        width: auto;
        padding: 1rem 1.5rem;
        padding-right: 2rem;
        margin-bottom: 0.25rem;
        margin-left: 2rem;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    }
    
    /* 電腦版尾巴指向下方的貓咪 */
    .qbei-guide-bubble::after {
        bottom: -8px;
        left: 3rem;
        transform: rotate(45deg);
    }
    
    .qbei-guide-text {
        font-size: 1.1rem;
    }
    
    .qbei-guide-avatar {
        width: 330px;
        height: 330px;
        margin-top: 0;
        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
    }
}

/* ========================================
   深色模式
   ======================================== */

[data-theme="dark"] .qbei-guide-bubble {
    background: #1c1917;
    border-color: #78350f;
}

[data-theme="dark"] .qbei-guide-bubble::after {
    background: #1c1917;
    border-color: #78350f;
}

[data-theme="dark"] .qbei-guide-text {
    color: #fef3c7;
}

[data-theme="dark"] .qbei-guide-text .highlight {
    color: #fca5a5;
}
