/* ==========================================================================
   Base Styles & Variables
   ========================================================================== */
:root {
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-hover: rgba(255, 255, 255, 0.2);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-color: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.5);
    
    --card-width: 90px;
    --card-height: 60px;
    
    --font-main: 'Outfit', 'Noto Sans JP', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* ==========================================================================
   Loader
   ========================================================================== */
.loader-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.loader-container.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-content {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
    box-shadow: 0 0 15px var(--accent-glow);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.loader-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.map-canvas {
    position: absolute;
    width: 3600px;
    height: 2700px;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
    background-color: #0b0f19;
    /* サイバー感のあるグリッド背景と、事前配置されたマップ画像のマルチ背景 */
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(to right, rgba(255, 255, 255, 0.007) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.007) 1px, transparent 1px),
        url('images/map_snapshot.png');
    background-size: 120px 120px, 30px 30px, 120px 120px, 30px 30px, 3600px 2700px;
    background-repeat: repeat, repeat, repeat, repeat, no-repeat;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.8);
}

/* ==========================================================================
   Flag Cards
   ========================================================================== */
.flag-card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    transform: translate(-50%, -50%); /* 中心座標で配置 */
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background-color: transparent; /* 通常時は背景画像を透かす */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: 
        transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 0.25s ease,
        border-color 0.25s ease,
        opacity 0.3s ease,
        filter 0.3s ease,
        background-color 0.3s ease;
}

/* 画面外の国旗カードを非表示にする（カリング） */
.flag-card.is-outside {
    display: none !important;
}

