/* ========================================
   World Map Tool - Digital Gene Style
   ======================================== */

/* CSS Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --gradient-start: #0feeb4;
    --gradient-end: #0372d8;
    --text-primary: #3f4a4f;
    --text-secondary: #495057;
    --text-white: #ffffff;
    --bg-white: #ffffff;
    --bg-light: #f8f9fa;
    --bg-page: #f5f7fa;
    --border-light: #e9ecef;
    --border-medium: #dee2e6;
    --accent-blue: #3498db;
    --accent-blue-dark: #2980b9;
    --accent-green: #28a745;
    --accent-green-dark: #218838;
    --accent-red: #dc3545;
    --accent-red-dark: #c82333;
    --border-radius: 6px;
    --container-width: 1400px;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, メイリオ, Meiryo, sans-serif;
}

body {
    font-family: var(--font-family);
    color: var(--text-primary);
    background-color: var(--bg-page);
    min-height: 100vh;
    padding: 0;
    margin: 0;
}

/* ========================================
   Title Banner (Digital Gene Style)
   Full width, outside container
   ======================================== */
.title-banner {
    background: linear-gradient(135deg, var(--gradient-start) 0%, var(--gradient-end) 100%);
    padding: 18px 30px;
    text-align: center;
    width: 100%;
}

.title-banner h2 {
    color: var(--text-white);
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 6px;
}

.title-banner p {
    color: var(--text-white);
    font-size: 14px;
    opacity: 0.9;
}

/* ========================================
   Container
   ======================================== */
.container {
    max-width: var(--container-width);
    margin: 10px auto 20px auto;
    background: var(--bg-white);
    border-radius: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* ========================================
   Controls
   ======================================== */
.controls {
    padding: 10px 20px;
    background: var(--bg-light);
    border-bottom: 2px solid var(--border-light);
    border-radius: 15px 15px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-start;
}

.control-section {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-white);
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    flex: 1;
    min-width: 300px;
}

/* 一括設定セクション：幅を抑え、縦をコンパクトに・内容は左揃え */
.control-section-bulk {
    flex: 0 1 auto;
    max-width: 720px;
    flex-direction: column;
    align-items: flex-start;
    padding: 6px 10px;
    gap: 6px;
}

.bulk-settings-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px 10px;
    width: 100%;
}

.bulk-settings-row label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    flex-shrink: 0;
}

.bulk-settings-row input[type="text"] {
    padding: 4px 8px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 13px;
    width: 140px;
}

.bulk-settings-row select {
    padding: 4px 8px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 13px;
    background: var(--bg-white);
}

.bulk-settings-row .btn-secondary {
    font-size: 13px;
    padding: 4px 8px;
}

.bulk-settings-row .toggle-switch-label {
    margin: 0;
}

.control-section-bulk .control-section-label {
    margin-bottom: 2px;
    padding-bottom: 2px;
}

/* 地理レイヤーセクション：幅を広く取り、高さ制限 */
.control-section:has(.control-group-layers) {
    align-items: flex-start;
    flex-direction: column;
    flex: 1 1 360px;
    min-width: 360px;
}

/* タブレットサイズでコントロールセクションの幅を調整 */
@media (min-width: 768px) and (max-width: 1200px) {
    .control-section {
        flex: 0 1 auto;
        max-width: 560px;
    }
    
    .control-section:first-of-type {
        max-width: 450px;
    }
    
    .control-section-right {
        flex-shrink: 0;
    }
}

.control-section-label {
    width: 100%;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 14px;
}

.control-group input[type="color"] {
    width: 36px;
    height: 28px;
    min-height: 28px;
    border: 2px solid var(--border-medium);
    border-radius: 5px;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: none;
    padding: 0;
    box-sizing: border-box;
}

.control-group input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border: none;
    border-radius: 3px;
}

.control-group input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.control-group input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 3px;
}

.control-group input[type="color"]:focus,
.control-group input[type="color"]:active {
    height: 28px;
    min-height: 28px;
    outline: none;
}

.control-group select {
    padding: 6px 12px;
    border: 2px solid var(--border-medium);
    border-radius: 5px;
    font-size: 13px;
    background: var(--bg-white);
    cursor: pointer;
}

