/* Reset 與基本設定 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a1a; /* 深色背景符合天文主題 */
    color: #e0e0e0;
    overflow: hidden; /* 防止捲動 */
}

/* 主容器：採用 Flexbox 切分左右 */
#app {
    display: flex;
    position: relative;
    width: 100%;
    height: 100%;
}

/* 左側主控台：佔據 25% 寬度，加入更現代的過渡效果與陰影 */
#controls {
    position: relative;
    width: 25%;
    min-width: 320px;
    max-width: 400px;
    background: rgba(30, 30, 30, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: inset -1px 0 0 rgba(255,255,255,0.1), 4px 0 15px rgba(0,0,0,0.6);
    z-index: 10;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

#controls.collapsed {
    margin-left: clamp(-400px, -25%, -320px);
}

/* 控制面板捲動區域 */
.controls-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 20px 20px;
}

/* 隱藏捲軸，但保留捲動功能 (網頁觀感更俐落) */
.controls-scroll-area::-webkit-scrollbar {
    width: 8px;
}
.controls-scroll-area::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}
.controls-scroll-area::-webkit-scrollbar-track {
    background: transparent;
}

#controls h2, .task-card h2 {
    text-align: center;
    margin: 20px 20px 10px;
    padding-bottom: 15px;
    font-weight: 600;
    letter-spacing: 1px;
}

#controls h2 {
    color: #4da6ff;
    border-bottom: 2px solid rgba(77, 166, 255, 0.3);
}

.task-card h2 {
    color: #ffd700;
    border-bottom: 2px solid rgba(255, 215, 0, 0.3);
}

/* 面板切換按鈕，設計成內嵌/懸浮在邊緣 */
#toggleControlsBtn {
    position: absolute;
    top: 50%;
    right: -24px;
    transform: translateY(-50%);
    width: 24px;
    height: 60px;
    background: rgba(40, 40, 40, 0.9);
    border: 1px solid rgba(255,255,255,0.1);
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: white;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    box-shadow: 4px 0 10px rgba(0,0,0,0.3);
    transition: background-color 0.2s, right 0.4s;
}

#toggleControlsBtn svg {
    width: 16px;
    height: 16px;
    transition: transform 0.4s ease;
}

#controls.collapsed #toggleControlsBtn {
    right: -24px;
    background: #4da6ff;
}

#controls.collapsed #toggleControlsBtn svg {
    transform: rotate(180deg);
}

#toggleControlsBtn:hover {
    background: rgba(77, 166, 255, 0.8) !important;
}

/* 控制模組群組設定 (卡片外觀) */
.control-group {
    margin-bottom: 16px;
    padding: 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s;
}

.control-group:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.control-group h3 {
    font-size: 1.05em;
    margin-bottom: 12px;
    color: #e5c07b; /* 偏向柔和的金色 */
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: color 0.2s;
}

.control-group h3:hover {
    color: #ffd700;
}

/* 箭頭樣式 */
.control-group h3::after {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.3s ease;
    margin-right: 4px;
}

/* 折疊狀態 (collapsed) */
.control-group.collapsed h3 {
    margin-bottom: 0;
}

.control-group.collapsed h3::after {
    transform: rotate(-45deg);
}

.control-group.collapsed > *:not(h3) {
    display: none !important; /* 簡單使用 display none 來收合 */
}

.control-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.95em;
    cursor: pointer;
}

/* 滑桿樣式 */
input[type="range"] {
    width: 100%;
    margin-top: 8px;
    margin-bottom: 8px;
    cursor: pointer;
}

/* 按鈕樣式 */
button {
    width: 100%;
    padding: 8px;
    margin-top: 5px;
    margin-bottom: 10px;
    background-color: #4da6ff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s, transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
}

button:hover {
    background-color: #3388dd;
}

button:active {
    transform: scale(0.95);
}

/* 右側畫布容器：佔據剩餘全部空間 (約 75%) */
#canvas-container {
    flex-grow: 1;
    position: relative;
    background-color: #000; /* 純黑色宇宙背景 */
    min-width: 0; /* 關鍵：讓 flex item 可以往內縮小，避免被內部 canvas 撐開 */
    overflow: hidden; /* 防止內部元素溢出或產生捲軸 */
}

/* 鎖定 Canvas 的 CSS 尺寸，將畫素更新委託給 JS，但讓外觀始終貼齊容器，解決彈縮閃爍與偏移問題 */
#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    outline: none;
}

/* 任務卡 UI (改版為右側面板) */
.task-card {
    position: relative;
    width: 25%;
    min-width: 320px;
    max-width: 400px;
    background: rgba(30, 30, 30, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: inset 1px 0 0 rgba(255,255,255,0.1), -4px 0 15px rgba(0,0,0,0.6);
    z-index: 10;
    display: flex; /* 在桌機版是預設顯示的 */
    flex-direction: column;
    color: #e0e0e0;
    transition: margin-right 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.task-card.collapsed {
    margin-right: clamp(-400px, -25%, -320px);
}

/* 隱藏桌機版的底部分頁按鈕 */
.mobile-tabs {
    display: none;
}

/* 任務卡面板切換按鈕，設計成內嵌/懸浮在邊緣 */
#toggleTaskCardBtn {
    position: absolute;
    top: 50%;
    left: -24px;
    transform: translateY(-50%);
    width: 24px;
    height: 60px;
    background: rgba(40, 40, 40, 0.9);
    border: 1px solid rgba(255,255,255,0.1);
    border-right: none;
    border-radius: 8px 0 0 8px;
    color: white;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    box-shadow: -4px 0 10px rgba(0,0,0,0.3);
    transition: background-color 0.2s, left 0.4s;
}

#toggleTaskCardBtn svg {
    width: 16px;
    height: 16px;
    transition: transform 0.4s ease;
}

