/*!
 * lp-map.css — 罗盘页「地图底图 / 等高线」模块
 * 数据源：天地图（NASG Tianditu）—— 合规白名单地图服务
 * 说明：不依赖 Mapbox / Leaflet / OSM，纯原生瓦片渲染 + Canvas 图层
 * 依赖：页面需提供 #lpMapRoot 容器，并由 assets/lp-map.js 初始化
 */

#lpMapRoot {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background: #20261f;
    isolation: isolate;
}

/* 罗盘图片浮在地图之上，但仍在十字线 / 原有按钮之下 */
.compass-container #svgClock { z-index: 5; }

#lpMapView {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
}
#lpMapView.is-panning { cursor: grabbing; }
#lpMapView.is-drawing { cursor: crosshair; }

.lp-tiles,
.lp-canvas-layer {
    position: absolute;
    inset: 0;
    transform-origin: 50% 50%;
}
.lp-tiles { pointer-events: none; will-change: transform; }
/* 图层显示用 <img>，内容由离屏 canvas 生成后导出，兼容性最稳 */
.lp-canvas-layer {
    pointer-events: none;
    width: 100%;
    height: 100%;
    max-width: none;
    will-change: auto;
}
.lp-tiles.lp-base { z-index: 1; }
.lp-tiles.lp-terrain { z-index: 2; }
.lp-tiles.lp-label { z-index: 3; }
#lpContourImg { z-index: 4; }
#lpWaterImg { z-index: 5; }
#lpDrawImg { z-index: 6; }

.lp-tiles img.lp-tile {
    position: absolute;
    width: 256px;
    height: 256px;
    max-width: none;
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: none;
}
.lp-tiles.lp-label { mix-blend-mode: normal; }
.lp-tiles.lp-terrain {
    /* 直接半透明叠加地形晕渲，避免混合模式在不同浏览器下被压没 */
    opacity: .34;
    filter: contrast(1.55) saturate(.75);
}

/* ---------- 控件层 ---------- */
#lpMapUI {
    position: absolute;
    inset: 0;
    z-index: 30;
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    color: #fff;
}
#lpMapUI > * { pointer-events: auto; }

.lp-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    background: rgba(18, 20, 18, .74);
    color: #f2f5ef;
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .28);
    cursor: pointer;
    font-size: 11px;
    line-height: 1.1;
    letter-spacing: .5px;
    -webkit-tap-highlight-color: transparent;
    transition: background .18s, color .18s, transform .18s;
}
.lp-btn:hover { background: rgba(38, 44, 36, .9); }
.lp-btn:active { transform: scale(.94); }
.lp-btn .lp-ico { font-size: 17px; line-height: 1; display: block; }
.lp-btn.on { color: #a6f04a; border-color: rgba(166, 240, 74, .5); }
.lp-btn.lp-round { width: 38px; height: 38px; border-radius: 50%; font-size: 17px; }

/* 左上：界面模式 */
#lpUiMode {
    position: absolute;
    top: 14px;
    left: 14px;
    flex-direction: row;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 22px;
    font-size: 12px;
    font-weight: 600;
}
#lpUiMode .lp-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: radial-gradient(circle at 50% 50%, #fff 0 2px, #2b2f2a 3px 100%);
    border: 1px solid #fff;
}

/* 右上：指北针 */
#lpNorth {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 44px; height: 44px;
    border-radius: 50%;
    padding: 0;
    background: rgba(18, 20, 18, .8);
}
#lpNorth .lp-needle {
    width: 22px; height: 22px;
    clip-path: polygon(50% 0, 62% 50%, 50% 42%, 38% 50%);
    background: #f04b4b;
}
#lpNorth .lp-needle::after { content: ""; }

/* 右侧竖排工具 */
#lpToolsRight {
    position: absolute;
    top: 76px;
    right: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
#lpToolsRight .lp-btn { width: 46px; height: 46px; }

/* 左下工具 */
#lpToolsLeft {
    position: absolute;
    left: 14px;
    bottom: 96px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
#lpToolsLeft .lp-btn { width: 46px; height: 46px; }

/* 右下缩放 */
#lpZoom {
    position: absolute;
    right: 14px;
    bottom: 96px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

/* 底部版权（审图号，按天地图要求显示） */
#lpCopyright {
    position: absolute;
    left: 10px;
    bottom: 6px;
    font-size: 11px;
    color: rgba(255, 255, 255, .78);
    text-shadow: 0 1px 3px #000;
    pointer-events: none;
    letter-spacing: .2px;
}

/* 中心定位点 */
#lpLocDot {
    position: absolute;
    left: 50%; top: 50%;
    width: 16px; height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #2f8cff;
    box-shadow: 0 0 0 4px rgba(47, 140, 255, .28);
    display: none;
    pointer-events: none;
}
#lpLocDot.show { display: block; }

