:root {
    --bg-color: #1e1e24;
    --panel-bg: #2b2b36;
    --text-color: #f5f5f5;
    --accent-blue: #4fa3d1;
    --cation-color: #ff6b6b;
    --anion-color: #4ecdc4;
    --pop-color: #ffd166; 
    --tm-color: #ff9f43; 
    /* --- NEW: Colors for Polyatomics! --- */
    --poly-cation-color: #a871f6; /* Purple for Ammonium */
    --poly-anion-color: #54a0ff;  /* Blue for Polyatomic Anions */
    /* ------------------------------------ */
}

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--panel-bg);
    border-bottom: 2px solid #333;
}

.layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    background-color: var(--panel-bg);
    padding: 20px;
    overflow-y: auto;
    border-right: 2px solid #333;
}

.right-sidebar {
    width: 250px;
    background-color: var(--panel-bg);
    padding: 20px;
    overflow-y: auto;
    border-left: 2px solid #333;
}

.challenge-item {
    background-color: #363642;
    color: var(--text-color);
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    font-weight: bold;
    font-size: 0.95rem;
    text-align: center;
}

.challenge-item:hover { background-color: #4a4a5a; }

.challenge-item.active-challenge {
    border-color: var(--pop-color);
    background-color: #2a2a35;
    box-shadow: 0 0 8px rgba(255, 209, 102, 0.4);
}

.challenge-item.completed-challenge {
    border-color: var(--anion-color);
    color: var(--anion-color);
    text-decoration: line-through;
    pointer-events: none;
    opacity: 0.6;
    background-color: #23232a;
}

.panel {
    background: #363642;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.mode-panel { padding: 10px; margin-bottom: 20px; }

.mode-toggle {
    display: flex;
    background: #23232a;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #4a4a5a;
}

.mode-btn {
    flex: 1;
    background: none;
    border: none;
    color: #aaa;
    padding: 10px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--accent-blue);
    color: white;
}

.workspace-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    align-items: stretch;
}

.stage-list {
    display: flex;
    flex: 1;
    background: #23232a;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #4a4a5a;
}

.stage-btn {
    flex: 1;
    background-color: transparent;
    color: #aaa;
    border: none;
    border-right: 2px solid #363642;
    padding: 8px 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    line-height: 1.1;
}

.stage-btn:last-child { border-right: none; }
.stage-btn small { font-size: 0.75rem; font-weight: normal; opacity: 0.8; margin-top: 4px; }
.stage-btn:hover { background-color: #363642; }
.stage-btn.active {
    background-color: var(--pop-color);
    color: #111;
}

.target-banner {
    background: linear-gradient(135deg, #2b2b36 0%, #363642 100%);
    border-left: 5px solid var(--pop-color);
    padding: 15px 25px;
    border-radius: 8px;
    margin-bottom: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.target-banner h3 {
    margin: 0 0 5px 0;
    color: #aaa;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.target-banner h2 {
    margin: 0;
    color: var(--pop-color);
    font-size: 2rem;
    text-shadow: 0 0 5px rgba(255, 209, 102, 0.3);
}

.score-display-sidebar {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    background: #23232a;
    padding: 12px 15px;
    border-radius: 8px;
    border: 2px solid var(--pop-color);
    box-shadow: 0 0 10px rgba(255, 209, 102, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

#score {
    color: var(--pop-color);
    font-size: 1.8rem;
    text-shadow: 0 0 8px rgba(255, 209, 102, 0.4);
}

#collected-list {
    margin: 0;
    padding-left: 20px;
    line-height: 1.6;
}

/* --- UPGRADED: 4 columns to perfectly fit 8 Transition Metals! --- */
.ion-bank {
    display: grid;
    grid-template-columns: repeat(4, 50px);
    gap: 15px 10px; 
    justify-content: center; 
    align-content: start; 
    min-height: 115px; 
}
/* ----------------------------------------------------------------- */

.ion {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    transition: transform 0.1s ease;
}

.ion:active { transform: scale(0.95); }
.cation { background-color: var(--cation-color); color: white; order: 1; }

/* --- NEW: Orange Transition Metal modifier --- */
.cation.tm { background-color: var(--tm-color); }

/* --- NEW: Shrink long polyatomic text to fit the circle --- */
/* --- UPGRADED: Polyatomic formatting AND colors --- */
.ion.poly { 
    font-size: 0.9rem; 
    letter-spacing: -0.5px; 
}

.cation.poly { 
    background-color: var(--poly-cation-color); 
    color: white; 
}

.anion.poly { 
    background-color: var(--poly-anion-color); 
    color: #111; 
}
/* ---------------------------------------------------------- */

.anion { background-color: var(--anion-color); color: #111; order: 2; }

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: relative;
    overflow-y: auto; 
}

.status-bar {
    background: #363642;
    padding: 15px 20px; 
    border-radius: 8px;
    margin-bottom: 10px;
    text-align: left; 
    font-size: 1.1rem;
}

.chamber-wrapper { position: relative; margin-top: 25px; }

/* --- UPGRADED: Split Charge Badge Styles --- */
.charge-badge {
    position: absolute;
    top: -30px;
    left: 20px; 
    background-color: #2a2a35;
    border: 2px solid var(--accent-blue);
    border-radius: 12px;
    padding: 5px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    z-index: 10; 
}

.charge-half {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.charge-half h2 { 
    margin: 0; 
    font-size: 0.9rem; 
    color: #aaa; 
    text-transform: uppercase;
    letter-spacing: 1px;
}

#total-positive {
    color: var(--cation-color);
    font-size: 2.2rem; 
    font-weight: 900;
    line-height: 1.1;
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.4);
}

#total-negative {
    color: var(--anion-color);
    font-size: 2.2rem; 
    font-weight: 900;
    line-height: 1.1;
    text-shadow: 0 0 10px rgba(78, 205, 196, 0.4);
}

.charge-divider {
    width: 2px;
    height: 40px;
    background-color: #4a4a5a;
    border-radius: 1px;
}

.chamber {
    min-height: 150px; 
    border: 2px dashed #666;
    border-radius: 10px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 15px;
    /* --- UPGRADED: Increased top padding from 35px to 65px to clear the taller badge! --- */
    padding: 65px 20px 20px 20px; 
    /* ------------------------------------------------------------------------------------ */
    background: #23232a;
}

.success-popup {
    display: none; 
    flex-direction: column;
    align-items: flex-start; 
    background-color: #363642;
    padding: 20px 30px; 
    border-radius: 10px;
    margin-top: 20px;
    border: 2px solid var(--anion-color);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    text-align: left; 
    animation: popIn 0.3s ease-out forwards;
    width: 100%; 
    max-width: 600px; 
    box-sizing: border-box; 
}

@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.success-popup h2 { margin-top: 0; margin-bottom: 5px; color: var(--anion-color); font-size: 1.5rem; }
.big-formula { font-size: 3rem; color: white; display: block; margin-bottom: 15px; font-weight: bold; }

#formula-entry-section {
    width: 100%;
    margin-top: 5px;
    padding-top: 15px;
    border-top: 1px dashed #555;
}

