/* WorldMap Modal - Vertical Layout */

#worldMapModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.97);
    z-index: 999999;
    overflow: hidden;
}

/* Main container - vertical split */
.worldmap-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* ========= TOP: Grid Section (fills available height) ========= */
.worldmap-grid-section {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Jade & ink atmosphere behind the grid */
    background:
        radial-gradient(ellipse at 50% 40%, rgba(32, 88, 60, 0.20) 0%, rgba(10, 18, 14, 0.0) 60%),
        linear-gradient(160deg, var(--p-0b1512) 0%, var(--p-0a1110) 60%, var(--p-070c0a) 100%);
}

/* Header overlay — a cohesive rounded jade HUD pill floating over the grid */
.worldmap-header-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    padding: 7px 12px;
    z-index: 10;
    border-radius: 12px;
    background: rgba(9, 18, 14, 0.72);
    border: 1px solid rgba(255, 215, 0, 0.14);
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.worldmap-header-overlay > * {
    pointer-events: auto;
}

/* Exit button — right-aligned inside the header pill */
.worldmap-exit-btn {
    margin-left: auto;
    background: linear-gradient(135deg, var(--p-b23a2f), var(--p-8f2b23));
    border: 1px solid rgba(255, 120, 100, 0.35);
    border-radius: 8px;
    padding: 5px 16px;
    color: var(--p-ffe7e2);
    font-weight: bold;
    cursor: pointer;
    font-size: 0.85em;
    transition: filter 0.15s;
}
.worldmap-exit-btn:hover { filter: brightness(1.15); }

/* Grid wrapper - fills available space */
.worldmap-grid-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

#worldMapModalGrid {
    border-radius: 6px;
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.15);
}

/* Minimap overlay (top-right of grid, below header pill) */
.worldmap-minimap-overlay {
    position: absolute;
    top: 60px;
    right: 10px;
    z-index: 10;
    border: 1px solid rgba(255, 215, 0, 0.30);
    border-radius: 8px;
    cursor: pointer;
    opacity: 0.85;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s, border-color 0.2s;
    overflow: hidden;
}

.worldmap-minimap-overlay:hover {
    opacity: 1;
    border-color: rgba(255, 215, 0, 0.6);
}

/* Zoom controls (bottom-left of grid) */
.worldmap-zoom-controls {
    position: absolute;
    bottom: 10px;
    left: 10px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.worldmap-zoom-btn {
    width: 32px;
    height: 32px;
    background: rgba(9, 18, 14, 0.8);
    border: 1px solid rgba(255, 215, 0, 0.28);
    border-radius: 8px;
    color: var(--p-e9c46a);
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
}

.worldmap-zoom-btn:hover {
    background: rgba(255, 215, 0, 0.14);
    border-color: rgba(255, 215, 0, 0.6);
}

/* Auto-walk indicator */
#autoWalkIndicator {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--ui-teal);
    border-radius: 6px;
    padding: 6px 15px;
    color: var(--ui-teal);
    font-size: 0.85em;
    white-space: nowrap;
}

/* ========= BOTTOM: Standardized HUD Section ========= */
.worldmap-info-section {
    flex: 0 0 auto;
    padding: 10px 16px 14px;
    border-top: 1px solid rgba(255, 215, 0, 0.14);
    position: relative;
    background: linear-gradient(180deg, rgba(12, 22, 18, 0.98), rgba(8, 14, 12, 0.98));
}

/* ========= Fullscreen Map Overlay ========= */
#worldMapFullscreenMap {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#worldMapFullscreenMap .fullmap-canvas-container {
    position: relative;
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#worldMapFullscreenMap .fullmap-controls {
    position: absolute;
    bottom: 15px;
    left: 15px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 10;
}

#worldMapFullscreenMap .fullmap-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: linear-gradient(135deg, var(--ui-red), var(--ui-red-2));
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    color: var(--p-ffffff);
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    font-size: 1em;
}

#worldMapFullscreenMap .fullmap-close-btn:hover {
    background: linear-gradient(135deg, var(--p-ff5f52), var(--p-d94639));
}

/* Fullscreen map tooltip */
#fullmapTooltip {
    position: absolute;
    background: rgba(0,0,0,0.9);
    border: 1px solid var(--ui-teal);
    border-radius: 6px;
    padding: 8px 12px;
    pointer-events: none;
    z-index: 1000;
    white-space: nowrap;
    font-size: 0.85em;
}

/* ============================================================
   Jade terrain depth + hover (layered over the inline base color)
   ============================================================ */
.wm-tile::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* Single gradient: a top sheen fading into a grounded bottom shadow (cheap, one paint per tile). */
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.05) 0%, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.3) 100%);
}
.wm-tile:hover {
    transform: scale(1.09);
    filter: brightness(1.16);
    z-index: 5;
}

