/* ═══════════════════════════════════════════════════════════════
   Ghost Path AR (虛擬路徑投影) — 專用樣式
   v20260328 — 夜間導航 AR 路徑渲染模組
   ═══════════════════════════════════════════════════════════════ */

/* ── 主容器：預設相對定位 (啟動前居中顯示) ── */
#ghost-path-container {
    position: relative;
    width: 100%;
    min-height: 100vh;
    overflow: hidden;
    background: #000;
    font-family: 'Inter', 'Noto Sans TC', sans-serif;
}

/* AR 運行中切換為全螢幕 fixed */
#ghost-path-container.ar-active {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    z-index: 900;
}

/* 強制突破 page-section 的 constraint，防止 transform 產生新的 stacking context 導致截斷 */
section#ghost-path:has(#ghost-path-container.ar-active) {
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    animation: none !important;
    transform: none !important;
    z-index: 1000 !important;
    border-radius: 0 !important;
    border: none !important;
    background: transparent !important;
    overflow: visible !important;
}

/* ── 相機視訊背景 ── */
#gp-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* ── Canvas 疊加層（用於渲染光點與箭頭） ── */
#gp-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

/* ── 啟動前覆蓋層 ── */
#gp-start-overlay {
    position: relative;
    z-index: 20;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    color: white;
    padding: 20px;
    text-align: center;
    overflow-y: auto;
    overflow-x: hidden;
}

#gp-start-overlay .gp-start-card {
    margin: auto;
    padding: 1.5rem;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(10, 15, 30, 0.9), rgba(15, 25, 50, 0.85));
    box-shadow: 0 0 40px rgba(0, 200, 255, 0.2), 0 0 80px rgba(0, 100, 200, 0.1);
    border: 1px solid rgba(0, 200, 255, 0.3);
    max-width: 420px;
    width: 95%;
}

#gp-start-overlay .gp-start-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    display: block;
    animation: gp-float 3s ease-in-out infinite;
}

@keyframes gp-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

#gp-start-overlay h2 {
    color: #00e5ff;
    margin-bottom: 0.5rem;
    font-size: 1.4rem;
    text-shadow: 0 0 20px rgba(0, 229, 255, 0.4);
}

#gp-start-overlay .gp-subtitle {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* GPX 檔案上傳按鈕 */
.gp-upload-area {
    position: relative;
    background: rgba(0, 200, 255, 0.08);
    border: 2px dashed rgba(0, 200, 255, 0.4);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.gp-upload-area:hover,
.gp-upload-area.dragover {
    background: rgba(0, 200, 255, 0.15);
    border-color: rgba(0, 200, 255, 0.7);
    box-shadow: 0 0 25px rgba(0, 200, 255, 0.15);
}

.gp-upload-area input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.gp-upload-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.gp-upload-text {
    color: #00e5ff;
    font-size: 0.9rem;
    font-weight: 600;
}

.gp-upload-hint {
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.75rem;
    margin-top: 0.3rem;
}

/* GPX 載入狀態 */
#gp-gpx-status {
    font-size: 0.82rem;
    min-height: 1.4rem;
    margin-bottom: 1rem;
    font-weight: 600;
    transition: color 0.3s;
}

/* 啟動按鈕 */
.gp-launch-btn {
    padding: 14px 50px;
    font-size: 1.1rem;
    border-radius: 50px;
    border: none;
    background: linear-gradient(135deg, #00b4d8, #0077b6);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 180, 216, 0.5);
    transition: all 0.3s ease;
    letter-spacing: 1px;
}

.gp-launch-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(0, 180, 216, 0.7);
}

.gp-launch-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ── AR 運行中的 UI 控制面板 ── */
#gp-ui-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 50;
    pointer-events: none;
}

/* HUD 資訊列 */
#gp-hud {
    position: absolute;
    top: 60px;
    left: 0;
    width: 100%;
    z-index: 50;
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 0 15px;
    pointer-events: none;
    flex-wrap: wrap;
}

.gp-hud-item {
    background: rgba(0, 10, 25, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 200, 255, 0.2);
    border-radius: 12px;
    padding: 6px 14px;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.gp-hud-item .gp-hud-val {
    color: #00e5ff;
    font-weight: 700;
    font-size: 0.82rem;
}

/* 偏離警告橫幅 */
#gp-offroute-banner {
    position: absolute;
    top: 110px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 55;
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.9), rgba(192, 57, 43, 0.9));
    color: #fff;
    padding: 8px 24px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 700;
    box-shadow: 0 4px 20px rgba(231, 76, 60, 0.5);
    display: none;
    pointer-events: none;
    animation: gp-pulse-warn 1.5s infinite;
}

@keyframes gp-pulse-warn {
    0%, 100% { opacity: 1; box-shadow: 0 4px 20px rgba(231, 76, 60, 0.5); }
    50% { opacity: 0.85; box-shadow: 0 4px 35px rgba(231, 76, 60, 0.8); }
}

