/* =================================================================
 * 日本100名城 登城ログ — style.css (Leaflet 版・モバイルファースト)
 * ================================================================= */

/* ---------- レイアウト ---------- */

.app-castle-main {
    display: flex;
    flex-direction: column;
    background: var(--bs-body-bg);
    min-height: 100dvh;
}

/* ヘッダー */
.cs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    flex-shrink: 0;
}

.cs-header-title {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
}

.cs-header-actions {
    flex-shrink: 0;
}

.cs-counter {
    display: inline-flex;
    align-items: baseline;
    gap: 0.15rem;
    white-space: nowrap;
}

.cs-counter strong {
    font-size: 1.15rem;
    color: var(--bs-primary);
    font-weight: 800;
}

.cs-filter-select {
    width: auto;
    min-width: 11rem;
    max-width: 16rem;
}

/* 地域ナビ */
.cs-region-nav {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--bs-body-tertiary-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    flex-shrink: 0;
}

.cs-region-nav::-webkit-scrollbar {
    height: 4px;
}

.cs-region-nav::-webkit-scrollbar-thumb {
    background: var(--bs-border-color);
    border-radius: 2px;
}

.cs-region-btn {
    flex-shrink: 0;
    padding: 0.35rem 0.9rem;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.cs-region-btn:hover {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

.cs-region-btn.is-active {
    background: var(--bs-primary);
    color: #fff;
    border-color: var(--bs-primary);
}

/* メインコンテンツ */
.cs-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.cs-map-wrap {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    background: #e0f2fe;
}

[data-bs-theme="dark"] .cs-map-wrap {
    /* タイル間の隙間（読み込み中のチラ見え）と同じ暗色 */
    background: #1a2433;
    /* 地図エリアの輪郭を明示してページ背景と分離 */
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* 地理院タイル（淡色地図）はライト前提の白地。
   ダークモードでは invert + hue-rotate でダーク反転する古典的トリック。
   ラベルや日本語テキストも自然に白基調になり、色相は元に戻る。 */
[data-bs-theme="dark"] .leaflet-tile-pane {
    filter: invert(0.92) hue-rotate(180deg) brightness(0.95) contrast(0.95);
}

#map {
    width: 100%;
    height: 100%;
}

/* 凡例 */
.cs-legend {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 600;
    background: rgba(var(--bs-body-bg-rgb), 0.92);
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    padding: 0.35rem 0.65rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    font-size: 0.78rem;
    display: flex;
    gap: 0.75rem;
    backdrop-filter: blur(4px);
}

.cs-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--bs-body-color);
}

.cs-legend-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.cs-legend-dot.is-none {
    background: #fff;
    border: 1.5px solid #94a3b8;
    color: #64748b;
}

.cs-legend-dot.is-visited {
    background: #7c5ac3;
    color: #fff;
    border: 1.5px solid #5a3da0;
}

[data-bs-theme="dark"] .cs-legend-dot.is-none {
    background: #1e293b;
    border-color: #94a3b8;
    color: #cbd5e1;
}

/* サイドバー */
.cs-sidebar {
    background: var(--bs-body-bg);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

.cs-progress-block {
    padding: 0.6rem 0.85rem;
    background: var(--bs-body-tertiary-bg);
    border-radius: 10px;
}

.cs-progress {
    height: 12px;
    border-radius: 6px;
    background: var(--bs-secondary-bg);
}

.cs-list-block {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.cs-list-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 0.6rem;
    color: var(--bs-body-color);
    flex-shrink: 0;
}

.cs-list {
    flex: 1;
    overflow-y: auto;
    min-height: 60px;
    padding-right: 0.25rem;
}

.cs-region-block + .cs-region-block {
    margin-top: 0.9rem;
}

.cs-region-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid var(--bs-border-color);
    padding-bottom: 0.2rem;
    margin-bottom: 0.45rem;
}

.cs-region-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--bs-secondary-color);
}

.cs-region-count {
    font-size: 1rem;
    font-weight: 700;
    color: var(--bs-primary);
    line-height: 1;
}

.cs-region-unit {
    font-size: 0.7rem;
    color: var(--bs-secondary-color);
    margin-left: 2px;
    font-weight: 400;
}

.cs-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.cs-badge {
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: 8px;
    padding: 3px 9px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
    line-height: 1.4;
}

