/* レイアウト基盤 */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    display: flex;
    overflow: hidden;
}

#sidebar {
    width: 240px;
    height: 100vh;
    background: #1a1a1a;
    color: white;
    padding: 15px;
    overflow-y: auto;
    z-index: 10;
    box-sizing: border-box;
	font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
}

#sidebar * {
    font-family: inherit;
}

#map {
    flex-grow: 1;
    height: 100vh;
    background: #222;
}

/* 自動再生ボタン */
.special-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    background: #f50057;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
}

.special-btn.stop {
    background: #666;
}

/* --- 【重要】位置ズレをゼロにするマーカー構造 --- */
.photo-marker-container {
    width: 0;
    height: 0;
    /* 箱のサイズをゼロにして、中心点を一点に固定 */
    position: relative;
    cursor: pointer;
}

/* 丸い写真本体 */
.photo-circle {
    width: 46px;
    height: 46px;
    background-size: cover;
    background-position: center;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    position: absolute;
    /* 46pxの円を自分の中心(0,0)に持ってくるための設定 */
    top: -23px;
    left: -23px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ホバー時の動作：本体を少し強調 */
.photo-marker-container:hover .photo-circle {
    transform: scale(1.3);
    z-index: 9999;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
}

/* 全てのプレビューの共通基盤：幅を固定せず中身に合わせる */
.photo-quick-preview {
    display: none;
    position: absolute;
    left: 50%;
    transform: translate(-50%, 0);
    
    /* 【解決の鍵】幅と高さを画像（中身）にピッタリ合わせる */
    width: fit-content;
    height: fit-content;
    
    background: white;
    padding: 8px; /* 通常のホバー用パディング */
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    z-index: 100000;
}

/* PCでの通常ホバー時の位置 */
.photo-marker-container:hover .photo-quick-preview {
    display: block;
    bottom: 100px;
}

/* 自動再生（auto-hover）時の位置と白い太枠スタイルへの上書き */
.photo-marker-container.auto-hover .photo-quick-preview {
    display: block !important;
    position: fixed;
    top: 45%;
    left: calc(var(--sidebar-width, 240px) + (100% - var(--sidebar-width, 240px)) / 2);
    transform: translate(-50%, -50%) !important;
    
    /* 自動再生時は白い太枠デザインに */
    padding: 0 !important;
    border: 4px solid white;
    border-radius: 12px;
    z-index: 1000000 !important;
    animation: albumIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* 画像自体のサイズ制約：ここで「440x440の仮想枠」を作る */
.photo-quick-preview img {
    display: block;
    margin: 0;
    
    /* 横長なら 440px 幅、縦長なら 440px 高さに自動フィット */
    max-width: 440px;
    max-height: 440px;
    
    /* 比率を維持する設定 */
    width: auto;
    height: auto;
    border-radius: 6px;
}

/* お寺マーカー（既存スタイル維持） */
.temple-marker {
    background: #d32f2f;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    border: 2px solid #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);

    /* --- 追加：マウスを載せた時に指の形に変える --- */
    cursor: pointer;
}

.temple-popup {
    color: #333;
    text-align: center;
}

/* --- ローディング画面 --- */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 26, 0.98);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.8s ease;
}

