:root {
    --primary-color: #007aff;
    --accent-color: #ffd700;
    --bg-overlay: rgba(0, 0, 0, 0.6);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.camera-container {
    position: relative;
    width: 100%;
    height: 100%;
}

video#cameraFeed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

canvas#drawingCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    touch-action: none; /* 防止滑動頁面 */
}

/* 單手框選：固定取景框 */
.reticle-overlay {
    position: absolute;
    z-index: 2;
    width: 70vmin;
    height: 70vmin;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border: 3px dashed rgba(255, 215, 0, 0.85);
    border-radius: 50%;
    pointer-events: none;
    box-sizing: border-box;
    transition: left 0.15s ease-out, top 0.15s ease-out;
}
.reticle-overlay.hidden {
    display: none;
}

.task-hud-dock {
    position: absolute;
    top: 78px;
    right: 18px;
    z-index: 18;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.task-hud-toggle {
    min-width: 104px;
    height: 46px;
    padding: 0 14px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(7, 12, 20, 0.82);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(12px);
    cursor: pointer;
}

.task-hud-main-icon {
    font-size: 18px;
    line-height: 1;
}

.task-hud-main-value {
    font-size: 14px;
    font-weight: 800;
}

.task-status-box {
    width: min(62vw, 268px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    border-radius: 18px;
    background: rgba(7, 12, 20, 0.72);
    color: #fff;
    pointer-events: none;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.task-stat-card {
    min-height: 52px;
    border-radius: 14px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.08);
}

.task-stat-wide {
    grid-column: 1 / -1;
}

.task-stat-icon {
    font-size: 18px;
    line-height: 1;
}

.task-stat-value {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.task-stat-coords {
    font-size: 12px;
    line-height: 1.4;
    letter-spacing: 0;
}

.task-guide-arrow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    margin-left: -30px;
    margin-top: -30px;
    z-index: 16;
    pointer-events: none;
}

.task-guide-arrow::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    border-top: 10px solid #ff3b30;
    border-right: 10px solid #ff3b30;
    transform: rotate(45deg);
    box-shadow: 2px -2px 2px rgba(0, 0, 0, 0.25);
}

.task-target-obj {
    position: absolute;
    top: 54%;
    left: 50%;
    width: 260px;
    z-index: 17;
    text-align: center;
    cursor: pointer;
    pointer-events: auto;
    transform: translate(-50%, -50%);
    transition: opacity 0.08s linear;
    will-change: transform, opacity;
}

.task-target-obj img {
    width: 180px;
    height: 180px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}

.task-target-label {
    margin-top: 10px;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.7);
}

.task-encounter-modal,
.answer-modal,
.lock-overlay,
.completion-modal {
    position: fixed;
    inset: 0;
    z-index: 6000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.85);
    pointer-events: auto;
}

.task-encounter-modal.hidden,
.answer-modal.hidden,
.lock-overlay.hidden,
.completion-modal.hidden {
    display: none !important;
}

.task-encounter-card,
.answer-card,
.lock-card,
.completion-card {
    width: min(460px, 92vw);
    background: rgba(25, 25, 25, 0.96);
    border-radius: 20px;
    padding: 22px;
    color: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.task-encounter-cover {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 12px;
    background: #fff;
}

.task-encounter-title,
.answer-title,
.lock-title,
.completion-title {
    margin-top: 14px;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
}

.task-encounter-actions,
.answer-actions,
.lock-actions,
.completion-actions {
    display: flex;
    gap: 12px;
    margin-top: 18px;
}

.answer-description,
.lock-subtitle,
.completion-reward,
.answer-message,
.lock-msg {
    margin-top: 10px;
    text-align: center;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.82);
}

.answer-input-group {
    margin-top: 14px;
}

.answer-input-group label {
    display: block;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.85);
}

.answer-input-group input[type="text"],
.answer-input-group input[type="file"] {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.answer-choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.answer-choice {
    padding: 14px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    cursor: pointer;
}

.answer-choice.selected {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.22);
}

