/* --- style.css --- */

:root { 
    --panel-bg: #2b2b36; 
    --border-color: #555; 
}

body { 
    font-family: Arial, sans-serif; 
    text-align: center; 
    background-color: #1e1e24; 
    color: #fff; 
    margin-top: 20px; /* Reduced from 80px to push everything up */
    user-select: none; 
    overflow-x: hidden; 
}

/* DESKTOP LAYOUT */
.left-panel { 
    float: left; 
    width: 340px; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    z-index: 100; 
    height: calc(100vh - 40px); /* Adjusted for new margins */
    position: fixed;
    top: 20px; /* Reduced from 80px */
    left: 20px;
}

.right-panel {
    float: right;
    position: fixed;
    top: 20px; /* Reduced from 80px */
    right: 20px;
    width: 300px;
    height: calc(100vh - 40px); /* Adjusted for new margins */
    display: flex;
    flex-direction: column;
    gap: 15px; 
    z-index: 100;
}

h1 { 
    position: relative; /* Changed from fixed */
    top: 0; 
    left: 0; 
    transform: none; 
    margin: 20px 0 40px 0; 
    z-index: 1000; 
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8); 
    width: 100%; 
}

/* DECAY VISUAL EFFECT */
#decay-overlay {
	position: fixed; 
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh;
	pointer-events: none; 
    z-index: 9999;
	box-shadow: inset 0 0 0px rgba(46, 204, 113, 0);
	transition: box-shadow 0.1s ease-out;
}

.flash-active {
	box-shadow: inset 0 0 100px rgba(46, 204, 113, 0.6) !important;
	animation: shake 0.2s ease-in-out;
}

@keyframes shake {
	0% { transform: translate(0, 0); }
	25% { transform: translate(2px, -2px); }
	50% { transform: translate(-2px, 2px); }
	75% { transform: translate(2px, 2px); }
	100% { transform: translate(0, 0); }
}

/* Redefine Actions Box to take only the space it needs */
.actions-box {
	background-color: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    overflow-y: auto;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    box-sizing: border-box;
    
    /* THE KEY CHANGES: */
    flex-grow: 1;    /* Tells the box to expand and fill empty space */
    max-height: 100%; /* Allows it to take the full panel height if needed */
}

/* Redefine Lab to be its own independent box */
.lab-section {
    background-color: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    text-align: left;
    transition: all 0.3s;
    /* Remove the old border-top dashed line since it's a separate box now */
    border-top: 2px solid var(--border-color); 
}

.main-content { 
    margin: 0 340px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    height: calc(100vh - 40px); /* Binds the container exactly to the screen height */
    position: relative; /* CRITICAL FIX: Anchors the decay log */
}

.atom-visualization { 
    margin-bottom: 40px; 
    height: 260px; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    width: 100%; 
}

/* --- Zen Mode Transitions --- */
.left-panel, .right-panel {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content { 
    margin: 0 340px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    min-height: 80vh; 
    position: relative; /* CRITICAL FIX: Anchors the decay log */
}

/* --- 2. Clean up the Toggle Button (Single Definition) --- */
/* Button changes color when Zen Mode is active */
body.zen-mode #zen-toggle {
    background: #27ae60;
    box-shadow: 0 0 15px rgba(39, 174, 96, 0.5);
}

.decay-event {
    background: rgba(231, 76, 60, 0.2);
    border-left: 3px solid #e74c3c;
    color: #ff7675;
    padding: 5px 10px;
    margin-bottom: 5px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: bold;
    animation: slideInFade 2s forwards;
    white-space: nowrap;
}

@keyframes slideInFade {
    0% { opacity: 0; transform: translateX(-10px); }
    15% { opacity: 1; transform: translateX(0); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-20px); }
}

