/* CSS Variables */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #0d1321;
    --bg-panel: rgba(13, 19, 33, 0.85);
    --border-color: #1a2744;
    --border-glow: #00d4ff;
    --text-primary: #e0e6ed;
    --text-secondary: #7a8ba3;
    --accent-cyan: #00d4ff;
    --accent-red: #ff3d3d;
    --accent-orange: #ff7b00;
    --accent-blue: #00a8ff;
    --accent-green: #00ff88;
    --inbound-color: #ff4444;
    --outbound-color: #00d4ff;
    --grid-color: rgba(0, 212, 255, 0.1);
}

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

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

body {
    font-family: 'Rajdhani', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    background-image: 
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 50px 50px;
    background-position: center center;
}

/* Container */
.container {
    display: grid;
    grid-template-rows: 80px 1fr 120px;
    grid-template-columns: 1fr;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, transparent 100%);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 30px;
    width: 560px;
}

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

.logo-icon {
    width: 52px;
    height: 52px;
    object-fit: contain;
    filter: drop-shadow(0 0 10px var(--accent-cyan));
    animation: pulse-glow 2s ease-in-out infinite;
}

.logo-text-somansa {
    font-size: 28px;
}

.logo-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--accent-cyan);
    text-align: center;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: rgba(255, 61, 61, 0.15);
    border: 1px solid var(--accent-red);
    border-radius: 20px;
}

.pulse {
    width: 10px;
    height: 10px;
    background: var(--accent-red);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

.status-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-red);
    letter-spacing: 2px;
}

.header-center {
    text-align: center;
    padding-right: 300px;
}

.title {
    font-family: 'Orbitron', sans-serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-orange);
    text-shadow: 0 0 30px rgba(255, 123, 0, 0.5);
    letter-spacing: 4px;
}

.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    letter-spacing: 2px;
    margin-top: 4px;
}

.header-right {
    text-align: right;
    font-family: 'Orbitron', sans-serif;
    width: 180px;
}

.datetime {
    font-size: 14px;
    color: var(--accent-cyan);
    letter-spacing: 1px;
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 42% 58%;
    position: relative;
    overflow: hidden;
}

/* 전환 모드: 지구본 전체 화면 (즉시 적용) */
.main-content.transitioning {
    display: block !important;
    grid-template-columns: 0 100% !important;
}

.main-content.transitioning .korea-panel {
    display: none !important;
}

.main-content.transitioning .globe-panel {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

/* 전환 중 트래픽 연결선 숨기기 */
.main-content.transitioning .connection-overlay,
.main-content.transitioning #connection-svg {
    opacity: 0 !important;
    pointer-events: none;
}

/* Panels */
.panel {
    position: relative;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent-cyan);
    letter-spacing: 2px;
}

.panel-stats {
    display: flex;
    gap: 20px;
}

.stat {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 4px;
    letter-spacing: 1px;
}

.stat.inbound {
    background: rgba(255, 68, 68, 0.2);
    border: 1px solid var(--inbound-color);
    color: var(--inbound-color);
}

.stat.outbound {
    background: rgba(0, 212, 255, 0.2);
    border: 1px solid var(--outbound-color);
    color: var(--outbound-color);
}

.stat.attacks {
    background: rgba(255, 123, 0, 0.2);
    border: 1px solid var(--accent-orange);
    color: var(--accent-orange);
}

/* Korea Map */
.korea-map-container {
    flex: 1;
    position: relative;
    background: radial-gradient(ellipse at center, rgba(0, 50, 80, 0.3) 0%, transparent 70%);
}

.korea-svg-overlay {
    z-index: 10;
    pointer-events: none;
}

#korea-canvas {
    width: 100%;
    height: 100%;
}

/* Globe */
.globe-container {
    flex: 1;
    position: relative;
    background: radial-gradient(ellipse at 70% 50%, rgba(0, 30, 60, 0.5) 0%, transparent 60%);
}

#globe-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Button Controls */
.button-controls {
    position: fixed;
    display: flex;
    gap: 5px;
    z-index: 9999;
}

.korea-zoom {
    left: 37%;
    bottom: 140px;
}

.globe-mode {
    right: 185px;
    bottom: 140px;
}

.mode-btn {
    font-size: 14px !important;
    transition: all 0.3s ease;
}

.mode-btn:hover {
    text-shadow: 0 0 10px var(--accent-cyan);
}

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

.mode-btn.flat-mode {
    background: rgba(0, 212, 255, 0.3);
    border-color: var(--accent-cyan);
}