.control-group input[type="text"] {
    padding: 6px 12px;
    border: 2px solid var(--border-medium);
    border-radius: 5px;
    font-size: 13px;
    width: 180px;
}

.control-group-vertical {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.control-group-vertical label {
    margin-bottom: 0;
}

.control-group-vertical select {
    min-width: 120px;
}

.control-group-bulk-add {
    flex-wrap: wrap;
    margin-top: 4px;
}

.control-group-bulk-add .btn-secondary {
    font-size: 12px;
    padding: 6px 12px;
}

.control-group-bulk-actions {
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.control-group-bulk-actions .btn-secondary {
    font-size: 12px;
    padding: 6px 12px;
}

/* ========================================
   Toggle Switch
   ======================================== */
.toggle-switch-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.toggle-switch-text {
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 22px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-switch-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #bbb;
    border-radius: 22px;
    transition: background-color 0.25s;
    overflow: hidden;
}

.toggle-switch-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.25s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    z-index: 1;
}

.toggle-switch-slider::after {
    content: attr(data-off);
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 8px;
    font-weight: 700;
    color: #fff;
    line-height: 1;
    pointer-events: none;
}

.toggle-switch input:checked + .toggle-switch-slider {
    background-color: var(--accent-blue);
}

.toggle-switch input:checked + .toggle-switch-slider::before {
    transform: translateX(26px);
}

.toggle-switch input:checked + .toggle-switch-slider::after {
    content: attr(data-on);
    right: auto;
    left: 6px;
}

.control-group-utils {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-top: 2px;
    padding-top: 6px;
    border-top: 1px solid var(--border-light);
}

.control-group-utils-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
}

.control-group-utils .btn-secondary {
    font-size: 12px;
    padding: 5px 10px;
}

/* 地理レイヤーチェックボックス（2列で1行あたりの幅を確保しプルダウンがはみ出さないようにする） */
.control-group-layers {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 6px;
    width: 100%;
}

/* 英語時はラベルが長いため1列にして途切れを防ぐ */
html[lang="en"] .control-group-layers {
    grid-template-columns: 1fr;
}

@media (max-width: 900px) {
    .control-group-layers {
        grid-template-columns: 1fr;
    }
}

/* 地理アイテム選択ボタンはグリッドの外に配置 */
.control-group-layers > button {
    grid-column: 1 / -1;
    margin-top: 4px;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    overflow: hidden;
}

.layer-item-all {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border-medium);
    padding-top: 4px;
    margin-top: 0;
}

.layer-label {
    font-size: 13px;
    min-width: 2em;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* レイヤースタイルコントロール（カラー＋パターン） */
.layer-style-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 1;
    min-width: 0;
}

.layer-color-picker {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border: 2px solid var(--border-medium);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: none;
    box-sizing: border-box;
    flex-shrink: 0;
}

.layer-color-picker::-webkit-color-swatch-wrapper {
    padding: 1px;
    border: none;
    border-radius: 3px;
}

.layer-color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.layer-color-picker::-moz-color-swatch {
    border: none;
    border-radius: 3px;
}

.layer-color-picker:hover {
    border-color: var(--primary);
}

.layer-pattern-select {
    padding: 2px 6px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 13px;
    background: var(--bg-white);
    cursor: pointer;
    flex-shrink: 0;
    min-width: 5.5em;
}

.layer-pattern-select:hover {
    border-color: var(--primary);
}

/* カスタムドロップダウン */
.layer-dropdown-container {
    position: relative;
    flex: 1;
    min-width: 150px;
}

.layer-dropdown-btn {
    width: 100%;
    padding: 6px 12px;
    border: 2px solid var(--border-medium);
    border-radius: 5px;
    font-size: 13px;
    background: var(--bg-white);
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.2s;
}

.layer-dropdown-btn:hover {
    border-color: var(--primary);
}

.layer-dropdown-btn.active {
    border-color: var(--primary);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.layer-dropdown-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-white);
    border: 2px solid var(--primary);
    border-top: none;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.layer-dropdown-list.open {
    display: block;
}

.layer-dropdown-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.layer-dropdown-item:hover {
    background: var(--bg-light);
}