.loader-content {
    text-align: center;
    color: white;
    font-family: sans-serif;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #333;
    border-top: 5px solid #f50057;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 全ルート表示用の線（控えめな表現） */
/* map.addLayer の paint 設定で制御するため、ここには補助的な定義は不要です */

/* 県別アコーディオン */
.pref-section {
    margin-bottom: 10px;
    border-bottom: 1px solid #333;
}

.pref-section summary {
    padding: 12px;
    background: #2a2a2a;
    cursor: pointer;
    font-weight: bold;
    list-style: none;
    display: flex;
    justify-content: space-between;
}

.pref-section summary::-webkit-details-marker {
    display: none;
}

.pref-section summary::after {
    content: '▶';
    font-size: 0.8em;
    color: #888;
}

.pref-section[open] summary::after {
    content: '▼';
}

/* 日別選択リスト */
.day-list-inner {
    padding: 5px 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* 2列に並べて省スペース化 */
    gap: 5px;
    background: #111;
}

.day-item {
    display: flex;
    align-items: center;
    padding: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.day-item:hover {
    background: #333;
}

.day-item input {
    margin-right: 8px;
    cursor: pointer;
}

/* 選択中の日の強調 */
.day-item.active {
    background: #f50057;
    color: white;
}

/* 複数選択時のカウンター表示 */
#selection-info {
    font-size: 0.8rem;
    color: #f50057;
    margin-bottom: 15px;
    font-weight: bold;
	line-height: 1.4;
}

/* ホバーしたマーカーを地図上の他の要素より最前面に表示 */
.photo-marker-container:hover {
    z-index: 99999 !important;
}

/* --- アバター（お遍路さん）のスタイル --- */
.avatar-marker {
    width: 36px;
    height: 36px;
    background: #ff1744; /* 鮮やかな赤 */
    border: 4px solid white;
    border-radius: 50%; /* 【修正】正方形から「円形」に変更 */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    
    /* 中の絵文字を中央に配置するための設定 */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500; /* ルート線より上で、ポップアップより下の高さ */
}

.avatar-marker::after {
    content: "🚶"; /* 【追加】歩行者のアイコンを指定 */
    font-size: 22px;
    display: block;
    line-height: 1;
}

/* 画面中央（サイドバー考慮）のポップアップ  */
/* 自動再生時のポップアップ：位置を上げ、枠をスリム化 */
.photo-marker-container.auto-hover .photo-quick-preview {
    display: block !important;
    position: fixed;
    /* 位置を 50% から 45% に引き上げ（上方向に移動） */
    top: 45%;
    /* 固定値 240px を var(--sidebar-width) に置換 */
    left: calc(var(--sidebar-width) + (100% - var(--sidebar-width)) / 2);
    transform: translate(-50%, -50%) !important;

    max-width: 75vw;
    height: auto;
    bottom: auto;
    /* 既存の bottom 指定を解除 */

    /* 白い枠（バー）の原因となる padding を 0 にし、枠線も細く調整 */
    padding: 0 !important;
    border: 4px solid white;
    border-radius: 12px;
    overflow: hidden;
    /* 画像の角を丸める */

    z-index: 1000000 !important;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.8);
    animation: albumIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* サムネイルが重ならないよう、再生中のマーカー自体の重なり順も最高値に */
.photo-marker-container.auto-hover {
    z-index: 1000001 !important;
}

@keyframes albumIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* サークルを強調 */
.photo-marker-container.auto-hover .photo-circle {
    transform: scale(1.5);
    border: 3px solid #f50057 !important;
    box-shadow: 0 0 20px rgba(245, 0, 87, 0.8);
    z-index: 99999;
}

/* 通常のホバー時も最前面に */
.photo-marker-container:hover {
    z-index: 100001 !important;
}

.accommodation-marker {
    /* サイズを大きく */
    width: 22px;
    height: 22px;

    /* 背景を「真っ白」にして、地図からくっきり浮かび上がらせる */
    background-color: #ffffff;
    /* 同じ白の太い枠線を付けて、少しリッチな「バッジ」のような質感にする */
    border: 3px solid #ffffff;
    /* 綺麗な丸にする */
    border-radius: 50%;

    /* 中のアイコンを中央揃え */
    display: flex;
    align-items: center;
    justify-content: center;

    /* アイコン（🏨）のサイズも大きく */
    font-size: 14px;

    cursor: pointer;

    /* 影を少し強く大きくして、立体感（浮遊感）を出す */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* ボタンコンテナのレイアウト */
#autoplay-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

/* グレーアウト（無効）状態のスタイル */
.special-btn.disabled {
    background: #666 !important;
    opacity: 0.6;
    cursor: not-allowed;
    /* クリックはJS側で制御するため pointer-events は off にしません */
}

/* 2つ並んだ時にサイズを調整 */
#autoplay-controls .special-btn {
    flex: 1;
    margin-bottom: 0;
    /* 既存のmarginをリセット */
}

/* 終了ボタン（グレー） */
.special-btn.stop {
    background: #444;
}

.day-item-wrapper {
    display: flex;
    flex-direction: column;
    padding: 4px 0;
    border-bottom: 1px solid #222;
}

.day-item {
    padding: 4px 8px !important;
}

.day-timetable-link {
    display: inline-block;
    font-size: 0.7rem;
    color: #00b0ff;
    text-decoration: none;
    padding-left: 32px;
    /* チェックボックスの横位置に合わせる */
    margin-bottom: 4px;
    opacity: 0.8;
}

.day-timetable-link:hover {
    text-decoration: underline;
    opacity: 1;
}

/* 立ち寄りスポットマーカーのスタイル */
.spot-marker {
    width: 22px;
    height: 22px;
    background-color: #ffffff;
    border: 3px solid #ff9800;
    /* 観光スポットを想起させる明るいオレンジ */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* --- style.css の最下部に貼り付け --- */

@media (max-width: 600px) {

    /* 1. 変数の上書き：サイドバー幅を0にすることで、ポップアップが画面中央に来る */
    :root {
        --sidebar-width: 0px !important;
    }

    body {
        flex-direction: column !important;
    }

    /* 2. サイドバーをボトムシート化：初期高度は画面の1/3 */
    #sidebar {
        width: 100% !important;
        height: 33vh !important;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 1000;
        background: #1a1a1a;
        border-radius: 20px 20px 0 0;
        padding-top: 25px;
        transition: height 0.3s ease;
        overflow-y: auto;
    }

    /* 押し込めた時の高さ */
    #sidebar.collapsed {
        height: 45px !important;
        overflow: hidden;
    }

    #sidebar::before {
        content: "";
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 45px;
        height: 5px;
        background: #555;
        border-radius: 10px;
    }

    #map {
        width: 100% !important;
        height: 100vh !important;
    }

    /* 3. 重要：モバイルではPC用のホバー挙動を完全に殺す */
    .photo-marker-container:hover .photo-quick-preview {
        display: none !important;
    }

    .photo-marker-container:hover .photo-circle {
        transform: none !important;
    }

	.photo-marker-container.auto-hover .photo-quick-preview {
	    display: block !important;
	    position: fixed;
	    top: 33% !important;
	    left: 50% !important;
	    transform: translate(-50%, -50%) !important;

	    /* 幅を中身に合わせ、最大幅を 60vw に下げて端切れを防止 */
	    width: fit-content !important;
	    max-width: 60vw !important; 
	    max-height: 45vh !important;

	    pointer-events: auto !important;
	    padding: 0 !important;
	    background: white;
	    border: 3px solid white;
	    border-radius: 12px;
	    overflow: hidden;
	    z-index: 1000000 !important;
	}

	/* 画像側：無理な幅指定を削除し、枠に吸い付かせる */
	.photo-marker-container.auto-hover .photo-quick-preview img {
	    width: auto !important;
	    height: auto !important;

	    /* 横長・縦長どちらもこの範囲内で比率を維持して最大化される */
	    max-width: 60vw !important;
	    max-height: 45vh !important;
	    
	    display: block;
	    object-fit: contain;
	}
    /* モバイル専用のサークル強調 */
    .photo-marker-container.auto-hover .photo-circle {
        transform: scale(1.5) !important;
        z-index: 99999;
    }
}