/* Player marker — gentle breathing pulse (transform only) */
.wm-player {
    animation: wm-player-breathe 2.6s ease-in-out infinite;
    transform-origin: 50% 60%;
}
@keyframes wm-player-breathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.1); }
}
html[data-fx="off"] .wm-player,
html[data-fx="reduced"] .wm-player { animation: none !important; }
@media (prefers-reduced-motion: reduce) { .wm-player { animation: none !important; } }

/* Static vignette over the grid section (pure chrome, never re-rendered) */
.worldmap-grid-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    background: radial-gradient(ellipse at 50% 45%, rgba(0, 0, 0, 0) 52%, rgba(0, 0, 0, 0.28) 82%, rgba(0, 0, 0, 0.55) 100%);
}

/* ============================================================
   Standardized HUD — Identity | Power | Actions (fixed footprint)
   ============================================================ */
.wm-hud {
    display: flex;
    align-items: stretch;
    gap: 14px;
    min-height: 62px;
    padding: 10px 14px;
    border: 1px solid rgba(255, 215, 0, 0.16);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(16, 30, 24, 0.9), rgba(10, 18, 15, 0.9));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.wm-hud__empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ui-text-mute);
    font-size: 0.9em;
}
.wm-hud__identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 190px;
    max-width: 42%;
    padding-right: 14px;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}
.wm-hud__identity--clickable { cursor: pointer; border-radius: 8px; transition: background 0.15s; }
.wm-hud__identity--clickable:hover { background: rgba(255, 255, 255, 0.04); }
.wm-hud__icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex-shrink: 0;
    font-size: 1.4em; line-height: 1; overflow: hidden;
}
.wm-hud__icon svg, .wm-hud__icon > div { max-width: 36px; max-height: 36px; display: block; }
.wm-hud__icon > div svg { max-width: 100%; max-height: 100%; }
.wm-hud__name { font-size: 1.05em; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wm-hud__info {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 215, 0, 0.5);
    color: var(--p-e9c46a);
    font-size: 10px; font-style: italic; font-weight: bold;
    font-family: Georgia, 'Times New Roman', serif;
}
.wm-hud__power { display: flex; align-items: center; min-width: 150px; flex: 0 1 auto; }
.wm-hud__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.wm-hud__actions .sect-btn { flex: 0 1 auto; min-width: 120px; }
.wm-hud__noact { color: var(--ui-text-mute); font-size: 0.85em; }

/* Power comparison chip (shared by HUD + modal shell) */
.wm-power-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.06);
}
.wm-power-chip__label { color: var(--ui-text-mute); font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.5px; }
.wm-power-chip__value { color: var(--ui-teal); font-weight: bold; font-size: 0.95em; }
.wm-power-chip__verdict { font-weight: bold; font-size: 0.8em; padding: 2px 9px; border-radius: 6px; border: 1px solid; }

/* ============================================================
   Descriptor-driven modal shell (WorldMapModal)
   ============================================================ */
.wm-modal-shell { display: flex; flex-direction: column; min-height: 0; }
.wm-modal__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.16);
}
.wm-modal__identity { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.wm-modal__icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; flex-shrink: 0;
    font-size: 1.8em; line-height: 1; overflow: hidden;
}
.wm-modal__icon svg, .wm-modal__icon > div { max-width: 44px; max-height: 44px; display: block; }
.wm-modal__icon > div svg { max-width: 100%; max-height: 100%; }
.wm-modal__titles { min-width: 0; }
.wm-modal__title { font-size: 1.25em; font-weight: bold; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wm-modal__subtitle { color: var(--ui-text-dim); font-size: 0.82em; margin-top: 2px; }
.wm-modal__power { flex-shrink: 0; }
.wm-modal__close {
    flex-shrink: 0;
    width: 34px; height: 34px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--ui-text-dim);
    font-size: 1.3em; line-height: 1; cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.wm-modal__close:hover { background: rgba(239, 68, 68, 0.18); color: var(--p-ff8f84); border-color: var(--p-ef4444); }
.wm-modal__body { overflow-y: auto; }
.wm-modal__section-label {
    color: var(--ui-text-mute); font-size: 0.72em; text-transform: uppercase;
    letter-spacing: 1px; margin: 4px 0 8px;
}
.wm-modal__stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px; margin-bottom: 16px;
}
.wm-modal__resources { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 16px; }
.wm-modal__resource { display: flex; flex-direction: column; gap: 2px; font-size: 0.9em; }
.wm-modal__actions { display: flex; flex-direction: column; gap: 10px; }
.wm-modal__empty { color: var(--ui-text-mute); text-align: center; padding: 24px; }