.layer-dropdown-item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--primary);
}

.layer-dropdown-item label,
.layer-dropdown-item .layer-dropdown-label {
    cursor: pointer;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-dropdown-item.checked {
    background: #e8f4fd;
}

.layer-dropdown-list::-webkit-scrollbar {
    width: 6px;
}

.layer-dropdown-list::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}

/* .layer-checkbox:hover は削除（チェックボックス機能を削除） */

.layer-placed-count {
    font-size: 13px;
    color: var(--primary, #2a7fff);
    font-weight: 600;
    min-width: 16px;
    text-align: right;
    flex-shrink: 0;
}

/* ===== 地理アイテム選択モーダル ===== */
.geo-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.geo-modal {
    background: var(--bg-white);
    border-radius: 12px;
    width: 100%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    overflow: hidden;
}

.geo-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.geo-modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.geo-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0 4px;
    line-height: 1;
}
.geo-modal-close:hover { color: #333; }

.geo-modal-filters {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.geo-filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.geo-filter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 40px;
    flex-shrink: 0;
}

.geo-filter-chips {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.geo-filter-chip {
    padding: 3px 10px;
    border-radius: 14px;
    font-size: 11px;
    cursor: pointer;
    border: 2px solid var(--border-medium);
    background: var(--bg-white);
    color: var(--text-secondary);
    transition: all 0.15s;
    user-select: none;
    font-weight: 500;
}

.geo-filter-chip:hover {
    border-color: var(--accent-blue);
}

.geo-filter-chip.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

.geo-filter-chip[data-layer].active {
    background: var(--chip-color, var(--accent-blue));
    border-color: var(--chip-color, var(--accent-blue));
    color: white;
}

.geo-level-switch {
    display: flex;
    border: 2px solid var(--border-medium);
    border-radius: 6px;
    overflow: hidden;
}

.geo-level-btn {
    padding: 4px 16px;
    border: none;
    background: var(--bg-white);
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.geo-level-btn:not(:last-child) {
    border-right: 1px solid var(--border-medium);
}

.geo-level-btn.active {
    background: var(--accent-blue);
    color: white;
}

.geo-modal-count {
    padding: 6px 20px;
    font-size: 11px;
    color: #888;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.geo-modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    min-height: 0;
}

.geo-modal-list::-webkit-scrollbar { width: 6px; }
.geo-modal-list::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 3px; }

.geo-list-section-header {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 6px 20px;
    font-size: 12px;
    font-weight: 700;
    background: var(--bg-light);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.geo-list-section-header:hover {
    background: #e8ecf0;
}

.geo-list-section-arrow {
    font-size: 10px;
    transition: transform 0.25s ease;
    flex-shrink: 0;
    color: #999;
}
.geo-list-section-header.collapsed .geo-list-section-arrow {
    transform: rotate(-90deg);
}

.geo-list-section-body {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 5000px;
    opacity: 1;
}
.geo-list-section-body.collapsed {
    max-height: 0;
    opacity: 0;
}

.geo-list-section-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.geo-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 20px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.12s;
    user-select: none;
    border-bottom: 1px solid #f0f0f0;
}

.geo-list-item:hover { background: #f4f8ff; }
.geo-list-item.checked { background: #e8f4fd; }

.geo-list-item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent-blue);
    flex-shrink: 0;
}

.geo-list-item-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.geo-list-item-kana {
    font-size: 10px;
    color: #aaa;
    flex-shrink: 0;
}

.geo-list-item-region {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    background: var(--bg-light);
    color: #777;
    flex-shrink: 0;
    border: 1px solid var(--border-light);
}

.geo-list-empty {
    padding: 40px 20px;
    text-align: center;
    color: #aaa;
    font-size: 13px;
}

/* .layer-checkbox input[type="checkbox"] は削除（チェックボックス機能を削除） */

/* ========================================
   Color Presets（一括設定・吹き出し共通: プリセットは○、カスタム色は□）
   ======================================== */
.color-presets {
    display: flex;
    gap: 5px;
    align-items: center;
}

.color-preset {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.color-preset:hover {
    transform: scale(1.1);
}

.color-preset.selected {
    border-color: #333;
}


/* ========================================
   Buttons
   ======================================== */
button {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent-blue);
    color: var(--text-white);
}

.btn-primary:hover {
    background: var(--accent-blue-dark);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--accent-green);
    color: var(--text-white);
}

.btn-success:hover {
    background: var(--accent-green-dark);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--accent-red);
    color: var(--text-white);
}

