:root {
    --map-bg: #08080f;
    --accent-glow: rgba(130, 100, 255, 0.4);
    --threat-high: #ff3b30;
    --threat-med: #ff9500;
    --threat-low: #34c759;
    --threat-critical: #ff2d55;
}

body { overflow-x: hidden; }

/* ── Header enhancement ────────────────────────────────────────────────────── */
header {
    position: relative;
}
header::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 200px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
}

/* ── Live indicator ────────────────────────────────────────────────────────── */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(255, 59, 48, 0.12);
    border: 1px solid rgba(255, 59, 48, 0.35);
    color: var(--threat-high);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    padding: 5px 14px;
    border-radius: 30px;
    margin-top: 8px;
}
.live-badge-dot {
    width: 7px;
    height: 7px;
    background: var(--threat-high);
    border-radius: 50%;
    animation: livepulse 1.2s ease-in-out infinite;
}
@keyframes livepulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%  { opacity: 0.4; transform: scale(1.4); }
}

/* ── Map wrapper ───────────────────────────────────────────────────────────── */
.map-wrapper {
    position: relative;
    width: 100%;
    height: 72vh;
    min-height: 420px;
    background:
        radial-gradient(ellipse at 50% 60%, rgba(80,50,160,0.15) 0%, transparent 70%),
        radial-gradient(circle at center, #101020 0%, #08080f 100%);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(130, 100, 255, 0.18);
    margin-top: 24px;
    overflow: hidden;
    box-shadow:
        inset 0 0 120px rgba(0,0,0,0.85),
        0 0 0 1px rgba(130,100,255,0.06),
        0 24px 60px rgba(0,0,0,0.6);
}

/* Grid overlay */
.map-wrapper::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(130, 100, 255, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(130, 100, 255, 0.04) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 1;
}

#threatCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

.world-map-svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 92%;
    height: 92%;
    opacity: 0.10;
    filter: drop-shadow(0 0 14px var(--primary));
    z-index: 2;
}

/* ── HUD overlays ──────────────────────────────────────────────────────────── */
.hud-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

/* Corner decorations */
.hud-corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: rgba(130, 100, 255, 0.5);
    border-style: solid;
}
.hud-corner.tl { top: 12px; left: 12px; border-width: 2px 0 0 2px; }
.hud-corner.tr { top: 12px; right: 12px; border-width: 2px 2px 0 0; }
.hud-corner.bl { bottom: 12px; left: 12px; border-width: 0 0 2px 2px; }
.hud-corner.br { bottom: 12px; right: 12px; border-width: 0 2px 2px 0; }

/* Scanning line */
.scanning-line {
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(130, 100, 255, 0.04), transparent);
    animation: scan 7s linear infinite;
}
@keyframes scan {
    0%   { left: -100%; }
    100% { left:  100%; }
}

/* CRT scanlines */
.crt-overlay {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0,0,0,0.03) 0px,
        rgba(0,0,0,0.03) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 15;
}

/* Vignette */
.crt-vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.65) 100%);
    pointer-events: none;
    z-index: 16;
}

/* Moving scanline glow */
.crt-scanline {
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(130,100,255,0.15), transparent);
    z-index: 17;
    animation: scanline 9s linear infinite;
}
@keyframes scanline {
    0%   { transform: translateY(-4px); opacity: 0; }
    5%   { opacity: 1; }
    95%  { opacity: 1; }
    100% { transform: translateY(72vh); opacity: 0; }
}

/* Status badge */
.threat-level-badge {
    position: absolute;
    top: 18px; right: 18px;
    padding: 8px 18px;
    border-radius: 30px;
    background: rgba(255, 59, 48, 0.12);
    border: 1px solid rgba(255, 59, 48, 0.35);
    color: var(--threat-high);
    font-weight: 800;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 9px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    backdrop-filter: blur(8px);
    z-index: 18;
}
.pulse-dot {
    width: 8px; height: 8px;
    background: var(--threat-high);
    border-radius: 50%;
    animation: pulse 1.5s ease-out infinite;
}
@keyframes pulse {
    0%   { transform: scale(1); opacity: 1; }
    80%  { transform: scale(2.8); opacity: 0; }
    100% { transform: scale(1); opacity: 0; }
}