/* ── 底部控制區 ── */
#gp-controls {
    pointer-events: auto;
    padding: 15px 20px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* 校準搖桿區塊 */
.gp-calibration-panel {
    background: rgba(10, 15, 30, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(0, 200, 255, 0.2);
    border-radius: 20px;
    padding: 12px 20px;
    width: 90%;
    max-width: 420px;
    display: none;
}

.gp-calibration-panel.active {
    display: block;
}

.gp-cal-title {
    color: #00e5ff;
    font-size: 0.78rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.gp-cal-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.gp-cal-label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.72rem;
    min-width: 60px;
    text-align: right;
}

.gp-cal-slider {
    flex: 1;
    accent-color: #00e5ff;
    height: 4px;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    touch-action: none;
}

.gp-cal-slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    background: #00e5ff;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(0, 229, 255, 0.5);
}

.gp-cal-val {
    color: #ffd700;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 45px;
    text-align: center;
}

/* 底部按鈕列 */
.gp-btn-row {
    display: flex;
    gap: 10px;
    width: 90%;
    max-width: 420px;
}

.gp-ctrl-btn {
    flex: 1;
    padding: 10px 8px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(10, 15, 30, 0.8);
    backdrop-filter: blur(10px);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.gp-ctrl-btn:active {
    transform: scale(0.96);
}

.gp-ctrl-btn.primary {
    background: linear-gradient(135deg, rgba(0, 180, 216, 0.3), rgba(0, 119, 182, 0.3));
    border-color: rgba(0, 200, 255, 0.4);
    color: #00e5ff;
}

.gp-ctrl-btn.danger {
    background: rgba(231, 76, 60, 0.15);
    border-color: rgba(231, 76, 60, 0.4);
    color: #e74c3c;
}

.gp-ctrl-btn.calibrate {
    background: rgba(155, 89, 182, 0.15);
    border-color: rgba(155, 89, 182, 0.4);
    color: #bb86fc;
}

/* ── 防止背景互動 ── */
body:has(#ghost-path.active) {
    overflow: hidden !important;
    height: 100dvh;
    position: fixed;
    width: 100%;
}

/* Ensure navigation is persistent and fully visible */
body:has(#ghost-path.active) .navbar {
    opacity: 1 !important;
    filter: none !important;
    pointer-events: auto !important;
}

/* ── 路徑色彩模式指示器 (僅 AR 運行時顯示) ── */
#gp-mode-indicator {
    position: absolute;
    top: 60px;
    right: 15px;
    z-index: 55;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #00e5ff;
    box-shadow: 0 0 10px #00e5ff, 0 0 20px rgba(0, 229, 255, 0.3);
    transition: all 0.5s ease;
    pointer-events: none;
    display: none;
}

.ar-active #gp-mode-indicator {
    display: block;
}

#gp-mode-indicator.warn {
    background: #ff6b35;
    box-shadow: 0 0 10px #ff6b35, 0 0 20px rgba(255, 107, 53, 0.3);
}

#gp-mode-indicator.danger {
    background: #e74c3c;
    box-shadow: 0 0 10px #e74c3c, 0 0 20px rgba(231, 76, 60, 0.3);
    animation: gp-blink-danger 0.8s infinite;
}

@keyframes gp-blink-danger {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── 響應式適配 ── */
@media (max-width: 380px) {
    .gp-hud-item {
        padding: 4px 10px;
        font-size: 0.65rem;
    }
    .gp-hud-item .gp-hud-val {
        font-size: 0.72rem;
    }
    .gp-ctrl-btn {
        font-size: 0.68rem;
        padding: 8px 6px;
    }
}

/* ── 小螢幕/矮螢幕 (例如 5 吋手機) 高度特化 ── */
@media screen and (max-height: 700px) {
    #gp-start-overlay { padding: 10px; }
    #gp-start-overlay .gp-start-card { padding: 1rem; margin: auto; }
    #gp-start-overlay .gp-start-icon { font-size: 2.2rem; margin-bottom: 0.5rem; }
    #gp-start-overlay h2 { font-size: 1.2rem; margin-bottom: 0.3rem; }
    #gp-start-overlay .gp-subtitle { font-size: 0.8rem; margin-bottom: 0.8rem; line-height: 1.3; }
    .gp-upload-area { padding: 0.8rem; margin-bottom: 0.8rem; }
    .gp-upload-icon { font-size: 1.5rem; margin-bottom: 0.2rem; }
    .gp-upload-text { font-size: 0.85rem; }
    .gp-upload-hint { font-size: 0.7rem; }
    .gp-launch-btn { padding: 0.8rem; font-size: 0.95rem; margin-top: 5px; }
}