.btn-danger:hover {
    background: var(--accent-red-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-light);
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
}

.btn-secondary:hover {
    background: var(--border-light);
    border-color: var(--border-medium);
}

.btn-large {
    padding: 12px 30px;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

/* ========================================
   Download Icon
   ======================================== */
.icon-download {
    display: inline-block;
    width: 20px;
    height: 20px;
    position: relative;
}

.icon-download::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 12px;
    background: currentColor;
}

.icon-download .arrow {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 8px;
    height: 8px;
    border: 2px solid currentColor;
    border-top: none;
    border-left: none;
}

.icon-download::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 20px;
    height: 6px;
    border: 2px solid currentColor;
    border-top: none;
    border-radius: 0 0 3px 3px;
    box-sizing: border-box;
}


/* ========================================
   Selected Countries List
   ======================================== */
.selected-countries {
    padding: 10px 25px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
    display: none;
}

.selected-countries.active {
    display: block;
}

.selected-countries h4 {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.selected-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.selected-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--bg-light);
    border-radius: 5px;
    font-size: 12px;
}

.selected-item .color-dot {
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid #ccc;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-sizing: border-box;
    overflow: hidden;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* スマートフォンでタップしやすくする */
@media (max-width: 768px) {
    .selected-item .color-dot {
        min-width: 24px;
        min-height: 24px;
        width: 24px;
        height: 24px;
    }
}

.selected-item .color-dot.has-pattern {
    width: 50px;
    height: 25px;
}

.selected-item .color-dot svg {
    width: 100%;
    height: 100%;
    display: block;
}

.selected-item .country-name {
    font-weight: 500;
}

.selected-item .remove-btn {
    cursor: pointer;
    color: var(--accent-red);
    font-weight: bold;
    margin-left: 4px;
}

.selected-item .remove-btn:hover {
    color: #a71d2a;
}

/* ========================================
   Map Container
   ======================================== */
.map-container {
    padding: 10px 20px 20px;
    background: var(--bg-white);
    position: relative;
    overflow: hidden;
}

#mapWrapper {
    position: relative;
    width: 100%;
    /* 縦横比はJavaScriptで動的に設定される */
    overflow: visible;
    /* スマホ: 1本指はページスクロール、2本指で地図の移動・ピンチ */
    -webkit-user-select: none;
    user-select: none;
}

.zoom-hint-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    pointer-events: none;
    z-index: 300;
    opacity: 0;
    transition: opacity 0.3s;
    white-space: nowrap;
}

.zoom-hint-overlay.visible {
    opacity: 1;
}

#worldMap {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#worldMap:active {
    cursor: grabbing;
}

#worldMap .zoom-group {
    pointer-events: all;
}

#worldMap .country {
    fill: #e9ecef;
    stroke: none;
    cursor: pointer;
    transition: fill 0.2s;
    pointer-events: all;
}

#worldMap .country:hover {
    filter: brightness(0.95);
}

#worldMap .country.selected {
    /* 選択時も境界線は描画しない（二重線防止） */
}

#worldMap .boundary {
    fill: none;
    stroke: #fff;
    stroke-width: 0.5;
    pointer-events: none;
}

#worldMap .map-background {
    pointer-events: all;
    fill: transparent;
}

/* 選択した国の輪郭を表示するレイヤー */
#worldMap .selection-outline {
    fill: none;
    stroke: #333;
    stroke-width: 0.5;
    pointer-events: none;
}

/* ========================================
   Copyright Overlay
   ======================================== */
.copyright-overlay {
    position: absolute;
    left: 12px;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    z-index: 90;
    pointer-events: none;
    user-select: none;
    opacity: 0.35;
}

.copyright-overlay.hidden {
    display: none;
}

.copyright-qr {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    image-rendering: pixelated;
}

