/**
 * Interactive Korea Map Styles
 * Production-ready, accessible, responsive
 */

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

:root {
    /* Color tokens */
    --bg-primary: #0b0d18;
    --bg-secondary: #1a1d2e;
    --text-primary: #ffffff;
    --text-secondary: #b0b8c9;
    --gray-fade: #bfbfbf;
    --accent-glow: rgba(255, 255, 255, 0.6);
    --border-color: rgba(255, 255, 255, 0.1);

    /* Interaction tokens */
    --transition-duration: 0.35s;
    --fade-opacity: 0.5;
    --active-scale: 1.05;
    --active-glow: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));

    /* Typography */
    --font-family: system-ui, -apple-system, 'Pretendard', 'Segoe UI', sans-serif;
    --font-size-base: 16px;
    --font-size-large: 18px;
    --font-size-small: 14px;
    --font-size-title: clamp(24px, 4vw, 32px);
}

html {
    font-size: var(--font-size-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-large);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ============================================================================
   Header
   ============================================================================ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.title {
    font-size: var(--font-size-title);
    font-weight: 600;
    letter-spacing: -0.02em;
}

.reset-btn {
    padding: 0.625rem 1.25rem;
    font-size: var(--font-size-small);
    font-family: inherit;
    font-weight: 500;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-1px);
}

.reset-btn:active {
    transform: translateY(0);
}

.reset-btn:focus-visible {
    outline: 2px solid var(--accent-glow);
    outline-offset: 2px;
}

/* ============================================================================
   Main Layout
   ============================================================================ */
.main-container {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 2rem;
    padding: 2rem;
    flex: 1;
    align-items: start;
}

@media (max-width: 1024px) {
    .main-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* ============================================================================
   Map Container
   ============================================================================ */
/* Map container styles are now handled in styles.css for consistency */

.loading {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
    font-size: var(--font-size-small);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* SVG Container - handled in styles.css */

/* ============================================================================
   Region Styles (SVG Elements)
   ============================================================================ */
.region {
    cursor: pointer;
    /* CRITICAL: NO CSS transform - use SVG transform attribute only! */
    transition:
        opacity var(--transition-duration) ease,
        fill var(--transition-duration) ease,
        filter var(--transition-duration) ease;
    outline: none;
    stroke: #000000;
    stroke-width: 1;
    /* CRITICAL: Prevent stroke from scaling when transform is applied */
    vector-effect: non-scaling-stroke;
}

/* Apply stroke to child paths in groups */
.region path {
    stroke: #000000;
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

/* Hover state */
.region:hover {
    opacity: 0.9;
    filter: brightness(1.1);
}

/* Focus state (keyboard navigation) */
.region:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

/* Faded state (non-selected regions) */
.region.fade {
    fill: var(--gray-fade) !important;
    opacity: var(--fade-opacity);
    /* NO transform - handled by JS via SVG transform attribute */
    filter: none;
}

/* Visited state (previously clicked regions) */
.region.visited {
    /* Keep original color but slightly less opaque than active */
    opacity: 0.85;
    filter: brightness(0.95);
    pointer-events: auto;
}

.region.visited path {
    opacity: 0.85;
}

/* Active state (selected region) */
.region.active {
    /* NO transform - scale is applied via JS using SVG transform attribute */
    opacity: 1;
    /* Glow effect - element is moved to end of SVG to prevent overlap */
    filter: var(--active-glow);
    stroke: #000000;
    stroke-width: 1.5;
    /* z-index doesn't work on SVG - we move element to end instead */
}

.region.active path {
    stroke: #000000;
    stroke-width: 1.5;
}

/* Ensure faded regions are still clickable */
.region.fade {
    pointer-events: auto;
}

/* ============================================================================
   Info Panel
   ============================================================================ */
.info-panel {
    position: sticky;
    top: 120px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

@media (max-width: 1024px) {
    .info-panel {
        position: relative;
        top: 0;
    }
}

.info-content {
    animation: fadeIn 0.3s ease;
}

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

.info-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.info-description {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.info-details {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.info-details dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.75rem 1rem;
    font-size: var(--font-size-base);
}

.info-details dt {
    font-weight: 600;
    color: var(--text-secondary);
}

.info-details dd {
    color: var(--text-primary);
    font-weight: 500;
}

/* ============================================================================
   Tooltip
   ============================================================================ */
.tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    font-size: var(--font-size-small);
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.tooltip.visible {
    opacity: 1;
}

/* ============================================================================
   Keyboard Help
   ============================================================================ */
.keyboard-help {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 50;
}

.keyboard-help details {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    cursor: pointer;
}

.keyboard-help summary {
    font-size: var(--font-size-small);
    font-weight: 500;
    color: var(--text-secondary);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.keyboard-help summary::-webkit-details-marker {
    display: none;
}

.keyboard-help summary::before {
    content: '⌨️';
}

.keyboard-help ul {
    list-style: none;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.keyboard-help li {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    padding: 0.25rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.keyboard-help kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.125rem 0.375rem;
    font-family: monospace;
    font-size: 0.875rem;
    color: var(--text-primary);
}

/* ============================================================================
   Responsive Adjustments
   ============================================================================ */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .reset-btn {
        width: 100%;
        justify-content: center;
    }

    .main-container {
        padding: 1rem;
    }

    .map-container {
        padding: 1rem;
    }

    .keyboard-help {
        display: none;
    }
}

/* ============================================================================
   Accessibility Enhancements
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .region {
        stroke-width: 2;
    }

    .region.active {
        stroke-width: 3;
    }
}

/* Focus visible for all interactive elements */
button:focus-visible,
details:focus-visible {
    outline: 2px solid var(--accent-glow);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .reset-btn,
    .keyboard-help,
    .tooltip {
        display: none;
    }

    body {
        background: white;
        color: black;
    }
}