/* ========= Mobile: map-first, HUD as a compact 2-row bottom bar ========= */
@media (max-width: 768px), (max-height: 700px), (pointer: coarse) {
    #worldMapModal { overflow: hidden; }

    .worldmap-container {
        height: 100vh;
        overflow: hidden;
    }

    .worldmap-grid-section {
        flex: 1 1 auto;
        height: auto;
        /* Push the map below the floating info/header pill so the Exit
           button and minimap don't sit on top of the map on mobile.
           --wm-header-h is measured in JS to track the pill's wrapped height. */
        padding-top: calc(var(--wm-header-h, 96px) + 8px);
    }

    .worldmap-info-section {
        flex: 0 0 auto;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    }

    /* Two short rows: identity + power, then up to 3 buttons. */
    .wm-hud {
        flex-wrap: wrap;
        min-height: 0;
        gap: 8px;
        padding: 8px 10px;
    }
    .wm-hud__identity {
        min-width: 0;
        max-width: none;
        flex: 1 1 auto;
        padding-right: 0;
        border-right: none;
    }
    .wm-hud__power { min-width: 0; flex: 0 0 auto; }
    .wm-hud__actions {
        flex: 1 0 100%;
        justify-content: stretch;
    }
    .wm-hud__actions .sect-btn { flex: 1 1 120px; min-width: 0; }

    .worldmap-minimap-overlay {
        width: 72px !important;
        height: 72px !important;
        /* Sit dynamically below the floating header/info pill (measured in JS)
           so it never overlaps it regardless of how many rows it wraps into. */
        top: calc(var(--wm-header-h, 96px) + 12px);
        right: 6px;
    }
    .worldmap-minimap-overlay canvas {
        width: 72px !important;
        height: 72px !important;
    }

    .worldmap-header-overlay {
        padding: 6px 10px;
        font-size: 0.85em;
    }

    .worldmap-zoom-controls { bottom: 6px; left: 6px; }
    .worldmap-zoom-btn { width: 30px; height: 30px; font-size: 1em; }

    /* Detail / management modals go full-screen on mobile (Modal handles sizing). */
    .wm-modal__body { max-height: none; }
}
.worldmap-strategy .worldmap-minimap-overlay,
.worldmap-strategy .worldmap-zoom-controls,
.worldmap-strategy .worldmap-grid-vignette {
    display: none;
}