/* 地図上の拡大・縮小ボタン（表示時のみ・印刷時は非表示） */
.map-zoom-controls {
    position: absolute;
    left: 12px;
    top: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 95;
    pointer-events: none;
}
.map-zoom-controls .map-zoom-btn {
    pointer-events: auto;
    width: 40px;
    height: 40px;
    border: 2px solid rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    background: #fff;
    color: #333;
    font-size: 22px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.map-zoom-controls .map-zoom-btn:hover {
    background: #f0f0f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.map-zoom-controls .map-zoom-btn:active {
    background: #e0e0e0;
}
.map-zoom-controls .map-zoom-btn:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}
.map-zoom-controls #mapZoomOutBtn {
    font-size: 24px;
    line-height: 0.9;
}

.copyright-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    line-height: 1.3;
    text-align: left;
}

.copyright-title {
    font-size: 11px;
    font-weight: 700;
    color: #000;
}

.copyright-name {
    font-size: 11px;
    font-weight: 600;
    color: #000;
}

.copyright-url {
    font-size: 9px;
    color: #333;
}

/* ========================================
   Annotations
   ======================================== */
.annotation-line {
    stroke: #333;
    stroke-width: 2;
    fill: none;
}

.anchor-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #333;
    cursor: move;
    z-index: 50; /* 吹き出し(z-index: 100)より背面に配置 */
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    transition: transform 0.2s, background-color 0.2s;
    margin-left: -5px;
    margin-top: -5px;
}

.anchor-handle:hover {
    transform: scale(1.3);
    background-color: #555;
}

.annotation-bubble {
    background: var(--bg-white);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 10px 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: move;
    min-width: 120px;
    max-width: 250px;
    position: absolute;
    z-index: 100;
    /* タッチ操作を改善 */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.annotation-bubble .bubble-furigana {
    display: block;
    font-size: calc(var(--bubble-title-size, 14px) * 0.55);
    color: #555;
    line-height: 1.2;
    margin-bottom: 0;
    min-height: 0;
}

.annotation-bubble .bubble-furigana:empty {
    display: none;
}

.annotation-bubble h4 {
    margin: 0 0 5px 0;
    font-size: var(--bubble-title-size, 14px);
    color: #333;
}

.annotation-bubble p {
    margin: 0;
    font-size: var(--bubble-desc-size, 12px);
    color: #666;
    white-space: pre-wrap;
    word-break: break-word;
}

/* 説明文が空のときは上下の余白を均等に */
.annotation-bubble:has(p:empty) h4 {
    margin-bottom: 0;
}

.annotation-bubble p:empty {
    margin: 0;
    padding: 0;
    line-height: 0;
    height: 0;
    overflow: hidden;
    min-height: 0;
}

/* 吹き出し編集モード（色プリセットを1行に収めるため幅を広め） */
.annotation-bubble.editing {
    cursor: default;
    min-width: 300px;
    max-width: 320px;
    touch-action: auto;
    z-index: 200; /* 他の吹き出し(z-index:100)より前面に表示 */
}

.annotation-bubble .edit-close-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #666;
    color: white;
    border: 2px solid white;
    font-size: 18px;
    font-weight: bold;
    font-family: Arial, sans-serif;
    line-height: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: background 0.2s;
    padding: 0;
    padding-bottom: 2px;
}

.annotation-bubble .edit-close-btn:hover {
    background: #444;
}

.annotation-bubble .edit-furigana {
    width: 100%;
    padding: 3px 8px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 11px;
    margin-bottom: 4px;
    box-sizing: border-box;
    color: var(--text-primary);
}

.annotation-bubble .edit-title-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}