/* 通常時はカード内の国旗を透明にし、ホバー/選択/ハイライト時のみ表示する */
.flag-card .sprite-flag {
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.flag-card:hover .sprite-flag,
.flag-card.selected .sprite-flag,
.flag-card.searched-highlight .sprite-flag {
    opacity: 1;
}

/* フィルター非該当時のフェードアウト表示（半透明の背景色マスクで覆う） */
.flag-card.dimmed {
    background-color: rgba(11, 15, 25, 0.75); /* 少し透けさせて視認性を維持 */
    border-color: rgba(255, 255, 255, 0.02);
    pointer-events: none;
    box-shadow: none;
}

/* 国旗カードのホバーエフェクト（ネオン発光） */
.flag-card:hover {
    transform: translate(-50%, -50%) scale(1.4);
    z-index: 100;
    border-color: rgba(255, 255, 255, 0.7);
    box-shadow: 
        0 10px 25px rgba(0, 0, 0, 0.6),
        0 0 15px var(--flag-color),
        0 0 30px var(--flag-color);
}

/* カードのアクティブ（クリック選択中）状態 */
.flag-card.selected {
    border-color: #ffffff;
    box-shadow: 
        0 0 0 3px #ffffff,
        0 0 25px var(--flag-color),
        0 0 50px var(--flag-color);
    z-index: 101;
    transform: translate(-50%, -50%) scale(1.3);
}


/* 検索マッチ時のハイライト */
.flag-card.searched-highlight {
    z-index: 105;
    animation: searched-pulse 1.5s infinite alternate;
}

@keyframes searched-pulse {
    0% {
        box-shadow: 0 0 10px #ffffff, 0 0 20px var(--flag-color);
        border-color: #ffffff;
    }
    100% {
        box-shadow: 0 0 25px #ffffff, 0 0 50px var(--flag-color);
        border-color: #ffffff;
        transform: translate(-50%, -50%) scale(1.4);
    }
}

/* ==========================================================================
   Header UI
   ========================================================================== */
.app-header {
    position: absolute;
    top: 24px;
    left: 24px;
    right: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none; /* 下のマップのドラッグを邪魔しない */
    z-index: 500;
}

.logo-area, .search-box {
    pointer-events: auto; /* ここだけイベントを有効化 */
}

.logo-area {
    display: flex;
    align-items: center;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    padding: 12px 20px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.logo-icon {
    font-size: 2.2rem;
    color: var(--accent-color);
    margin-right: 14px;
    text-shadow: 0 0 10px var(--accent-glow);
}

.title-group h1 {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 1px;
}

/* 検索ボックス */
.search-box {
    position: relative;
    width: 380px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    align-items: center;
    padding: 2px 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: border-color 0.3s ease, box-shadow 0.3s ease, width 0.3s ease;
}

.search-box:focus-within {
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 0 15px rgba(255, 255, 255, 0.05);
}

.search-icon {
    color: var(--text-secondary);
    margin-right: 12px;
}

.search-box input {
    width: 100%;
    height: 48px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.95rem;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-clear {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.search-clear:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.search-clear.hidden {
    display: none;
}

/* 検索サジェスト */
.search-suggestions {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    max-height: 320px;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.search-suggestions.hidden {
    display: none;
}

.suggestion-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover, .suggestion-item.active {
    background-color: rgba(255, 255, 255, 0.08);
}

.suggestion-flag {
    width: 36px;
    height: 24px;
    object-fit: cover;
    border-radius: 3px;
    margin-right: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.suggestion-info {
    display: flex;
    flex-direction: column;
}

.suggestion-name-ja {
    font-size: 0.9rem;
    font-weight: 600;
}

.suggestion-name-en {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ==========================================================================
   Controls Overlay (Bottom panels)
   ========================================================================== */
.controls-overlay {
    position: absolute;
    bottom: 24px;
    left: 24px;
    right: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
    z-index: 500;
}

.control-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
}

/* フィルターカード */
.filter-card {
    max-width: 500px;
}

.filter-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    letter-spacing: 0.05em;
}

.filter-card h3 span {
    font-size: 1.1rem;
    margin-right: 6px;
}

.filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    font-family: var(--font-main);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: var(--border-color-hover);
}

.filter-btn.active {
    background: var(--accent-color);
    color: #ffffff;
    border-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-glow);
}

.color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* ナビゲーション（ズーム・ツアー） */
.navigation-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    pointer-events: auto;
}

.control-btn {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 16px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* ツアー中発光アニメーション */
.tour-btn.active {
    background: #10b981;
    border-color: #10b981;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.6);
    animation: tour-pulse 1.5s infinite alternate;
}

@keyframes tour-pulse {
    0% { box-shadow: 0 0 10px rgba(16, 185, 129, 0.5); }
    100% { box-shadow: 0 0 25px rgba(16, 185, 129, 0.9); }
}

.zoom-card {
    display: flex;
    padding: 6px;
    gap: 2px;
    border-radius: 14px;
}

.zoom-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.zoom-btn:active {
    transform: scale(0.9);
}

/* ==========================================================================
   Detail Slide Panel
   ========================================================================== */
.detail-panel {
    position: absolute;
    right: 0;
    top: 0;
    width: 400px;
    height: 100%;
    background: rgba(10, 15, 28, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border-color);
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.detail-panel.open {
    transform: translateX(0);
}

.close-panel-btn {
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    background: rgba(10, 15, 28, 0.85);
    border: 1px solid var(--border-color);
    border-right: none;
    border-radius: 8px 0 0 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    transition: color 0.2s;
}

.close-panel-btn:hover {
    color: var(--text-primary);
}

.close-panel-top-btn {
    position: absolute;
    right: 16px;
    top: 16px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s ease;
}

.close-panel-top-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.close-panel-top-btn:active {
    transform: scale(0.95);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 48px 32px 32px 32px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* 国旗プレビューと背景グロー効果 */
.flag-preview-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 3/2;
    border-radius: 12px;
    overflow: visible; /* グローがはみ出せるようにする */
    margin-bottom: 8px;
}

#detail-flag-img {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    z-index: 2;
}

.flag-glow-bg {
    position: absolute;
    top: 5%;
    left: 5%;
    width: 90%;
    height: 90%;
    border-radius: 8px;
    background: var(--flag-color, var(--accent-color));
    filter: blur(25px);
    opacity: 0.55;
    z-index: 1;
    transition: background 0.4s ease;
}

/* 国情報 */
.country-info {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 20px;
}

#detail-country-ja {
    font-size: 1.7rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

#detail-country-en {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 300;
    letter-spacing: 0.05em;
}

/* ドミナントカラー */
.color-tag-section h4 {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

.color-swatch-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: inline-block;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.color-hex {
    font-size: 0.95rem;
    font-family: var(--font-main);
    color: var(--text-primary);
    font-weight: 600;
}

/* 類似セクション */
.similar-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.similar-section h3 span {
    color: var(--accent-color);
}

.section-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 16px;
}

.similar-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.similar-item {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.similar-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-color-hover);
    transform: translateX(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.similar-flag-thumb {
    width: 48px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    margin-right: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.similar-flag-info {
    display: flex;
    flex-direction: column;
}

.similar-flag-ja {
    font-size: 0.88rem;
    font-weight: 600;
}

.similar-flag-en {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

/* ==========================================================================
   Map Hint UI
   ========================================================================== */
.map-hint {
    position: absolute;
    top: 100px;
    left: 24px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    max-width: 380px;
    animation: fade-in 0.5s ease;
    z-index: 450;
    pointer-events: auto;
}

.map-hint.hidden {
    display: none;
}

.map-hint span {
    color: var(--accent-color);
}

.map-hint p {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.close-hint-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
}

.close-hint-btn:hover {
    color: var(--text-primary);
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Map Container (Restored)
   ========================================================================== */
.map-container {
    width: 100%;
    height: 100%;
    cursor: grab;
    overflow: hidden;
    position: relative;
    touch-action: none;
}

.map-container:active {
    cursor: grabbing;
}

/* ==========================================================================
   CSS Sprite System
   ========================================================================== */
.sprite-flag {
    background-image: url('images/flags_sprite.png');
    background-size: 1400% 1400%; /* 14列14行 */
    background-repeat: no-repeat;
    display: block;
}

/* ==========================================================================
   Scrollbars
   ========================================================================== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}