.worldmap-strategy .worldmap-info-section { display: none; }
.worldmap-structure-card .wm-hud { display: flex; flex-direction: column; padding: 0; border: 0; background: none; box-shadow: none; gap: 8px; }
.worldmap-structure-card .wm-hud__identity { display: flex; width: 100%; padding: 4px 0; }
.worldmap-structure-card .wm-hud__actions { display: flex; flex-direction: column; width: 100%; gap: 6px; }
.worldmap-structure-card .wm-hud__power { width: 100%; }
.worldmap-structure-card .wm-hud > * { min-width: 0; max-width: 100%; box-sizing: border-box; }
.worldmap-structure-card .wm-hud__name { white-space: normal; overflow-wrap: anywhere; }
.worldmap-structure-card .wm-power-chip { flex-wrap: wrap; min-width: 0; max-width: 100%; box-sizing: border-box; }
.worldmap-structure-card .sect-btn { min-width: 0; width: 100%; white-space: normal; }
.worldmap-strategy .worldmap-header-overlay { right: 10px; padding: 0; gap: 8px; background: none; border: 0; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; flex-direction: column; align-items: flex-start; }
.worldmap-strategy .worldmap-header-overlay > .wm-travel-card,
.worldmap-strategy .worldmap-header-overlay > .wm-map-tools { width: min(220px, calc(100% - 100px)); box-sizing: border-box; }
.worldmap-strategy .wm-map-tools { flex-direction: column; }
.wm-travel-card { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #202e27; background-image: repeating-linear-gradient(35deg,#ead8a605 0px,#ead8a605 1px,transparent 1px,transparent 4px); border: 1px solid #a3926e; border-radius: 5px; box-shadow: inset 0 0 0 2px #131f1955,0 3px 10px #0004; }
.wm-travel-card__body { display: flex; flex-direction: column; gap: 4px; }
.wm-travel-card__label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #c8bc9b; }
.wm-travel-card__icon { font-size: 23px; color: #e2c582; }
.wm-travel-card__body > span:last-child > span { color: #e8dfc4 !important; font-size: 12px !important; }
.worldmap-strategy .wm-map-tools button { min-height: 58px; box-shadow: inset 0 0 0 2px #131f1955,0 3px 10px #0004; }
.worldmap-strategy .worldmap-exit-btn { position: absolute; top: 0; right: 0; margin-left: 0; min-height: 58px; }
.wm-travel-card__icon { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; flex: 0 0 26px; }
.wm-travel-card__icon svg { display: block; width: 100%; height: 100%; }
.worldmap-strategy .wm-map-tools button, .worldmap-exit-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }

#worldPortalModal .wm-modal-shell { background: #202e27; background-image: repeating-linear-gradient(35deg,#ead8a605 0px,#ead8a605 1px,transparent 1px,transparent 4px); border: 1px solid #b89a5c; border-radius: 6px; box-shadow: inset 0 0 0 3px #18231e,inset 0 0 0 4px #b89a5c55,0 16px 48px #0009; padding: 20px; }
#worldPortalModal .wm-modal__title { font-family: Georgia,serif; color: #f0d99c; }
#worldPortalModal .wm-modal__close { border: 1px solid #9e8857; background: #182b25; color: #efd69a; border-radius: 4px; }
#worldPortalModal .wm-portal-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
#worldPortalModal .wm-portal-card { padding: 14px; margin: 0; border-style: solid; border-radius: 5px; background: linear-gradient(140deg,#2f4034,#18271f) !important; box-shadow: inset 0 0 0 2px #d7bd7810; align-items: center; gap: 16px !important; }
#worldPortalModal .wm-portal-card[data-action]:hover { outline: 1px solid #e0c47f; background: linear-gradient(140deg,#3b4b39,#223328) !important; }
#worldPortalModal .wm-portal-card > div:first-of-type { width: 126px; min-width: 126px !important; }
#worldPortalModal .wm-portal-map { width: 126px; height: 126px; object-fit: contain; border: 1px solid #b89a5c; border-radius: 3px; box-shadow: 0 3px 10px #0006; }
#worldPortalModal .wm-portal-card > div:last-child > div:first-child { font-family: Georgia,serif; font-size: 18px !important; color: #ebd59d !important; }
#worldPortalModal .wm-portal-card > div:last-child > div:last-child { font-size: 12px !important; line-height: 1.55; }
#worldPortalModal .sect-badge { font-size: 10px; padding: 3px 8px; border-radius: 3px; }
@media (max-width: 760px) { #worldPortalModal .wm-portal-grid { grid-template-columns: 1fr; } #worldPortalModal .wm-modal-shell { padding: 14px; } }
@media (max-width: 380px) { #worldPortalModal .wm-portal-card > div:first-of-type { width: 88px; min-width: 88px !important; } #worldPortalModal .wm-portal-map { width: 88px; height: 88px; } }
.wm-filter-panel {
    left: 44px;
    width: min(350px, calc(100% - 60px));
    box-sizing: border-box;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 5px 10px 10px;
    color: #eee2c6;
    background-color: #202e27;
    background-image: var(--tex-weave, repeating-linear-gradient(35deg, #ead8a605 0px, #ead8a605 1px, transparent 1px, transparent 4px)), radial-gradient(ellipse at 50% 0%, #b496492b, transparent 65%);
    border: 1px solid #a58c59;
    border-radius: 5px;
    box-shadow: inset 0 0 0 3px #18231e, inset 0 0 0 4px #b89a5c40, 0 10px 28px #0008;
    scrollbar-width: thin;
    scrollbar-color: #998453 #18231e;
}
.wm-filter-panel[hidden] { display: none; }
.wm-filter-header {
    position: sticky;
    top: -5px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 46px;
    padding: 5px 7px;
    margin-bottom: 4px;
    background-color: #202e27;
    background-image: var(--tex-weave, repeating-linear-gradient(35deg, #ead8a605 0px, #ead8a605 1px, transparent 1px, transparent 4px));
    border-bottom: 1px solid #b89a5c55;
}
.wm-filter-title { display: flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none; color: #e5ce94; font: bold 16px Georgia, serif; cursor: pointer; }
.wm-filter-actions { display: flex; gap: 6px; }
.wm-filter-actions button { padding: 5px 9px; border: 1px solid #a58c5966; border-radius: 3px; background: #15251c66; color: #d9c99f; font-size: 12px; cursor: pointer; }
.wm-filter-actions button:hover { background: #b89a5c22; border-color: #b89a5c; }
.wm-filter-list { display: grid; gap: 0; }
.wm-filter-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 66px; box-sizing: border-box; padding: 4px 8px; text-align: left; color: #eee2c6; background: transparent; border: 0; border-bottom: 1px solid #baa77b24; border-radius: 2px; font-size: 14px; cursor: pointer; }
.wm-filter-row:last-child { border-bottom-color: transparent; }
.wm-filter-row[aria-pressed="true"] { background: linear-gradient(90deg, #819a6920, transparent 85%); }
.wm-filter-row[aria-pressed="false"] { color: #8c9489; }
.wm-filter-row:hover { background: #c2ab6530; }
.wm-filter-row:focus-visible, .wm-filter-actions button:focus-visible, .wm-filter-title:focus-visible { outline: 2px solid #e0c47f; outline-offset: -2px; }
@media (max-width: 480px) {
    .wm-filter-panel { left: 24px; width: calc(100% - 40px); }
}