.cs-badge:hover {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

.cs-badge:active {
    transform: scale(0.96);
}

.cs-emoji-icon {
    display: inline-flex;
    align-items: center;
    font-size: 1.1em;
    line-height: 1;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.cs-badge-mark {
    display: inline-flex;
    align-items: center;
    font-size: 0.85rem;
    line-height: 1;
    margin-right: 3px;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.cs-hint {
    margin: 0;
    padding: 0.6rem 0.85rem;
    font-size: 0.8rem;
}

.cs-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ---------- Leaflet マーカー (城) ---------- */

.cs-marker {
    background: transparent !important;
    border: 0 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.cs-marker-inner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    border: 2px solid;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.cs-marker.is-none .cs-marker-inner {
    background: #ffffff;
    color: #64748b;
    border-color: #94a3b8;
}

.cs-marker.is-visited .cs-marker-inner {
    background: #7c5ac3;     /* マッハーバイオレット */
    color: #ffffff;
    border-color: #5a3da0;
}

.cs-marker:hover .cs-marker-inner {
    transform: scale(1.25);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
}

[data-bs-theme="dark"] .cs-marker.is-none .cs-marker-inner {
    background: #1e293b;
    color: #cbd5e1;
    border-color: #cbd5e1;
}

[data-bs-theme="dark"] .cs-marker.is-visited .cs-marker-inner {
    background: #9d83d9;
    color: #0f172a;
    border-color: #c4b5fd;
}

/* Leaflet ツールチップ */
.cs-tooltip {
    background: rgba(33, 37, 41, 0.94);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 4px 9px;
    font-size: 0.82rem;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.cs-tooltip::before {
    border-top-color: rgba(33, 37, 41, 0.94) !important;
}

.cs-tooltip-code {
    opacity: 0.7;
    font-size: 0.72rem;
    margin-left: 4px;
    font-weight: 400;
}

/* Leaflet 帰属表示を控えめに */
.leaflet-control-attribution {
    font-size: 0.65rem !important;
    background: rgba(255, 255, 255, 0.75) !important;
}

[data-bs-theme="dark"] .leaflet-control-attribution {
    background: rgba(15, 23, 42, 0.75) !important;
    color: #cbd5e1 !important;
}

[data-bs-theme="dark"] .leaflet-control-attribution a {
    color: #9d83d9 !important;
}

/* Leaflet ズームコントロール（ダークモード対応） */
[data-bs-theme="dark"] .leaflet-bar a {
    background-color: #1e293b;
    color: #e2e8f0;
    border-bottom-color: #334155;
}

[data-bs-theme="dark"] .leaflet-bar a:hover {
    background-color: #334155;
}

/* ---------- ローディング ---------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.loading-overlay[hidden] {
    display: none;
}

/* ---------- レスポンシブ ---------- */

/* スマホ：地図とサイドバーを縦並び */
@media (max-width: 991.98px) {
    .cs-header {
        padding: 0.5rem 0.75rem;
    }

    .cs-region-nav {
        padding: 0.45rem 0.75rem;
    }

    .cs-filter-select {
        min-width: 9rem;
        max-width: 12rem;
        font-size: 0.8rem;
    }

    .cs-map-wrap {
        height: 60dvh;
        min-height: 360px;
    }

    .cs-sidebar {
        padding: 0.85rem 0.85rem 1.5rem;
        border-top: 1px solid var(--bs-border-color);
    }

    .cs-list {
        max-height: none;
        overflow: visible;
    }

    .cs-list-block {
        flex: initial;
    }

    .cs-marker svg {
        width: 34px;
        height: 34px;
    }

    .cs-marker {
        width: 34px !important;
        height: 34px !important;
        margin-left: -17px !important;
        margin-top: -17px !important;
    }
}

/* PC：地図とサイドバーを横並び */
@media (min-width: 992px) {
    .app-castle-main {
        height: calc(100vh - 60px);
        min-height: 640px;
        max-height: 100dvh;
    }

    .cs-content {
        flex-direction: row;
    }

    .cs-map-wrap {
        flex: 7;
        height: auto;
        min-width: 0;
    }

    .cs-sidebar {
        flex: 3;
        max-width: 480px;
        min-width: 300px;
        flex-shrink: 0;
        border-left: 1px solid var(--bs-border-color);
        overflow-y: auto;
    }
}

/* X (旧 Twitter) シェアボタン: ダークモードで body bg と同化しないよう、純黒+ボーダーで分離 */
[data-bs-theme="dark"] #btn-share-x {
    background-color: #000000;
    border: 1px solid #495057;
    color: #ffffff;
}
[data-bs-theme="dark"] #btn-share-x:hover {
    background-color: #1a1a1a;
    border-color: #6c757d;
    color: #ffffff;
}
