/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a1f2e;
    --text-primary: #f0f4ff;
    --text-secondary: #94a3b8;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --proton-color: #f43f5e;
    --neutron-color: #22d3ee;
    --electron-color: #a78bfa;
    --border-color: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --transition: 0.25s ease;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(34, 211, 238, 0.06) 0%, transparent 50%);
}

/* === Header / Controls === */
#controls {
    text-align: center;
    padding: 2rem 1rem 1.5rem;
    z-index: 100;
    background: linear-gradient(180deg, rgba(10, 14, 23, 0.95) 0%, transparent 100%);
    backdrop-filter: blur(8px);
}

.header-inner {
    max-width: 600px;
    margin: 0 auto;
}

#title-section h1 {
    font-size: 2.75rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    filter: blur(10px);
    transform: translateY(-20px);
    opacity: 0;
    animation: drop 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    letter-spacing: 0.05em;
    opacity: 0;
    animation: fadeIn 1s 0.6s forwards;
}

@keyframes drop {
    0% { filter: blur(10px); transform: translateY(-20px); opacity: 0; }
    100% { filter: blur(0); transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    to { opacity: 1; }
}

/* === Search Group === */
.search-group {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
    margin-top: 1.25rem;
}

.input-wrapper {
    position: relative;
}

#elementInput {
    width: 260px;
    padding: 0.65rem 1rem;
    font-family: 'JetBrains Mono', 'Inter', monospace;
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

#elementInput::placeholder {
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
}

#elementInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

#generateBtn {
    padding: 0.65rem 1.25rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

#generateBtn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

#generateBtn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.1rem;
}

/* === Main Content === */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    gap: 1.5rem;
}

#periodic-table {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

#periodic-table img {
    width: min(700px, 90vw);
    height: auto;
    border-radius: var(--radius);
    opacity: 0.85;
    transition: opacity var(--transition);
}

#periodic-table img:hover {
    opacity: 1;
}

/* === Info Panel === */
#info-panel {
    width: 100%;
    max-width: 480px;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#info-panel.hidden {
    display: none;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.info-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.element-symbol {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
    min-width: 3rem;
    text-align: center;
}

.info-title h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
}

.atomic-number {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.info-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.detail-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.detail-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.05rem;
    font-weight: 500;
}

.proton-color { color: var(--proton-color); }
.neutron-color { color: var(--neutron-color); }
.electron-color { color: var(--electron-color); }

/* === Legend === */
.legend {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.proton-dot { background: var(--proton-color); }
.neutron-dot { background: var(--neutron-color); }
.electron-dot { background: var(--electron-color); }

/* === 3D Model Container === */
#d-model {
    display: flex;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
}

canvas { display: block; }

/* === Modal === */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin: auto;
    padding: 0.75rem;
    width: min(70%, 800px);
    height: 60%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    top: 20%;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.close {
    color: var(--text-secondary);
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-size: 1.75rem;
    font-weight: 400;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 10;
    line-height: 1;
    transition: color var(--transition);
}

.close:hover,
.close:focus {
    color: var(--text-primary);
}

/* === Footer === */
footer {
    text-align: center;
    padding: 1.5rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* === Responsive === */
@media (max-width: 768px) {
    #title-section h1 {
        font-size: 2rem;
    }

    .search-group {
        flex-direction: column;
    }

    #elementInput {
        width: 100%;
        max-width: 300px;
    }

    #periodic-table img {
        width: 95vw;
    }

    .modal-content {
        width: 90%;
        height: 55%;
        top: 15%;
    }

    .info-details {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    #controls {
        padding: 1.5rem 0.75rem 1rem;
    }

    #title-section h1 {
        font-size: 1.6rem;
    }

    .element-symbol {
        font-size: 2rem;
    }

    .modal-content {
        width: 95%;
        height: 50%;
        top: 10%;
    }

    #chatbot-panel {
        width: 92vw;
        right: 4vw;
        bottom: 4.5rem;
        height: 55vh;
    }
}

/* === Chatbot === */
#chatbot-toggle {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
    transition: background var(--transition), transform var(--transition);
}

#chatbot-toggle:hover {
    background: var(--accent-hover);
    transform: scale(1.08);
}

#chatbot-toggle.chatbot-active {
    background: var(--accent-hover);
}

.chatbot-icon {
    font-size: 1.4rem;
    line-height: 1;
}

#chatbot-panel {
    position: fixed;
    bottom: 5rem;
    right: 1.5rem;
    width: 360px;
    height: 480px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#chatbot-panel.chatbot-hidden {
    display: none;
}

.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}

.chatbot-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chatbot-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: color var(--transition);
}

.chatbot-close:hover {
    color: var(--text-primary);
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chatbot-message {
    display: flex;
}

.chatbot-bot {
    justify-content: flex-start;
}

.chatbot-user {
    justify-content: flex-end;
}

.chatbot-bubble {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 10px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chatbot-bot .chatbot-bubble {
    background: var(--bg-card);
    color: var(--text-primary);
    border-bottom-left-radius: 3px;
}

.chatbot-user .chatbot-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 3px;
}

.chatbot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0 0.75rem 0.5rem;
}

.chatbot-chip {
    font-size: 0.72rem;
    padding: 0.3rem 0.6rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    font-family: 'Inter', sans-serif;
}

.chatbot-chip:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.chatbot-input-area {
    display: flex;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
}

#chatbot-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition);
}

#chatbot-input::placeholder {
    color: var(--text-secondary);
}

#chatbot-input:focus {
    border-color: var(--accent);
}

#chatbot-send {
    padding: 0.5rem 0.7rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background var(--transition);
}

#chatbot-send:hover {
    background: var(--accent-hover);
}
