/* --- 基本レイアウト --- */
body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background-color: #1a1a1a;
    position: relative;
    font-family: sans-serif;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;

    /* 長押しによるコンテキストメニューとテキスト選択を無効化 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* --- 地図本体の制御 --- */
#map-view-container {
    position: absolute;
    top: 0;
    left: 0;
    cursor: grab;
    user-select: none;
    transform-origin: 0 0;
    will-change: transform;
    z-index: 1;
    touch-action: none;
}

#map-view-container:active {
    cursor: grabbing;
}

#map-view-image {
    display: block;
    max-width: none;
    -webkit-user-drag: none;
}

/* --- ピン（マーカー） --- */
#map-marker-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.map-marker-item {
    position: absolute;
    width: 32px;
    height: 32px;
    transform: translate(-50%, -50%);
    cursor: pointer;
    z-index: 10;
    pointer-events: auto;
    transition: transform 0.1s ease-out;
}

/* 選択時の薄い背景色演出 */
.map-marker-item::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background-color: var(--active-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: width 0.2s, height 0.2s, opacity 0.2s;
    z-index: -1;
}

.map-marker-item.active-marker::before {
    width: 54px;
    height: 54px;
    opacity: 0.25;
}

.map-marker-item img {
    width: 100%;
    height: 100%;
    display: block;
    -webkit-user-drag: none;
}

/* ホバー時のツールチップ（名前） */
.map-marker-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    background: rgba(20, 20, 20, 0.95);
    color: #fff;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    white-space: nowrap;
    pointer-events: none;
    display: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 110;
}

/* PC: ホバーで名前を表示 */
@media (hover: hover) {
    .map-marker-item:hover {
        transform: translate(-50%, -50%) scale(1.15);
        z-index: 105;
    }
    .map-marker-item:hover .map-marker-tooltip {
        display: block;
    }
}

/* 【重要】重なり回避ロジック
   詳細ポップアップ（active-marker）が表示されているときは、
   背後のツールチップを非表示にしてポップアップの可読性を優先する
*/
.map-marker-item.active-marker .map-marker-tooltip {
    display: none !important;
}

.map-marker-item.active-marker img {
    filter: drop-shadow(0 0 6px var(--active-color));
}

/* --- ポップアップカード --- */
#map-popup-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 200;
}

.popup-card {
    position: absolute;
    background: rgba(30, 30, 30, 0.98);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 198, 49, 0.6);
    border-radius: 12px;
    padding: 16px;
    color: #eee;
    pointer-events: auto;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.8);
    animation: popupFloatIn 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    transform: translate(-50%, -100%);
    margin-top: -28px; /* ピンの少し上から表示 */
    min-width: 260px;
    max-width: 88vw;
    box-sizing: border-box;
}

@keyframes popupFloatIn {
    from { opacity: 0; transform: translate(-50%, -95%); }
    to { opacity: 1; transform: translate(-50%, -100%); }
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.popup-title {
    font-size: 16px;
    font-weight: bold;
    color: #FFC631;
}

.popup-category-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 4px;
    color: #fff;
    white-space: nowrap;
    text-transform: uppercase;
}

.popup-body {
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #FFC631 transparent;
}

/* --- 管理用フッターエリア --- */
#app-footer-container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 2000;
    background: rgba(15, 15, 15, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
    /* テキスト選択を確実に防止 */
    user-select: none;
}

.app-lang-switch {
    display: flex;
    background-color: #2a2a2a;
    border-radius: 6px;
    border: 1px solid #444;
}

.app-lang-switch button {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: bold;
    color: #888;
    background-color: transparent;
    border: none;
    cursor: pointer;
    user-select: none;
}

.app-lang-switch button.active {
    color: #000;
    background-color: #FFC631;
    border-radius: 4px;
}

.app-action-container {
    display: flex;
    gap: 8px;
}

#app-btn-filter, #app-btn-reset, .app-zoom-control button {
    width: 42px;
    height: 36px;
    background-color: #FFC631;
    color: #111;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
}

.app-zoom-control {
    display: flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 2px 6px;
    gap: 4px;
}

#app-zoom-label {
    color: #FFC631;
    font-size: 12px;
    font-weight: bold;
    min-width: 40px;
    text-align: center;
    user-select: none;
}

/* --- フィルターメニュー --- */
#filter-menu-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    pointer-events: none;
}

.filter-menu-card {
    position: absolute;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(25, 25, 25, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px;
    width: 220px;
    pointer-events: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    user-select: none;
}

/* フィルターメニューの吹き出し（外側のボーダー用） */
.filter-menu-card::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-top: 10px solid rgba(255, 255, 255, 0.1);
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
}

/* フィルターメニューの吹き出し（内側の背景用） */
.filter-menu-card::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: -1px; /* ボーダー分だけ上に重ねる */
    border-top: 10px solid rgba(25, 25, 25, 0.98);
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
}

.filter-item-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    color: #ccc;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

.filter-item-label input {
    width: 16px;
    height: 16px;
    accent-color: #FFC631;
}

.filter-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 6px 0;
}