/* =========================================
   World Map Explorer - Production CSS
   Optimized, Touch-Friendly, Lightweight
   ========================================= */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-glass: rgba(255, 255, 255, 0.95);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-light: rgba(148, 163, 184, 0.2);
    --border-medium: rgba(148, 163, 184, 0.3);
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --country-default: #e2e8f0;
    --country-hover: #cbd5e1;
    --country-stroke: #94a3b8;
    --ocean-color: #f1f5f9;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.globe-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-light);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loader {
    text-align: center;
}

.loader p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-glass);
    border-bottom: 1px solid var(--border-light);
    z-index: 100;
    flex-wrap: wrap;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-primary);
}

.logo h1 {
    font-size: 18px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.map-toggle {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
    gap: 4px;
}

.toggle-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

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

.toggle-btn.active {
    background: white;
    color: var(--accent-primary);
    box-shadow: var(--shadow-sm);
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
    background: var(--ocean-color);
    min-height: 500px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#world-map {
    width: 100%;
    height: 100%;
    display: block;
}

#world-map .country {
    fill: var(--country-default);
    stroke: var(--country-stroke);
    stroke-width: 0.5;
}

#world-map .country:hover {
    fill: var(--country-hover);
}

#world-map .country.colored {
    stroke: var(--accent-primary);
    stroke-width: 1;
}

/* Labels */
.country-labels {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.country-label {
    position: absolute;
    font-size: 8px;
    font-weight: 600;
    color: var(--text-primary);
    text-shadow: 1px 1px 0 white, -1px 1px 0 white, 1px -1px 0 white, -1px -1px 0 white;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    opacity: 0;
    user-select: none;
}

.country-labels.visible .country-label {
    opacity: 1;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 80px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 50;
}

.zoom-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform 0.1s;
}

.zoom-btn:hover {
    transform: scale(1.05);
}

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

.zoom-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* Integrated Legend */
.legend {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 12px;
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    z-index: 40;
}

.legend.hidden {
    display: none;
}

.legend-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* Control Panel */
.control-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 12px 20px;
    background: var(--bg-glass);
    border-top: 1px solid var(--border-light);
    flex-wrap: wrap;
    z-index: 100;
}

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

.toggle-control {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.toggle-control input {
    display: none;
}

.toggle-slider {
    width: 36px;
    height: 20px;
    background: var(--border-medium);
    border-radius: 10px;
    position: relative;
    transition: background 0.15s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.15s;
}

.toggle-control input:checked+.toggle-slider {
    background: var(--accent-primary);
}

.toggle-control input:checked+.toggle-slider::after {
    transform: translateX(16px);
}

.toggle-label {
    font-size: 13px;
    font-weight: 500;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s;
}

.control-btn:hover {
    box-shadow: var(--shadow-md);
}

.control-btn:active {
    transform: scale(0.98);
}

.btn-random {
    background: var(--accent-gradient);
    color: white;
    border: none;
}

.btn-clear {
    color: #dc2626;
    border-color: #fecaca;
}

.btn-download {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
}

/* Color Popup - Right-aligned, compact */
.color-popup {
    position: fixed;
    top: 120px;
    right: 80px;
    left: auto;
    transform: none;
    width: 220px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    z-index: 200;
    overflow: hidden;
}

.color-popup.hidden {
    display: none;
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--accent-gradient);
    color: white;
}

.popup-header h4 {
    font-size: 12px;
    font-weight: 600;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.popup-close {
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    color: white;
    cursor: pointer;
}

.popup-body {
    padding: 12px;
}

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

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s;
}

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

.color-swatch.active {
    border-color: var(--text-primary);
}

.btn-remove {
    width: 100%;
    padding: 8px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    color: #dc2626;
    cursor: pointer;
}

/* Tooltip */
.tooltip {
    position: fixed;
    padding: 6px 12px;
    background: var(--text-primary);
    color: white;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    pointer-events: none;
    z-index: 300;
    white-space: nowrap;
}

.tooltip.hidden {
    display: none;
}

/* SEO Content Section */
.content-section {
    background: var(--bg-secondary);
    padding: 60px 20px;
}

.content-wrapper {
    max-width: 1000px;
    margin: 0 auto;
}

.content-section h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.content-section h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 32px 0 16px;
}

.content-section p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 24px;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-top: 32px;
}

.feature-card {
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.feature-card h3 {
    font-size: 18px;
    margin: 0 0 12px;
}

.feature-card p {
    font-size: 14px;
    margin: 0;
}

.usage-steps {
    margin-left: 20px;
    color: var(--text-secondary);
}

.usage-steps li {
    margin-bottom: 12px;
    font-size: 15px;
}

.applications-list {
    margin-left: 20px;
    color: var(--text-secondary);
}

.applications-list li {
    margin-bottom: 8px;
    font-size: 15px;
}

/* Footer */
.footer {
    padding: 20px;
    text-align: center;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
}

.footer p {
    font-size: 13px;
    color: var(--text-secondary);
}

.footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 600;
}

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

/* Lock Mode */
body.lock-mode .header,
body.lock-mode .control-panel,
body.lock-mode .footer,
body.lock-mode .content-section,
body.lock-mode .legend,
body.lock-mode .color-popup,
body.lock-mode .tooltip {
    display: none !important;
}

body.lock-mode .zoom-controls .zoom-btn:not(#btn-lock) {
    display: none;
}

body.lock-mode .map-container {
    height: 100vh;
}

/* Mobile */
@media (max-width: 640px) {
    .header {
        padding: 10px 12px;
    }

    .logo h1 {
        font-size: 14px;
    }

    .toggle-btn {
        padding: 6px 12px;
        font-size: 13px;
    }

    .map-container {
        min-height: 400px;
    }

    .control-panel {
        padding: 10px 12px;
        gap: 10px;
    }

    .control-group {
        gap: 8px;
    }

    .control-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .toggle-label {
        display: none;
    }

    .zoom-controls {
        bottom: 70px;
        right: 12px;
    }

    .zoom-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .legend {
        left: 12px;
        bottom: 12px;
        max-width: 200px;
    }

    .content-section {
        padding: 40px 16px;
    }

    .content-section h2 {
        font-size: 24px;
    }
}

/* Touch-friendly */
@media (pointer: coarse) {
    .zoom-btn {
        width: 48px;
        height: 48px;
    }

    .control-btn {
        padding: 12px 18px;
    }

    .color-swatch {
        min-width: 44px;
        min-height: 44px;
    }
}