/* Time badge inside map */
.map-time {
    position: absolute;
    top: 18px; left: 18px;
    font-family: 'ui-monospace', monospace;
    font-size: 0.75rem;
    color: rgba(130,100,255,0.7);
    letter-spacing: 0.08em;
    z-index: 18;
    backdrop-filter: blur(4px);
}

/* ── Stats grid ───────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 28px;
}

.stat-card {
    background: rgba(255,255,255,0.025);
    border: 1px solid rgba(255,255,255,0.07);
    padding: 22px 20px 18px;
    border-radius: var(--radius-lg);
    text-align: center;
    backdrop-filter: blur(12px);
    position: relative;
    overflow: hidden;
    transition: border-color 0.3s, transform 0.3s;
}
.stat-card:hover {
    border-color: rgba(130,100,255,0.3);
    transform: translateY(-3px);
}
.stat-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    opacity: 0.6;
}

.stat-card i {
    font-size: 1.6rem;
    opacity: 0.15;
    position: absolute;
    bottom: 14px; right: 16px;
}

.stat-value {
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--primary);
    font-family: 'ui-monospace', monospace;
    margin: 8px 0 4px;
    text-shadow: 0 0 24px var(--accent-glow);
    letter-spacing: -0.03em;
}
.stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.45;
}
.stat-trend {
    font-size: 0.68rem;
    margin-top: 6px;
    opacity: 0.5;
}
.stat-trend.up   { color: var(--threat-high); }
.stat-trend.down { color: var(--threat-low); }

/* ── Bottom panels ────────────────────────────────────────────────────────── */
.bottom-panels {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 20px;
    margin-top: 24px;
}

/* ── Threat Log ───────────────────────────────────────────────────────────── */
.threat-log-container {
    background: rgba(0,0,0,0.3);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255,255,255,0.05);
    padding: 0;
    height: 420px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.log-header h3 { font-size: 0.9rem; margin: 0; opacity: 0.8; }
.log-live-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--threat-low);
    letter-spacing: 0.12em;
}
.log-live-badge::before {
    content: "";
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--threat-low);
    border-radius: 50%;
    animation: livepulse 1.2s ease-in-out infinite;
}

.log-entries {
    flex: 1;
    overflow-y: auto;
    font-family: 'ui-monospace', monospace;
    font-size: 0.8rem;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(130,100,255,0.2) transparent;
}

.log-entry {
    display: grid;
    grid-template-columns: 64px 130px 1fr 72px 80px;
    gap: 10px;
    align-items: center;
    padding: 7px 12px;
    background: rgba(255,255,255,0.018);
    border-radius: 6px;
    border-left: 2px solid transparent;
    animation: logSlide 0.3s ease;
    flex-shrink: 0;
}
.log-entry:hover { background: rgba(255,255,255,0.04); }

@keyframes logSlide {
    from { opacity: 0; transform: translateX(-14px); }
    to   { opacity: 1; transform: translateX(0); }
}

.log-ts    { opacity: 0.35; font-size: 0.75em; }
.log-type  { font-weight: 700; font-size: 0.78em; }
.log-loc   { opacity: 0.6; font-size: 0.78em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-sev   { font-size: 0.68em; font-weight: 800; text-align: center; }
.log-status {
    font-size: 0.68em;
    font-weight: 800;
    text-align: right;
    color: var(--threat-low);
    letter-spacing: 0.05em;
}

/* ── Legend panel ─────────────────────────────────────────────────────────── */
.legend-panel {
    background: rgba(0,0,0,0.3);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255,255,255,0.05);
    padding: 20px;
    height: 420px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.legend-panel h3 { font-size: 0.9rem; margin: 0 0 16px; opacity: 0.8; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.8rem;
}
.legend-item:last-child { border-bottom: none; }
.legend-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}
.legend-label { flex: 1; opacity: 0.7; }
.legend-sev {
    font-size: 0.68rem;
    font-weight: 700;
    opacity: 0.5;
    letter-spacing: 0.08em;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .bottom-panels { grid-template-columns: 1fr; }
    .legend-panel  { height: auto; }
    .log-entry { grid-template-columns: 58px 110px 1fr 60px; }
    .log-sev   { display: none; }
}
