/* main.css (UI 優化 - 飛行畫面重構) */

/* 針對考核與偏離修正模式，隱藏搖桿上的所有提示文字(包含主標籤) */
body.mode-assessment .joystick-sector-text,
body.mode-assessment .joystick-label,
body.mode-atti .joystick-sector-text,
body.mode-atti .joystick-label,
body.mode-deviation_correction .joystick-sector-text, /* 【新增】 */
body.mode-deviation_correction .joystick-label {       /* 【新增】 */
    display: none;
}

/* 【新增】針對智慧按鈕的隱藏狀態 */
#context-action-btn.hidden {
    display: none;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    background: linear-gradient(135deg, #87CEEB, #E0F6FF);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-overflow-scrolling: touch;
}

.hidden {
    display: none !important;
}

/* 強制橫屏提示 */
.orientation-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    color: #fff;
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.rotate-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: rotate 2s infinite ease-in-out;
}

@keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

/* 只有在 body 有 'in-game' class 且為直向時，才觸發橫向鎖定 */
@media (orientation: portrait) {
    body.in-game .orientation-warning {
        display: flex;
    }
    body.in-game > div:not(.orientation-warning) {
        display: none !important;
    }
}

#gameContainer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: block;
    overflow: hidden;
}

#renderer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: 1;
}

#renderer canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.hud-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
}