/* 状态提示 */
#lpToast {
    position: absolute;
    left: 50%;
    bottom: 118px;
    transform: translateX(-50%) translateY(8px);
    background: rgba(16, 18, 16, .9);
    border: 1px solid rgba(255, 255, 255, .14);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    opacity: 0;
    transition: opacity .22s, transform .22s;
    pointer-events: none;
    white-space: nowrap;
}
#lpToast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 图层面板 */
#lpLayerPanel {
    position: absolute;
    left: 70px;
    bottom: 96px;
    width: 232px;
    max-height: min(70vh, 460px);
    overflow-y: auto;
    background: rgba(20, 23, 20, .93);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
    font-size: 12px;
    display: none;
}
#lpLayerPanel.show { display: block; }
#lpLayerPanel h4 {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: #c9f28a;
}
#lpLayerPanel .lp-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 0;
}
#lpLayerPanel .lp-seg { display: flex; gap: 5px; flex-wrap: wrap; }
#lpLayerPanel .lp-seg button {
    flex: 1 1 auto;
    min-width: 56px;
    padding: 6px 4px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .16);
    background: rgba(255, 255, 255, .06);
    color: #e9eee4;
    font-size: 11px;
    cursor: pointer;
}
#lpLayerPanel .lp-seg button.on {
    background: #a6f04a;
    border-color: #a6f04a;
    color: #1c2415;
    font-weight: 700;
}
#lpLayerPanel input[type=range] { width: 108px; accent-color: #a6f04a; }
#lpLayerPanel .lp-switch {
    position: relative;
    width: 36px; height: 20px;
    border-radius: 12px;
    background: #4a5147;
    border: none;
    cursor: pointer;
    transition: background .2s;
    flex: none;
}
#lpLayerPanel .lp-switch::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform .2s;
}
#lpLayerPanel .lp-switch.on { background: #8ed13a; }
#lpLayerPanel .lp-switch.on::after { transform: translateX(16px); }
#lpLayerPanel .lp-note {
    color: #9ba596;
    font-size: 10.5px;
    line-height: 1.6;
    margin: 8px 0 0;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, .1);
}
#lpLayerPanel .lp-file {
    display: block;
    margin-top: 8px;
    padding: 7px;
    text-align: center;
    border-radius: 8px;
    border: 1px dashed rgba(166, 240, 74, .5);
    color: #c9f28a;
    cursor: pointer;
    font-size: 11px;
}

/* 天地图 Key 配置引导 */
#lpKeyBar {
    position: absolute;
    left: 50%;
    top: 14px;
    transform: translateX(-50%);
    width: min(92vw, 520px);
    background: rgba(24, 27, 22, .95);
    border: 1px solid rgba(166, 240, 74, .45);
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 8px 26px rgba(0, 0, 0, .4);
    font-size: 12px;
    line-height: 1.6;
    display: none;
}
#lpKeyBar.show { display: block; }
#lpKeyBar b { color: #c9f28a; }
#lpKeyBar .lp-keyrow { display: flex; gap: 6px; margin-top: 8px; }
#lpKeyBar input {
    flex: 1;
    min-width: 0;
    padding: 7px 9px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .2);
    background: rgba(255, 255, 255, .08);
    color: #fff;
    font-size: 12px;
    outline: none;
}
#lpKeyBar input::placeholder { color: #9ba596; }
#lpKeyBar button {
    padding: 7px 14px;
    border-radius: 8px;
    border: none;
    background: #a6f04a;
    color: #1c2415;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
#lpKeyBar a { color: #c9f28a; }

/* 绘图工具条 */
#lpDrawBar {
    position: absolute;
    left: 50%;
    bottom: 96px;
    transform: translateX(-50%);
    display: none;
    gap: 6px;
    padding: 6px;
    border-radius: 14px;
    background: rgba(20, 23, 20, .9);
    border: 1px solid rgba(255, 255, 255, .14);
}
#lpDrawBar.show { display: flex; }
#lpDrawBar .lp-btn { width: 40px; height: 36px; border-radius: 9px; font-size: 10px; flex-direction: row; }
#lpDrawBar .lp-color {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .6);
    cursor: pointer;
}
#lpDrawInfo {
    align-self: center;
    padding: 0 8px;
    font-size: 11px;
    color: #c9f28a;
    white-space: nowrap;
}

/* 未配置密钥：保持原有罗盘页面外观，只显示顶部申请引导 */
#lpMapRoot.lp-no-key { background: transparent; }
#lpMapRoot.lp-no-key #lpToolsRight,
#lpMapRoot.lp-no-key #lpToolsLeft,
#lpMapRoot.lp-no-key #lpZoom,
#lpMapRoot.lp-no-key #lpUiMode,
#lpMapRoot.lp-no-key #lpNorth,
#lpMapRoot.lp-no-key #lpCopyright,
#lpMapRoot.lp-no-key #lpMapView { display: none; }

/* 仅罗盘 / 仅地图模式 */
#lpMapRoot.lp-hide-map { visibility: hidden; }
.compass-container.lp-hide-compass #svgClock,
.compass-container.lp-hide-compass .crosshair { visibility: hidden; }

@media (max-width: 520px) {
    #lpLayerPanel { left: 10px; right: 10px; width: auto; bottom: 150px; max-height: 56vh; }
    #lpToolsLeft, #lpZoom { bottom: 150px; }
    #lpKeyBar { top: 66px; }
}
