:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #111128;
    --text-primary: #e8e8f0;
    --text-secondary: #9898b8;
    --accent: #6c63ff;
    --accent-glow: rgba(108, 99, 255, 0.3);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-hover: rgba(255, 255, 255, 0.1);
    --cat-alkali: #ff6b6b;
    --cat-alkaline: #ffa94d;
    --cat-transition: #ffd43b;
    --cat-post-transition: #69db7c;
    --cat-metalloid: #38d9a9;
    --cat-nonmetal: #4dabf7;
    --cat-halogen: #9775fa;
    --cat-noble: #e599f7;
    --cat-lanthanide: #f783ac;
    --cat-actinide: #e8590c;
    --cat-unknown: #868e96;
    --font-main: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --top-bar-height: 60px;
    --nav-height: 52px;
}

[data-theme="light"] {
    --bg-primary: #f5f5f8;
    --bg-secondary: #e8e8f0;
    --text-primary: #1a1a2e;
    --text-secondary: #555570;
    --accent: #5b52ee;
    --accent-glow: rgba(91, 82, 238, 0.2);
    --glass-bg: rgba(0, 0, 0, 0.03);
    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-hover: rgba(0, 0, 0, 0.06);
}

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

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    transition: background 0.4s ease, color 0.4s ease;
}

#container {
    position: fixed;
    inset: 0;
    z-index: 0;
}

#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: linear-gradient(180deg, rgba(10, 10, 26, 0.9) 0%, transparent 100%);
    z-index: 100;
    pointer-events: none;
}

[data-theme="light"] #top-bar {
    background: linear-gradient(180deg, rgba(245, 245, 248, 0.9) 0%, transparent 100%);
}

#top-bar > * {
    pointer-events: auto;
}

#title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

#search-box {
    position: relative;
    display: flex;
    align-items: center;
}

#search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-secondary);
    pointer-events: none;
    transition: color 0.3s;
}

#search-input {
    width: 200px;
    padding: 8px 32px 8px 36px;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: var(--glass-bg);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 13px;
    outline: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

#search-input::placeholder {
    color: var(--text-secondary);
}

#search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    width: 260px;
}

#search-clear {
    position: absolute;
    right: 6px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 50%;
    display: none;
    line-height: 1;
}

#search-clear:hover {
    background: var(--glass-bg);
    color: var(--text-primary);
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: var(--text-primary);
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.icon-btn:hover {
    background: var(--glass-hover);
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(1.05);
}

#theme-icon-sun {
    display: none;
}

[data-theme="light"] #theme-icon-moon {
    display: none;
}

[data-theme="light"] #theme-icon-sun {
    display: block;
}

#layout-nav {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 6px;
    background: rgba(10, 10, 26, 0.85);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] #layout-nav {
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.nav-btn:hover {
    background: var(--glass-bg);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.nav-btn svg {
    transition: transform 0.3s ease;
}

.nav-btn:hover svg {
    transform: scale(1.1);
}

#element-legend {
    position: fixed;
    right: 16px;
    top: calc(var(--top-bar-height) + 16px);
    width: 180px;
    padding: 14px;
    background: rgba(10, 10, 26, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    max-height: calc(100vh - var(--top-bar-height) - 90px);
    overflow-y: auto;
}

[data-theme="light"] #element-legend {
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

#element-legend h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 11px;
    color: var(--text-primary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

#detail-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(400px, 90vw);
    padding: 24px;
    background: rgba(15, 15, 35, 0.95);
    backdrop-filter: blur(30px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    z-index: 200;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

[data-theme="light"] #detail-panel {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

#detail-panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.9);
}

#detail-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    font-size: 20px;
    border-radius: 50%;
}

#detail-content {
    text-align: center;
}

#detail-symbol {
    font-size: 72px;
    font-weight: 700;
    line-height: 1;
    margin: 8px 0 4px;
}

#detail-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

#detail-number {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-secondary);
}

#detail-mass {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

#detail-category {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    margin-top: 12px;
    color: white;
}

#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    transition: opacity 0.3s;
}

#overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#loading {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    transition: opacity 0.5s ease;
}

#loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loader span {
    font-size: 14px;
    color: var(--text-secondary);
}

.loader-ring {
    width: 48px;
    height: 48px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.element {
    width: 100px;
    height: 130px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    background: rgba(15, 15, 35, 0.6);
    backdrop-filter: blur(8px);
    transition: transform 0.2s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    user-select: none;
}

.element:hover {
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 20px rgba(108, 99, 255, 0.3);
    transform: scale(1.08);
    z-index: 10;
}

[data-theme="light"] .element {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .element:hover {
    box-shadow: 0 0 20px rgba(91, 82, 238, 0.15);
}

.element .number {
    position: absolute;
    top: 8px;
    right: 10px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.element .symbol {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-55%);
    font-size: 44px;
    font-weight: 700;
    color: var(--text-primary);
    text-shadow: none;
    line-height: 1;
}

.element .name {
    position: absolute;
    bottom: 32px;
    left: 0;
    right: 0;
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.element .mass {
    position: absolute;
    bottom: 10px;
    left: 0;
    right: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
}

.element.highlighted {
    border-color: var(--accent) !important;
    box-shadow: 0 0 25px var(--accent-glow) !important;
}

.element.dimmed {
    opacity: 0.15 !important;
    pointer-events: none !important;
}

@media (max-width: 768px) {
    #title {
        font-size: 14px;
    }

    #search-input {
        width: 140px;
        font-size: 12px;
    }

    #search-input:focus {
        width: 180px;
    }

    #element-legend {
        display: none;
    }

    .nav-btn span {
        display: none;
    }

    .nav-btn {
        padding: 10px 14px;
    }

    .element {
        width: 80px;
        height: 110px;
        border-radius: 8px;
    }

    .element .symbol {
        font-size: 36px;
    }

    .element .number {
        font-size: 11px;
    }

    .element .name {
        font-size: 8px;
        bottom: 28px;
    }

    .element .mass {
        font-size: 9px;
        bottom: 8px;
    }

    #detail-panel {
        width: 90vw;
        padding: 20px;
    }

    #detail-symbol {
        font-size: 56px;
    }
}

@media (max-width: 480px) {
    #top-bar {
        padding: 0 12px;
        height: 50px;
    }

    #search-box {
        display: none;
    }

    #layout-nav {
        bottom: 12px;
        gap: 4px;
        padding: 4px;
    }

    .nav-btn {
        padding: 8px 10px;
    }
}