.globe-texture {
    right: 155px;
    bottom: 140px;
}

.texture-btn {
    font-size: 14px !important;
    transition: all 0.3s ease;
}

.texture-btn:hover {
    text-shadow: 0 0 10px var(--accent-cyan);
}

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

.globe-rotate {
    right: 115px;
    bottom: 140px;
}

.globe-zoom {
    right: 20px;
    bottom: 140px;
}

.reset-btn {
    font-size: 16px !important;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    color: var(--accent-cyan);
}

.rotate-btn {
    font-size: 14px !important;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rotate-icon-svg {
    transition: all 0.3s ease;
}

.rotate-btn:not(.paused) .rotate-icon-svg {
    color: var(--accent-cyan);
    filter: drop-shadow(0 0 4px var(--accent-cyan));
}

.rotate-btn.paused .rotate-icon-svg {
    color: #666;
    filter: none;
}

.rotate-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.rotate-btn:disabled .rotate-icon-svg {
    color: #444;
    filter: none;
}

.zoom-btn {
    width: 26px;
    height: 26px;
    background: #001428;
    border: 1px solid #8ed8e7;
    border-radius: 6px;
    color: #8ed8e7;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-family: 'Rajdhani', sans-serif;
    box-shadow: 0 0 5px rgba(0, 212, 255, 0.5);
}

.zoom-btn:hover {
    background: rgba(0, 212, 255, 0.2);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

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

/* Connection Overlay */
.connection-overlay {
    position: absolute;
    top: 80px;
    left: 0;
    right: 0;
    bottom: 120px;
    pointer-events: none;
    z-index: 50;
}

#connection-svg {
    width: 100%;
    height: 100%;
}

/* Stats Footer */
.stats-footer {
    display: flex;
    align-items: center;
    padding: 15px 30px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    gap: 30px;
}

.stats-grid {
    display: flex;
    gap: 30px;
}

.stats-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 25px;
    background: rgba(0, 212, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-width: 120px;
}

.stats-label {
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.stats-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-cyan);
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.traffic-chart {
    flex: 1;
    height: 80px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

#traffic-chart {
    width: 100%;
    height: 100%;
}

/* Event Log */
.event-log {
    position: absolute;
    right: 20px;
    top: 137px;
    width: 350px;
    max-height: 400px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.event-log h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    padding: 12px 15px;
    background: rgba(0, 212, 255, 0.1);
    border-bottom: 1px solid var(--border-color);
    color: var(--accent-cyan);
    letter-spacing: 1px;
}

.event-log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

.event-log-header:hover {
    background: rgba(0, 212, 255, 0.2);
}

.toggle-icon {
    font-size: 10px;
    transition: transform 0.3s ease;
}

.event-log.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.event-log.collapsed .log-container {
    max-height: 0;
    padding: 0 10px;
    overflow: hidden;
}

.event-log.collapsed h3 {
    border-bottom: none;
}

.log-container {
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.log-container {
    max-height: 350px;
    overflow-y: auto;
    padding: 10px;
}

.log-container::-webkit-scrollbar {
    width: 6px;
}

.log-container::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.log-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.log-entry {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 5px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    font-size: 11px;
    animation: slide-in 0.3s ease-out;
}

.log-entry.inbound {
    border-left: 3px solid var(--inbound-color);
}

.log-entry.outbound {
    border-left: 3px solid var(--outbound-color);
}

.log-time {
    color: var(--text-secondary);
    white-space: nowrap;
}

.log-type {
    font-weight: 600;
    min-width: 35px;
}

.log-type.inbound {
    color: var(--inbound-color);
}

.log-type.outbound {
    color: var(--outbound-color);
}

.log-country {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
}

.country-flag {
    width: 16px;
    height: 12px;
    border-radius: 2px;
    box-shadow: 0 0 4px rgba(0, 212, 255, 0.5);
    object-fit: cover;
}

.log-entry.inbound .country-flag {
    box-shadow: 0 0 4px rgba(255, 68, 68, 0.5);
}

.log-details {
    color: var(--text-primary);
    flex: 1;
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

@keyframes pulse-glow {
    0%, 100% {
        text-shadow: 0 0 20px var(--accent-cyan);
    }
    50% {
        text-shadow: 0 0 40px var(--accent-cyan), 0 0 60px var(--accent-cyan);
    }
}

@keyframes slide-in {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Traffic Line Animations */
.traffic-line {
    stroke-linecap: round;
    fill: none;
    stroke-width: 2px;
}

.traffic-line.inbound {
    stroke: var(--inbound-color);
    filter: drop-shadow(0 0 8px var(--inbound-color)) drop-shadow(0 0 4px var(--inbound-color));
}

.traffic-line.outbound {
    stroke: var(--outbound-color);
    filter: drop-shadow(0 0 8px var(--outbound-color)) drop-shadow(0 0 4px var(--outbound-color));
}

.traffic-particle {
    filter: blur(1px);
}

.traffic-particle.inbound {
    fill: var(--inbound-color);
    filter: drop-shadow(0 0 8px var(--inbound-color));
}

.traffic-particle.outbound {
    fill: var(--outbound-color);
    filter: drop-shadow(0 0 8px var(--outbound-color));
}

/* Responsive */
@media (max-width: 1400px) {
    .event-log {
        width: 280px;
    }
    
    .stats-item {
        min-width: 100px;
        padding: 8px 15px;
    }
    
    .stats-value {
        font-size: 20px;
    }
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 40% 60%;
    }
    
    .event-log {
        display: none;
    }
}

/* Korea Map Tooltip */
.korea-map-tooltip {
    background: linear-gradient(135deg, rgba(10, 25, 40, 0.95), rgba(20, 45, 70, 0.95));
    border: 1px solid var(--accent-cyan);
    border-radius: 8px;
    padding: 10px 16px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 4px 20px rgba(0, 212, 255, 0.3), 
                0 0 30px rgba(0, 212, 255, 0.1),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    white-space: nowrap;
    transition: opacity 0.15s ease;
}

/* Korea Region Hover Effect */
.korea-region {
    transition: all 0.2s ease;
}

/* ===== Flat Map Mode ===== */

/* Korea Panel 숨김 애니메이션 */
.korea-panel.hidden {
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
}

.korea-panel {
    transition: opacity 0.3s ease-out, width 0.3s ease-out;
}

/* Globe Panel 전체 화면 모드 */
.globe-panel.fullscreen {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    border-right: none;
    z-index: 10;
    transition: all 0.5s ease;
}

.globe-panel {
    transition: all 0.5s ease;
}

/* Main content 플랫 맵 모드 */
.main-content.flat-map-mode {
    grid-template-columns: 1fr;
}

/* 2D 모드에서 3D canvas 숨김 */
.main-content.flat-map-mode #globe-canvas {
    display: none;
}

/* 2D 모드에서 body 격자 배경 숨김 */
body:has(.main-content.flat-map-mode) {
    background-image: none;
}

/* 평면 세계 지도 컨테이너 */
.flat-world-map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    opacity: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(0, 30, 60, 0.6) 0%, transparent 70%);
    transform-origin: center center;
    top: 55px
}

