@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

/* Variables - Neon Palette */
:root {
    --pt-bg: #0f172a;
    --pt-glass-bg: rgba(255, 255, 255, 0.03);
    --pt-glass-border: rgba(255, 255, 255, 0.08);
    --pt-glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

    /* Group Colors - Vibrant Neon */
    --c-alkali: #ff5252;
    --c-alkaline-earth: #ffb142;
    --c-transition: #2ecc71;
    --c-post-transition: #3498db;
    --c-metalloid: #1abc9c;
    --c-nonmetal: #9b59b6;
    --c-halogen: #e056fd;
    --c-noble: #f1c40f;
    --c-lanthanide: #e67e22;
    --c-actinide: #e74c3c;
    --c-unknown: #95a5a6;
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    height: 10px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Glass Panel Utility */
.glass-panel {
    background: var(--pt-glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--pt-glass-border);
    box-shadow: var(--pt-glass-shadow);
}

/* Periodic Table Grid Layout */
.periodic-table {
    display: grid;
    /* 19 columns: 1 for row headers, 18 for groups */
    grid-template-columns: 40px repeat(18, minmax(65px, 90px));
    /* Rows: 1 for col headers, 7 for periods, gap, 2 for f-block */
    grid-template-rows: 40px repeat(7, minmax(65px, 90px)) 60px repeat(2, minmax(65px, 90px));
    gap: 6px;
    width: fit-content;
    padding: 20px;
    margin: 0 auto;
}

/* Base headers style */
.pt-header-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.9rem;
    font-weight: 600;
    user-select: none;
}

/* Element Card Styles */
.element {
    aspect-ratio: 1;
    position: relative;
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 4px 6px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* Changed to start to layout items manually or grid */
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    background-clip: padding-box;
    user-select: none;
    z-index: 1;
}

/* Inner Layout for Element Data */
.element .top-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 2px;
}

.element .at-num {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1;
}

.element .electronegativity {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.4);
    line-height: 1;
}

.element .symbol {
    font-size: 1.5rem;
    font-weight: 700;
    align-self: center;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    line-height: 1.1;
    margin: 2px 0;
}

.element .name {
    font-size: 0.6rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
    margin-bottom: auto;
}

.element .mass {
    display: block;
    font-size: 0.55rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.4);
    width: 100%;
    margin-top: 2px;
}

.element::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, var(--glow-color, rgba(255, 255, 255, 0.1)), transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
    border-radius: inherit;
}

.element:hover {
    transform: translateY(-5px) scale(1.15);
    z-index: 100 !important;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6), 0 0 20px -5px var(--glow-color);
    border-color: var(--glow-color);
    background: #0f172a;
    /* Darker bg on hover for contrast */
}

.element:hover::before {
    opacity: 0.3;
}

/* Category Colors Applied via CSS Variable on JS injection or classes */
.group-alkali {
    --glow-color: var(--c-alkali);
    border-bottom: 3px solid var(--c-alkali);
}

.group-alkaline-earth {
    --glow-color: var(--c-alkaline-earth);
    border-bottom: 3px solid var(--c-alkaline-earth);
}

/* ... keep other groups ... */

.group-transition {
    --glow-color: var(--c-transition);
    border-bottom: 3px solid var(--c-transition);
}

.group-post-transition {
    --glow-color: var(--c-post-transition);
    border-bottom: 3px solid var(--c-post-transition);
}

.group-metalloid {
    --glow-color: var(--c-metalloid);
    border-bottom: 3px solid var(--c-metalloid);
}

.group-nonmetal {
    --glow-color: var(--c-nonmetal);
    border-bottom: 3px solid var(--c-nonmetal);
}

.group-halogen {
    --glow-color: var(--c-halogen);
    border-bottom: 3px solid var(--c-halogen);
}

.group-noble {
    --glow-color: var(--c-noble);
    border-bottom: 3px solid var(--c-noble);
}

.group-lanthanide {
    --glow-color: var(--c-lanthanide);
    border-bottom: 3px solid var(--c-lanthanide);
}

.group-actinide {
    --glow-color: var(--c-actinide);
    border-bottom: 3px solid var(--c-actinide);
}

.group-unknown {
    --glow-color: var(--c-unknown);
    border-bottom: 3px solid var(--c-unknown);
}

/* Legend Styles */
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.02);
}

.legend-item:hover,
.legend-item.active {
    background: rgba(255, 255, 255, 0.1);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    box-shadow: 0 0 8px var(--c-glow);
}

