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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f172a; /* Slate 900 */
    background: radial-gradient(circle at top right, #1e293b, #0f172a);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    color: #f1f5f9; /* Slate 100 */
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 1600px;
    min-height: 100vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

h1 {
    text-align: center;
    color: #f8fafc;
    margin-bottom: 20px;
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    background: linear-gradient(to bottom right, #f8fafc, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.search-input {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    padding: 10px 20px;
    color: #f8fafc;
    font-size: 14px;
    width: 320px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

.search-input::placeholder {
    color: #94a3b8;
}

.search-input:focus {
    outline: none;
    border-color: #38bdf8;
    background: rgba(30, 41, 59, 0.9);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.1);
}

.random-btn {
    background: #38bdf8;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    color: #0f172a;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
}

.random-btn:hover {
    transform: translateY(-1px);
    background: #7dd3fc;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    padding: 8px;
    background: rgba(30, 41, 59, 0.2);
    border-radius: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #94a3b8;
    font-weight: 500;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

/* Category colors for legend dots */
.dot.alkali-metal { background: rgba(239, 68, 68, 0.6); border: 1px solid rgba(239, 68, 68, 1); }
.dot.alkaline-earth-metal { background: rgba(245, 158, 11, 0.6); border: 1px solid rgba(245, 158, 11, 1); }
.dot.transition-metal { background: rgba(14, 165, 233, 0.6); border: 1px solid rgba(14, 165, 233, 1); }
.dot.post-transition-metal { background: rgba(168, 85, 247, 0.6); border: 1px solid rgba(168, 85, 247, 1); }
.dot.metalloid { background: rgba(20, 184, 166, 0.6); border: 1px solid rgba(20, 184, 166, 1); }
.dot.nonmetal { background: rgba(132, 204, 22, 0.6); border: 1px solid rgba(132, 204, 22, 1); }
.dot.halogen { background: rgba(236, 72, 153, 0.6); border: 1px solid rgba(236, 72, 153, 1); }
.dot.noble-gas { background: rgba(99, 102, 241, 0.6); border: 1px solid rgba(99, 102, 241, 1); }
.dot.lanthanide { background: rgba(251, 191, 36, 0.6); border: 1px solid rgba(251, 191, 36, 1); }
.dot.actinide { background: rgba(244, 114, 182, 0.6); border: 1px solid rgba(244, 114, 182, 1); }

.table-container {
    width: 100%;
    overflow-x: auto;
    padding: 10px 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #38bdf8 rgba(30, 41, 59, 0.2);
}

.table-container::-webkit-scrollbar {
    height: 6px;
}

.table-container::-webkit-scrollbar-track {
    background: rgba(30, 41, 59, 0.2);
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #38bdf8;
    border-radius: 10px;
}

.scroll-hint {
    display: none;
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
    margin-bottom: 8px;
    font-weight: 500;
    font-style: italic;
}

.periodic-table {
    display: grid;
    grid-template-columns: repeat(18, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 2px;
    background: rgba(30, 41, 59, 0.2);
    padding: 12px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 16px;
    width: max-content;
    min-width: 100%;
    max-width: 1500px;
    margin: 0 auto;
}

.element {
    background: rgba(51, 65, 85, 0.3);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 4px;
    padding: 10px 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    color: #f1f5f9;
    min-height: 70px;
}

.element.empty {
    background: transparent;
    border: none;
    cursor: default;
}

.element.label {
    background: rgba(30, 41, 59, 0.2);
    cursor: default;
    border: 1px dashed rgba(148, 163, 184, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Category colors for elements */
.element.alkali-metal { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.4); }
.element.alkaline-earth-metal { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.4); }
.element.transition-metal { background: rgba(14, 165, 233, 0.1); border-color: rgba(14, 165, 233, 0.4); }
.element.post-transition-metal { background: rgba(168, 85, 247, 0.1); border-color: rgba(168, 85, 247, 0.4); }
.element.metalloid { background: rgba(20, 184, 166, 0.1); border-color: rgba(20, 184, 166, 0.4); }
.element.nonmetal { background: rgba(132, 204, 22, 0.1); border-color: rgba(132, 204, 22, 0.4); }
.element.halogen { background: rgba(236, 72, 153, 0.1); border-color: rgba(236, 72, 153, 0.4); }
.element.noble-gas { background: rgba(99, 102, 241, 0.1); border-color: rgba(99, 102, 241, 0.4); }
.element.lanthanide { background: rgba(251, 191, 36, 0.1); border-color: rgba(251, 191, 36, 0.4); }
.element.actinide { background: rgba(244, 114, 182, 0.1); border-color: rgba(244, 114, 182, 0.4); }

.element:hover:not(.empty):not(.label) {
    transform: scale(1.1);
    border-color: #38bdf8;
    background: rgba(51, 65, 85, 0.8);
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.element .number {
    font-size: 10px;
    font-weight: 600;
    position: absolute;
    top: 4px;
    left: 6px;
    color: #94a3b8;
}

.element .symbol {
    font-size: 20px;
    font-weight: 700;
    margin: 2px 0;
    color: #f8fafc;
}

.element .name {
    font-size: 8px;
    font-weight: 500;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.element .mass {
    display: none;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    transition: all 0.3s ease;
}

.modal-content {
    background: #1e293b;
    margin: 8% auto;
    padding: 40px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 24px;
    width: 90%;
    max-width: 550px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: modalSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlide {
    from { transform: translateY(20px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.close {
    color: #94a3b8;
    float: right;
    font-size: 24px;
    font-weight: 400;
    cursor: pointer;
    position: absolute;
    right: 24px;
    top: 24px;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.close:hover {
    color: #f8fafc;
    background: rgba(148, 163, 184, 0.1);
}

.element-detail h2 {
    color: #f8fafc;
    margin-bottom: 32px;
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    text-align: left;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-item {
    background: rgba(30, 41, 59, 0.5);
    padding: 20px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    transition: all 0.2s ease;
    text-align: left;
}

.detail-item:hover {
    background: rgba(30, 41, 59, 0.8);
    border-color: rgba(56, 189, 248, 0.3);
}

.detail-item strong {
    color: #94a3b8;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.detail-item span {
    color: #f1f5f9;
    font-size: 1.125rem;
    font-weight: 500;
}

/* Animations */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
    100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

/* Developer Credit Footer */
.developer-credit {
    text-align: center;
    margin-top: 20px;
    padding: 20px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.developer-credit p {
    color: #64748b;
    font-size: 14px;
    margin: 0;
    font-weight: 500;
}

.developer-credit a {
    color: #38bdf8;
    text-decoration: none;
    transition: all 0.2s ease;
    margin-left: 4px;
}

.developer-credit a:hover {
    color: #7dd3fc;
    text-decoration: underline;
}

/* Responsive Adjustments */
@media (max-width: 1200px) {
    .container {
        padding: 20px 10px;
    }

    h1 {
        font-size: 2.2rem;
    }

    .periodic-table {
        padding: 10px;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.8rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        max-width: 400px;
        margin: 0 auto 20px auto;
    }

    .search-input {
        width: 100%;
    }

    .legend {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 12px;
        justify-items: start;
    }

    .legend-item {
        font-size: 10px;
        width: 100%;
        padding: 4px;
        background: rgba(30, 41, 59, 0.3);
        border-radius: 6px;
    }

    .periodic-table {
        padding: 8px;
        gap: 1px;
        min-width: 800px; /* Ensure enough room for 18 columns on mobile before scroll */
    }

    .scroll-hint {
        display: block;
    }

    .element {
        min-height: 55px;
        padding: 6px 2px;
    }

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

    .element .number {
        font-size: 8px;
        top: 2px;
        left: 4px;
    }

    .element .name {
        font-size: 6px;
    }

    .modal-content {
        margin: 5% auto;
        padding: 20px;
        width: 95%;
        border-radius: 16px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .close {
        right: 16px;
        top: 16px;
        width: 44px; /* Larger hit area for mobile */
        height: 44px;
        font-size: 28px;
        background: rgba(30, 41, 59, 0.5);
    }

    .element-detail h2 {
        font-size: 1.5rem;
        margin-top: 20px;
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .detail-item {
        padding: 12px;
    }

    .detail-item span {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }

    .legend {
        grid-template-columns: repeat(2, 1fr);
        padding: 10px;
    }

    .legend-item {
        font-size: 9px;
    }

    .developer-credit p {
        font-size: 12px;
    }
}
