@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@300;400;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-glow: #00f0ff;
    --secondary-glow: #ff00ff;
    --accent-glow: #00ff88;
    --bg-dark: #0a0e27;
    --bg-darker: #050818;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
}

body {
    font-family: 'Rajdhani', sans-serif;
    background: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(0, 240, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 0, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(0, 255, 136, 0.1) 0%, transparent 50%);
    background-attachment: fixed;
    color: #fff;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        repeating-linear-gradient(
            0deg,
            rgba(0, 240, 255, 0.03) 0px,
            transparent 1px,
            transparent 40px,
            rgba(0, 240, 255, 0.03) 41px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(0, 240, 255, 0.03) 0px,
            transparent 1px,
            transparent 40px,
            rgba(0, 240, 255, 0.03) 41px
        );
    pointer-events: none;
    z-index: 1;
}

header {
    background: rgba(10, 14, 39, 0.6);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    padding: 2rem;
    text-align: center;
    position: relative;
    z-index: 10;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

header h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: 3.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-glow), var(--secondary-glow), var(--accent-glow));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 30px rgba(0, 240, 255, 0.5);
}

@media (prefers-reduced-motion: no-preference) {
    @keyframes glow-pulse {
        0%, 100% { filter: brightness(1); }
        50% { filter: brightness(1.2); }
    }
    
    header h1 {
        animation: glow-pulse 4s ease-in-out infinite;
    }
}

.search-container {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

#searchInput {
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    font-family: 'Rajdhani', sans-serif;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 2px solid var(--glass-border);
    border-radius: 50px;
    outline: none;
    color: #fff;
    transition: all 0.3s ease;
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#searchInput::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#searchInput:focus {
    border-color: var(--primary-glow);
    box-shadow: 
        0 0 20px rgba(0, 240, 255, 0.4),
        0 4px 15px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

main {
    flex: 1;
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    position: relative;
    z-index: 2;
}

.periodic-table {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.element-tile {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.element-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-glow), var(--secondary-glow));
    opacity: 0;
    transition: opacity 0.4s ease;
}

.element-tile:hover::before,
.element-tile:focus::before {
    opacity: 0.1;
}

.element-tile:hover,
.element-tile:focus {
    transform: translateY(-8px) scale(1.05) !important;
    border-color: var(--primary-glow);
    box-shadow: 
        0 0 30px rgba(0, 240, 255, 0.4),
        0 10px 40px rgba(0, 0, 0, 0.3);
    animation: none !important;
}

.element-tile .atomic-number {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.7rem;
    color: var(--primary-glow);
    font-weight: 600;
    opacity: 0.8;
}

.element-tile .symbol {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-glow), var(--accent-glow));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0.25rem 0;
    position: relative;
    z-index: 1;
}

.element-tile .name {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
    font-weight: 400;
    position: relative;
    z-index: 1;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 8, 24, 0.95);
    backdrop-filter: blur(10px);
    animation: fadeIn 0.3s ease;
}

.modal:not([hidden]) {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: rgba(10, 14, 39, 0.9);
    backdrop-filter: blur(30px);
    border: 2px solid var(--glass-border);
    border-radius: 24px;
    width: 90%;
    max-width: 1400px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 2.5rem;
    box-shadow: 
        0 0 60px rgba(0, 240, 255, 0.3),
        0 20px 60px rgba(0, 0, 0, 0.5);
}

@keyframes slideIn {
    from {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    font-size: 1.5rem;
    cursor: pointer;
    color: #fff;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
}

.modal-close:hover,
.modal-close:focus {
    background: rgba(255, 0, 100, 0.3);
    border-color: var(--secondary-glow);
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.5);
}

.modal-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
    margin-top: 1rem;
}

.modal-left {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.canvas-container {
    width: 100%;
    height: 450px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: 
        inset 0 0 30px rgba(0, 240, 255, 0.1),
        0 4px 20px rgba(0, 0, 0, 0.3);
}

#nucleusCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.webgl-fallback {
    text-align: center;
    padding: 2rem;
}

.webgl-fallback p {
    margin-bottom: 1rem;
    color: rgba(255, 255, 255, 0.7);
}

#fallbackCanvas {
    max-width: 100%;
    height: auto;
}

.controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.control-btn {
    flex: 1;
    min-width: 180px;
    padding: 1rem 1.5rem;
    background: rgba(0, 240, 255, 0.1);
    backdrop-filter: blur(10px);
    color: var(--primary-glow);
    border: 2px solid var(--primary-glow);
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-family: 'Rajdhani', sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: var(--primary-glow);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
    opacity: 0.2;
}

.control-btn:hover::before,
.control-btn:focus::before {
    width: 300px;
    height: 300px;
}

.control-btn:hover,
.control-btn:focus {
    transform: translateY(-3px);
    box-shadow: 
        0 0 20px rgba(0, 240, 255, 0.5),
        0 8px 25px rgba(0, 0, 0, 0.3);
}

.control-btn.active {
    background: rgba(0, 240, 255, 0.2);
    box-shadow: 
        0 0 20px rgba(0, 240, 255, 0.6),
        inset 0 0 10px rgba(0, 240, 255, 0.3);
}

.modal-right h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-glow), var(--accent-glow));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.element-info {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 1rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.info-row:last-of-type {
    border-bottom: none;
}

.info-label {
    font-weight: 600;
    color: var(--primary-glow);
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.info-value {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    font-size: 1.1rem;
}

.summary {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: rgba(0, 240, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border-left: 4px solid var(--primary-glow);
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.8;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.element-facts {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: rgba(255, 0, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border-left: 4px solid var(--secondary-glow);
}

.element-facts h3 {
    font-family: 'Orbitron', sans-serif;
    color: var(--secondary-glow);
    margin-bottom: 1rem;
    font-size: 1.3rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.fact-item {
    padding: 0.75rem 0;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.6;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.fact-item:last-child {
    border-bottom: none;
}

.fact-label {
    color: var(--accent-glow);
    font-weight: 600;
    margin-right: 0.5rem;
}

footer {
    background: rgba(10, 14, 39, 0.8);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    padding: 1.5rem;
    text-align: center;
    position: relative;
    z-index: 10;
}

footer p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.modal-content::-webkit-scrollbar {
    width: 10px;
}

.modal-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-glow), var(--secondary-glow));
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--secondary-glow), var(--accent-glow));
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
        letter-spacing: 2px;
    }

    .periodic-table {
        grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
        gap: 0.6rem;
    }

    .element-tile {
        min-height: 90px;
        padding: 0.6rem;
    }

    .element-tile .symbol {
        font-size: 1.8rem;
    }

    .element-tile .name {
        font-size: 0.75rem;
    }

    .modal-layout {
        grid-template-columns: 1fr;
    }

    .canvas-container {
        height: 300px;
    }

    .modal-content {
        width: 95%;
        padding: 1.5rem;
    }

    .controls {
        flex-direction: column;
    }

    .control-btn {
        min-width: 100%;
    }

    .modal-right h2 {
        font-size: 1.8rem;
    }
}

.hidden {
    display: none !important;
}

@media (prefers-reduced-motion: no-preference) {
    @keyframes float {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-10px); }
    }
    
    .element-tile:nth-child(6n):not(:hover):not(:focus) {
        animation: float 8s ease-in-out infinite;
    }
    
    .element-tile:nth-child(6n+2):not(:hover):not(:focus) {
        animation: float 9s ease-in-out infinite;
        animation-delay: 1s;
    }
    
    .element-tile:nth-child(6n+4):not(:hover):not(:focus) {
        animation: float 10s ease-in-out infinite;
        animation-delay: 2s;
    }
}