.task-card.collapsed #toggleTaskCardBtn {
    left: -24px;
    background: #4da6ff;
}

.task-card.collapsed #toggleTaskCardBtn svg {
    transform: rotate(180deg);
}

#toggleTaskCardBtn:hover {
    background: rgba(77, 166, 255, 0.8) !important;
}

.task-nav-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
    flex-shrink: 0;
    margin: 0;
    padding: 0;
}

.task-nav-btn:hover:not(:disabled) {
    background: rgba(77, 166, 255, 0.5);
    border-color: rgba(77, 166, 255, 0.8);
}

.task-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.task-content-container {
    flex: 1;
    margin: 0 20px;
    overflow-y: auto;
    padding-right: 8px; /* 為了讓滾動條好看一點所以加一點右邊距 */
    padding-bottom: 20px;
}

/* 隱藏捲軸，但保留捲動功能 (網頁觀感更俐落) */
.task-content-container::-webkit-scrollbar {
    width: 6px;
}
.task-content-container::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}
.task-content-container::-webkit-scrollbar-track {
    background: transparent;
}

.task-content-container h3 {
    margin: 0 0 12px 0;
    font-size: 1.1em;
    color: #4da6ff;
    text-align: left;
    line-height: 1.4;
}

.task-content-container p {
    margin: 0;
    font-size: 0.95em;
    line-height: 1.6;
    color: #e8e8e8;
    text-align: left;
    white-space: pre-line;
}

/* 緯度輸入框樣式 */
.custom-number-input {
    width: 55px;
    background: #333;
    color: white;
    padding: 6px 4px;
    text-align: center;
    box-sizing: border-box;
    -moz-appearance: textfield;
    appearance: textfield;
}

/* 隱藏預設的黑白按鈕邊框 */
.custom-number-input::-webkit-inner-spin-button,
.custom-number-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#latUp:hover, #latDown:hover {
    background-color: #666 !important;
}

#latUp:active, #latDown:active {
    background-color: #888 !important;
}

/* RWD: 當螢幕寬度小於 768px 時，改為上下佈局，天球在上，控制台在下，各佔 1/2 */
@media (max-width: 768px) {
    #app {
        flex-direction: column-reverse;
    }

    /* ===== 面板切換按鈕隱藏 ===== */
    /* 因為改用底部分頁切換，隱藏原本的收合展開按鈕 */
    #toggleControlsBtn, #toggleTaskCardBtn {
        display: none !important;
    }

    #controls.collapsed, .task-card.collapsed {
        /* 取消之前的 margin 負值隱藏，改全憑 active class 控制 */
        margin: 0 !important; 
    }

    /* ===== 手機版標題縮小 ===== */
    #controls h2, .task-card h2 {
        font-size: 1.1rem;
        margin: 12px 15px 8px;
        padding-bottom: 10px;
    }

    /* ===== 手機版控制台與任務卡共同設定 ===== */
    #controls, .task-card {
        width: 100%;
        min-width: 0;
        max-width: none;
        height: 50%; /* 下方 50% 空間保留給按鈕和面板 */
        flex: none;
        margin: 0 !important;
        border: none;
        border-top: 1px solid rgba(255,255,255,0.1);
        box-shadow: 0 -5px 15px rgba(0,0,0,0.5); /* 上方陰影 */
        
        /* 預設隱藏，由 active class 控制顯示 */
        display: none;
        position: absolute;
        bottom: 0px; 
        left: 0;
        z-index: 10;
        
        /* 騰出空間給底部分頁按鈕 */
        padding-bottom: 50px; 
    }

    #controls.active, .task-card.active {
        display: flex; /* 顯示使用 flex 繼續保持內部排版 */
    }
    
    .controls-scroll-area, .task-content-container {
        /* 內部滾動區域需要減去高度避免被下方按鈕蓋住 */
        height: 100%;
    }

    #canvas-container {
        width: 100%;
        height: 50%; /* 上方 50% 給天球 */
        min-height: 0;
        flex: none;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1;
    }

    /* ===== 手機版底部切換分頁按鈕 ===== */
    .mobile-tabs {
        display: flex;
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 50px;
        background: #111;
        z-index: 20;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.5);
    }

    .mobile-tab-btn {
        flex: 1;
        background: transparent;
        color: #888;
        border: none;
        border-top: 3px solid transparent;
        border-radius: 0;
        margin: 0;
        padding: 0;
        font-size: 1.1em;
        font-weight: bold;
        cursor: pointer;
        transition: all 0.2s;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-tab-btn.active {
        color: #4da6ff;
        border-top: 3px solid #4da6ff;
        background: rgba(77, 166, 255, 0.1);
    }
}