.command-panel {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    width: 220px;
    font-size: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    pointer-events: auto;
    
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.command-display {
    background: #666;
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    line-height: 1.3;
    order: 1;
}

.start-button {
    background: #FF9800;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    font-size: 16px;
    pointer-events: auto;
    min-height: 32px;
    order: 4;
}

.start-button:active {
    background: #F57C00;
}

.stats-display {
    position: absolute;
    top: 90px;
    right: 10px;
    background: rgba(76, 175, 80, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: bold;
    backdrop-filter: blur(10px);
    display: none;
    min-width: 130px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.keyboard-help {
    position: absolute;
    bottom: 170px;
    left: 10px; 
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 10px;
    backdrop-filter: blur(10px);
    display: none;
    max-width: 300px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    pointer-events: none;
}

.keyboard-help h4 { margin: 0 0 8px 0; color: #4CAF50; font-size: 12px; text-align: center; font-weight: bold; }
.keyboard-help .control-group { margin: 5px 0; display: flex; justify-content: space-between; align-items: center; }
.keyboard-help .control-keys { font-family: 'Courier New', monospace; background: rgba(255, 255, 255, 0.15); padding: 3px 8px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.3); font-weight: bold; color: #FFD700; font-size: 10px; min-width: 50px; text-align: center; }
.keyboard-help .control-desc { color: #E0E0E0; font-size: 10px; flex: 1; margin-left: 10px; }
.keyboard-help .special-keys { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.2); }
.keyboard-help .special-group { display: flex; justify-content: space-between; align-items: center; margin: 3px 0; }
.keyboard-help .special-group .control-keys { min-width: 20px; padding: 2px 6px; font-size: 9px; }
.keyboard-help .special-group .control-desc { font-size: 9px; margin-left: 8px; }
.keyboard-help .engine-hint { margin-top: 8px; padding: 6px 8px; background: rgba(255, 152, 0, 0.2); border-radius: 5px; border: 1px solid rgba(255, 152, 0, 0.4); font-size: 9px; color: #FFB74D; text-align: center; line-height: 1.3; }
.keyboard-help .key-layout { margin: 6px 0; font-size: 9px; color: #B0B0B0; text-align: center; }

.top-hud-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 150;
    pointer-events: none;
}

.top-left-hud, .top-right-menu {
    pointer-events: auto;
}

.status-panel {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    min-width: 130px;
}
.status-item {
    display: flex;
    justify-content: space-between;
    margin: 3px 0;
    line-height: 1.2;
    white-space: nowrap;
    gap: 10px;
    font-size: 16px;
}

.top-right-menu {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

#menu-toggle-btn {
    width: 44px;
    height: 44px;
    background: transparent; 
    border: none;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: background-color 0.2s;
    padding: 0;
    
    display: flex;
    align-items: center;
    justify-content: center;
}

#menu-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

.hud-icon-button {
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    font-size: 20px;
    line-height: 1; 
    text-align: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: background-color 0.2s;
    padding: 0;
}
.hud-icon-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

#collapsible-menu {
    position: absolute;
    top: 0;
    right: 54px;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    transition: opacity 0.2s, transform 0.2s;
    transform-origin: top right;
}
#collapsible-menu.hidden {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
    pointer-events: none;
}
#collapsible-menu .action-button {
    width: 100%;
    min-width: 140px;
    padding: 10px 16px;
    font-size: 14px;
}

.controls-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 160px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    z-index: 200;
}

.joystick { width: 140px; height: 140px; position: relative; touch-action: none; flex-shrink: 0; background: transparent; border: none; margin: 0; }
.joystick-outer-ring { width: 100%; height: 100%; border: 3px solid rgba(255, 255, 255, 0.8); border-radius: 50%; background: rgba(64, 64, 64, 0.8); position: relative; backdrop-filter: blur(5px); }
.joystick-sector { position: absolute; width: 50%; height: 50%; transition: background-color 0.2s ease; cursor: pointer; display: flex; align-items: center; justify-content: center; pointer-events: auto; overflow: hidden; }
.joystick-sector.top { top: 0; left: 25%; background: rgba(128, 128, 128, 0.6); border-radius: 70px 70px 0 0; clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }
.joystick-sector.right { top: 25%; right: 0; background: rgba(128, 128, 128, 0.6); border-radius: 0 70px 70px 0; clip-path: polygon(0% 0%, 100% 50%, 0% 100%); }
.joystick-sector.bottom { bottom: 0; left: 25%; background: rgba(128, 128, 128, 0.6); border-radius: 0 0 70px 70px; clip-path: polygon(0% 0%, 50% 100%, 100% 0%); }
.joystick-sector.left { top: 25%; left: 0; background: rgba(128, 128, 128, 0.6); border-radius: 70px 0 0 70px; clip-path: polygon(100% 0%, 0% 50%, 100% 100%); }
.joystick-sector.outward-active { background: rgba(255, 152, 0, 0.9) !important; animation: outwardGlow 0.8s ease-in-out infinite alternate; }
@keyframes outwardGlow { 0% { box-shadow: inset 0 0 15px rgba(255, 152, 0, 0.6); } 100% { box-shadow: inset 0 0 25px rgba(255, 152, 0, 0.9); } }
.joystick-sector-text { color: rgba(255, 255, 255, 0.9); font-size: 10px; font-weight: bold; text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8); pointer-events: none; white-space: nowrap; position: absolute; z-index: 2; }
.joystick-handle { position: absolute; top: 50%; left: 50%; width: 50px; height: 50px; background: radial-gradient(circle at 30% 30%, #ff6666, #ff4444, #cc0000); border: 3px solid rgba(255, 255, 255, 0.9); border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), inset -2px -2px 8px rgba(0, 0, 0, 0.3), inset 2px 2px 8px rgba(255, 255, 255, 0.3); transition: all 0.1s ease; pointer-events: none; z-index: 10; }
.joystick-handle.moving { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), inset -1px -1px 4px rgba(0, 0, 0, 0.4), inset 1px 1px 4px rgba(255, 255, 255, 0.4); }
.joystick-label { position: absolute; top: -30px; left: 50%; transform: translateX(-50%); color: rgba(255, 255, 255, 0.95); font-weight: bold; font-size: 11px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8); white-space: nowrap; background: rgba(0, 0, 0, 0.8); padding: 3px 8px; border-radius: 8px; backdrop-filter: blur(5px); border: 1px solid rgba(255, 255, 255, 0.3); pointer-events: none; z-index: 15; }