.wheels {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.wheel {
    width: 62px;
    background: #0b1220;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 10px 8px;
    text-align: center;
    touch-action: none;
}

.wheel .btn-up,
.wheel .btn-down {
    width: 100%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 8px;
    padding: 8px 0;
    font-weight: 900;
    cursor: pointer;
}

.wheel .digit {
    font-size: 28px;
    font-weight: 900;
    margin: 10px 0;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 10px 0;
}

.completion-card {
    border: 2px solid rgba(34, 197, 94, 0.45);
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.18), rgba(20, 20, 20, 0.98));
}

.completion-icon {
    font-size: 4rem;
    text-align: center;
}

.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none; /* 讓點擊穿透到 canvas */
}

.mini-map-wrap {
    position: absolute;
    right: 12px;
    bottom: 120px;
    z-index: 15;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.mini-map-toggle {
    align-self: flex-end;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    border-radius: 12px;
    font-size: 12px;
    padding: 4px 8px;
    cursor: pointer;
    pointer-events: auto;
}

.mini-map-refresh {
    align-self: flex-end;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    border-radius: 12px;
    font-size: 12px;
    padding: 4px 8px;
    cursor: pointer;
    pointer-events: auto;
}

.mini-map {
    width: 220px;
    height: 220px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
    opacity: 0.9;
    pointer-events: auto;
}

.mini-map-task-indicators {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
    pointer-events: none;
}

.mini-map-task-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 220px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(7, 12, 20, 0.82);
    color: #fff;
    font-size: 11px;
    line-height: 1.3;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(10px);
}

.mini-map-task-arrow {
    display: inline-flex;
    width: 18px;
    height: 18px;
    align-items: center;
    justify-content: center;
    color: #f97316;
    font-size: 16px;
    transform-origin: center;
}

.location-info {
    max-width: 220px;
    font-size: 10px;
    color: #fff;
    background: rgba(0, 0, 0, 0.45);
    padding: 6px 8px;
    border-radius: 10px;
    line-height: 1.4;
    opacity: 0.95;
}

.mini-map-wrap.collapsed .mini-map,
.mini-map-wrap.collapsed .mini-map-task-indicators,
.mini-map-wrap.collapsed .location-info {
    display: none;
}

/* 任務景點介紹面板（AR-VIEW 風格：任務封面＋說明） */
.task-intro-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 70vh;
    background: rgba(20, 20, 20, 0.97);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    animation: slideUpPanel 0.3s ease-out;
}
.task-intro-panel.hidden {
    display: none !important;
}
@keyframes slideUpPanel {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.task-intro-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.task-intro-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}
.task-intro-body {
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.task-intro-cover {
    width: 100%;
    max-height: 240px;
    object-fit: contain;
    border-radius: 12px;
    background: #111;
    margin-bottom: 14px;
}
.task-intro-description {
    font-size: 0.95rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.9);
    white-space: pre-wrap;
}

