:root {
    --ui-bg: rgba(255, 255, 255, 0.96);
    --brand: #0b74ff;
    --text: #2b2f36;
    --radius: 12px;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
    background: #e6f3ff;
}

#canvas-container {
    width: 100%;
    height: 100vh;
    display: block;
}

/* 控制面板 */
#controls {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 340px;
    max-width: calc(100vw - 32px);
    background: var(--ui-bg);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    z-index: 10;
    backdrop-filter: saturate(180%) blur(8px);
    transition: transform .25s ease, opacity .2s ease, height .25s ease, width .25s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.control-group {
    margin-bottom: 14px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}

select,
input[type="range"],
input[type="number"] {
    width: 100%;
}

select,
input[type="number"] {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #dcdfe6;
    background: #fff;
    color: #333;
    font-size: 14px;
}

input[type="range"] {
    accent-color: var(--brand);
}

.time-display {
    text-align: center;
    margin-top: 6px;
    font-weight: 800;
    color: var(--brand);
    font-size: 18px;
    letter-spacing: 0.5px;
}

h2 {
    margin: 0 0 12px;
    font-size: 16px;
    text-align: center;
    color: #111;
    border-bottom: 1px solid #e9eef5;
    padding-bottom: 10px;
}

/* 文件上传按钮 */
.file-upload {
    position: relative;
    display: inline-block;
    width: 100%;
}

.file-upload input[type="file"] {
    display: none;
}

.file-upload-btn {
    width: 100%;
    padding: 10px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    font-size: 14px;
    display: block;
    box-sizing: border-box;
    transition: background 0.2s;
}

.file-upload-btn:hover {
    background: #218838;
}

/* 位置配置 */
.location-config {
    background: #f0f7ff;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #c5dcf7;
}

.location-config label {
    color: #0056b3;
    margin-bottom: 10px;
}

.location-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
    margin-bottom: 8px;
}

.location-row.single {
    grid-template-columns: 1fr;
}

.location-row .field {
    display: flex;
    flex-direction: column;
}

.location-row .field span {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.location-row select,
.location-row input {
    width: 100%;
    margin-bottom: 0;
    box-sizing: border-box;
}

.lat-display {
    font-size: 13px;
    color: #555;
    text-align: center;
    padding-top: 4px;
}

/* 开关行 */
.inline-row {
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.inline-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand);
}

/* 指南针 */
#compass {
    position: absolute;
    bottom: 18px;
    right: 18px;
    width: 80px;
    height: 80px;
    pointer-events: none;
    z-index: 5;
}

/* 空状态提示 */
#empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #666;
    font-size: 16px;
    z-index: 4;
    pointer-events: none;
}

/* 图例提示 */
.legend {
    display: flex;
    gap: 10px;
    font-size: 12px;
    margin-top: 8px;
    justify-content: center;
    color: #666;
}

/* 移动端适配 */
@media (max-width: 600px) {
    #controls {
        top: env(safe-area-inset-top, 8px);
        right: 8px;
        width: 280px;
        padding: 12px;
        border-radius: 14px;
    }

    #timeBlock {
        display: none;
    }

    #controls[data-collapsed="true"] {
        width: 54px;
        height: 54px;
        padding: 0;
        border-radius: 50%;
        display: grid;
        place-items: center;
    }

    #controls[data-collapsed="true"] .panel-content {
        display: none;
    }

    #controls[data-collapsed="true"] .fab {
        display: grid;
    }

    #controls[data-collapsed="false"] .panel-content {
        display: block;
    }

    #controls[data-collapsed="false"] .fab {
        display: none;
    }

    .fab {
        display: none;
        width: 54px;
        height: 54px;
        border-radius: 50%;
        background: var(--ui-bg);
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
        color: var(--brand);
        font-weight: 900;
        place-items: center;
        user-select: none;
        cursor: pointer;
    }

    /* 底部时间条 */
    #timeDock {
        position: absolute;
        left: 10px;
        right: 10px;
        bottom: env(safe-area-inset-bottom, 10px);
        height: 56px;
        background: var(--ui-bg);
        border-radius: 14px;
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 12px;
        z-index: 12;
        backdrop-filter: saturate(180%) blur(8px);
    }

    #timeDock .timeLabel {
        font-size: 13px;
        color: #3b3f46;
        font-weight: 700;
        white-space: nowrap;
    }

    #timeDock input[type="range"] {
        flex: 1;
        height: 28px;
        accent-color: var(--brand);
    }

    #timeDock .timeValue {
        width: 64px;
        text-align: right;
        font-weight: 800;
        color: var(--brand);
    }

    #compass {
        width: 64px;
        height: 64px;
        bottom: calc(env(safe-area-inset-bottom, 16px) + 56px);
        right: 12px;
    }
}

/* 控制面板 */
#controls {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 340px;
    max-width: calc(100vw - 32px);
    background: var(--ui-bg);
    padding: 16px;
    padding-top: 52px; /* 给按钮留出空间 */
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    z-index: 10;
    backdrop-filter: saturate(180%) blur(8px);
    transition: width .3s ease, height .3s ease, padding .3s ease;
    overflow: hidden;
}

.panel-content {
    max-height: calc(90vh - 80px);
    overflow-y: auto;
    transition: opacity .2s ease;
}

/* 切换按钮 - 框内左上角 */
.sidebar-toggle {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 36px;
    height: 36px;
    background: #f0f4f8;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s;
    z-index: 11;
    color: var(--text);
}

.sidebar-toggle:hover {
    background: #e2e8f0;
}

/* 收起状态 */
#controls.collapsed {
    width: 52px;
    height: 52px;
    padding: 8px;
    border-radius: 12px;
}

#controls.collapsed .panel-content {
    opacity: 0;
    pointer-events: none;
}

/* 移动端适配 */
@media (max-width: 600px) {
    #controls {
        top: env(safe-area-inset-top, 8px);
        right: 8px;
        width: 280px;
        padding: 12px;
        padding-top: 48px;
    }

    #controls.collapsed {
        width: 48px;
        height: 48px;
        padding: 6px;
    }

    .sidebar-toggle {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }

    #timeBlock {
        display: none;
    }

    #timeDock {
        position: absolute;
        left: 10px;
        right: 10px;
        bottom: env(safe-area-inset-bottom, 10px);
        height: 56px;
        background: var(--ui-bg);
        border-radius: 14px;
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 12px;
        z-index: 12;
        backdrop-filter: saturate(180%) blur(8px);
    }

    #timeDock .timeLabel {
        font-size: 13px;
        color: #3b3f46;
        font-weight: 700;
        white-space: nowrap;
    }

    #timeDock input[type="range"] {
        flex: 1;
        height: 28px;
        accent-color: var(--brand);
    }

    #timeDock .timeValue {
        width: 64px;
        text-align: right;
        font-weight: 800;
        color: var(--brand);
    }

    #compass {
        width: 64px;
        height: 64px;
        bottom: calc(env(safe-area-inset-bottom, 16px) + 56px);
        right: 12px;
    }
}