.flat-world-map-container.active {
    pointer-events: all;
    z-index: 15;
}

.flat-world-map-svg {
    width: 100%;
    height: 100%;
    /* 전체 지도에 filter 제거 (개별 국가에만 적용하여 깜박임 방지) */
}

/* 지구본 전환 애니메이션 */
#globe-canvas {
    transition: filter 0.3s ease;
}

#globe-canvas.globe-transitioning-out {
    filter: blur(0px);
}

#globe-canvas.globe-transitioning-in {
    filter: blur(0px);
}

/* 평면 지도 국가 스타일 */
.flat-country {
    fill: var(--theme-fill, #1a3a4a);
    stroke: var(--theme-stroke, #29e6d6);
    stroke-width: 1.5;
    stroke-opacity: 0.8;
    /* transition을 구체적인 속성으로 제한하여 깜박임 방지 */
    transition: fill 0.15s ease, stroke 0.15s ease, stroke-opacity 0.15s ease;
    cursor: pointer;
    /* GPU 가속으로 성능 개선 */
    will-change: fill, stroke-opacity;
    /* 기본 filter 없음 (hover 시에만 추가) */
    filter: none;
}

.flat-country:hover,
.flat-country.hovered {
    fill: var(--theme-fill-hover, #2d6878);
    stroke: var(--theme-stroke-hover, #00ffff);
    stroke-width: 1.5;
    stroke-opacity: 1;
    /* filter는 transition 없이 즉시 적용하여 깜박임 방지 */
    filter: drop-shadow(0 0 8px var(--theme-shadow, rgba(0, 212, 255, 0.6)));
}

.flat-country.korea {
    fill: #2d5a3d;
    stroke: #ff4444;
    stroke-width: 2;
    stroke-opacity: 1;
    /* 한국도 기본 filter 없음 */
    filter: none;
}

.flat-country.korea:hover,
.flat-country.korea.hovered {
    fill: #4d8a5d;
    stroke: #ff6666;
    stroke-width: 2.5;
    /* filter는 transition 없이 즉시 적용 */
    filter: drop-shadow(0 0 10px rgba(255, 68, 68, 0.6));
}

/* 평면 지도 위도/경도 그리드 */
.flat-map-grid {
    stroke: rgba(0, 212, 255, 0.15);
    stroke-width: 0.5;
    fill: none;
}

.flat-map-equator {
    stroke: rgba(0, 212, 255, 0.35);
    stroke-width: 1;
    fill: none;
}

/* 평면 지도 도시 마커 */
.flat-city-marker {
    fill: rgba(0, 212, 255, 0.9);
    filter: drop-shadow(0 0 4px rgba(0, 212, 255, 0.8));
}

.flat-city-marker.seoul {
    fill: #ff4444;
    filter: drop-shadow(0 0 8px rgba(255, 68, 68, 0.8));
}

/* 평면 지도 도시 글로우 */
.flat-city-glow {
    fill: rgba(0, 212, 255, 0.15);
    filter: blur(3px);
}

.flat-city-glow.seoul {
    fill: rgba(255, 68, 68, 0.2);
}

/* 평면 지도 툴팁 */
.flat-map-tooltip {
    position: fixed;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #00d4ff;
    border-radius: 6px;
    color: #00e6ff;
    font-family: 'Rajdhani', sans-serif;
    font-size: 14px;
    font-weight: 600;
    pointer-events: none;
    z-index: 1000;
    display: none;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.4);
    text-shadow: 0 0 5px rgba(0, 212, 255, 0.5);
}

/* 버튼 숨김 (플랫 맵 모드) */
body:has(.main-content.flat-map-mode) .korea-zoom {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* ===== 평면 지도 테마 ===== */

/* 테마 1: 기본 시안색 (default) */
.flat-country {
    --theme-fill: #1a3a4a;
    --theme-fill-hover: #2d6878;
    --theme-stroke: #29e6d6;
    --theme-stroke-hover: #00ffff;
    --theme-shadow: rgba(0, 212, 255, 0.6);
}

/* 테마 2: 오렌지색 계열 */
body.flat-theme-orange .flat-country {
    --theme-fill: #3d2a1a;
    --theme-fill-hover: #5a3d24;
    --theme-stroke: #ff8c00;
    --theme-stroke-hover: #ffaa33;
    --theme-shadow: rgba(255, 140, 0, 0.6);
}

body.flat-theme-orange .flat-map-grid {
    stroke: rgba(255, 140, 0, 0.15);
}

body.flat-theme-orange .flat-map-equator {
    stroke: rgba(255, 140, 0, 0.35);
}

body.flat-theme-orange .flat-city-marker:not(.seoul) {
    fill: rgba(255, 165, 0, 0.9);
    filter: drop-shadow(0 0 4px rgba(255, 140, 0, 0.8));
}

body.flat-theme-orange .flat-city-glow:not(.seoul) {
    fill: rgba(255, 140, 0, 0.15);
}

body.flat-theme-orange .flat-map-tooltip {
    border-color: #ff8c00;
    color: #ffaa33;
    box-shadow: 0 0 15px rgba(255, 140, 0, 0.4);
    text-shadow: 0 0 5px rgba(255, 140, 0, 0.5);
}

body.flat-theme-orange .flat-world-map-container {
    background: radial-gradient(ellipse at center, rgba(60, 30, 0, 0.5) 0%, transparent 70%);
}

/* 테마 3: 화이트 계열 */
body.flat-theme-white .flat-country {
    --theme-fill: #1a2030;
    --theme-fill-hover: #2a3448;
    --theme-stroke: #c0c8d0;
    --theme-stroke-hover: #ffffff;
    --theme-shadow: rgba(255, 255, 255, 0.5);
}

body.flat-theme-white .flat-map-grid {
    stroke: rgba(255, 255, 255, 0.12);
}

body.flat-theme-white .flat-map-equator {
    stroke: rgba(255, 255, 255, 0.25);
}

body.flat-theme-white .flat-city-marker:not(.seoul) {
    fill: rgba(200, 210, 220, 0.9);
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.7));
}

body.flat-theme-white .flat-city-glow:not(.seoul) {
    fill: rgba(255, 255, 255, 0.12);
}

body.flat-theme-white .flat-map-tooltip {
    border-color: #c0c8d0;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.4);
}

body.flat-theme-white .flat-world-map-container {
    background: radial-gradient(ellipse at center, rgba(40, 50, 70, 0.5) 0%, transparent 70%);
}