/* MOBILE ADAPTATION (< 1000px) */
@media (max-width: 1000px) {
    body { margin-top: 20px; }
    h1 { position: relative; top: 0; left: 0; transform: none; margin-bottom: 20px; }

    .left-panel {
        float: none;
        position: static;
        margin: 0 auto 20px auto;
        width: 90%;
        max-width: 340px;
        height: auto;
        max-height: 400px;
    }

    /* Ensure the main-container exists for flex logic */
    .main-container {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
	
	/* Reset the right panel container */
    .right-panel {
        float: none;
        position: static;
        width: 90%;
        height: auto;
        margin: 0 auto;
        order: 4; /* Appears after Trophy/Inventory */
    }

    #lab-container {
       order: 5;
	    position: static;
	    float: none;
	    margin: 5px auto 20px auto; /* Tightened margin */
	    width: 90%;
	    max-width: 340px;
	    /* Removed the forced 'display: block' so JS can hide/show it */
    }

    /* Keep unique properties (like max-height) separate */
    .actions-box {
		float: none;
        position: static;
        margin: 0 auto 0 auto;
        width: 90%;
        max-width: 340px;
        box-sizing: border-box; /* Ensures padding doesn't push width out */
        height: auto;
        max-height: 225px;
    }
    
    .main-content {
        margin: 0 auto;
        width: 95%;
        position: static;
        float: none;
    }

    .atom-visualization { 
	    margin-bottom: 40px; 
	    height: 450px; /* Increased from 260px to accommodate 7 shells */
	    display: flex; 
	    justify-content: center; 
	    align-items: center; 
	    width: 100%; 
	}
    
    .atom-grid {
        margin: 40px auto;
        width: 100%;
        padding: 10px;
    }
	
	/* THE FIX: Lab moves to its own row under Actions */
    #lab-container {
        order: 5;
        position: static;
        float: none;
        margin: 20px auto;
        width: 90%;
        max-width: 340px;
        display: block; /* Ensure it stays visible even if display:none was removed by JS */
        border-top: 2px dashed #e74c3c; /* Re-apply the lab styling */
    }    
    
	#zen-toggle {
        right: 50%;
        left: auto;
        transform: translateX(50%); /* Horizontal centering math */
        bottom: 10px;
    }

    /* Force the transform to stay centered even when the class changes */
    body.zen-mode #zen-toggle {
        transform: translateX(50%) !important;
    }
    
    #decay-log-container {
        left: 50%;
        top: -40px;
        transform: translateX(-50%);
        width: 100%;
        text-align: center;
    }
    .mute-btn {
        top: 10px;
        right: 10px;
        font-size: 12px;
        padding: 8px 12px;
    }

}

/* UI COMPONENTS */
.hud-box { 
    background-color: var(--panel-bg); 
    border-radius: 8px; 
    padding: 12px 20px; 
    box-shadow: 0 4px 8px rgba(0,0,0,0.5); 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}