.legend-label {
    font-size: 0.75rem;
    color: #cbd5e1;
    font-weight: 500;
}

/* Modal Styling - Premium Look Redesign - Optimized Dimensions */
.element-modal {
    background-color: #0f172a !important;
    /* Force dark background */
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9), 0 0 30px rgba(255, 255, 255, 0.05);
    width: 92%;
    max-width: 1000px;
    /* Wider to allow content to spread horizontally */
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    max-height: 98vh;
    /* Allow almost full screen height */
    overflow-y: auto;
    display: flex;
    flex-direction: column;

    /* Hide Scrollbar Visually but allow scrolling */
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.element-modal::-webkit-scrollbar {
    display: none;
}

.element-modal .close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 50;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.element-modal .close-modal:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal-content {
    display: grid;
    grid-template-columns: 350px 1fr;
    /* Spacious sidebar */
    gap: 0;
    min-height: 450px;
    background-color: #0f172a !important;
    width: 100%;
}

/* Modal Sidebar / Preview */
.element-preview {
    background: linear-gradient(135deg, rgba(30, 41, 59, 1), rgba(15, 23, 42, 1)) !important;
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    user-select: none;
}

.element-preview::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, var(--glow-color, rgba(255, 255, 255, 0.05)), transparent 70%);
    opacity: 0.3;
    pointer-events: none;
}

.element-preview .atomic-number {
    position: absolute;
    top: 24px;
    left: 24px;
    font-size: 1.8rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
}

.element-preview .symbol {
    font-size: 7.5rem;
    font-weight: 800;
    line-height: 1;
    background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
    margin: 10px 0;
}

.element-preview .atomic-mass {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 10px;
    font-variant-numeric: tabular-nums;
}

/* Modal Details Area */
.element-info {
    padding: 40px;
    display: flex;
    flex-direction: column;
    background-color: #0f172a !important;
}

.element-info h2.name {
    font-size: 3rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.1;
    background: linear-gradient(to right, #ffffff, #cbd5e1);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}

.element-info h3.latin-name {
    font-size: 1.4rem;
    font-weight: 400;
    color: #94a3b8;
    margin: 0 0 24px 0;
    font-style: italic;
}

.category-badge {
    display: inline-block;
    padding: 8px 20px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.95rem;
    font-weight: 500;
    color: #f1f5f9;
    margin-bottom: 30px;
    align-self: flex-start;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.properties-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* 4 columns on desktop to save vertical space */
    gap: 16px;
    margin-bottom: 30px;
}

/* On wider screens, maybe 4 cols? */
@media (min-width: 600px) {
    .properties-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.prop-item {
    background: transparent;
    border-left: 3px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    transition: all 0.2s;
}

.prop-item:hover {
    border-left-color: var(--glow-color, white);
    background: linear-gradient(to right, rgba(255, 255, 255, 0.02), transparent);
    transform: translateX(4px);
}

.prop-item .label {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.prop-item .value {
    font-size: 1.25rem;
    font-weight: 500;
    color: #ffffff;
}

.element-info .description {
    font-size: 1.05rem;
    line-height: 1.6;
    color: #cbd5e1;
    margin-bottom: 30px;
    flex-grow: 1;
}

.element-info .wiki-link {
    display: inline-flex;
    align-items: center;
    color: #38bdf8;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    transition: color 0.2s;
    align-self: flex-start;
}

.element-info .wiki-link:hover {
    color: #60a5fa;
    text-decoration: underline;
}

.element-info .wiki-link::after {
    content: '\f35d';
    /* FontAwesome external link */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    margin-left: 8px;
    font-size: 0.8rem;
}

/* Mobile Responsive Modal */
@media (max-width: 768px) {
    .modal-content {
        grid-template-columns: 1fr;
    }

    .element-preview {
        padding: 30px;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .element-preview .symbol {
        font-size: 4rem;
    }

    .element-info {
        padding: 24px;
    }
}

/* Modal Overlay - FIXED */
.element-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    z-index: 9999;
    /* Very high z-index */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

.element-modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    /* Ensure it doesn't block clicks when hidden */
}

/* Dimming Effect */
.element.dimmed {
    opacity: 0.1;
    filter: blur(2px) grayscale(100%);
    transform: scale(0.9);
}

/* Active State for Buttons */
.filter-btn.active,
.lang-btn.active {
    background: rgba(56, 189, 248, 0.3) !important;
    /* Sky blue tint */
    border: 1px solid rgba(56, 189, 248, 0.5);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.2);
    color: #fff;
    text-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
    transform: translateY(-1px);
}