.formula-input-group {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

#formula-input {
    flex: 1;
    background-color: #23232a;
    border: 2px solid #555;
    color: var(--pop-color);
    font-size: 2.5rem;
    font-weight: bold;
    padding: 10px 15px;
    border-radius: 8px;
    box-sizing: border-box;
    font-family: monospace;
    transition: border-color 0.2s;
}

#formula-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 10px rgba(79, 163, 209, 0.4);
}

#check-formula-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 0 25px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

#check-formula-btn:hover { background-color: #3a8ebd; }
#check-formula-btn:active { transform: scale(0.95); }

#naming-section {
    width: 100%;
    margin-top: 5px;
    padding-top: 15px;
    border-top: 1px dashed #555;
}

#built-name-display {
    font-size: 1.8rem;
    color: var(--pop-color);
    margin-bottom: 15px;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(255, 209, 102, 0.3);
}

.name-banks { display: flex; gap: 20px; width: 100%; }
.name-options { display: flex; flex-direction: column; gap: 8px; flex: 1; }

.name-btn {
    background-color: #4a4a5a;
    color: #fff;
    border: 2px solid transparent;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    transition: all 0.1s;
    text-align: center;
}

.name-btn:hover { background-color: #5a5a6a; }
.name-btn.selected { background-color: var(--accent-blue); border-color: #fff; }

#collect-btn {
    background-color: var(--anion-color);
    color: #111;
    border: none;
    padding: 12px 25px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

#collect-btn:active { transform: scale(0.95); }

.toast {
    position: fixed;
    bottom: -60px; 
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--anion-color);
    color: #111;
    padding: 15px 25px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.1rem;
    transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.toast.show { bottom: 30px; }

.mastery-modal {
    display: none; 
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.4s;
}

.mastery-content {
    background: #2b2b36;
    padding: 40px;
    border-radius: 15px;
    border: 4px solid var(--pop-color);
    text-align: center;
    max-width: 500px;
    box-shadow: 0 0 30px rgba(255, 209, 102, 0.5);
    animation: popIn 0.5s ease-out;
}

.mastery-content h1 {
    color: var(--pop-color);
    margin-top: 0;
    font-size: 2.2rem;
    text-shadow: 0 0 10px rgba(255, 209, 102, 0.4);
}
.mastery-content p { font-size: 1.2rem; line-height: 1.5; color: var(--text-color); }

#close-mastery-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

#close-mastery-btn:active { transform: scale(0.95); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