.location-bar {
    position: static;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 12px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

@media (max-width: 480px) {
    .feature-dock {
        top: 16px;
        left: 10px;
        gap: 8px;
    }

    .feature-drawer-panel {
        min-width: 148px;
    }

    .dock-panel {
        padding: 8px;
    }

    .task-hud-dock {
        top: 78px;
        right: 10px;
    }

    .task-hud-toggle {
        min-width: 92px;
        height: 42px;
        padding: 0 12px;
    }

    .task-status-box {
        width: min(58vw, 230px);
        padding: 8px;
        gap: 6px;
    }

    .task-stat-card {
        min-height: 46px;
        padding: 7px 8px;
    }

    .task-stat-icon {
        font-size: 16px;
    }

    .task-stat-value {
        font-size: 12px;
    }

    .task-stat-coords {
        font-size: 11px;
    }

    .task-target-obj {
        width: 220px;
    }

    .task-target-obj img {
        width: 150px;
        height: 150px;
    }

    .task-target-label {
        font-size: 16px;
    }

    .header {
        top: 8px;
        padding: 0 56px;
    }

    .status-pill {
        font-size: 12px;
        padding: 4px 10px;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }

    .top-controls {
        top: 60px;
        width: 72vw;
    }

    .location-bar {
        font-size: 11px;
    }

    .mode-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .instruction {
        bottom: 110px;
    }

    .voice-panel {
        bottom: 120px;
    }

    .mini-map-wrap {
        right: 8px;
        bottom: 140px;
    }

    .mini-map {
        width: 180px;
        height: 180px;
    }

    .mini-map-task-indicator {
        max-width: 180px;
        font-size: 10px;
        padding: 5px 8px;
    }
}

.mini-map .leaflet-control-container {
    display: none;
}

/* 讓按鈕可以被點擊 */
.ui-layer button, .result-panel, .director-panel, .director-toggle {
    pointer-events: auto;
}

.header {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    padding: 0 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.feature-dock {
    position: absolute;
    top: 20px;
    left: 14px;
    z-index: 30;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    pointer-events: auto;
}

.feature-dock-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.feature-drawer-panel {
    min-width: 170px;
}

.dock-panel {
    background: rgba(0, 0, 0, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 10px;
    backdrop-filter: blur(10px);
}

.dock-panel.hidden,
.feature-drawer-panel.hidden,
.feature-dock-menu.hidden {
    display: none !important;
}

.feature-dock-toggle {
    background: rgba(0, 0, 0, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.top-controls {
    position: absolute;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    width: min(76vw, 360px);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 20;
    pointer-events: none;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 20px;
    backdrop-filter: blur(10px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.exit-btn {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.4px;
}

.status-pill {
    background: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 14px;
    backdrop-filter: blur(10px);
}

.dock-panel .mode-switcher {
    position: static;
    transform: none;
    width: 100%;
    justify-content: center;
    pointer-events: auto;
}

.instruction {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 16px;
    text-align: center;
    pointer-events: none;
    transition: opacity 0.3s;
}

/* 單手／手繪切換 + 框內拍照 */
.selection-instruction {
    position: absolute;
    bottom: 88px;
    left: 50%;
    transform: translateX(-50%);
    width: min(92vw, 320px);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: opacity 0.3s;
}
.selection-mode-toggle {
    display: flex;
    border-radius: 20px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.25);
}
.mode-toggle-btn {
    padding: 6px 14px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.mode-toggle-btn.active {
    background: var(--accent-color);
    color: #1a1a1a;
    font-weight: 600;
}
.mode-toggle-btn:not(.active):hover {
    background: rgba(255, 255, 255, 0.1);
}
.instruction-text {
    margin: 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.95);
    text-align: center;
    line-height: 1.35;
}
.capture-reticle-btn {
    padding: 12px 28px;
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
    background: var(--accent-color);
    border: none;
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(255, 215, 0, 0.4);
    transition: transform 0.15s, box-shadow 0.15s;
}
.capture-reticle-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.5);
}
.capture-reticle-btn:active {
    transform: scale(0.98);
}
.selection-instruction.hide-for-draw .capture-reticle-btn {
    display: none;
}
.selection-instruction.hide-for-draw .instruction-text {
    font-size: 15px;
}

/* 導演控制台樣式 */
.director-toggle {
    position: absolute;
    top: 70px;
    right: 20px;
    background: rgba(0, 0, 0, 0.6);
    color: #ffd700;
    border: 1px solid #ffd700;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    z-index: 20;
}

.director-panel {
    position: absolute;
    top: 100px;
    right: 20px;
    width: 80%;
    max-width: 300px;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #444;
    border-radius: 12px;
    padding: 15px;
    display: none; /* 預設隱藏 */
    flex-direction: column;
    gap: 10px;
    z-index: 20;
    backdrop-filter: blur(10px);
}

.director-toggle.hidden,
.director-panel.hidden {
    display: none !important;
}

.lang-selector {
    position: static;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #444;
    border-radius: 12px;
    padding: 6px 10px;
    color: #fff;
    font-size: 12px;
    pointer-events: auto;
}

.zoom-control {
    position: static;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #444;
    border-radius: 14px;
    padding: 6px 10px;
    color: #fff;
    font-size: 12px;
    pointer-events: auto;
}

.zoom-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    border-radius: 10px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
}

.zoom-btn.active {
    background: #ffd700;
    color: #000;
}

.floating-mic-btn {
    position: absolute;
    right: 18px;
    bottom: 18px;
    width: 58px;
    height: 58px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff7a18, #ff3d81);
    color: #fff;
    font-size: 24px;
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35);
    z-index: 26;
    cursor: pointer;
}

.floating-mic-btn.active {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
}

.voice-panel {
    position: absolute;
    right: 18px;
    bottom: 86px;
    width: min(92vw, 380px);
    background: rgba(7, 12, 20, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 18px;
    padding: 14px;
    color: #fff;
    font-size: 12px;
    z-index: 25;
    pointer-events: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(14px);
}

.voice-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.voice-panel-title {
    font-size: 15px;
    font-weight: 700;
}

.voice-close-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
}

.voice-helper-text {
    margin-top: 8px;
    color: rgba(255, 255, 255, 0.72);
    line-height: 1.5;
}

.voice-draft-input {
    width: 100%;
    min-height: 88px;
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    resize: vertical;
    font: inherit;
}

.voice-draft-input::placeholder {
    color: rgba(255, 255, 255, 0.48);
}

.voice-action-row {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.voice-action-btn {
    flex: 1;
    border: none;
    border-radius: 12px;
    padding: 12px 14px;
    font-weight: 700;
    cursor: pointer;
}

.voice-action-btn.primary {
    background: #22c55e;
    color: #04130a;
}

.voice-action-btn.secondary {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.voice-action-btn.secondary.active {
    background: #ef4444;
}

.voice-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    margin-bottom: 8px;
    color: #fff;
    font-size: 12px;
    pointer-events: auto;
}

.voice-row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
}

.voice-label {
    color: #ffd700;
    min-width: 28px;
}

.voice-text {
    flex: 1;
    color: #fff;
}

.voice-status {
    color: #9fd3ff;
    font-size: 11px;
    text-align: right;
    margin-top: 8px;
}

.query-transit {
    position: absolute;
    left: 50%;
    bottom: 144px;
    transform: translateX(-50%);
    z-index: 35;
    pointer-events: none;
}

.query-transit-card {
    min-width: min(82vw, 280px);
    padding: 12px 16px;
    border-radius: 22px;
    background: rgba(7, 12, 20, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #fff;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qp-container {
    position: relative;
    width: 200px;
    height: 120px;
}

.qp-paper {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.96);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    padding: 12px 14px;
    box-sizing: border-box;
    transform-origin: center;
    transition: transform 0.6s ease-in-out, opacity 0.6s ease-in-out;
}

.qp-paper-text {
    font-size: 13px;
    line-height: 1.5;
    color: rgba(248, 250, 252, 0.96);
    display: flex;
    align-items: center;
    gap: 6px;
}

.qp-paper-text .qp-dot {
    width: 4px;
    height: 4px;
    border-radius: 999px;
    background: rgba(248, 250, 252, 0.9);
    animation: qpDotBounce 1.1s infinite ease-in-out;
}

.qp-paper-text .qp-dot:nth-child(2) {
    animation-delay: 0.12s;
}

.qp-paper-text .qp-dot:nth-child(3) {
    animation-delay: 0.24s;
}

.qp-paper-text .qp-spinner {
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 2px solid rgba(148, 163, 184, 0.5);
    border-top-color: #e5f3ff;
    animation: qpSpin 0.9s linear infinite;
}

.qp-plane {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 64px;
    height: 64px;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
}

/* 寄出階段：紙張微縮但保持可見，飛機飛出 */
.query-transit.sending .qp-paper {
    transform: scale(0.9);
    opacity: 1;
}

.query-transit.sending .qp-plane {
    animation: qpFlyOut 1.5s ease-in forwards;
}

/* 回程：先讓紙飛機從遠方飛回來 */
.query-transit.returning .qp-plane {
    animation: qpFlyIn 1.5s ease-out forwards;
}

/* 飛回來後展開紙張 */
.query-transit.returning .qp-paper {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

@keyframes qpFlyOut {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(40%, -150%) scale(0.7); opacity: 1; }
    100% { transform: translate(220%, -320%) scale(0.1); opacity: 0; }
}

@keyframes qpFlyIn {
    0% { transform: translate(-220%, -320%) scale(0.1) rotate(-35deg); opacity: 0; }
    50% { transform: translate(-50%, -140%) scale(0.7) rotate(-12deg); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
}

@keyframes qpDotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes qpSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes returnPlaneFly {
    0% { opacity: 0; transform: translate(64px, -18px) rotate(16deg) scale(0.84); }
    28% { opacity: 1; transform: translate(30px, -8px) rotate(6deg) scale(0.96); }
    72% { opacity: 1; transform: translate(8px, -2px) rotate(-3deg) scale(1); }
    100% { opacity: 0; transform: translate(-8px, 0) rotate(-8deg) scale(0.76); }
}

@keyframes returnBubbleOpen {
    0% { opacity: 0; transform: translateX(24px) scale(0.34) rotate(-10deg); }
    54% { opacity: 0; transform: translateX(14px) scale(0.48) rotate(-6deg); }
    100% { opacity: 1; transform: translateX(0) scale(1) rotate(0deg); }
}

.answer-toast {
    position: absolute;
    right: 18px;
    bottom: 158px;
    width: min(86vw, 340px);
    z-index: 34;
    background: rgba(8, 14, 24, 0.92);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(14px);
    padding: 14px;
}

.answer-toast-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.answer-toast-title {
    font-size: 13px;
    font-weight: 700;
    color: #fde68a;
}

.answer-toast-close {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
}

.answer-toast-text {
    font-size: 13px;
    line-height: 1.6;
    max-height: 180px;
    overflow-y: auto;
    white-space: pre-wrap;
}

@media (max-width: 480px) {
    .query-transit {
        bottom: 122px;
    }

    .query-transit-card {
        min-width: min(78vw, 250px);
        padding: 10px 12px;
        gap: 10px;
    }

    .query-transit-visual {
        width: 64px;
        height: 36px;
        flex-basis: 64px;
    }

    .query-transit-label {
        font-size: 12px;
        white-space: normal;
    }

    .answer-toast {
        right: 12px;
        bottom: 146px;
        width: min(84vw, 300px);
    }
}

.lang-selector select {
    background: #111;
    color: #fff;
    border: 1px solid #555;
    border-radius: 8px;
    padding: 4px 6px;
    font-size: 12px;
}

.director-panel.open {
    display: flex;
}

.panel-title {
    color: #ffd700;
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 5px;
}

.input-group label {
    display: block;
    color: #ccc;
    font-size: 12px;
    margin-bottom: 3px;
}

.director-input {
    width: 100%;
    background: #222;
    border: 1px solid #555;
    color: white;
    padding: 8px;
    border-radius: 6px;
    font-size: 12px;
    resize: vertical;
    min-height: 60px;
}

/* 結果面板 */
.result-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 20px;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    gap: 15px;
    z-index: 10000;
}

.result-panel.active {
    display: flex !important;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.result-content {
    display: flex;
    gap: 15px;
}

/* Mobile: 直向顯示，避免右側分析區被擠到看不到（就會覺得「沒動畫沒結果」） */
@media (max-width: 480px) {
    .result-panel {
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .result-content {
        flex-direction: column;
    }

    .preview-area {
        max-height: 220px;
    }

    .analysis-box {
        max-height: 45vh;
        overflow: visible;
    }

    .ai-text {
        max-height: 40vh;
    }
}

/* 預覽區：1 張為單圖、2 張橫排、3 張網格，不裁切、不空白 */
.preview-area {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    min-height: 100px;
    max-height: 200px;
    width: 100%;
    background: #f5f5f5;
    border-radius: 12px;
    padding: 8px;
    box-sizing: border-box;
}

.preview-area img {
    display: block;
    max-height: 180px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #eee;
}

/* 1 張：單圖置中 */
.preview-area.preview-count-1 img {
    max-width: 100%;
    max-height: 200px;
}

/* 2 張：橫排均分 */
.preview-area.preview-count-2 {
    flex-direction: row;
}
.preview-area.preview-count-2 img {
    flex: 1;
    min-width: 0;
    max-width: 50%;
}

/* 3 張：三格均分 */
.preview-area.preview-count-3 img {
    flex: 1;
    min-width: 0;
    max-width: 33.333%;
}

.analysis-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    max-height: 200px; /* 限制高度 */
    overflow: hidden;
}

.ai-text {
    font-size: 15px;
    color: #333;
    line-height: 1.4;
    overflow-y: auto;
    padding-right: 5px;
}

/* 讓 Raw Output 有區別 */
.raw-output {
    font-family: monospace;
    font-size: 12px;
    color: #666;
    background: #f5f5f5;
    padding: 5px;
    margin-top: 10px;
    border-radius: 4px;
    display: none; /* 預設隱藏 */
}

.action-buttons {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
}

.btn.secondary {
    background: #f0f0f0;
    color: #333;
}

.hidden {
    display: none !important;
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ccc;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

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

/* Multi-photo Strip */
.photo-strip {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.photo-slot {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    border: 2px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
}

.photo-slot.filled {
    border: 2px solid #4caf50;
}

.photo-slot.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.3);
}

.photo-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.slot-placeholder {
    font-size: 18px;
    font-weight: 600;
    color: #ccc;
}

.photo-slot.filled .slot-placeholder {
    display: none;
}

.photo-hint {
    font-size: 13px;
    color: #666;
    text-align: center;
    margin-bottom: 10px;
    line-height: 1.5;
    max-width: 100%;
}

.photo-hint.complete {
    color: #4caf50;
    font-weight: 500;
}

/* Enhanced Loading State */
#aiLoading {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f0f7ff 0%, #e8f4fd 100%);
    border-radius: 12px;
    border: 1px solid #d0e8ff;
}

#loadingText {
    font-size: 14px;
    color: #1976d2;
    transition: opacity 0.15s ease;
    min-width: 200px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Confidence Indicator */
.confidence-bar {
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}

.confidence-fill.high { background: linear-gradient(90deg, #4caf50, #8bc34a); }
.confidence-fill.medium { background: linear-gradient(90deg, #ff9800, #ffc107); }
.confidence-fill.low { background: linear-gradient(90deg, #f44336, #ff5722); }

/* Action Buttons Update */
#addPhotoBtn {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #81c784;
}

#addPhotoBtn:hover {
    background: #c8e6c9;
}

#addPhotoBtn:disabled {
    background: #f5f5f5;
    color: #bbb;
    border-color: #ddd;
}

/* Need More Photos Message */
.need-more-photos {
    padding: 16px;
    background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
    border-radius: 12px;
    border: 1px solid #ffe082;
    text-align: center;
}

.need-more-photos .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.need-more-photos .message {
    font-size: 15px;
    color: #f57c00;
    font-weight: 500;
}

.need-more-photos .hint {
    font-size: 13px;
    color: #795548;
    margin-top: 4px;
}

/* Retry Message */
.retry-message {
    padding: 16px;
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    border-radius: 12px;
    border: 1px solid #ef9a9a;
    text-align: center;
}

.retry-message .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.retry-message .message {
    font-size: 15px;
    color: #c62828;
    font-weight: 500;
}

.retry-message .hint {
    font-size: 13px;
    color: #795548;
    margin-top: 4px;
}