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

body {
    font-family: Georgia, 'Times New Roman', serif;
    background: #f4f1eb;
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s, color 0.3s;
}

body.dark {
    background: #1a1a2e;
    color: #eee;
}

header {
    text-align: center;
    margin-bottom: 25px;
}

h1 {
    color: #2c3e50;
    font-weight: normal;
    font-size: 28px;
    margin-bottom: 8px;
}

body.dark h1 {
    color: #ecf0f1;
}

.subtitle {
    color: #666;
    font-size: 15px;
    margin-bottom: 12px;
}

body.dark .subtitle {
    color: #aaa;
}

.back-link {
    display: inline-block;
    color: #3498db;
    text-decoration: none;
    padding: 8px 20px;
    border: 1px solid #3498db;
    border-radius: 20px;
    transition: all 0.2s;
}

.back-link:hover {
    background: #3498db;
    color: white;
}

.builder-container {
    max-width: 900px;
    margin: 0 auto 30px;
}

.workspace-section {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

body.dark .workspace-section {
    background: #2d2d44;
}

.formula-display {
    text-align: center;
    margin-bottom: 25px;
}

.formula-display h3 {
    color: #2c3e50;
    font-weight: normal;
    margin-bottom: 15px;
}

body.dark .formula-display h3 {
    color: #ecf0f1;
}

#formula-output {
    font-size: 36px;
    font-family: 'Courier New', monospace;
    color: #2c3e50;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 15px;
}

body.dark #formula-output {
    background: #1a1a2e;
    color: #ecf0f1;
}

#formula-output .element-token {
    display: inline-flex;
    align-items: baseline;
    padding: 5px 10px;
    background: #3498db;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

#formula-output .element-token:hover {
    background: #e74c3c;
    transform: scale(1.05);
}

#formula-output .element-token sub {
    font-size: 0.6em;
    margin-left: 2px;
}

.formula-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.formula-actions button {
    padding: 10px 25px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

#clear-btn {
    background: #e74c3c;
    color: white;
}

#clear-btn:hover {
    background: #c0392b;
}

#undo-btn {
    background: #95a5a6;
    color: white;
}

#undo-btn:hover {
    background: #7f8c8d;
}


.formula-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.info-card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

body.dark .info-card {
    background: #1a1a2e;
}

.info-label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 5px;
}

.info-value {
    display: block;
    font-size: 22px;
    color: #3498db;
    font-weight: bold;
}

.composition-section h4 {
    color: #2c3e50;
    font-weight: normal;
    margin-bottom: 15px;
}

body.dark .composition-section h4 {
    color: #ecf0f1;
}

#composition-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.composition-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.composition-bar .bar-label {
    width: 40px;
    font-weight: bold;
    color: #2c3e50;
}

body.dark .composition-bar .bar-label {
    color: #ecf0f1;
}

.composition-bar .bar-track {
    flex: 1;
    height: 20px;
    background: #ecf0f1;
    border-radius: 10px;
    overflow: hidden;
}

body.dark .composition-bar .bar-track {
    background: #1a1a2e;
}

.composition-bar .bar-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s;
}

.composition-bar .bar-percent {
    width: 50px;
    text-align: right;
    font-size: 13px;
    color: #666;
}

body.dark .composition-bar .bar-percent {
    color: #aaa;
}

.common-compounds {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

body.dark .common-compounds {
    background: #2d2d44;
}

.common-compounds h3 {
    color: #2c3e50;
    font-weight: normal;
    margin-bottom: 15px;
    text-align: center;
}

body.dark .common-compounds h3 {
    color: #ecf0f1;
}

.compounds-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.compound-btn {
    padding: 10px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    text-align: left;
}

body.dark .compound-btn {
    background: #1a1a2e;
    border-color: #444;
    color: #eee;
}

.compound-btn:hover {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

.elements-palette {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
}

body.dark .elements-palette {
    background: #2d2d44;
}

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

.palette-controls input, .palette-controls select {
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

body.dark .palette-controls input, body.dark .palette-controls select {
    background: #1a1a2e;
    color: #eee;
    border-color: #444;
}

.palette-controls button {
    padding: 10px 15px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.palette-controls button:hover {
    background: #2980b9;
}

#elements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 8px;
}

.element-btn {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    padding: 5px;
}

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

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

.element-btn .symbol {
    font-size: 18px;
    font-weight: bold;
    color: #222;
}

.element-btn .number {
    font-size: 9px;
    color: #555;
}

.element-btn.hidden {
    display: none;
}

.alkali { background: #ffb3ba; }
.alkaline { background: #ffdfba; }
.transition { background: #ffffba; }
.post-transition { background: #baffc9; }
.metalloid { background: #bae1ff; }
.nonmetal { background: #e2baff; }
.halogen { background: #ffbaf3; }
.noble { background: #d4baff; }
.lanthanide { background: #ffd9ba; }
.actinide { background: #c9ffba; }
.unknown { background: #ddd; }

@media (max-width: 600px) {
    .formula-info { grid-template-columns: 1fr; }
    #formula-output { font-size: 24px; padding: 15px; }
    .compounds-grid { grid-template-columns: 1fr 1fr; }
    #elements-grid { grid-template-columns: repeat(6, 1fr); gap: 5px; }
    .element-btn .symbol { font-size: 14px; }
    .element-btn .number { font-size: 7px; }
    .palette-controls { flex-direction: column; }
    .palette-controls input, .palette-controls select, .palette-controls button { width: 100%; }
    h1 { font-size: 22px; }
    .info-value { font-size: 18px; }
}