.annotation-bubble .edit-title-row .edit-title {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.annotation-bubble .edit-title-quick-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.annotation-bubble .edit-btn-pref,
.annotation-bubble .edit-btn-capital {
    padding: 4px 6px;
    font-size: 10px;
    white-space: nowrap;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    background: var(--bg-white);
    cursor: pointer;
    font-weight: 500;
}

.annotation-bubble .edit-btn-pref:hover,
.annotation-bubble .edit-btn-capital:hover {
    background: var(--bg-light);
}

.annotation-bubble .edit-title {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    box-sizing: border-box;
}

.annotation-bubble .edit-desc {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 12px;
    resize: vertical;
    min-height: 60px;
    max-height: 200px;
    margin-bottom: 2px;
    box-sizing: border-box;
    font-family: inherit;
}

.annotation-bubble .edit-hint {
    font-size: 9px;
    color: #999;
    margin-top: 0;
    margin-bottom: 8px;
}

.annotation-bubble .edit-style-section {
    margin-bottom: 12px;
    padding: 8px;
    background: var(--bg-light);
    border-radius: 4px;
}

.annotation-bubble .edit-style-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.annotation-bubble .edit-style-row:last-child {
    margin-bottom: 0;
}

.annotation-bubble .edit-style-row label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 60px;
}