#preflight-screen { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(10px); z-index: 10000; display: flex; align-items: center; justify-content: center; color: white; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; transition: opacity 0.5s ease-in-out; }
.preflight-box { position: relative; background: rgba(20, 20, 30, 0.85); padding: 30px 40px; border-radius: 15px; border: 1px solid rgba(255, 255, 255, 0.2); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.preflight-title { font-size: 24px; margin: 0; margin-bottom: 10px; }
.preflight-subtitle { font-size: 14px; color: #ccc; margin-bottom: 25px; }

.preflight-box .back-button {
    position: absolute;
    top: 15px;
    left: 15px;
    background: none;
    border: none;
    color: #ccc;
    font-size: 28px;
    cursor: pointer;
    padding: 5px 10px;
}
.preflight-box .back-button:hover {
    color: white;
}

.mode-selector { display: flex; gap: 20px; margin-bottom: 30px; align-items: stretch; }
.mode-button { background: rgba(255, 255, 255, 0.05); border: 2px solid rgba(255, 255, 255, 0.3); color: #eee; padding: 15px 20px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 160px; height: 120px; transition: all 0.2s ease-in-out; }
.mode-button:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.7); }
.mode-button.selected { background: rgba(29, 161, 242, 0.8); border-color: #1DA1F2; transform: scale(1.05); }
.mode-icon { font-size: 32px; }
.mode-text { 
    font-size: 16px; 
    font-weight: bold; 
    margin-top: 8px; 
    display: block;
}
.mode-desc { 
    font-size: 12px; 
    color: #bbb; 
    margin-top: 4px; 
    display: block;
}
.start-flight-button { background: #4CAF50; color: white; border: none; padding: 12px 40px; border-radius: 8px; font-size: 16px; font-weight: bold; cursor: pointer; transition: background-color 0.2s; }
.start-flight-button:hover { background: #45a049; }
.start-flight-button:disabled { background: #555; color: #999; cursor: not-allowed; }
.mode-container { padding: 20px; border: 2px solid rgba(255, 255, 255, 0.5); border-radius: 10px; background: rgba(255, 255, 255, 0.1); display: flex; flex-direction: column; gap: 15px; }
.mode-container-title { font-size: 18px; font-weight: bold; color: #fff; margin-bottom: 10px; }
.mode-container-desc { font-size: 12px; color: #ccc; margin-top: -10px; margin-bottom: 10px; }
.mode-sub-selector { display: flex; flex-direction: column; gap: 15px; }
.mode-button-sub { background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.4); color: #eee; padding: 10px; border-radius: 8px; cursor: pointer; width: 100%; transition: all 0.2s ease-in-out; text-align: center; }
.mode-button-sub:hover { background: rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.8); }
.mode-button-sub.selected { background: rgba(76, 175, 80, 0.8); border-color: #4CAF50; transform: scale(1.05); }
.mode-button-sub .mode-text { font-size: 14px; }
.mode-button-sub .mode-desc { font-size: 11px; }
.mode-button.disabled { background: rgba(0, 0, 0, 0.2); border-color: rgba(255, 255, 255, 0.1); color: #888; cursor: not-allowed; transform: none; }
.mode-button.disabled:hover { background: rgba(0, 0, 0, 0.2); border-color: rgba(255, 255, 255, 0.1); }

@media (max-width: 768px) {
    #preflight-screen {
        overflow-y: auto;          
        align-items: flex-start;
        padding: 20px 0;
    }

    .preflight-box {
        max-height: 90vh;         
        overflow-y: auto;
    }
}

@media (min-width: 769px) {
    #preflight-screen {
        overflow-y: hidden;
        align-items: center;
        padding: 0;
    }

    .preflight-box {
        max-height: none;
        overflow-y: visible;
    }
}

body.mode-tutorial #currentCommand {
    background: #4a4a4a;
    color: #FFD700;
    border: 1px solid rgba(255, 215, 0, 0.5);
}

body.mode-tutorial #currentCommand.summary {
    color: white; 
}

body:not(.mode-tutorial) #tutorial-hint,
body:not(.mode-tutorial) #tutorial-step-counter {
    display: none !important;
}

#tutorial-hint {
    color: #FFD700;
    text-align: center;
    font-weight: bold;
    font-size: 11px;
    line-height: 1.3;
    display: none;
    order: 3;
}

#tutorial-step-counter {
    color: #00BCD4;
    font-size: 11px;
    text-align: center;
    display: none;
    order: 2;
}

.joystick-sector.hint-blink {
    animation: hintBlink 1s ease-in-out infinite alternate;
}

@keyframes hintBlink {
    from {
        background-color: rgba(255, 215, 0, 0.7);
        box-shadow: inset 0 0 15px rgba(255, 215, 0, 0.8);
    }
    to {
        background-color: rgba(200, 160, 0, 0.6);
        box-shadow: inset 0 0 8px rgba(200, 160, 0, 0.7);
    }
}

.joystick-sector.pressed {
    background: rgba(255, 20, 20, 0.8) !important;
    animation: pressFlash 0.8s ease-in-out infinite alternate;
}

@keyframes pressFlash {
    from {
        background: rgba(255, 20, 20, 0.8) !important;
        box-shadow: inset 0 0 15px rgba(255, 20, 20, 0.7);
    }
    to {
        background: rgba(180, 0, 0, 0.7) !important;
        box-shadow: inset 0 0 8px rgba(180, 0, 0, 0.6);
    }
}

#training-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: black;
    color: white;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.loading-text {
  font-size: 24px;
  animation: pulse 1.5s infinite ease-in-out;
}