* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: #000;
    color: #fff;
    overflow: hidden;
}

#container {
    position: relative;
    width: 100vw;
    height: 100vh;
}

#earth-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

#header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#title {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(90deg, #00c6ff, #0072ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#stats {
    display: flex;
    gap: 20px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 14px;
    backdrop-filter: blur(5px);
}

#asteroid-panel {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 350px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(15px);
    border-radius: 15px;
    padding: 25px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: all 0.5s ease;
    pointer-events: auto;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 20; /* Increased z-index */
}

#asteroid-panel.active {
    opacity: 1;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

#close-panel {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#asteroid-name {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 5px;
    color: #ff9d00;
}

#asteroid-subtitle {
    font-size: 14px;
    color: #aaa;
    margin-bottom: 20px;
}

.info-section {
    margin-bottom: 25px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #00c6ff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.info-item {
    display: flex;
    flex-direction: column;
}

.info-label {
    font-size: 12px;
    color: #aaa;
    margin-bottom: 3px;
}

.info-value {
    font-size: 16px;
    font-weight: 500;
}

#asteroid-visualization {
    width: 100%;
    height: 200px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    margin: 20px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

#mini-asteroid {
    width: 80px;
    height: 80px;
    background: radial-gradient(circle at 30% 30%, #ff9d00, #ff6b00);
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(255, 157, 0, 0.5);
    animation: rotate 10s infinite linear;
    z-index: 1;
    position: relative;
}

#scan-animation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    z-index: 2;
}

#scan-animation.scanning {
    display: block;
}

.scan-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, #00c6ff, transparent);
    animation: scan 2s linear infinite;
    box-shadow: 0 0 10px rgba(0, 198, 255, 0.7);
}

.scan-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 198, 255, 0.3) 0%, transparent 70%);
    animation: pulse 2s ease-out infinite;
    opacity: 0;
}

@keyframes scan {
    0% { top: 0; }
    100% { top: 100%; }
}

@keyframes pulse {
    0% { transform: scale(0.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#hazard-indicator {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 10px;
}

.hazardous {
    background: rgba(255, 0, 0, 0.2);
    color: #ff5555;
    border: 1px solid rgba(255, 0, 0, 0.3);
}

.safe {
    background: rgba(0, 255, 0, 0.2);
    color: #55ff55;
    border: 1px solid rgba(0, 255, 0, 0.3);
}

.scan-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(90deg, #00c6ff, #0072ff);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    margin: 15px 0;
    transition: all 0.3s ease;
    pointer-events: auto;
}

.scan-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 198, 255, 0.4);
}

.scan-btn:disabled {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.5);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#scan-progress {
    display: none;
    margin: 15px 0;
}

#scan-progress.scanning {
    display: block;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #00c6ff, #0072ff);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 12px;
    text-align: center;
    color: #aaa;
}

#composition-data {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composition-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.composition-name {
    font-size: 14px;
}

.composition-percentage {
    font-size: 14px;
    font-weight: 600;
    color: #00c6ff;
}

#asteroid-value {
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    background: linear-gradient(90deg, #ff9d00, #ff6b00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 10px 0;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    z-index: 100; /* Very high z-index for loading */
    background: rgba(0, 0, 0, 0.7);
    padding: 20px 30px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left: 4px solid #00c6ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#instructions {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    backdrop-filter: blur(5px);
    z-index: 10; /* Higher z-index */
}

.asteroid-label {
    position: absolute;
    color: white;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: auto;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 5; /* Lower than chatbot */
    display: flex;
    align-items: center;
    gap: 5px;
}

.asteroid-label:hover {
    background: rgba(255, 157, 0, 0.7);
    transform: scale(1.1);
}

.asteroid-icon {
    width: 12px;
    height: 12px;
    background: #ff9d00;
    border-radius: 50%;
    display: inline-block;
}

#error-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 0, 0, 0.7);
    padding: 20px 30px;
    border-radius: 10px;
    text-align: center;
    z-index: 100; /* Very high z-index for error */
    display: none;
}

#refresh-btn {
    background: linear-gradient(90deg, #00c6ff, #0072ff);
    border: none;
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
}

#back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    z-index: 15; /* Higher than asteroid labels */
    display: none;
    backdrop-filter: blur(5px);
}

/* Chatbot Styles - UPDATED Z-INDEX */
#chatbot-icon {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #00c6ff, #0072ff);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 25; /* Higher than everything else */
    box-shadow: 0 4px 15px rgba(0, 198, 255, 0.4);
    transition: all 0.3s ease;
    pointer-events: auto;
}

#chatbot-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 198, 255, 0.6);
}

#chatbot-icon svg {
    width: 30px;
    height: 30px;
    fill: white;
}

#chatbot-panel {
    position: absolute;
    bottom: 90px;
    right: 20px;
    width: 350px;
    height: 500px;
    background: rgba(0, 0, 0, 0.9); /* More opaque background */
    backdrop-filter: blur(15px);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 30; /* Highest z-index - above everything */
}

#chatbot-panel.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#chat-header {
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-header h3 {
    color: #00c6ff;
    font-size: 18px;
}

#close-chat {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

#chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    padding: 10px 15px;
    border-radius: 15px;
    max-width: 80%;
    word-wrap: break-word;
}

.user-message {
    background: rgba(0, 198, 255, 0.3);
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.bot-message {
    background: rgba(255, 255, 255, 0.1);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

#chat-input-container {
    padding: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 10px;
}

#chat-input {
    flex: 1;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    color: white;
    outline: none;
}

#chat-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#send-message {
    background: linear-gradient(135deg, #00c6ff, #0072ff);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#api-key-container {
    padding: 10px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 10px;
}

/* Enhanced Chatbot Styles */
#chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
    position: relative;
    animation: fadeIn 0.3s ease;
}

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

.user-message {
    background: linear-gradient(135deg, #00c6ff, #0072ff);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 8px rgba(0, 198, 255, 0.3);
}

.bot-message {
    background: rgba(255, 255, 255, 0.15);
    color: #e0e0e0;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message strong {
    color: #00c6ff;
    font-weight: 600;
}

.message em {
    font-style: italic;
    color: #cccccc;
}

.message p {
    margin: 5px 0;
}

.message p:first-child {
    margin-top: 0;
}

.message p:last-child {
    margin-bottom: 0;
}

/* Improved scrollbar for chat */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 198, 255, 0.5);
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 198, 255, 0.7);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

#api-key-input {
    flex: 1;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    color: white;
    outline: none;
    font-size: 12px;
}

#save-api-key {
    background: rgba(0, 198, 255, 0.3);
    border: 1px solid rgba(0, 198, 255, 0.5);
    color: white;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
}