.annotation-bubble .edit-color-presets {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.annotation-bubble .edit-color-preset {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.annotation-bubble .edit-color-preset:hover {
    transform: scale(1.1);
}

.annotation-bubble .edit-color-preset.selected {
    border-color: #333;
}

.annotation-bubble .edit-color-picker {
    width: 24px;
    height: 20px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}

.annotation-bubble .edit-style-row-left {
    align-items: flex-start;
}

.annotation-bubble .edit-style-row-left .edit-pattern-select {
    flex: 0 1 auto;
    min-width: 140px;
}

.annotation-bubble .edit-pattern-select {
    padding: 4px 8px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 11px;
    background: var(--bg-white);
    cursor: pointer;
    text-align: left;
}

.annotation-bubble .edit-buttons {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.annotation-bubble .edit-buttons button {
    padding: 8px 16px;
    font-size: 13px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    min-width: 60px;
    min-height: 36px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.annotation-bubble .edit-save {
    background: var(--accent-green);
    color: var(--text-white);
}

.annotation-bubble .edit-save:hover,
.annotation-bubble .edit-save:active {
    background: var(--accent-green-dark);
}

.annotation-bubble .edit-cancel {
    background: #6c757d;
    color: var(--text-white);
}

.annotation-bubble .edit-cancel:hover,
.annotation-bubble .edit-cancel:active {
    background: #5a6268;
}

.annotation-bubble .edit-reset {
    background: #6c757d;
    color: var(--text-white);
}

.annotation-bubble .edit-reset:hover,
.annotation-bubble .edit-reset:active {
    background: #5a6268;
}

.annotation-bubble .edit-delete {
    background: var(--accent-red);
    color: var(--text-white);
}

.annotation-bubble .edit-delete:hover,
.annotation-bubble .edit-delete:active {
    background: var(--accent-red-dark);
}

/* ========================================
   Footer
   ======================================== */
.footer {
    padding: 15px 25px;
    background: var(--bg-light);
    border-radius: 0 0 15px 15px;
    text-align: center;
    font-size: 12px;
    color: #6c757d;
}

.footer a {
    color: var(--accent-blue);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ========================================
   Loading & Error
   ======================================== */
.loading {
    text-align: center;
    padding: 50px;
    color: #6c757d;
}

.error-message {
    text-align: center;
    padding: 30px;
    color: var(--accent-red);
    background: #f8d7da;
    border-radius: 8px;
    margin: 20px;
}

/* ========================================
   Color Picker Popup
   ======================================== */
.color-picker-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: none;
}

.color-picker-overlay.active {
    display: block;
}

.color-picker-popup {
    position: absolute;
    background: var(--bg-white);
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    display: none;
    min-width: 200px;
}

.color-picker-popup.active {
    display: block;
}

/* スマートフォン向けスタイル */
@media (max-width: 768px) {
    .color-picker-popup {
        width: 90%;
        max-width: 300px;
        padding: 20px;
    }
}

.color-picker-popup .preset-colors {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin-bottom: 10px;
}

.color-picker-popup .preset-color {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.color-picker-popup .preset-color:hover,
.color-picker-popup .preset-color:active {
    border-color: #333;
}

/* スマートフォン向けスタイル */
@media (max-width: 768px) {
    .color-picker-popup .preset-color {
        width: 40px;
        height: 40px;
    }
}

.color-picker-popup input[type="color"] {
    width: 100%;
    height: 40px;
    border: 2px solid var(--border-medium);
    border-radius: 4px;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: none;
    padding: 0;
    box-sizing: border-box;
}

.color-picker-popup input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border: none;
    border-radius: 4px;
}

.color-picker-popup input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.color-picker-popup input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

/* ========================================
   Help Dialog
   ======================================== */
.help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
}

.help-overlay.active {
    display: flex;
}

.help-dialog {
    background: var(--bg-white);
    border-radius: 12px;
    padding: 30px;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 10001;
    margin: 20px;
}

.help-dialog h2 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #2c3e50;
    font-size: 24px;
    border-bottom: 2px solid var(--accent-blue);
    padding-bottom: 10px;
}

.help-dialog h3 {
    margin-top: 25px;
    margin-bottom: 12px;
    color: #34495e;
    font-size: 18px;
}

.help-dialog p {
    margin-bottom: 12px;
    line-height: 1.6;
    color: #555;
}

.help-dialog ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.help-dialog li {
    margin-bottom: 8px;
    line-height: 1.6;
    color: #555;
}

.help-dialog .close-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #e74c3c;
    color: var(--text-white);
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.help-dialog .close-button:hover {
    background: #c0392b;
    transform: scale(1.1);
}

.help-dialog a {
    color: var(--accent-blue);
    text-decoration: none;
    font-weight: 600;
}

.help-dialog a:hover {
    text-decoration: underline;
}

.help-dialog .help-copyright-note {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px solid #ecf0f1;
    font-size: 12px;
    color: #7f8c8d;
}

@media (max-width: 768px) {
    .help-dialog {
        max-width: 95%;
        padding: 20px;
    }
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 600px) {
    .title-banner {
        padding: 40px 20px;
    }

    .title-banner h2 {
        font-size: 24px;
    }

    .title-banner p {
        font-size: 14px;
    }

    .controls {
        border-radius: 0;
    }

    .container {
        margin: 0;
        border-radius: 0;
    }
}

/* ========================================
   Initial Setup Modal
   ======================================== */
.setup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.setup-dialog {
    background: var(--bg-white);
    border-radius: 15px;
    padding: 40px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.setup-dialog h2 {
    color: var(--text-primary);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
    text-align: center;
}

.setup-dialog > p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 30px;
    text-align: center;
}

.setup-form {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.setup-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setup-group label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 16px;
}

.setup-group .button-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.setup-btn {
    flex: 1;
    min-width: 120px;
    padding: 14px 20px;
    border: 2px solid var(--border-medium);
    border-radius: var(--border-radius);
    background-color: var(--bg-white);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

/* 用紙向きボタン：アイコン＋テキスト */
.button-group-orientation .setup-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.button-group-orientation .orientation-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}

.button-group-orientation .orientation-icon svg {
    display: block;
}

.setup-btn:hover {
    background-color: #f0f0f0;
    border-color: var(--accent-blue);
}

.setup-btn.active {
    background-color: #e8f4fd;
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    font-weight: 600;
}

.setup-form .btn-success {
    margin-top: 10px;
    width: 100%;
    justify-content: center;
}

/* ダウンロードダイアログのボタン配置 */
.setup-buttons {
    display: flex;
    gap: 12px;
    margin-top: 10px;
}

.setup-buttons .btn-secondary {
    flex: 0 0 auto;
    padding: 12px 24px;
}

.setup-buttons .btn-success {
    flex: 1;
    margin-top: 0;
    justify-content: center;
    padding: 16px 30px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.35);
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.setup-buttons .btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(40, 167, 69, 0.45);
}

/* ボタンの縦並び */
.button-group-vertical {
    flex-direction: column;
}

.button-group-vertical .setup-btn {
    text-align: center;
    justify-content: center;
}

@media (max-width: 600px) {
    .setup-dialog {
        padding: 25px 20px;
    }

    .setup-dialog h2 {
        font-size: 22px;
    }

    .setup-group .button-group {
        flex-direction: column;
    }

    .setup-btn {
        min-width: auto;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .no-print,
    .controls,
    .title-banner,
    .footer,
    .selected-countries {
        display: none !important;
    }

    body {
        background: var(--bg-white);
        padding: 0;
    }

    .container {
        box-shadow: none;
        border-radius: 0;
        margin: 0;
    }
}