.energy-hud { border: 2px solid #f1c40f; }
.rad-hud { border: 2px solid #e74c3c; color: #ff7675; }

.energy-main, .rad-main { font-size: 24px; font-weight: bold; }
.energy-rate, .rad-rate { font-size: 14px; opacity: 0.9; margin-top: 2px; }

.resource-box { 
    border: 2px solid var(--border-color); 
    padding: 20px; 
    background-color: var(--panel-bg); 
    border-radius: 8px; 
    text-align: left; 
    overflow-y: auto; 
    box-shadow: 0 4px 8px rgba(0,0,0,0.5); 
    flex-grow: 1; 
}

.lab-section { 
    margin-top: 20px; 
    padding-top: 15px; 
    border-top: 2px dashed #e74c3c; 
    text-align: left; 
    transition: all 0.3s; 
}

.lab-active { 
    background: rgba(231, 76, 60, 0.1); 
    box-shadow: inset 0 0 10px rgba(231, 76, 60, 0.5); 
}

.lab-title { 
    color: #ff7675; 
    font-weight: bold; 
    font-size: 1.1em; 
    margin-bottom: 10px; 
    display: block; 
    text-align: center; 
}

/* BUTTON STYLES */
button { 
    padding: 12px 10px; 
    margin: 5px 0; 
    width: 100%; 
    cursor: pointer; 
    border-radius: 4px; 
    border: none; 
    color: white; 
    font-weight: bold; 
    transition: filter 0.2s; 
    line-height: 1.4; 
}

button:disabled { 
    background-color: #555 !important; 
    color: #888 !important; 
    cursor: not-allowed; 
    filter: none !important; 
}

.element-btn { background-color: var(--btn-color); color: var(--text-color, white); }
.element-btn:hover:not(:disabled) { filter: brightness(1.15); }

.bulk-btn { 
    background-color: #2c3e50; 
    border: 1px solid #555; 
    font-size: 0.75em; 
    margin-top: -5px; 
    margin-bottom: 10px; 
}

.lab-btn { background-color: #c0392b; font-size: 0.85em; }
.stim-btn { background-color: #8e44ad; }
.shield-toggle-btn { background-color: #27ae60; margin-bottom: 10px; }
.shield-off { background-color: #7f8c8d; }
.danger-btn { 
    background-color: #e74c3c; 
    color: white; 
    width: auto; 
    margin-top: 40px; 
    padding: 10px 30px; 
}

.fission-active { outline: 3px solid #ff7675; background: rgba(231, 76, 60, 0.2); }

/* ATOM ANIMATIONS */
.atom-container { 
    position: relative; 
    width: 200px; /* Wider to prevent larger nuclei from touching shells */
    height: 200px; 
    display: flex;
    justify-content: center;
    align-items: center;
}

.pulse { transform: scale(0.9); }

.nucleus {
    position: absolute;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    padding: 0; /* Clear padding to prevent squishing */
    line-height: 1; /* Center text vertically */
}

.shell { 
    position: absolute; 
    border-radius: 50%; 
    border: 2px dashed #555; 
    box-sizing: border-box; 
    animation: spin 4s linear infinite; 
    pointer-events: none; 
}

.electron { 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    width: 10px; 
    height: 10px; 
    background: #1e90ff; 
    border-radius: 50%; 
    margin-top: -5px; 
    margin-left: -5px; 
    box-shadow: 0 0 6px #1e90ff; 
}

/* ATOM GRID */
#atom-grid-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* This is the magic rule that fills the empty space */
    min-height: 0; /* Prevents layout breaking on small screens */
}

.atom-grid { 
    display: block; 
    position: relative;
    padding: 0; 
    background-color: #22222a; 
    border: 2px solid #333;
    border-radius: 8px; 
    width: 100%; 
    flex-grow: 1; /* Forces the visual box to stretch */
    height: 100%; 
    min-height: 400px; /* Ensures it doesn't get squished too small */
    box-sizing: border-box; 
    overflow: hidden; 
}

.mini-atom-container {
    position: absolute;
    display: flex; 
    justify-content: center; 
    align-items: center; 
    /* Smooth out the transition so it doesn't jitter during overlaps */
    transition: opacity 0.3s ease, transform 0.3s ease, filter 0.1s ease;
    will-change: transform, opacity;
}

/* The Ghostly effect for Post-Supernova overlaps */
.phasing {
    opacity: 0.4 !important;
    transform: scale(1.15);
    z-index: 5; /* Puts overlapping atoms slightly behind others */
}

.mini-count { 
    position: absolute; 
    top: -10px; 
    right: -10px; 
    background: #fff; 
    color: #000; 
    font-size: 11px; 
    font-weight: bold; 
    padding: 2px 6px; 
    border-radius: 10px; 
    z-index: 20; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.5); 
    pointer-events: none; 
}

.mini-nucleus { 
    position: absolute; 
    border-radius: 50%; 
    z-index: 10; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: bold; 
}

.mini-shell { 
    position: absolute; 
    border-radius: 50%; 
    border: 1px dashed #444; 
    box-sizing: border-box; 
    animation: spin 2s linear infinite; 
}

.mini-electron { 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    width: 4px; 
    height: 4px; 
    background: #1e90ff; 
    border-radius: 50%; 
    margin-top: -2px; 
    margin-left: -2px; 
    box-shadow: 0 0 3px #1e90ff; 
}

/* MISC */
.floating-text { 
    position: fixed; 
    color: #f1c40f; 
    font-weight: bold; 
    font-size: 24px; 
    pointer-events: none; 
    z-index: 9999; 
    text-shadow: 1px 1px 3px black; 
    animation: floatUp 1s ease-out forwards; 
}

.supernova-flash { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh; 
    background: white; 
    z-index: 10000; 
    opacity: 0; 
    pointer-events: none; 
    transition: opacity 2s ease-in-out; 
}

.supernova-active { opacity: 1; }
.supernova-text { 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%); 
    color: black; 
    font-size: 48px; 
    font-weight: bold; 
    display: none; 
}

.inventory-item { padding: 8px; transition: background 0.2s; border-radius: 4px; }
.inventory-item:hover { background: rgba(255,255,255,0.05); }

@keyframes floatUp { 0% { opacity: 1; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(-60px) scale(1.2); } }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- FUSION CHAMBER TITLE --- */
.fusion-title {
    color: #a4b0be;
    font-size: 0.9em;
    font-weight: bold;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 25px; 
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    transition: color 0.3s ease, text-shadow 0.3s ease; /* ADD THIS LINE */
}

.fusion-chamber {
    width: 300px;
    height: 80px;
    margin: -20px auto 20px auto;
    border: 2px solid #444;
    border-radius: 40px;
    background: radial-gradient(circle, #1a1a2e 0%, #0f0f1a 100%);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 15px rgba(0, 255, 255, 0.1);
}

.fusion-particle {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    top: 50%;
    margin-top: -10px;
    opacity: 0;
    z-index: 5;
    line-height: 1;
    text-shadow: 0 0 2px rgba(0,0,0,0.3);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#fusion-particle-l { left: -30px; }
#fusion-particle-r { right: -30px; }

/* Animation to reveal the product atom in the center */
@keyframes product-reveal {
    0% { transform: scale(0); opacity: 0; }
    10% { transform: scale(1.4); opacity: 1; } /* Slight overshoot pop */
    100% { transform: scale(1); opacity: 1; }
}

.fusing-reveal #fusion-particle-product {
    animation: product-reveal 0.3s ease-out forwards;
}

/* Add this to style.css */
#fusion-symbol-text {
    pointer-events: none;
    line-height: 1;
    text-shadow: 0 0 2px rgba(0,0,0,0.5);
}

#fusion-flash {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: white;
    opacity: 0;
    z-index: 10;
    pointer-events: none;
}

/* The Collision Animation */
@keyframes collide {
    0% { transform: translateX(0); opacity: 1; scale: 1; }
    90% { transform: translateX(130px); opacity: 1; scale: 0.8; }
    100% { transform: translateX(150px); opacity: 0; scale: 2; }
}

@keyframes collide-reverse {
    0% { transform: translateX(0); opacity: 1; scale: 1; }
    90% { transform: translateX(-130px); opacity: 1; scale: 0.8; }
    100% { transform: translateX(-150px); opacity: 0; scale: 2; }
}

/* Update the collision speed to 1.5s */
.fusing #fusion-particle-l { animation: collide 1.5s ease-in forwards; }
.fusing #fusion-particle-r { animation: collide-reverse 1.5s ease-in forwards; }
.fusing #fusion-flash { animation: flashEffect 1.6s ease-out; }

@keyframes flashEffect {
    0% { opacity: 0; }
    90% { opacity: 0; } /* Wait for the 1.5s mark */
    94% { opacity: 1; } /* Quick flash at the end */
    100% { opacity: 0; }
}

.fusion-spark {
    position: fixed;
    width: 10px; /* Slightly larger for visibility */
    height: 10px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10002;
    filter: blur(0.5px);
    box-shadow: 0 0 15px white, 0 0 5px var(--spark-color);
    transition: background 0.2s;
}

@keyframes spark-fly {
    0% { transform: translate(0, 0) scale(1.5); opacity: 1; }
    20% { opacity: 1; } /* Stay bright at the start */
    100% { transform: translate(var(--tx), var(--ty)) scale(0.3); opacity: 0; }
}

/* Trophy Reaction Animation */
@keyframes trophy-react {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.1) rotate(1deg); filter: brightness(1.2); }
    75% { transform: scale(1.15) rotate(-1deg); filter: brightness(1.3); }
    100% { transform: scale(1); filter: brightness(1); }
}

.trophy-reacting {
    animation: trophy-react 1.5s ease-in-out;
}

.mute-btn:hover {
    filter: brightness(1.2);
    transform: scale(1.05);
}

.mute-active {
    background-color: #2f3542;
    color: #a4b0be;
    border-color: #1e1e24;
}

/* --- ZEN MODE: FULL SCREEN PARTICLE EXPANSION --- */
body.zen-mode {
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important; /* Kills scrollbars */
}

/* Completely hide UI elements */
body.zen-mode .atom-visualization,
body.zen-mode #fusion-title, /* ADDED HERE */
body.zen-mode #fusion-chamber,
body.zen-mode .left-panel,
body.zen-mode .right-panel,
body.zen-mode h1 {
    display: none !important;
}

/* Force all containers and the grid to be exactly 100% of the screen */
body.zen-mode .main-content,
body.zen-mode #atom-grid-container,
body.zen-mode .atom-grid {
    margin: 0 !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    border: none !important; /* Removes the border so it flushes to the edges */
    border-radius: 0 !important; /* Squares off the corners */
}

body.zen-mode .atom-grid {
    background-color: #0a0a0f; /* Darker background for Zen focus */
}

/* --- SETTINGS MENU --- */
.settings-box {
    background-color: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    text-align: left;
}

.setting-btn {
    background-color: #34495e;
    color: white;
    margin: 0;
    flex: 1; /* Makes buttons sit side-by-side evenly */
    font-size: 0.85em;
    padding: 10px 5px;
    border: 2px solid #2f3542;
}

.setting-btn:hover { filter: brightness(1.2); }

.mute-active {
    background-color: #2f3542 !important;
    color: #a4b0be !important;
}

/* --- FLOATING EXIT BUTTON (Only shows in Zen Mode) --- */
#exit-zen-btn {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    background: #27ae60;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    border: 2px solid #555;
    font-weight: bold;
    cursor: pointer;
    opacity: 0.2; /* Very subtle to preserve Zen feel */
    transition: opacity 0.2s ease;
}

#exit-zen-btn:hover { opacity: 1; }

body.zen-mode #exit-zen-btn {
    display: block !important; /* Forces it to appear when Zen is active */
}

/* --- TYPING BUFFER VISUAL --- */
#typing-buffer-display {
    position: fixed;
    background: rgba(10, 10, 15, 0.9);
    border: 1px solid #1abc9c;
    color: #1abc9c;
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 10005;
    transition: opacity 0.2s ease, transform 0.2s ease;
    opacity: 0;
    transform: scale(0.8);
    box-shadow: 0 0 10px rgba(26, 188, 156, 0.3);
}
