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

body {
    font-family: 'Inter', sans-serif;
    background: #fafafa;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

.header {
    text-align: center;
    padding: 2rem 1rem;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    color: #666;
    font-size: 1.1rem;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 1rem;
    flex-wrap: wrap;
}

.control-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    background: #667eea;
    color: white;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.control-btn:hover {
    background: #5a6fd8;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.control-btn.secondary {
    background: #6c757d;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.control-btn.secondary:hover {
    background: #5a6268;
}

.control-btn.delete {
    background: #e74c3c;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.control-btn.delete:hover {
    background: #c0392b;
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.table-container {
    padding: 1rem;
    overflow-x: auto;
}

.periodic-table {
    display: grid;
    grid-template-columns: repeat(18, 60px);
    grid-template-rows: repeat(7, 60px);
    gap: 2px;
    margin: 0 auto;
    width: fit-content;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.element {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
    transition: all 0.3s ease;
    background: white;
    position: relative;
    overflow: hidden;
    user-select: none;
}

.element:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 10;
}

.element.empty {
    border: 2px dashed #ccc;
    background: #f9f9f9;
    color: #999;
}

.element.empty:hover {
    border-color: #667eea;
    background: #f0f2ff;
}

.element-symbol {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.element-number {
    font-size: 8px;
    position: absolute;
    top: 2px;
    left: 3px;
}

.element-mass {
    font-size: 8px;
    position: absolute;
    bottom: 2px;
    right: 3px;
}

/* Element categories */
.element.alkali { background: #ff6b6b; color: white; }
.element.alkaline { background: #feca57; color: #333; }
.element.transition { background: #48dbfb; color: #333; }
.element.post-transition { background: #0abde3; color: white; }
.element.metalloid { background: #00d2d3; color: white; }
.element.nonmetal { background: #54a0ff; color: white; }
.element.halogen { background: #5f27cd; color: white; }
.element.noble { background: #a55eea; color: white; }
.element.lanthanide { background: #fd79a8; color: white; }
.element.actinide { background: #fdcb6e; color: #333; }
.element.unknown { background: #636e72; color: white; }

.element.deletable {
    position: relative;
}

/* Explicit delete button for main-table elements for reliable touch/click handling */
.element .delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 13px;
    line-height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: transform 0.12s ease, opacity 0.12s ease;
    opacity: 0.95;
    padding: 0;
}

.element .delete-btn:active {
    transform: scale(0.95);
}

/* Ensure visibility on hover (desktop) */
.element.deletable:hover .delete-btn {
    opacity: 1;
}

.element.series-trigger {
    position: relative;
    cursor: pointer;
}

.element.series-trigger::before {
    content: '⚡';
    position: absolute;
    top: -2px;
    right: -2px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.element.series-trigger:hover::before {
    opacity: 1;
}

.element.editable {
    position: relative;
}

.element.editable::before {
    content: '✏️';
    position: absolute;
    top: -2px;
    left: -2px;
    font-size: 10px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 5;
}

.element.editable:hover::before {
    opacity: 1;
}

.series-container {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.series {
    display: flex;
    flex-wrap: nowrap;
    gap: 2px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Make elements inside series larger */
.series .element {
    width: 60px;
    height: 60px;
}

.series-label {
    text-align: center;
    font-weight: 600;
    margin-bottom: 10px;
    color: #333;
}

.block {
    width: 100%;
    max-width: 1100px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.08);
    padding: 12px 16px 16px 16px;
}

.block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.block-label {
    font-weight: 600;
    color: #333;
    cursor: pointer;
}

.block-label:hover {
    text-decoration: underline;
}

.block-series-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.element-info {
    background: white;
    margin: 2rem auto;
    padding: 2rem;
    max-width: 600px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    text-align: center;
}

.element-info h3 {
    color: #667eea;
    margin-bottom: 1rem;
}

.series-toggle-btn {
    margin-top: 1rem;
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.series-toggle-btn:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease;
}

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

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #333;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

button[type="submit"] {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button[type="submit"]:hover {
    background: #5a6fd8;
}

@media (max-width: 768px) {
    .periodic-table {
        grid-template-columns: repeat(18, 40px);
        grid-template-rows: repeat(7, 40px);
    }
    
    .element {
        font-size: 8px;
    }
    
    .element-symbol {
        font-size: 10px;
    }
    
    .series {
        display: flex;
        flex-wrap: nowrap;
    }

    /* Slightly smaller but still larger series elements on mobile */
    .series .element {
        width: 50px;
        height: 50px;
    }

    .block {
        padding: 10px 12px 12px 12px;
    }
}