:root {
    /* Light Mode Variables */
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --map-border: #e2e8f0;
    --country-default: #cbd5e1;
    --country-hover: #3b82f6;
    --country-active: #ef4444; 
    --country-stroke: rgba(255, 255, 255, 0.6); /* Semi-transparent stroke to blend gaps */
    --tooltip-bg: #1e293b;
    --tooltip-text: #ffffff;
    --modal-overlay: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
    /* Dark Mode Variables */
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --map-border: #334155;
    --country-default: #334155;
    --country-hover: #60a5fa;
    --country-active: #f87171; 
    --country-stroke: rgba(30, 41, 59, 0.6);
    --tooltip-bg: #f8fafc;
    --tooltip-text: #0f172a;
    --modal-overlay: rgba(0, 0, 0, 0.8);
}

.map-section {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 10px;    
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    touch-action: none;
    border-radius: 8px;
}

.header-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 0 20px;
    z-index: 10;
}

.map-section h1 { margin: 0; font-weight: 300; font-size: 1.5rem; }

.controls {
    display: flex;
    gap: 8px;
}

.map-section button {
    background: var(--card-bg);
    border: 1px solid var(--map-border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

button:hover {
    border-color: var(--country-hover);
    background: var(--bg-color);
}

#map-wrapper {
    height: 65vh;
    background: var(--card-bg);
    border: 1px solid var(--map-border);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    position: relative;
    overflow: hidden;
    cursor: default;
}

#map-wrapper.can-pan { cursor: grab; }
#map-wrapper.panning { cursor: grabbing !important; }

#zoom-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1);
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

#zoom-container.is-dragging {
    transition: none;
}

#zoom-container svg {
    width: 100%;
    height: 100%;
    display: block;
    shape-rendering: geometricPrecision;
}

path {
    fill: var(--country-default);
    stroke: var(--country-stroke);
    /* Reduced stroke width coefficient for finer lines */
    stroke-width: 0.25; 
    transition: fill 0.2s ease;
    pointer-events: all;
    cursor: default;
    /* CRITICAL: Keeps the line thin even at 800% zoom */
    vector-effect: non-scaling-stroke;
    /* Helps close the tiny visual gaps between path coordinates */
    stroke-linejoin: round;
    stroke-linecap: round;
}

path.has-content {
    fill: var(--country-active) !important;
    cursor: pointer;
}

path:hover, path.highlight-group {
    fill: var(--country-hover) !important;
}

.highlight-group {
    fill: var(--country-hover) !important;
}

#tooltip {
    position: fixed;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    pointer-events: none;
    display: none;
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    transform: translate(-50%, -120%);
}

#status {
    margin-top: 15px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-overlay);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 30px;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    position: relative;
    animation: modalSlide 0.3s ease-out;
}

@keyframes modalSlide {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 15px; right: 15px;
    background: none; border: none; font-size: 24px;
    cursor: pointer; color: var(--text-secondary);
}

.modal-footer { margin-top: 20px; text-align: right; }

.btn-primary {
    background: var(--country-hover);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    display: inline-block;
}

@media (max-width: 600px) {
    h1 { font-size: 1.2rem; }
    #map-wrapper { height: 50vh; }
}