* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, 'Microsoft YaHei', sans-serif;
    background-color: #2c3e50;
    color: #ecf0f1;
}

#ui {
    width: 320px;
    flex: 0 0 320px;
    height: 100%;
    background-color: #34495e;
    padding: 18px 16px;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.5);
    z-index: 10;
    overflow-y: auto;
}

#ui::-webkit-scrollbar {
    width: 8px;
}

#ui::-webkit-scrollbar-track {
    background: #2c3e50;
}

#ui::-webkit-scrollbar-thumb {
    background: #7f8c8d;
    border-radius: 4px;
}

#ui::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

h2 {
    margin: 4px 0 14px;
    font-size: 20px;
    letter-spacing: 1px;
}

h3 {
    margin: 0 0 10px;
    font-size: 15px;
    color: #bdc3c7;
}

hr {
    border: 0;
    border-top: 1px solid #4a6274;
    margin: 16px 0;
}

button {
    width: 100%;
    padding: 11px;
    margin-bottom: 10px;
    background-color: #3498db;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    border-radius: 4px;
    font-weight: bold;
    transition: background-color 0.2s, opacity 0.2s;
}

button:hover:not(:disabled) {
    background-color: #2980b9;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

button.green { background-color: #27ae60; }
button.green:hover:not(:disabled) { background-color: #219150; }
button.warn { background-color: #d35400; }
button.warn:hover:not(:disabled) { background-color: #b04600; }
button.purple { background-color: #8e44ad; }
button.purple:hover:not(:disabled) { background-color: #763a91; }
button.ghost {
    background-color: #2c3e50;
    color: #bdc3c7;
    border: 1px solid #4a6274;
}
button.ghost:hover:not(:disabled) { background-color: #3b5266; }

/* 控制栏分组：把「生成 / 视图 / 编辑 / 存档 / 图例」在视觉上分开，
   避免原来一长串控件全部挤在同一列、找不到重点。 */
.group {
    margin-bottom: 16px;
}

.group-primary {
    margin-bottom: 14px;
}

.group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #4a6274;
    font-size: 11px;
    letter-spacing: 2px;
    font-weight: 700;
    color: #95a5a6;
}

.group-title::before {
    content: "";
    width: 3px;
    height: 10px;
    border-radius: 1px;
    background: #2ecc71;
}

.control {
    margin-bottom: 10px;
}

.cloud-control {
    display: none;
    padding: 8px 10px;
    border: 1px dashed #4a6274;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.12);
}

.mini-hint {
    margin-top: 4px;
    font-size: 10px;
    line-height: 1.45;
    color: #7f8c8d;
}

.control label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.control input[type="number"] {
    width: 64px;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid #4a6274;
    background: #2c3e50;
    color: #ecf0f1;
}

.control input[type="range"] {
    width: 110px;
}

.control select {
    max-width: 180px;
    padding: 5px 6px;
    border-radius: 4px;
    border: 1px solid #4a6274;
    background: #2c3e50;
    color: #ecf0f1;
    font-size: 12px;
}

.control span {
    min-width: 38px;
    text-align: right;
    font-size: 12px;
    color: #bdc3c7;
}

#progressWrap {
    display: none;
    margin: -2px 0 10px;
}

#progressBar {
    height: 6px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 3px;
    overflow: hidden;
}

#progressFill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #2ecc71, #1abc9c);
    transition: width 0.15s linear;
}

#progressText {
    margin-top: 4px;
    font-size: 11px;
    color: #95a5a6;
    min-height: 14px;
}

.btn-row {
    display: flex;
    gap: 8px;
}

.btn-row button {
    flex: 1;
    margin-bottom: 8px;
}

.btn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 6px;
}

.btn-grid button {
    margin: 0;
    padding: 8px 4px;
    font-size: 12px;
    background-color: #2c3e50;
    border: 1px solid #4a6274;
}

.btn-grid button:hover:not(:disabled) {
    background-color: #3b5266;
}

#editPanel {
    display: none;
}

#lassoPanel {
    border: 1px dashed #5a7183;
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.12);
}

#lassoPanel.active {
    border-color: #e74c3c;
    box-shadow: 0 0 0 1px rgba(231, 76, 60, 0.35) inset;
}

.hidden {
    display: none;
}

.hint {
    font-size: 11px;
    line-height: 1.6;
    color: #95a5a6;
    margin: 6px 0;
}

kbd {
    background: #2c3e50;
    border: 1px solid #4a6274;
    border-radius: 3px;
    padding: 0 4px;
    font-size: 10px;
    color: #bdc3c7;
}

#legendContainer {
    margin-top: 14px;
}

.legend-title {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 8px;
    color: #bdc3c7;
}

.legend {
    font-size: 12px;
}

.legend h3 {
    margin-bottom: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.color-box {
    width: 14px;
    height: 14px;
    margin-right: 8px;
    border-radius: 2px;
    flex: 0 0 auto;
    border: 1px solid rgba(0, 0, 0, 0.25);
}

.status {
    margin-top: 14px;
    padding: 10px 0 20px;
    border-top: 1px solid #4a6274;
    font-size: 12px;
    line-height: 1.6;
    color: #95a5a6;
    word-break: break-all;
}

#map-container {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background:
        radial-gradient(ellipse at 50% 42%, #22374a 0%, #16212c 58%, #0d141b 100%);
    overflow: hidden;
}

#canvas-stack {
    position: relative;
    width: min(1000px, 92%);
    aspect-ratio: 2 / 1;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.85);
}

#mapCanvas,
#overlayCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#mapCanvas {
    z-index: 1;
    background-color: #000;
}

#mapCanvas.editing {
    cursor: crosshair;
}

#overlayCanvas {
    z-index: 2;
    pointer-events: none;
    background: transparent;
}

#threeCanvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    position: absolute !important;
    inset: 0;
}

/* ==================== 3D 星球 HUD ====================
   贴图、云层、大气是「画面」，HUD 是「图幅元素」：
   左上图名卡、右上徽标、底部操作提示，三层信息互不遮挡。 */
#globeHud {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}

#map-container.is-3d #globeHud {
    display: block;
}

.hud-title-card {
    position: absolute;
    top: 22px;
    left: 26px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 180px;
    max-width: min(46%, 360px);
    padding: 12px 18px 11px;
    border: 1px solid rgba(160, 196, 220, 0.35);
    border-left: 3px solid rgba(120, 205, 245, 0.9);
    border-radius: 4px;
    background: linear-gradient(135deg, rgba(10, 24, 38, 0.80), rgba(10, 18, 28, 0.55));
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    color: #eaf5ff;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

.hud-kicker {
    font-size: 10px;
    letter-spacing: 3px;
    color: #8fc6e2;
}

.hud-title-card strong {
    font-size: 21px;
    font-weight: 700;
    letter-spacing: 1px;
    line-height: 1.3;
}

.hud-mode {
    font-size: 11px;
    letter-spacing: 1px;
    color: #9fb7c9;
}

.hud-badge {
    position: absolute;
    top: 24px;
    right: 26px;
    padding: 6px 12px;
    border: 1px solid rgba(140, 200, 235, 0.35);
    border-radius: 999px;
    background: rgba(10, 22, 34, 0.68);
    font-size: 10px;
    letter-spacing: 2px;
    color: #a9d8f0;
}

.hud-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 7px 16px;
    border-radius: 999px;
    background: rgba(8, 16, 24, 0.55);
    border: 1px solid rgba(140, 190, 220, 0.16);
    font-size: 11px;
    letter-spacing: 1px;
    color: #8fa8b9;
    white-space: nowrap;
}

/* 3D 罗盘：右下角固定，压在星空而不是球体上 */
.hud-compass {
    position: absolute;
    right: 24px;
    bottom: 18px;
    width: 66px;
    height: 74px;
    color: #9fd4ef;
    opacity: 0.78;
}

.hud-compass svg {
    display: block;
    width: 100%;
    height: 100%;
}

.compass-line {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.2;
}

.compass-star {
    fill: currentColor;
}

.compass-dot {
    fill: currentColor;
    opacity: 0.9;
}

.compass-label {
    fill: currentColor;
    font: 700 10px 'Segoe UI', Tahoma, sans-serif;
    letter-spacing: 1px;
}

/* 手绘模式进 3D：HUD 也换成纸墨语言，避免蓝黑科技卡与羊皮纸星球打架 */
#map-container.hand-mode .hud-title-card {
    border-color: rgba(120, 92, 62, 0.45);
    border-left-color: rgba(160, 54, 42, 0.85);
    background: linear-gradient(135deg, rgba(246, 238, 219, 0.94), rgba(233, 222, 199, 0.86));
    color: #3a2c20;
    text-shadow: 0 1px 0 rgba(255, 250, 238, 0.75);
    box-shadow: 0 8px 28px rgba(20, 12, 6, 0.35);
}

#map-container.hand-mode .hud-kicker {
    color: #8d6e4d;
}

#map-container.hand-mode .hud-mode {
    color: #6d5946;
}

#map-container.hand-mode .hud-badge {
    border-color: rgba(120, 92, 62, 0.35);
    background: rgba(246, 238, 219, 0.88);
    color: #6d5946;
}

#map-container.hand-mode .hud-hint {
    background: rgba(246, 238, 219, 0.76);
    border-color: rgba(120, 92, 62, 0.25);
    color: #6d5946;
}

#map-container.hand-mode .hud-compass {
    color: #5c4832;
    opacity: 0.86;
}

#exportModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background-color: rgba(0, 0, 0, 0.9);
    overflow: auto;
    text-align: center;
    padding: 24px 0;
}

.modal-content {
    display: inline-block;
    max-width: 95%;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

#closeModal {
    background: #e74c3c;
    padding: 10px 18px;
    border-radius: 5px;
    color: #fff;
    font-weight: bold;
    cursor: pointer;
}

#directDownloadBtn {
    width: auto;
    margin: 0;
    padding: 10px 20px;
}

.modal-tip {
    margin: 12px 0;
    font-size: 14px;
    font-weight: bold;
    color: #2ecc71;
}

#exportedImg {
    max-width: 100%;
    border: 3px solid #ecf0f1;
    border-radius: 4px;
}

@media (max-width: 900px) {
    body {
        flex-direction: column;
    }

    #ui {
        width: 100%;
        flex: 0 0 auto;
        max-height: 46vh;
    }

    #canvas-stack {
        width: 96%;
    }

    .hud-title-card {
        top: 12px;
        left: 12px;
        padding: 9px 13px 8px;
        min-width: 140px;
    }

    .hud-title-card strong {
        font-size: 16px;
    }

    .hud-badge {
        top: 14px;
        right: 12px;
    }

    .hud-hint {
        bottom: 10px;
        font-size: 10px;
        padding: 5px 12px;
    }

    .hud-compass {
        right: 12px;
        bottom: 8px;
        width: 52px;
        height: 58px;
    }
}
